Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions form.ui
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>812</width>
<height>666</height>
</rect>
</property>
<property name="windowTitle">
<string>SeedQReader</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
Expand Down Expand Up @@ -455,7 +442,6 @@
</widget>
</widget>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ numpy==1.24.3
opencv-python==4.7.0.72
Pillow==9.5.0
pypng==0.20220715.0
PySide2==5.13.2
PyYAML==6.0
pyzbar==0.1.9
qrcode==7.4.2
shiboken2==5.13.2
typing_extensions==4.6.2
PySide6==6.5.1
shiboken6==6.5.1
urtypes @ git+https://github.com/selfcustody/urtypes.git@7fb280eab3b3563dfc57d2733b0bf5cbc0a96a6a
29 changes: 20 additions & 9 deletions seedqreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from yaml import load, dump
from yaml.loader import SafeLoader as Loader

from PySide2.QtWidgets import QApplication, QMainWindow
from PySide2.QtGui import QImage, QPixmap, QPalette, QColor
from PySide2.QtCore import Qt, QFile, QThread, Signal
from PySide2.QtUiTools import QUiLoader
from PySide2.QtGui import QTextOption
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtGui import QImage, QPixmap, QPalette, QColor
from PySide6.QtCore import Qt, QFile, QThread, Signal
from PySide6.QtUiTools import QUiLoader
from PySide6.QtGui import QTextOption

from PIL import ImageQt

Expand All @@ -37,6 +37,7 @@

MAX_LEN = 100
QR_DELAY = 400
FILL_COLOR = "#434343"

def to_str(bin_):
return bin_.decode('utf-8')
Expand Down Expand Up @@ -422,7 +423,7 @@ class MainWindow(QMainWindow):
stop_display = Signal()

def __init__(self):
QMainWindow.__init__(self)
super().__init__()

# Set up the main window
loader = QUiLoader()
Expand All @@ -432,8 +433,9 @@ def __init__(self):
self.ui = loader.load(ui_file, self)
ui_file.close()
self.setWindowTitle("SeedQReader")
self.setFixedSize(812,670)

self.ui.show()
self.setCentralWidget(self.ui)

self.load_config()

Expand Down Expand Up @@ -518,7 +520,7 @@ def list_available_cameras():
available_cameras = []
while True:
cap = cv2.VideoCapture(index)
if not cap.isOpened():
if not cap.isOpened() and available_cameras:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this change, what about if the soft is run on a VM (no camera), in that case, the loop will be endless

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not, I was getting an error because I had no cameras, this made the error stop and the program execute, later I can plug the camera and the code still works

Copy link
Contributor Author

@tadeubas tadeubas Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code available_cameras.append(str(index)) on line 528 make everything to work just fine without any endless loop...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error before this fix was (with none usbcamera):

seedqreader.py", line 522, in list_available_cameras
    if (index - int(available_cameras[-1])) > 2:
                    ~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range

if (index - int(available_cameras[-1])) > 2:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no available camera here we got an exception and the program stops, so we need to check it before trying to access the index -1

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall similar and failed to report it, maybe pyqt window didn't even start. Plugged in usbcam, and solved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it won't start without a usb camera... but now with this small fix it will start with or without a usb_cam

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no available camera here we got an exception and the program stops, so we need to check it before trying to access the index -1

I got it but I think is better to check it there (L523)

if available_cameras and (index - int(available_cameras[-1])) > 2:

if not, even if no camera, #0 will be listed

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add this check (L523) because, under Linux, it seems when 1 camera is plugged, I got 2 listed (only the first one available to get video stream)

break
else:
Expand Down Expand Up @@ -563,6 +565,10 @@ def on_data_type_change(self):
self.data_type = self.ui.combo_type.currentText()

def on_qr_display(self, frame):
if frame is None:
frame = QPixmap(self.ui.video_in.size())
frame.fill(QColor(FILL_COLOR))

self.ui.video_out.setPixmap(frame)

def on_qr_read(self):
Expand All @@ -578,6 +584,10 @@ def on_qr_data_read(self, data):
self.ui.data_in.setPlainText(data)

def upd_camera_stream(self, frame):
if frame is None:
frame = QPixmap(self.ui.video_in.size())
frame.fill(QColor(FILL_COLOR))

self.ui.video_in.setPixmap(frame)

def on_slider_move(self):
Expand Down Expand Up @@ -710,5 +720,6 @@ def on_btn_save(self):
app.setPalette(palette)

main_win = MainWindow()
sys.exit(app.exec_())
main_win.show()
app.exec()