Skip to content

Commit

Permalink
Update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed Sep 3, 2024
1 parent 0dadc34 commit f2827c4
Show file tree
Hide file tree
Showing 4 changed files with 344 additions and 243 deletions.
2 changes: 1 addition & 1 deletion examples/official/9.x/qt_gui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
38 changes: 30 additions & 8 deletions examples/official/9.x/qt_gui/barcode_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 != '':
Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand All @@ -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
193 changes: 109 additions & 84 deletions examples/official/9.x/qt_gui/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
Loading

0 comments on commit f2827c4

Please sign in to comment.