Skip to content

Conversation

@barpavel
Copy link
Contributor

@barpavel barpavel commented Nov 5, 2025

  1. Improved handling of camera & video errors:
  • Display error message in the video area in the following cases (runtime error detection during frame reading):
    • Camera is unavailable (at initialization or gets disconnected during use).
    • Prerecorded video can't be played (file doesn't exist or video stream gets interrupted/corrupted).
      A visual error message (white bold text, centered, on a black background with a red border) is displayed in the exact same location where the video would appear.
      Documentation was updated accordingly and a screenshot displaying the camera error was added to the README.md file.
  • Robust camera detection using a small delay (0.1 seconds), to give camera time to initialize properly.
    Cameras (especially USB cameras) often need a brief moment to become fully operational.
    The delay reduces false negatives where camera exists but isn't ready yet.
  1. Fixed strange black areas at small display.
    In certain cases the main UI window when opened at the small resolution display has some strange black areas at the top and right (see the below screenshot).
Screenshot_black_area

When the UI window is repainted by Qt, the issue is solved:

  • Minimize and maximize.
  • Move the UI window to the large display and then back to the small display.
  • Switch to another application that partially hides the dashboard's window and then switch back.

Several root causes related to UI were identified and fixed:

  • Fixed window and content dimension mismatch: the main window is set to 1,117x636 pixels, while background label is set to 1,111x651 pixels.
  • Added DPI awareness and automatic high DPI scaling support to properly handle different display DPI settings and scaling factors.
  • Added automatic window centering on the primary screen. This ensures consistent positioning regardless of monitor setup.

The solution was tested on both small and large displays to ensure black areas are eliminated.

  1. Using module level dunders to state the author and additional module information.
    More info can be found at the PEP 8 – Style Guide for Python Code manual.
  2. Fixed a few warnings in the code.
  3. Some minor code refactoring & documentation updates.

Co-authored-by: Cursor AI
Signed-off-by: Pavel Bar pbar@redhat.com

@barpavel barpavel force-pushed the ui-fixes branch 2 times, most recently from 216810c to e506915 Compare November 5, 2025 14:41
@barpavel
Copy link
Contributor Author

barpavel commented Nov 6, 2025

@SihabSahariar if you have any comments, please write me and I will fix / add / revert whatever you will ask.
Nothing has to be merged as-is and my approach might be wrong, you are the code owner and maintainer 😃

@barpavel barpavel force-pushed the ui-fixes branch 2 times, most recently from 7ccc312 to 812a754 Compare November 6, 2025 12:25
1. Refactored the "_read_video_frame()" method
to be static to fix a warning, see [2].
2. Using the class name to access class-level constants.
3. Using module level "dunders" to state the author
and additional module information. This is probably a more
elegant solution compared to using comments and/or
a dedicated "creator()" method (the latter was removed).
More info at the "PEP 8 – Style Guide for Python Code", see [1].
4. Fixed a few additional warnings, see [3], [4] & [5].
5. Minor "README.md" update.

[1] https://peps.python.org/pep-0008/#module-level-dunder-names
[2] Method '_read_video_frame' may be 'static'
[3] Ui_MainWindow::setupUi()
Shadows name 'MainWindow' from outer scope
[4] AnalogGaugeWidget::set_MinValue()
Shadows built-in name 'min'
[5] AnalogGaugeWidget::set_MaxValue()
Shadows built-in name 'max'

Signed-off-by: Pavel Bar <pbar@redhat.com>
Refactored in "AnalogGaugeWidget" class a few conditional
statements using Python's built-in "min()" and "max()"
functions with clear comments.
The new code is more Pythonic & readable.

1. "rescale_method()" method.
2. "update_value()" method - implemented a classic value
"clamping" operation (constraining a value to stay within a
min/max range). This is a well-known Python idiom for clamping values.
3. "set_MinValue()" & "set_MinValue()" methods.
4. "set_scala_main_count()" method.

Co-authored-by: Cursor AI

Signed-off-by: Pavel Bar <pbar@redhat.com>
1. Display error message in the video area in the following
cases (runtime error detection during frame reading):
  a. Camera is unavailable
 (at initialization or gets disconnected during use).
  b. Prerecorded video can't be played
 (file doesn't exist or video stream gets interrupted/corrupted).
Created a dedicated "display_error_message()" method
to display a visual error message in the exact same location
where the video would appear.
It uses a black background with a red border to match the UI styling.
Shows white text that's bold and centered for clear readability.
Maintains the exact same dimensions as the video area (321x331 pixels).
The error handling ensures the application won't crash and provides
a clear feedback to users about what went wrong,
making the dashboard much more user-friendly and robust.

2. Hardware consideration - a more reliable camera detection.
Added a small delay (0.1 seconds), to give camera time
to initialize properly. Cameras (especially USB cameras) often need
a brief moment to become fully operational
after a "cv2.VideoCapture()" call.
This ensures camera is ready before "view_video()" starts
getting called every 20ms, which reduces false negatives where
camera exists but isn't ready yet.

Documentation was updated accordingly and a screenshot displaying
the camera error was added to the "README.md" file.

Co-authored-by: Cursor AI

Signed-off-by: Pavel Bar <pbar@redhat.com>
In certain cases the main UI window when opened
at the small resolution display has some strange
black areas at the top and right.
When the UI window is repainted by "Qt", the issue is solved:
1. Minimize and maximize.
2. Move the UI window to the large display
and then back to the small display.
3. Switch to another application that partially
hides the dashboard's window and then switch back.

Several root causes related to UI were identified and fixed:
1. Fixed window and content dimension mismatch: the main window
is set to 1117x636 pixels, while background label is set to
1111x651 pixels, that's 15 pixels taller than the main window
(this caused content to be drawn outside the visible area,
creating overflow areas that appeared black).
After the fix the background perfectly matches the main window size.
To avoid such problem in the future, the magic numbers were
refactored into the class-level constants.
2. Added DPI awareness and automatic high DPI scaling support
to properly handle different display DPI settings and scaling
factors, which caused rendering issues when moving between displays.
3. Added automatic window centering on the primary screen.
This ensures consistent positioning regardless of monitor setup.
4. Also disabled the window context help button (the "?" button
that appears in window title bars on some platforms).

The solution was tested on both small and large displays
to ensure black areas are eliminated.

Co-authored-by: Cursor AI

Signed-off-by: Pavel Bar <pbar@redhat.com>
@SihabSahariar
Copy link
Owner

@barpavel kindly integrate QThread for camera feed. I've added an issue, you can look into it.

@barpavel
Copy link
Contributor Author

barpavel commented Nov 7, 2025

QThread

I'll look at it 😃
Though, maybe do it in a separate MR, that way there is a logical separation and it will be easier to code review and merge.
So this currently opened MR can be merged separately, unless you have comments related to it.

@barpavel barpavel marked this pull request as draft November 7, 2025 17:57
@SihabSahariar SihabSahariar marked this pull request as ready for review November 8, 2025 05:42
@SihabSahariar
Copy link
Owner

I've reviewed. Good work @barpavel
I'm merging.

@SihabSahariar SihabSahariar reopened this Nov 8, 2025
@SihabSahariar SihabSahariar merged commit 73093f2 into SihabSahariar:main Nov 8, 2025
@barpavel barpavel deleted the ui-fixes branch November 8, 2025 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants