Skip to content

Commit

Permalink
use AppContext in MainWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
achimmihca committed Sep 5, 2021
1 parent b120dc0 commit aef4991
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/common/AppContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self) -> None:
apply_stylesheet(self.qt_application, theme=self.config.ui_theme.value)
self.config.ui_theme.subscribe(lambda new_theme: apply_stylesheet(self.qt_application, theme=new_theme))

self.main_window = MainWindow(self.config, self.webcam_control)
self.main_window = MainWindow(self)

# Register global shortcut control
shortcut_control = GlobalShortcutControl(self)
Expand Down
16 changes: 9 additions & 7 deletions src/gui/MainWindow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python

from __future__ import annotations
from typing import Any
from PySide6.QtGui import QResizeEvent
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QMainWindow, QLabel
from common.version import version
import common.AppContext as AppContext
from common.Config import Config
from common.Config import VideoCaptureSource
from common.LogHolder import LogHolder
Expand All @@ -16,12 +18,12 @@
from rx import operators as ops

class MainWindow(QMainWindow, LogHolder):
def __init__(self, config: Config, webcam_control: WebcamControl) -> None:
def __init__(self, app_context: AppContext.AppContext) -> None:
QMainWindow.__init__(self)
LogHolder.__init__(self)
self.setWindowTitle(f"DedoMouse")
self.config = config
self.webcam_control = webcam_control
self.app_context = app_context
self.config = app_context.config

self.setup_style_sheet()
self.setup_ui()
Expand All @@ -40,7 +42,7 @@ def update_config_window_size(new_value: Vector) -> None:
self.resize_event_reactive_property.pipe(ops.debounce(0.1)).subscribe(update_config_window_size)

def setup_video_capture(self) -> None:
self.video_capture_thread = VideoCaptureThread(self.config, self.webcam_control, self.main_widget.image_label)
self.video_capture_thread = VideoCaptureThread(self.config, self.app_context.webcam_control, self.main_widget.image_label)
self.video_capture_thread.start()

def resizeEvent(self, event: QResizeEvent) -> None:
Expand Down Expand Up @@ -85,8 +87,8 @@ def setup_status_bar(self) -> None:
self.performed_action_description_count = 0
self.performed_action_description_label = QLabel()
self.statusBar().addWidget(self.performed_action_description_label)
self.webcam_control.gesture_recognizer.jitter_pause_time_ms.subscribe(lambda new_value: self.update_performed_action_description_label(float(new_value), ""))
self.webcam_control.gesture_recognizer.mouse_control.performed_action_desciption.subscribe(lambda new_value: self.update_performed_action_description_label(0, new_value))
self.app_context.gesture_recognizer.jitter_pause_time_ms.subscribe(lambda new_value: self.update_performed_action_description_label(float(new_value), ""))
self.app_context.mouse_control.performed_action_desciption.subscribe(lambda new_value: self.update_performed_action_description_label(0, new_value))

def update_performed_action_description_label(self, new_jitter_pause_time_ms: float, performed_action_description: str) -> None:
if (new_jitter_pause_time_ms <= 0):
Expand All @@ -104,7 +106,7 @@ def update_performed_action_description_label(self, new_jitter_pause_time_ms: fl

def update_video_settings_label(self, new_value: Any) -> None:
if (self.config.capture_source.value == VideoCaptureSource.INTEGRATED_WEBCAM):
self.video_settings_label.setText(f"Video: {self.webcam_control.actual_capture_size.x}x{self.webcam_control.actual_capture_size.y}@{self.webcam_control.fps}")
self.video_settings_label.setText(f"Video: {self.app_context.webcam_control.actual_capture_size.x}x{self.app_context.webcam_control.actual_capture_size.y}@{self.app_context.webcam_control.fps}")
else:
self.video_settings_label.setText(f"Video: {self.config.capture_source_url.value}")

Expand Down

0 comments on commit aef4991

Please sign in to comment.