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