Skip to content
Snippets Groups Projects
Commit ac988aab authored by Vincent Texier's avatar Vincent Texier
Browse files

[enh] add debug logs in scan_qr_code.py

parent 7ba47654
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import sys import sys
from typing import TYPE_CHECKING, Any, List, Optional from typing import TYPE_CHECKING, Any, List, Optional
...@@ -506,6 +507,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -506,6 +507,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
:return: :return:
""" """
logging.debug("create instance of ScanQRCodeWindow")
ScanQRCodeWindow(self.application, self).exec_() ScanQRCodeWindow(self.application, self).exec_()
def open_add_address_window(self) -> None: def open_add_address_window(self) -> None:
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import sys import sys
from typing import List, Optional from typing import List, Optional
...@@ -65,16 +66,21 @@ class QRCodeVideoSurface(QAbstractVideoSurface): ...@@ -65,16 +66,21 @@ class QRCodeVideoSurface(QAbstractVideoSurface):
self.video_label = video_label self.video_label = video_label
# initialize the OpenCV QRCode detector # initialize the OpenCV QRCode detector
logging.debug(
"Create OpenVC qrcode detector instance with cv2.QRCodeDetector()"
)
self.detector = cv2.QRCodeDetector() self.detector = cv2.QRCodeDetector()
def supportedPixelFormats( def supportedPixelFormats(
self, type: QAbstractVideoBuffer.HandleType = QAbstractVideoBuffer.NoHandle self, type: QAbstractVideoBuffer.HandleType = QAbstractVideoBuffer.NoHandle
) -> List[QVideoFrame.PixelFormat]: ) -> List[QVideoFrame.PixelFormat]:
result = [] result = []
logging.debug("supportedPixelFormats Type = %s", type)
if type == QtMultimedia.QAbstractVideoBuffer.NoHandle: if type == QtMultimedia.QAbstractVideoBuffer.NoHandle:
result = [ logging.debug(
QtMultimedia.QVideoFrame.Format_RGB32, "supportedPixelFormats returns QtMultimedia.QVideoFrame.Format_RGB24"
] )
result = [QtMultimedia.QVideoFrame.Format_RGB24]
return result return result
...@@ -178,19 +184,26 @@ class ScanQRCodeWindow(QDialog, Ui_ScanQRCodeDialog): ...@@ -178,19 +184,26 @@ class ScanQRCodeWindow(QDialog, Ui_ScanQRCodeDialog):
self.addressValueLabel.setFont(monospace_font) self.addressValueLabel.setFont(monospace_font)
# fill form # fill form
if self.check_camera_availability() is False: camera_available = self.check_camera_availability()
if camera_available is False:
self.errorLabel.setText(self._("No camera available")) self.errorLabel.setText(self._("No camera available"))
else: else:
logging.debug("Create instance of QCamera()")
self.camera = QCamera() self.camera = QCamera()
logging.debug("Create instance of QRCodeVideoSurface()")
self.video_surface = QRCodeVideoSurface(self.videoLabel) self.video_surface = QRCodeVideoSurface(self.videoLabel)
logging.debug(
"set VideoSurface instance as camera viewfinder with camera.setViewfinder(self.video_surface)"
)
self.camera.setViewfinder(self.video_surface) self.camera.setViewfinder(self.video_surface)
logging.debug("Start camera with camera.start()")
self.camera.start() self.camera.start()
# buttons # buttons
self.buttonBox.button(self.buttonBox.Ok).setEnabled(False) self.buttonBox.button(self.buttonBox.Ok).setEnabled(False)
# events # events
if self.check_camera_availability() is True: if camera_available is True:
self.video_surface.detected.connect(self.qrcode_detected) self.video_surface.detected.connect(self.qrcode_detected)
self.buttonBox.accepted.connect(self.on_accepted_button) self.buttonBox.accepted.connect(self.on_accepted_button)
self.buttonBox.rejected.connect(self.close) self.buttonBox.rejected.connect(self.close)
...@@ -202,6 +215,7 @@ class ScanQRCodeWindow(QDialog, Ui_ScanQRCodeDialog): ...@@ -202,6 +215,7 @@ class ScanQRCodeWindow(QDialog, Ui_ScanQRCodeDialog):
:return: :return:
""" """
logging.debug("Check if there is a webcam : QCameraInfo.availableCameras()")
return len(QCameraInfo.availableCameras()) > 0 return len(QCameraInfo.availableCameras()) > 0
def qrcode_detected(self, data: str): def qrcode_detected(self, data: str):
...@@ -246,6 +260,7 @@ class ScanQRCodeWindow(QDialog, Ui_ScanQRCodeDialog): ...@@ -246,6 +260,7 @@ class ScanQRCodeWindow(QDialog, Ui_ScanQRCodeDialog):
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
qapp = QApplication(sys.argv) qapp = QApplication(sys.argv)
application_ = Application(DATA_PATH) application_ = Application(DATA_PATH)
ScanQRCodeWindow(application_).exec_() ScanQRCodeWindow(application_).exec_()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment