diff --git a/examples/official/9.x/qt_gui/README.md b/examples/official/9.x/qt_gui/README.md index aaf0998..fef2d7f 100644 --- a/examples/official/9.x/qt_gui/README.md +++ b/examples/official/9.x/qt_gui/README.md @@ -39,7 +39,7 @@ This is a cross-platform GUI barcode reader application built with `Python 3`, ` The advanced demo supports reading barcodes from image files, webcam, and desktop screenshots: ``` - pyside2-uic design.ui -o design.py + pyside6-uic design.ui -o design.py python3 app_advanced.py license.txt ``` diff --git a/examples/official/9.x/qt_gui/barcode_manager.py b/examples/official/9.x/qt_gui/barcode_manager.py index af2ab78..2634b39 100644 --- a/examples/official/9.x/qt_gui/barcode_manager.py +++ b/examples/official/9.x/qt_gui/barcode_manager.py @@ -65,8 +65,10 @@ def __init__(self): self._template = None self._types = 0 self._types2 = 0 - - self.frameQueue, self.resultQueue, self.barcodeScanning = None, None, None + self.barcodeScanning = None + size = 1 + self.frameQueue = Queue(size) + self.resultQueue = Queue(size) def __init_params(self): if self._template != None and self._template != '': @@ -165,14 +167,15 @@ def set_barcode_types(self, types): def set_barcode_types_2(self, types): self._types2 = types - def create_barcode_process(self): - self.destroy_barcode_process() - + def initQueue(self): size = 1 self.frameQueue = Queue(size) self.resultQueue = Queue(size) - self.barcodeScanning = Process(target=process_barcode_frame, args=( - self.frameQueue, self.resultQueue, self._template, self._types, self._types2)) + + def create_barcode_process(self): + self.destroy_barcode_process() + self.initQueue() + self.barcodeScanning = Process(target=process_barcode_frame, args=(self.frameQueue, self.resultQueue, self._template, self._types, self._types2)) self.barcodeScanning.start() def destroy_barcode_process(self): @@ -189,12 +192,18 @@ def destroy_barcode_process(self): self.frameQueue = None if self.resultQueue != None: + while not self.resultQueue.empty(): + try: + self.resultQueue.get(timeout=0.001) + except: + pass self.resultQueue.close() self.resultQueue = None def append_frame(self, frame): try: - self.frameQueue.put(frame.copy(), False, 10) + if self.frameQueue != None: + self.frameQueue.put(frame.copy(), False, 10) except: pass @@ -209,3 +218,16 @@ def get_template(self): def set_license(self, key): BarcodeReader.init_license(key) + def decodeLatestFrame(self): + try: + frame = self.frameQueue.get(False, 10) + if type(frame) is str: + return None + + start = time.time() + results = self._reader.decode_buffer(frame) + end = time.time() + return [results, (end - start) * 1000] + except Exception as e: + time.sleep(0.01) + return None diff --git a/examples/official/9.x/qt_gui/design.py b/examples/official/9.x/qt_gui/design.py index 61afa3f..78c7916 100644 --- a/examples/official/9.x/qt_gui/design.py +++ b/examples/official/9.x/qt_gui/design.py @@ -3,22 +3,31 @@ ################################################################################ ## Form generated from reading UI file 'design.ui' ## -## Created by: Qt User Interface Compiler version 5.15.1 +## Created by: Qt User Interface Compiler version 6.7.2 ## ## WARNING! All changes made in this file will be lost when recompiling UI file! ################################################################################ -from PySide6.QtCore import * -from PySide6.QtGui import * -from PySide6.QtWidgets import * - +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QAction, QBrush, QColor, QConicalGradient, + QCursor, QFont, QFontDatabase, QGradient, + QIcon, QImage, QKeySequence, QLinearGradient, + QPainter, QPalette, QPixmap, QRadialGradient, + QTransform) +from PySide6.QtWidgets import (QApplication, QCheckBox, QComboBox, QGridLayout, + QGroupBox, QLabel, QListWidget, QListWidgetItem, + QMainWindow, QMenu, QMenuBar, QPushButton, + QSizePolicy, QStatusBar, QTabWidget, QTextEdit, + QWidget) class Ui_MainWindow(object): def setupUi(self, MainWindow): if not MainWindow.objectName(): MainWindow.setObjectName(u"MainWindow") - MainWindow.resize(1600, 848) - sizePolicy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) + MainWindow.resize(1819, 998) + sizePolicy = QSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Maximum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth()) @@ -38,51 +47,30 @@ def setupUi(self, MainWindow): self.actionEnter_License_Key.setObjectName(u"actionEnter_License_Key") self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(u"centralwidget") - sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) + sizePolicy1 = QSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Preferred) sizePolicy1.setHorizontalStretch(0) sizePolicy1.setVerticalStretch(0) sizePolicy1.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth()) self.centralwidget.setSizePolicy(sizePolicy1) self.gridLayout = QGridLayout(self.centralwidget) self.gridLayout.setObjectName(u"gridLayout") - self.groupBox_camera = QGroupBox(self.centralwidget) - self.groupBox_camera.setObjectName(u"groupBox_camera") - sizePolicy2 = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Preferred) + self.listWidget = QListWidget(self.centralwidget) + self.listWidget.setObjectName(u"listWidget") + sizePolicy2 = QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Expanding) sizePolicy2.setHorizontalStretch(0) sizePolicy2.setVerticalStretch(0) - sizePolicy2.setHeightForWidth(self.groupBox_camera.sizePolicy().hasHeightForWidth()) - self.groupBox_camera.setSizePolicy(sizePolicy2) - self.groupBox_camera.setMinimumSize(QSize(450, 150)) - self.comboBox = QComboBox(self.groupBox_camera) - self.comboBox.addItem("") - self.comboBox.addItem("") - self.comboBox.setObjectName(u"comboBox") - self.comboBox.setGeometry(QRect(180, 50, 101, 31)) - self.label_2 = QLabel(self.groupBox_camera) - self.label_2.setObjectName(u"label_2") - self.label_2.setGeometry(QRect(90, 50, 131, 31)) - font = QFont() - font.setPointSize(10) - self.label_2.setFont(font) - self.pushButton_open = QPushButton(self.groupBox_camera) - self.pushButton_open.setObjectName(u"pushButton_open") - self.pushButton_open.setGeometry(QRect(90, 90, 93, 28)) - self.pushButton_stop = QPushButton(self.groupBox_camera) - self.pushButton_stop.setObjectName(u"pushButton_stop") - self.pushButton_stop.setGeometry(QRect(190, 90, 93, 28)) - self.checkBox_autostop = QCheckBox(self.groupBox_camera) - self.checkBox_autostop.setObjectName(u"checkBox_autostop") - self.checkBox_autostop.setGeometry(QRect(90, 20, 101, 20)) - self.checkBox_syncdisplay = QCheckBox(self.groupBox_camera) - self.checkBox_syncdisplay.setObjectName(u"checkBox_syncdisplay") - self.checkBox_syncdisplay.setGeometry(QRect(210, 20, 121, 20)) + sizePolicy2.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth()) + self.listWidget.setSizePolicy(sizePolicy2) - self.gridLayout.addWidget(self.groupBox_camera, 0, 2, 1, 1) + self.gridLayout.addWidget(self.listWidget, 0, 0, 6, 1) self.groupBox_template = QGroupBox(self.centralwidget) self.groupBox_template.setObjectName(u"groupBox_template") - sizePolicy2.setHeightForWidth(self.groupBox_template.sizePolicy().hasHeightForWidth()) - self.groupBox_template.setSizePolicy(sizePolicy2) + sizePolicy3 = QSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) + sizePolicy3.setHorizontalStretch(0) + sizePolicy3.setVerticalStretch(0) + sizePolicy3.setHeightForWidth(self.groupBox_template.sizePolicy().hasHeightForWidth()) + self.groupBox_template.setSizePolicy(sizePolicy3) self.groupBox_template.setMinimumSize(QSize(450, 200)) self.pushButton_template = QPushButton(self.groupBox_template) self.pushButton_template.setObjectName(u"pushButton_template") @@ -94,35 +82,12 @@ def setupUi(self, MainWindow): self.pushButton_export_template.setObjectName(u"pushButton_export_template") self.pushButton_export_template.setGeometry(QRect(220, 20, 141, 28)) - self.gridLayout.addWidget(self.groupBox_template, 1, 2, 1, 1) - - self.listWidget = QListWidget(self.centralwidget) - self.listWidget.setObjectName(u"listWidget") - sizePolicy3 = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) - sizePolicy3.setHorizontalStretch(0) - sizePolicy3.setVerticalStretch(0) - sizePolicy3.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth()) - self.listWidget.setSizePolicy(sizePolicy3) - - self.gridLayout.addWidget(self.listWidget, 0, 0, 4, 1) - - self.label = QLabel(self.centralwidget) - self.label.setObjectName(u"label") - sizePolicy4 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - sizePolicy4.setHorizontalStretch(0) - sizePolicy4.setVerticalStretch(0) - sizePolicy4.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) - self.label.setSizePolicy(sizePolicy4) - self.label.setMinimumSize(QSize(800, 800)) - self.label.setMaximumSize(QSize(16777215, 16777215)) - self.label.setMouseTracking(True) - - self.gridLayout.addWidget(self.label, 0, 1, 4, 1) + self.gridLayout.addWidget(self.groupBox_template, 3, 2, 1, 1) self.groupBox_barcode = QGroupBox(self.centralwidget) self.groupBox_barcode.setObjectName(u"groupBox_barcode") - sizePolicy2.setHeightForWidth(self.groupBox_barcode.sizePolicy().hasHeightForWidth()) - self.groupBox_barcode.setSizePolicy(sizePolicy2) + sizePolicy3.setHeightForWidth(self.groupBox_barcode.sizePolicy().hasHeightForWidth()) + self.groupBox_barcode.setSizePolicy(sizePolicy3) self.groupBox_barcode.setMinimumSize(QSize(450, 220)) self.groupBox_4 = QGroupBox(self.groupBox_barcode) self.groupBox_4.setObjectName(u"groupBox_4") @@ -170,6 +135,7 @@ def setupUi(self, MainWindow): self.groupBox_5 = QGroupBox(self.groupBox_barcode) self.groupBox_5.setObjectName(u"groupBox_5") self.groupBox_5.setGeometry(QRect(9, 139, 431, 71)) + self.groupBox_5.setMinimumSize(QSize(150, 40)) self.checkBox_qrcode = QCheckBox(self.groupBox_5) self.checkBox_qrcode.setObjectName(u"checkBox_qrcode") self.checkBox_qrcode.setGeometry(QRect(50, 10, 81, 20)) @@ -207,23 +173,79 @@ def setupUi(self, MainWindow): self.checkBox_gs1.setGeometry(QRect(50, 70, 121, 20)) self.checkBox_gs1.setChecked(True) - self.gridLayout.addWidget(self.groupBox_barcode, 2, 2, 1, 1) + self.gridLayout.addWidget(self.groupBox_barcode, 4, 2, 1, 1) + + self.label = QLabel(self.centralwidget) + self.label.setObjectName(u"label") + sizePolicy4 = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) + sizePolicy4.setHorizontalStretch(0) + sizePolicy4.setVerticalStretch(0) + sizePolicy4.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) + self.label.setSizePolicy(sizePolicy4) + self.label.setMinimumSize(QSize(800, 800)) + self.label.setMaximumSize(QSize(4096, 4096)) + self.label.setMouseTracking(True) + + self.gridLayout.addWidget(self.label, 0, 1, 6, 1) self.textEdit_results = QTextEdit(self.centralwidget) self.textEdit_results.setObjectName(u"textEdit_results") - sizePolicy5 = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Expanding) - sizePolicy5.setHorizontalStretch(0) - sizePolicy5.setVerticalStretch(0) - sizePolicy5.setHeightForWidth(self.textEdit_results.sizePolicy().hasHeightForWidth()) - self.textEdit_results.setSizePolicy(sizePolicy5) + sizePolicy2.setHeightForWidth(self.textEdit_results.sizePolicy().hasHeightForWidth()) + self.textEdit_results.setSizePolicy(sizePolicy2) self.textEdit_results.setMinimumSize(QSize(450, 200)) - self.gridLayout.addWidget(self.textEdit_results, 3, 2, 1, 1) + self.gridLayout.addWidget(self.textEdit_results, 5, 2, 1, 1) + + self.groupBox_camera = QGroupBox(self.centralwidget) + self.groupBox_camera.setObjectName(u"groupBox_camera") + sizePolicy3.setHeightForWidth(self.groupBox_camera.sizePolicy().hasHeightForWidth()) + self.groupBox_camera.setSizePolicy(sizePolicy3) + self.groupBox_camera.setMinimumSize(QSize(450, 150)) + self.comboBox = QComboBox(self.groupBox_camera) + self.comboBox.addItem("") + self.comboBox.addItem("") + self.comboBox.setObjectName(u"comboBox") + self.comboBox.setGeometry(QRect(180, 50, 101, 31)) + self.label_2 = QLabel(self.groupBox_camera) + self.label_2.setObjectName(u"label_2") + self.label_2.setGeometry(QRect(90, 50, 131, 31)) + font = QFont() + font.setPointSize(10) + self.label_2.setFont(font) + self.pushButton_open = QPushButton(self.groupBox_camera) + self.pushButton_open.setObjectName(u"pushButton_open") + self.pushButton_open.setGeometry(QRect(90, 90, 93, 28)) + self.pushButton_stop = QPushButton(self.groupBox_camera) + self.pushButton_stop.setObjectName(u"pushButton_stop") + self.pushButton_stop.setGeometry(QRect(190, 90, 93, 28)) + self.checkBox_autostop = QCheckBox(self.groupBox_camera) + self.checkBox_autostop.setObjectName(u"checkBox_autostop") + self.checkBox_autostop.setGeometry(QRect(90, 20, 101, 20)) + self.checkBox_syncdisplay = QCheckBox(self.groupBox_camera) + self.checkBox_syncdisplay.setObjectName(u"checkBox_syncdisplay") + self.checkBox_syncdisplay.setGeometry(QRect(210, 20, 121, 20)) + + self.gridLayout.addWidget(self.groupBox_camera, 1, 2, 1, 1) + + self.groupBox_screen = QGroupBox(self.centralwidget) + self.groupBox_screen.setObjectName(u"groupBox_screen") + self.groupBox_screen.setEnabled(True) + sizePolicy3.setHeightForWidth(self.groupBox_screen.sizePolicy().hasHeightForWidth()) + self.groupBox_screen.setSizePolicy(sizePolicy3) + self.groupBox_screen.setMinimumSize(QSize(450, 50)) + self.pushButton_area = QPushButton(self.groupBox_screen) + self.pushButton_area.setObjectName(u"pushButton_area") + self.pushButton_area.setGeometry(QRect(90, 20, 75, 23)) + self.pushButton_full = QPushButton(self.groupBox_screen) + self.pushButton_full.setObjectName(u"pushButton_full") + self.pushButton_full.setGeometry(QRect(200, 20, 75, 23)) + + self.gridLayout.addWidget(self.groupBox_screen, 0, 2, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(MainWindow) self.menubar.setObjectName(u"menubar") - self.menubar.setGeometry(QRect(0, 0, 1600, 26)) + self.menubar.setGeometry(QRect(0, 0, 1819, 21)) self.menuAbout = QMenu(self.menubar) self.menuAbout.setObjectName(u"menuAbout") self.menuHelp = QMenu(self.menubar) @@ -256,20 +278,10 @@ def retranslateUi(self, MainWindow): self.actionOpen_Folder.setText(QCoreApplication.translate("MainWindow", u"Open Folder...", None)) self.actionExport_template.setText(QCoreApplication.translate("MainWindow", u"Save Template", None)) self.actionEnter_License_Key.setText(QCoreApplication.translate("MainWindow", u"Enter License Key", None)) - self.groupBox_camera.setTitle(QCoreApplication.translate("MainWindow", u"Camera", None)) - self.comboBox.setItemText(0, QCoreApplication.translate("MainWindow", u"640 x 480", None)) - self.comboBox.setItemText(1, QCoreApplication.translate("MainWindow", u"320 x 240", None)) - - self.label_2.setText(QCoreApplication.translate("MainWindow", u"Resolution:", None)) - self.pushButton_open.setText(QCoreApplication.translate("MainWindow", u"Start", None)) - self.pushButton_stop.setText(QCoreApplication.translate("MainWindow", u"Stop", None)) - self.checkBox_autostop.setText(QCoreApplication.translate("MainWindow", u"Auto Stop", None)) - self.checkBox_syncdisplay.setText(QCoreApplication.translate("MainWindow", u"Sync Display", None)) self.groupBox_template.setTitle(QCoreApplication.translate("MainWindow", u"Template", None)) self.pushButton_template.setText(QCoreApplication.translate("MainWindow", u"Load Template File", None)) self.textEdit_template.setPlaceholderText(QCoreApplication.translate("MainWindow", u"Paste template string here", None)) self.pushButton_export_template.setText(QCoreApplication.translate("MainWindow", u"Export Template File", None)) - self.label.setText("") self.groupBox_barcode.setTitle(QCoreApplication.translate("MainWindow", u"Barcode Types", None)) self.groupBox_4.setTitle(QCoreApplication.translate("MainWindow", u"1D", None)) self.checkBox_code39.setText(QCoreApplication.translate("MainWindow", u"Code 39", None)) @@ -292,7 +304,20 @@ def retranslateUi(self, MainWindow): self.checkBox_patchcode.setText(QCoreApplication.translate("MainWindow", u"Patch Code", None)) self.checkBox_datamatrix.setText(QCoreApplication.translate("MainWindow", u"DataMatrix", None)) self.checkBox_gs1.setText(QCoreApplication.translate("MainWindow", u"GS1 Composite", None)) + self.label.setText("") self.textEdit_results.setDocumentTitle("") + self.groupBox_camera.setTitle(QCoreApplication.translate("MainWindow", u"Camera", None)) + self.comboBox.setItemText(0, QCoreApplication.translate("MainWindow", u"640 x 480", None)) + self.comboBox.setItemText(1, QCoreApplication.translate("MainWindow", u"320 x 240", None)) + + self.label_2.setText(QCoreApplication.translate("MainWindow", u"Resolution:", None)) + self.pushButton_open.setText(QCoreApplication.translate("MainWindow", u"Start", None)) + self.pushButton_stop.setText(QCoreApplication.translate("MainWindow", u"Stop", None)) + self.checkBox_autostop.setText(QCoreApplication.translate("MainWindow", u"Auto Stop", None)) + self.checkBox_syncdisplay.setText(QCoreApplication.translate("MainWindow", u"Sync Display", None)) + self.groupBox_screen.setTitle(QCoreApplication.translate("MainWindow", u"Screen", None)) + self.pushButton_area.setText(QCoreApplication.translate("MainWindow", u"Select Area", None)) + self.pushButton_full.setText(QCoreApplication.translate("MainWindow", u"Fullscreen", None)) self.menuAbout.setTitle(QCoreApplication.translate("MainWindow", u"File", None)) self.menuHelp.setTitle(QCoreApplication.translate("MainWindow", u"Help", None)) # retranslateUi diff --git a/examples/official/9.x/qt_gui/design.ui b/examples/official/9.x/qt_gui/design.ui index b0d2313..ba579d8 100644 --- a/examples/official/9.x/qt_gui/design.ui +++ b/examples/official/9.x/qt_gui/design.ui @@ -6,8 +6,8 @@ 0 0 - 1600 - 848 + 1819 + 998 @@ -45,119 +45,20 @@ - - + + - + 0 0 - - - 450 - 150 - - - - Camera - - - - - 180 - 50 - 101 - 31 - - - - - 640 x 480 - - - - - 320 x 240 - - - - - - - 90 - 50 - 131 - 31 - - - - - 10 - - - - Resolution: - - - - - - 90 - 90 - 93 - 28 - - - - Start - - - - - - 190 - 90 - 93 - 28 - - - - Stop - - - - - - 90 - 20 - 101 - 20 - - - - Auto Stop - - - - - - 210 - 20 - 121 - 20 - - - - Sync Display - - - + - + 0 0 @@ -212,48 +113,10 @@ - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - 800 - 800 - - - - - 16777215 - 16777215 - - - - true - - - - - - - + - + 0 0 @@ -449,6 +312,12 @@ 71 + + + 150 + 40 + + 2D @@ -599,10 +468,38 @@ - + + + + + 0 + 0 + + + + + 800 + 800 + + + + + 4096 + 4096 + + + + true + + + + + + + - + 0 0 @@ -618,6 +515,163 @@ + + + + + 0 + 0 + + + + + 450 + 150 + + + + Camera + + + + + 180 + 50 + 101 + 31 + + + + + 640 x 480 + + + + + 320 x 240 + + + + + + + 90 + 50 + 131 + 31 + + + + + 10 + + + + Resolution: + + + + + + 90 + 90 + 93 + 28 + + + + Start + + + + + + 190 + 90 + 93 + 28 + + + + Stop + + + + + + 90 + 20 + 101 + 20 + + + + Auto Stop + + + + + + 210 + 20 + 121 + 20 + + + + Sync Display + + + + + + + + true + + + + 0 + 0 + + + + + 450 + 50 + + + + Screen + + + + + 90 + 20 + 75 + 23 + + + + Select Area + + + + + + 200 + 20 + 75 + 23 + + + + Fullscreen + + + + @@ -625,8 +679,8 @@ 0 0 - 1600 - 26 + 1819 + 21