From d38835db54a33510ec2b4ace19138644be00faa7 Mon Sep 17 00:00:00 2001 From: xnegativx Date: Mon, 28 Aug 2023 01:02:56 +0200 Subject: [PATCH 1/2] make gui_config independent of PyQt --- modules/gui_config.py | 126 ------------------------------------------ modules/gui_pyqt.py | 121 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 127 deletions(-) diff --git a/modules/gui_config.py b/modules/gui_config.py index c6cc9d7c..72912ea8 100644 --- a/modules/gui_config.py +++ b/modules/gui_config.py @@ -1,14 +1,5 @@ import os -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - import oyaml as yaml @@ -360,123 +351,6 @@ def __init__(self, config): if self.config.G_IS_RASPI: self.icon_dir = self.config.G_INSTALL_PATH - def set_qt5_or_qt6_constants(self, USE_PYQT6): - self.key_space = QtCore.Qt.Key.Key_Space if USE_PYQT6 else QtCore.Qt.Key_Space - self.key_press = ( - QtCore.QEvent.Type.KeyPress if USE_PYQT6 else QtCore.QEvent.KeyPress - ) - self.key_release = ( - QtCore.QEvent.Type.KeyRelease if USE_PYQT6 else QtCore.QEvent.KeyRelease - ) - self.no_modifier = ( - QtCore.Qt.KeyboardModifier.NoModifier if USE_PYQT6 else QtCore.Qt.NoModifier - ) - - self.align_left = ( - QtCore.Qt.AlignmentFlag.AlignLeft if USE_PYQT6 else QtCore.Qt.AlignLeft - ) - self.align_center = ( - QtCore.Qt.AlignmentFlag.AlignCenter if USE_PYQT6 else QtCore.Qt.AlignCenter - ) - self.align_h_center = ( - QtCore.Qt.AlignmentFlag.AlignHCenter - if USE_PYQT6 - else QtCore.Qt.AlignHCenter - ) - self.align_v_center = ( - QtCore.Qt.AlignmentFlag.AlignVCenter - if USE_PYQT6 - else QtCore.Qt.AlignVCenter - ) - self.align_right = ( - QtCore.Qt.AlignmentFlag.AlignRight if USE_PYQT6 else QtCore.Qt.AlignRight - ) - self.align_bottom = ( - QtCore.Qt.AlignmentFlag.AlignBottom if USE_PYQT6 else QtCore.Qt.AlignBottom - ) - self.align_top = ( - QtCore.Qt.AlignmentFlag.AlignTop if USE_PYQT6 else QtCore.Qt.AlignTop - ) - self.expanding = ( - QtWidgets.QSizePolicy.Policy.Expanding - if USE_PYQT6 - else QtWidgets.QSizePolicy.Expanding - ) - self.fixed = ( - QtWidgets.QSizePolicy.Policy.Fixed - if USE_PYQT6 - else QtWidgets.QSizePolicy.Fixed - ) - - self.no_focus = ( - QtCore.Qt.FocusPolicy.NoFocus if USE_PYQT6 else QtCore.Qt.NoFocus - ) - self.strong_focus = ( - QtCore.Qt.FocusPolicy.StrongFocus if USE_PYQT6 else QtCore.Qt.StrongFocus - ) - self.tab_focus_reason = ( - QtCore.Qt.FocusReason.TabFocusReason - if USE_PYQT6 - else QtCore.Qt.TabFocusReason - ) - self.backtab_focus_reason = ( - QtCore.Qt.FocusReason.BacktabFocusReason - if USE_PYQT6 - else QtCore.Qt.BacktabFocusReason - ) - - self.scrollbar_alwaysoff = ( - QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff - if USE_PYQT6 - else QtCore.Qt.ScrollBarAlwaysOff - ) - self.qtextedit_nowrap = ( - QtWidgets.QTextEdit.LineWrapMode.NoWrap - if USE_PYQT6 - else QtWidgets.QTextEdit.NoWrap - ) - - self.stackingmode_stackone = ( - QtWidgets.QStackedLayout.StackingMode.StackOne - if USE_PYQT6 - else QtWidgets.QStackedLayout.StackOne - ) - self.stackingmode_stackall = ( - QtWidgets.QStackedLayout.StackingMode.StackAll - if USE_PYQT6 - else QtWidgets.QStackedLayout.StackAll - ) - - self.PE_Widget = ( - QtWidgets.QStyle.PrimitiveElement.PE_Widget - if USE_PYQT6 - else QtWidgets.QStyle.PE_Widget - ) - self.WA_TranslucentBackground = ( - QtCore.Qt.WidgetAttribute.WA_TranslucentBackground - if USE_PYQT6 - else QtCore.Qt.WA_TranslucentBackground - ) - self.WA_TransparentForMouseEvents = ( - QtCore.Qt.WidgetAttribute.WA_TransparentForMouseEvents - if USE_PYQT6 - else QtCore.Qt.WA_TransparentForMouseEvents - ) - - # for draw_display - self.format_rgb888 = ( - QtGui.QImage.Format.Format_RGB888 - if USE_PYQT6 - else QtGui.QImage.Format_RGB888 - ) - self.format_mono = ( - QtGui.QImage.Format.Format_Mono if USE_PYQT6 else QtGui.QImage.Format_Mono - ) - if self.config.display.has_color(): - self.format = self.format_rgb888 - else: - self.format = self.format_mono - def get_screen_shape(self, p): remove_bytes = 0 if self.config.display.has_color(): diff --git a/modules/gui_pyqt.py b/modules/gui_pyqt.py index a673299b..2af93e88 100644 --- a/modules/gui_pyqt.py +++ b/modules/gui_pyqt.py @@ -99,7 +99,7 @@ def __init__(self, config): self.config.gui = self self.gui_config = GUI_Config(config) - self.gui_config.set_qt5_or_qt6_constants(USE_PYQT6) + self.set_qt5_or_qt6_constants() self.style = PyQtStyle() self.logger = self.config.logger @@ -113,6 +113,125 @@ def __init__(self, config): self.init_window() + def set_qt5_or_qt6_constants(self): + self.gui_config.key_space = ( + QtCore.Qt.Key.Key_Space if USE_PYQT6 else QtCore.Qt.Key_Space + ) + self.gui_config.key_press = ( + QtCore.QEvent.Type.KeyPress if USE_PYQT6 else QtCore.QEvent.KeyPress + ) + self.gui_config.key_release = ( + QtCore.QEvent.Type.KeyRelease if USE_PYQT6 else QtCore.QEvent.KeyRelease + ) + self.gui_config.no_modifier = ( + QtCore.Qt.KeyboardModifier.NoModifier if USE_PYQT6 else QtCore.Qt.NoModifier + ) + + self.gui_config.align_left = ( + QtCore.Qt.AlignmentFlag.AlignLeft if USE_PYQT6 else QtCore.Qt.AlignLeft + ) + self.gui_config.align_center = ( + QtCore.Qt.AlignmentFlag.AlignCenter if USE_PYQT6 else QtCore.Qt.AlignCenter + ) + self.gui_config.align_h_center = ( + QtCore.Qt.AlignmentFlag.AlignHCenter + if USE_PYQT6 + else QtCore.Qt.AlignHCenter + ) + self.gui_config.align_v_center = ( + QtCore.Qt.AlignmentFlag.AlignVCenter + if USE_PYQT6 + else QtCore.Qt.AlignVCenter + ) + self.gui_config.align_right = ( + QtCore.Qt.AlignmentFlag.AlignRight if USE_PYQT6 else QtCore.Qt.AlignRight + ) + self.gui_config.align_bottom = ( + QtCore.Qt.AlignmentFlag.AlignBottom if USE_PYQT6 else QtCore.Qt.AlignBottom + ) + self.gui_config.align_top = ( + QtCore.Qt.AlignmentFlag.AlignTop if USE_PYQT6 else QtCore.Qt.AlignTop + ) + self.gui_config.expanding = ( + QtWidgets.QSizePolicy.Policy.Expanding + if USE_PYQT6 + else QtWidgets.QSizePolicy.Expanding + ) + self.gui_config.fixed = ( + QtWidgets.QSizePolicy.Policy.Fixed + if USE_PYQT6 + else QtWidgets.QSizePolicy.Fixed + ) + + self.gui_config.no_focus = ( + QtCore.Qt.FocusPolicy.NoFocus if USE_PYQT6 else QtCore.Qt.NoFocus + ) + self.gui_config.strong_focus = ( + QtCore.Qt.FocusPolicy.StrongFocus if USE_PYQT6 else QtCore.Qt.StrongFocus + ) + self.gui_config.tab_focus_reason = ( + QtCore.Qt.FocusReason.TabFocusReason + if USE_PYQT6 + else QtCore.Qt.TabFocusReason + ) + self.gui_config.backtab_focus_reason = ( + QtCore.Qt.FocusReason.BacktabFocusReason + if USE_PYQT6 + else QtCore.Qt.BacktabFocusReason + ) + + self.gui_config.scrollbar_alwaysoff = ( + QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff + if USE_PYQT6 + else QtCore.Qt.ScrollBarAlwaysOff + ) + self.gui_config.qtextedit_nowrap = ( + QtWidgets.QTextEdit.LineWrapMode.NoWrap + if USE_PYQT6 + else QtWidgets.QTextEdit.NoWrap + ) + + self.gui_config.stackingmode_stackone = ( + QtWidgets.QStackedLayout.StackingMode.StackOne + if USE_PYQT6 + else QtWidgets.QStackedLayout.StackOne + ) + self.gui_config.stackingmode_stackall = ( + QtWidgets.QStackedLayout.StackingMode.StackAll + if USE_PYQT6 + else QtWidgets.QStackedLayout.StackAll + ) + + self.gui_config.PE_Widget = ( + QtWidgets.QStyle.PrimitiveElement.PE_Widget + if USE_PYQT6 + else QtWidgets.QStyle.PE_Widget + ) + self.gui_config.WA_TranslucentBackground = ( + QtCore.Qt.WidgetAttribute.WA_TranslucentBackground + if USE_PYQT6 + else QtCore.Qt.WA_TranslucentBackground + ) + self.gui_config.WA_TransparentForMouseEvents = ( + QtCore.Qt.WidgetAttribute.WA_TransparentForMouseEvents + if USE_PYQT6 + else QtCore.Qt.WA_TransparentForMouseEvents + ) + + # for draw_display + self.gui_config.format_rgb888 = ( + QtGui.QImage.Format.Format_RGB888 + if USE_PYQT6 + else QtGui.QImage.Format_RGB888 + ) + self.gui_config.format_mono = ( + QtGui.QImage.Format.Format_Mono if USE_PYQT6 else QtGui.QImage.Format_Mono + ) + if self.config.display.has_color(): + self.gui_config.format = self.gui_config.format_rgb888 + else: + self.gui_config.format = self.gui_config.format_mono + def init_window(self): self.app = QtWidgets.QApplication(sys.argv) self.config.loop = qasync.QEventLoop(self.app) From d23f22d8d100dbf524a08d9fa67b5b5bbb6abb46 Mon Sep 17 00:00:00 2001 From: xnegativx Date: Mon, 28 Aug 2023 11:19:03 +0200 Subject: [PATCH 2/2] have one import for qt object make sure qasync/pyqtgraph rely on the same qt version --- modules/_pyqt.py | 35 ++++++++++++++++++++ modules/gui_pyqt.py | 15 +-------- modules/pyqt/graph/pyqt_base_map.py | 25 ++++---------- modules/pyqt/graph/pyqt_course_profile.py | 11 +----- modules/pyqt/graph/pyqt_map.py | 15 ++------- modules/pyqt/graph/pyqt_value_graph.py | 2 +- modules/pyqt/menu/pyqt_adjust_widget.py | 14 ++------ modules/pyqt/menu/pyqt_course_menu_widget.py | 27 +++++---------- modules/pyqt/menu/pyqt_map_menu_widget.py | 9 ----- modules/pyqt/menu/pyqt_menu_widget.py | 20 +++-------- modules/pyqt/menu/pyqt_profile_widget.py | 9 ----- modules/pyqt/menu/pyqt_sensor_menu_widget.py | 12 ++----- modules/pyqt/menu/pyqt_system_menu_widget.py | 16 ++------- modules/pyqt/pyqt_button_box_widget.py | 13 +------- modules/pyqt/pyqt_cuesheet_widget.py | 9 +---- modules/pyqt/pyqt_graph_debug.py | 2 +- modules/pyqt/pyqt_item.py | 11 ++---- modules/pyqt/pyqt_screen_widget.py | 12 ++----- 18 files changed, 74 insertions(+), 183 deletions(-) create mode 100644 modules/_pyqt.py diff --git a/modules/_pyqt.py b/modules/_pyqt.py new file mode 100644 index 00000000..e2503ec7 --- /dev/null +++ b/modules/_pyqt.py @@ -0,0 +1,35 @@ +import os + +__all__ = ["USE_PYQT6", "QtCore", "QtWidgets", "QtGui", "pg", "qasync"] + +USE_PYQT6 = False +try: + import PyQt6.QtCore as QtCore + import PyQt6.QtWidgets as QtWidgets + import PyQt6.QtGui as QtGui + + USE_PYQT6 = True +except (ImportError, ModuleNotFoundError): + import PyQt5.QtCore as QtCore + import PyQt5.QtWidgets as QtWidgets + import PyQt5.QtGui as QtGui + +# import qasync once pyQt is imported so the correct version is used (it starts with PyQt5 then tries PyQt6) +import qasync # noqa + +# make sure the version is correct in case the underlying code for qasync changed +if USE_PYQT6 and qasync.QtModuleName != "PyQt6": + raise AssertionError( + f"Wrong version of PyQt6 used for qasync: {qasync.QtModuleName}" + ) +elif not USE_PYQT6 and qasync.QtModuleName != "PyQt5": + raise AssertionError( + f"Wrong version of PyQt5 used for qasync: {qasync.QtModuleName}" + ) + +# pyqtgraph will check/try to import PyQT6 on load and might fail if some packages were imported +# (if pyQt6 is halfway installed): so we force the version here +os.environ.setdefault("PYQTGRAPH_QT_LIB", qasync.QtModuleName) + +# make sure pyqtgraph it imported from here so PYQTGRAPH_QT_LIB will always be set +import pyqtgraph as pg # noqa diff --git a/modules/gui_pyqt.py b/modules/gui_pyqt.py index 2af93e88..17d81ca5 100644 --- a/modules/gui_pyqt.py +++ b/modules/gui_pyqt.py @@ -6,23 +6,10 @@ import asyncio import numpy as np -USE_PYQT6 = False -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui - - USE_PYQT6 = True -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - -import qasync - from logger import app_logger from modules.gui_config import GUI_Config from modules.pyqt.pyqt_style import PyQtStyle +from modules._pyqt import USE_PYQT6, QtCore, QtWidgets, QtGui, qasync from modules.utils.timer import Timer, log_timers diff --git a/modules/pyqt/graph/pyqt_base_map.py b/modules/pyqt/graph/pyqt_base_map.py index 8f6560ab..fd27bd20 100644 --- a/modules/pyqt/graph/pyqt_base_map.py +++ b/modules/pyqt/graph/pyqt_base_map.py @@ -1,17 +1,6 @@ import numpy as np -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - -import pyqtgraph as pg -from qasync import asyncSlot - +from modules._pyqt import QtCore, QtWidgets, pg, qasync from modules.pyqt.pyqt_screen_widget import ScreenWidget pg.setConfigOptions(antialias=True) @@ -162,19 +151,19 @@ def change_move(self): self.move_factor = 1.0 self.move_adjust_mode = False - @asyncSlot() + @qasync.asyncSlot() async def move_x_plus(self): await self.move_x(+self.zoom / 2) - @asyncSlot() + @qasync.asyncSlot() async def move_x_minus(self): await self.move_x(-self.zoom / 2) - @asyncSlot() + @qasync.asyncSlot() async def move_y_plus(self): await self.move_y(+self.zoom / 2) - @asyncSlot() + @qasync.asyncSlot() async def move_y_minus(self): await self.move_y(-self.zoom / 2) @@ -186,13 +175,13 @@ async def move_y(self, delta): self.move_pos["y"] += delta await self.update_extra() - @asyncSlot() + @qasync.asyncSlot() async def zoom_plus(self): self.zoom /= 2 self.zoomlevel += 1 await self.update_extra() - @asyncSlot() + @qasync.asyncSlot() async def zoom_minus(self): self.zoom *= 2 self.zoomlevel -= 1 diff --git a/modules/pyqt/graph/pyqt_course_profile.py b/modules/pyqt/graph/pyqt_course_profile.py index 7f5414e6..dbc410cd 100644 --- a/modules/pyqt/graph/pyqt_course_profile.py +++ b/modules/pyqt/graph/pyqt_course_profile.py @@ -1,15 +1,6 @@ import numpy as np -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - -import pyqtgraph as pg +from modules._pyqt import QtGui, pg pg.setConfigOptions(antialias=True) pg.setConfigOption("background", "w") diff --git a/modules/pyqt/graph/pyqt_map.py b/modules/pyqt/graph/pyqt_map.py index 82b6a072..5f09925d 100644 --- a/modules/pyqt/graph/pyqt_map.py +++ b/modules/pyqt/graph/pyqt_map.py @@ -7,19 +7,8 @@ import numpy as np from PIL import Image -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - -import pyqtgraph as pg -from qasync import asyncSlot - from logger import app_logger +from modules._pyqt import QtCore, QtGui, pg, qasync from modules.pyqt.pyqt_cuesheet_widget import CueSheetWidget from modules.pyqt.graph.pyqtgraph.CoursePlotItem import CoursePlotItem from modules.utils.timer import Timer, log_timers @@ -585,7 +574,7 @@ def init_course(self): self.course_loaded = False self.resizeEvent(None) - @asyncSlot() + @qasync.asyncSlot() async def search_route(self): if self.lock_status: return diff --git a/modules/pyqt/graph/pyqt_value_graph.py b/modules/pyqt/graph/pyqt_value_graph.py index 24033f84..ae99b14d 100644 --- a/modules/pyqt/graph/pyqt_value_graph.py +++ b/modules/pyqt/graph/pyqt_value_graph.py @@ -1,6 +1,6 @@ import numpy as np -import pyqtgraph as pg +from modules._pyqt import pg from modules.pyqt.pyqt_screen_widget import ScreenWidget pg.setConfigOptions(antialias=True) diff --git a/modules/pyqt/menu/pyqt_adjust_widget.py b/modules/pyqt/menu/pyqt_adjust_widget.py index cf940577..e8addb5f 100644 --- a/modules/pyqt/menu/pyqt_adjust_widget.py +++ b/modules/pyqt/menu/pyqt_adjust_widget.py @@ -1,15 +1,5 @@ -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - -from qasync import asyncSlot - from logger import app_logger +from modules._pyqt import QtWidgets, qasync from .pyqt_menu_widget import MenuWidget ################################## @@ -89,7 +79,7 @@ def digit_clicked(self): self.display.setText("") self.display.setText(self.display.text() + str(digit_value)) - @asyncSlot() + @qasync.asyncSlot() async def set_value(self): value = self.display.text() if value == "": diff --git a/modules/pyqt/menu/pyqt_course_menu_widget.py b/modules/pyqt/menu/pyqt_course_menu_widget.py index d2b701fc..93ca0ced 100644 --- a/modules/pyqt/menu/pyqt_course_menu_widget.py +++ b/modules/pyqt/menu/pyqt_course_menu_widget.py @@ -1,17 +1,8 @@ -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - import asyncio import os import shutil -from qasync import asyncSlot +from modules._pyqt import QtCore, QtWidgets, QtGui, qasync from .pyqt_menu_widget import MenuWidget, ListWidget, ListItemWidget @@ -57,12 +48,12 @@ def setup_menu(self): def preprocess(self): self.onoff_course_cancel_button() - @asyncSlot() + @qasync.asyncSlot() async def load_local_courses(self): await self.change_course_page("Local Storage") await self.parentWidget().widget(self.child_index).list_local_courses() - @asyncSlot() + @qasync.asyncSlot() async def load_rwgps_courses(self): asyncio.gather( self.change_course_page("Ride with GPS"), @@ -90,7 +81,7 @@ def cancel_course(self, replace=False): self.config.logger.reset_course(delete_course_file=True, replace=replace) self.onoff_course_cancel_button() - @asyncSlot() + @qasync.asyncSlot() async def receive_route(self): self.config.gui.show_dialog_cancel_only( self.cancel_receive_route, "Share directions > Bluetooth..." @@ -137,7 +128,7 @@ async def receive_route(self): stdout, stderr = await self.proc_receive_route.communicate() - @asyncSlot() + @qasync.asyncSlot() async def cancel_receive_route(self): self.is_check_folder = False if self.proc_receive_route.returncode is None: @@ -198,20 +189,20 @@ def setup_menu_extra(self): self.vertical_scrollbar = self.list.verticalScrollBar() self.vertical_scrollbar.valueChanged.connect(self.detect_bottom) - @asyncSlot(int) + @qasync.asyncSlot(int) async def detect_bottom(self, value): if self.list_type == "Ride with GPS": if value == self.vertical_scrollbar.maximum(): await self.list_ride_with_gps(add=True) - @asyncSlot() + @qasync.asyncSlot() async def button_func(self): if self.list_type == "Local Storage": self.set_course() elif self.list_type == "Ride with GPS": await self.change_course_detail_page() - @asyncSlot() + @qasync.asyncSlot() async def change_course_detail_page(self): if self.selected_item is None: return @@ -430,7 +421,7 @@ async def load_images(self): def on_back_menu(self): self.timer.stop() - @asyncSlot() + @qasync.asyncSlot() async def update_display(self): if self.check_all_image_and_draw(): self.timer.stop() diff --git a/modules/pyqt/menu/pyqt_map_menu_widget.py b/modules/pyqt/menu/pyqt_map_menu_widget.py index f6812041..38c580b8 100644 --- a/modules/pyqt/menu/pyqt_map_menu_widget.py +++ b/modules/pyqt/menu/pyqt_map_menu_widget.py @@ -1,14 +1,5 @@ import asyncio -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - from .pyqt_menu_widget import MenuWidget, ListWidget diff --git a/modules/pyqt/menu/pyqt_menu_widget.py b/modules/pyqt/menu/pyqt_menu_widget.py index 8988ebf0..ccbd486c 100644 --- a/modules/pyqt/menu/pyqt_menu_widget.py +++ b/modules/pyqt/menu/pyqt_menu_widget.py @@ -1,14 +1,4 @@ -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - -from qasync import asyncSlot - +from modules._pyqt import QtCore, QtWidgets, QtGui, qasync ################################# # Menu @@ -511,7 +501,7 @@ def connect_buttons(self): self.list.itemSelectionChanged.connect(self.changed_item) self.list.itemClicked.connect(self.button_func) - @asyncSlot() + @qasync.asyncSlot() async def button_func(self): await self.button_func_extra() self.back() @@ -675,15 +665,15 @@ def setup_menu(self): ) self.add_buttons(button_conf) - @asyncSlot() + @qasync.asyncSlot() async def strava_upload(self): await self.button["Strava"].run(self.config.network.api.strava_upload) - @asyncSlot() + @qasync.asyncSlot() async def garmin_upload(self): await self.button["Garmin"].run(self.config.network.api.garmin_upload) - @asyncSlot() + @qasync.asyncSlot() async def rwgps_upload(self): await self.button["Ride with GPS"].run(self.config.network.api.rwgps_upload) diff --git a/modules/pyqt/menu/pyqt_profile_widget.py b/modules/pyqt/menu/pyqt_profile_widget.py index c476fd00..4c836f0b 100644 --- a/modules/pyqt/menu/pyqt_profile_widget.py +++ b/modules/pyqt/menu/pyqt_profile_widget.py @@ -1,12 +1,3 @@ -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - from .pyqt_menu_widget import MenuWidget diff --git a/modules/pyqt/menu/pyqt_sensor_menu_widget.py b/modules/pyqt/menu/pyqt_sensor_menu_widget.py index ac3cb467..5400ff4e 100644 --- a/modules/pyqt/menu/pyqt_sensor_menu_widget.py +++ b/modules/pyqt/menu/pyqt_sensor_menu_widget.py @@ -1,15 +1,7 @@ -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - -from .pyqt_menu_widget import MenuWidget, ListWidget, ListItemWidget from logger import app_logger +from modules._pyqt import QtCore, QtWidgets, QtGui import modules.pyqt.pyqt_multiscan_widget as pyqt_multiscan +from .pyqt_menu_widget import MenuWidget, ListWidget, ListItemWidget class SensorMenuWidget(MenuWidget): diff --git a/modules/pyqt/menu/pyqt_system_menu_widget.py b/modules/pyqt/menu/pyqt_system_menu_widget.py index 46ed07cc..8f19bf76 100644 --- a/modules/pyqt/menu/pyqt_system_menu_widget.py +++ b/modules/pyqt/menu/pyqt_system_menu_widget.py @@ -1,16 +1,4 @@ -import os - -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui - -from qasync import asyncSlot - +from modules._pyqt import QtWidgets, QtGui, qasync from .pyqt_menu_widget import MenuWidget, ListWidget @@ -103,7 +91,7 @@ def show_ip_address(self): # Button is OK only self.config.gui.show_dialog_ok_only(None, self.config.G_IP_ADDRESS) - @asyncSlot() + @qasync.asyncSlot() async def onoff_ble_uart_service(self, change=True): if change: await self.config.ble_uart.on_off_uart_service() diff --git a/modules/pyqt/pyqt_button_box_widget.py b/modules/pyqt/pyqt_button_box_widget.py index df7de2d8..d2a72834 100644 --- a/modules/pyqt/pyqt_button_box_widget.py +++ b/modules/pyqt/pyqt_button_box_widget.py @@ -1,16 +1,5 @@ from logger import app_logger - -USE_PYQT6 = False -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui - - USE_PYQT6 = True -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui +from modules._pyqt import QtWidgets, QtGui class ButtonBoxWidget(QtWidgets.QWidget): diff --git a/modules/pyqt/pyqt_cuesheet_widget.py b/modules/pyqt/pyqt_cuesheet_widget.py index c6c72d49..b38b95e6 100644 --- a/modules/pyqt/pyqt_cuesheet_widget.py +++ b/modules/pyqt/pyqt_cuesheet_widget.py @@ -1,11 +1,4 @@ -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets - import PyQt6.QtGui as QtGui -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - import PyQt5.QtGui as QtGui +from modules._pyqt import QtCore, QtWidgets, QtGui from .pyqt_screen_widget import ScreenWidget diff --git a/modules/pyqt/pyqt_graph_debug.py b/modules/pyqt/pyqt_graph_debug.py index 19d0e640..28729c11 100644 --- a/modules/pyqt/pyqt_graph_debug.py +++ b/modules/pyqt/pyqt_graph_debug.py @@ -1,6 +1,6 @@ import numpy as np -import pyqtgraph as pg +from modules._pyqt import pg from .pyqt_screen_widget import ScreenWidget pg.setConfigOptions(antialias=True) diff --git a/modules/pyqt/pyqt_item.py b/modules/pyqt/pyqt_item.py index 61bb314e..3c05ce2a 100644 --- a/modules/pyqt/pyqt_item.py +++ b/modules/pyqt/pyqt_item.py @@ -1,16 +1,9 @@ import time -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtGui as QtGui - import PyQt6.QtWidgets as QtWidgets -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtGui as QtGui - import PyQt5.QtWidgets as QtWidgets - import numpy as np +from modules._pyqt import QtWidgets + ################################# # Item Class diff --git a/modules/pyqt/pyqt_screen_widget.py b/modules/pyqt/pyqt_screen_widget.py index fdede2aa..bff5cc8c 100644 --- a/modules/pyqt/pyqt_screen_widget.py +++ b/modules/pyqt/pyqt_screen_widget.py @@ -1,13 +1,5 @@ from logger import app_logger - -try: - import PyQt6.QtCore as QtCore - import PyQt6.QtWidgets as QtWidgets -except ImportError: - import PyQt5.QtCore as QtCore - import PyQt5.QtWidgets as QtWidgets - -from qasync import asyncSlot +from modules._pyqt import QtCore, QtWidgets, qasync from .pyqt_item import Item @@ -148,7 +140,7 @@ def add_items(self): def add_extra(self): pass - @asyncSlot() + @qasync.asyncSlot() async def update_display(self): if self.items is None: return