-
Notifications
You must be signed in to change notification settings - Fork 5
Adding some code checks to avoid exceptions and reworked QMainWindow and the way main code executes #1
Adding some code checks to avoid exceptions and reworked QMainWindow and the way main code executes #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -37,6 +37,7 @@ | |
|
|
||
| MAX_LEN = 100 | ||
| QR_DELAY = 400 | ||
| FILL_COLOR = "#434343" | ||
|
|
||
| def to_str(bin_): | ||
| return bin_.decode('utf-8') | ||
|
|
@@ -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() | ||
|
|
@@ -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() | ||
|
|
||
|
|
@@ -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: | ||
| if (index - int(available_cameras[-1])) > 2: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
|
@@ -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): | ||
|
|
@@ -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): | ||
|
|
@@ -710,5 +720,6 @@ def on_btn_save(self): | |
| app.setPalette(palette) | ||
|
|
||
| main_win = MainWindow() | ||
| sys.exit(app.exec_()) | ||
| main_win.show() | ||
| app.exec() | ||
|
|
||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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...There was a problem hiding this comment.
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):