From cbf101aed8ede842bfb27675768a03c090e668c5 Mon Sep 17 00:00:00 2001 From: xnegativx Date: Thu, 7 Sep 2023 21:24:14 +0200 Subject: [PATCH] remove non-needed path manipulation + clean code and naming --- modules/config.py | 44 ++++---------------- modules/gui_config.py | 4 -- modules/helper/setting.py | 6 --- modules/pyqt/menu/pyqt_course_menu_widget.py | 8 ++-- modules/pyqt/menu/pyqt_menu_widget.py | 25 ++++------- modules/pyqt/menu/pyqt_sensor_menu_widget.py | 5 +-- modules/pyqt/pyqt_button_box_widget.py | 23 ++++------ 7 files changed, 30 insertions(+), 85 deletions(-) diff --git a/modules/config.py b/modules/config.py index 8d406822..a30e303e 100644 --- a/modules/config.py +++ b/modules/config.py @@ -78,9 +78,6 @@ class Config: G_UNIT_MODEL = "" G_UNIT_HARDWARE = "" - # install_dir - G_INSTALL_PATH = os.path.join(os.path.expanduser("~"), "pizero_bikecomputer") - # layout def G_LAYOUT_FILE = "layout.yaml" @@ -709,20 +706,6 @@ def __init__(self): self.setting = Setting(self) self.setting.read() - # set dir - if self.G_IS_RASPI: - self.G_SCREENSHOT_DIR = os.path.join( - self.G_INSTALL_PATH, self.G_SCREENSHOT_DIR - ) - self.G_LOG_DIR = os.path.join(self.G_INSTALL_PATH, self.G_LOG_DIR) - self.G_LOG_DB = os.path.join(self.G_INSTALL_PATH, self.G_LOG_DB) - self.G_LOG_DEBUG_FILE = os.path.join(self.G_INSTALL_PATH, self.G_LOG_DEBUG_FILE) - self.G_LAYOUT_FILE = os.path.join(self.G_INSTALL_PATH, self.G_LAYOUT_FILE) - self.G_COURSE_DIR = os.path.join(self.G_INSTALL_PATH, self.G_COURSE_DIR) - self.G_COURSE_FILE_PATH = os.path.join( - self.G_INSTALL_PATH, self.G_COURSE_FILE_PATH - ) - # make sure all folders exist os.makedirs(self.G_SCREENSHOT_DIR, exist_ok=True) os.makedirs(self.G_LOG_DIR, exist_ok=True) @@ -738,11 +721,6 @@ def __init__(self): # layout file if not os.path.exists(self.G_LAYOUT_FILE): default_layout_file = os.path.join("layouts", "layout-cycling.yaml") - if self.G_IS_RASPI: - default_layout_file = os.path.join( - self.G_INSTALL_PATH, default_layout_file - ) - shutil.copy(default_layout_file, self.G_LAYOUT_FILE) # font file @@ -1026,34 +1004,30 @@ async def quit(self): def poweroff(self): if self.G_IS_RASPI: - cmd = ["sudo", "systemctl", "start", "pizero_bikecomputer_shutdown.service"] - exec_cmd(cmd) + exec_cmd( + ["sudo", "systemctl", "start", "pizero_bikecomputer_shutdown.service"] + ) def reboot(self): if self.G_IS_RASPI: - cmd = ["sudo", "reboot"] - exec_cmd(cmd) + exec_cmd(["sudo", "reboot"]) def hardware_wifi_bt_on(self): if self.G_IS_RASPI: - cmd = [os.path.join(self.G_INSTALL_PATH, "scripts/comment_out.sh")] - exec_cmd(cmd) + exec_cmd(["scripts/comment_out.sh"]) def hardware_wifi_bt_off(self): if self.G_IS_RASPI: - cmd = [os.path.join(self.G_INSTALL_PATH, "scripts/uncomment.sh")] - exec_cmd(cmd) + exec_cmd(["scripts/uncomment.sh"]) def update_application(self): if self.G_IS_RASPI: - cmd = ["git", "pull", "origin", "master"] - exec_cmd(cmd) + exec_cmd(["git", "pull", "origin", "master"]) self.restart_application() def restart_application(self): if self.G_IS_RASPI: - cmd = ["sudo", "systemctl", "restart", "pizero_bikecomputer.service"] - exec_cmd(cmd) + exec_cmd(["sudo", "systemctl", "restart", "pizero_bikecomputer"]) def detect_network(self): try: @@ -1082,7 +1056,7 @@ def get_wifi_bt_status(self): status[l["type"]] = True except: pass - return (status["wlan"], status["bluetooth"]) + return status["wlan"], status["bluetooth"] def onoff_wifi_bt(self, key=None): # in the future, manage with pycomman diff --git a/modules/gui_config.py b/modules/gui_config.py index 72912ea8..684c5ddf 100644 --- a/modules/gui_config.py +++ b/modules/gui_config.py @@ -347,10 +347,6 @@ def __init__(self, config): if os.path.exists(self.config.G_LAYOUT_FILE): self.read_layout() - self.icon_dir = "" - if self.config.G_IS_RASPI: - self.icon_dir = self.config.G_INSTALL_PATH - def get_screen_shape(self, p): remove_bytes = 0 if self.config.display.has_color(): diff --git a/modules/helper/setting.py b/modules/helper/setting.py index f8dfcf11..77f30239 100644 --- a/modules/helper/setting.py +++ b/modules/helper/setting.py @@ -25,12 +25,6 @@ def __init__(self, config): self.config = config self.config_parser = configparser.ConfigParser() - if self.config.G_IS_RASPI: - self.config_file = self.config.G_INSTALL_PATH + self.config_file - self.config_pickle_file = ( - self.config.G_INSTALL_PATH + self.config_pickle_file - ) - def read(self): if os.path.exists(self.config_file): self.read_config() diff --git a/modules/pyqt/menu/pyqt_course_menu_widget.py b/modules/pyqt/menu/pyqt_course_menu_widget.py index 93ca0ced..e98142b9 100644 --- a/modules/pyqt/menu/pyqt_course_menu_widget.py +++ b/modules/pyqt/menu/pyqt_course_menu_widget.py @@ -308,8 +308,8 @@ def add_extra(self): self.outer_layout.addStretch() self.outer_layout.addWidget(self.right_icon) - def set_info(self, **kargs): - self.list_info = kargs.copy() + def set_info(self, **kwargs): + self.list_info = kwargs.copy() self.title_label.setText(self.list_info["name"]) if self.list_type == "Ride with GPS": self.detail_label.setText( @@ -378,9 +378,7 @@ def setup_menu(self): def enable_next_button(self): self.next_button.setEnabled(True) - self.next_button.setIcon( - QtGui.QIcon(self.config.gui.gui_config.icon_dir + "img/forward_white.svg") - ) + self.next_button.setIcon(QtGui.QIcon("img/forward_white.svg")) self.next_button.setIconSize(QtCore.QSize(20, 20)) self.next_button.setProperty("style", "menu") self.next_button.setStyleSheet( diff --git a/modules/pyqt/menu/pyqt_menu_widget.py b/modules/pyqt/menu/pyqt_menu_widget.py index ccbd486c..8639d0c9 100644 --- a/modules/pyqt/menu/pyqt_menu_widget.py +++ b/modules/pyqt/menu/pyqt_menu_widget.py @@ -14,17 +14,14 @@ class MenuWidget(QtWidgets.QWidget): button = {} menu_layout = None + icon_x = 40 + icon_y = 32 logo_size = 30 def __init__(self, parent, page_name, config): QtWidgets.QWidget.__init__(self, parent=parent) self.config = config self.page_name = page_name - self.icon = QtGui.QIcon( - self.config.gui.gui_config.icon_dir + "img/back_white.svg" - ) - self.icon_x = 40 - self.icon_y = 32 self.setup_ui() @@ -35,8 +32,7 @@ def setup_ui(self): self.top_bar = QtWidgets.QWidget(self) self.top_bar.setStyleSheet(self.config.gui.style.G_GUI_PYQT_menu_topbar) - self.back_button = QtWidgets.QPushButton() - self.back_button.setIcon(self.icon) + self.back_button = QtWidgets.QPushButton(QtGui.QIcon("img/back_white.svg"), "") self.back_button.setIconSize(QtCore.QSize(20, 20)) self.back_button.setProperty("style", "menu") self.back_button.setStyleSheet( @@ -181,10 +177,10 @@ def back(self): def on_back_menu(self): pass - def change_page(self, page, preprocess=False, **kargs): + def change_page(self, page, preprocess=False, **kwargs): index = self.config.gui.gui_config.G_GUI_INDEX[page] if preprocess: - self.parentWidget().widget(index).preprocess(**kargs) + self.parentWidget().widget(index).preprocess(**kwargs) self.config.gui.change_menu_page(index) class MenuButton(QtWidgets.QPushButton): @@ -526,9 +522,9 @@ def resizeEvent(self, event): def resize_extra(self): pass - def preprocess(self, **kargs): - self.list_type = kargs.get("list_type") - reset = kargs.get("reset", False) + def preprocess(self, **kwargs): + self.list_type = kwargs.get("list_type") + reset = kwargs.get("reset", False) if reset: self.selected_item = None self.list.clear() @@ -601,16 +597,13 @@ def add_extra(self): self.inner_layout, self.config.gui.gui_config.align_left ) - def set_info(self, **kargs): + def set_info(self, **kwargs): pass def keyPressEvent(self, e): if e.key() == self.config.gui.gui_config.key_space: self.enter_signal.emit() - def set_icon(self, image_path): - self.icon.setPixmap(QtGui.QPixmap(image_path).scaled(30, 30)) - def resizeEvent(self, event): h = self.size().height() for text, fsize in zip( diff --git a/modules/pyqt/menu/pyqt_sensor_menu_widget.py b/modules/pyqt/menu/pyqt_sensor_menu_widget.py index 5400ff4e..8aff4d19 100644 --- a/modules/pyqt/menu/pyqt_sensor_menu_widget.py +++ b/modules/pyqt/menu/pyqt_sensor_menu_widget.py @@ -165,7 +165,6 @@ def update_display(self): status=status, ) self.add_list_item(ant_item) - # ant_item.set_icon('img/ant.png') class ANTListItemWidget(ListItemWidget): @@ -185,8 +184,8 @@ def add_extra(self): # self.enter_signal.connect(self.parentWidget().connect_ant_sensor) self.enter_signal.connect(self.parentWidget().button_func) - def set_info(self, **kargs): # ant_id, ant_type): - self.list_info = kargs.copy() + def set_info(self, **kwargs): # ant_id, ant_type): + self.list_info = kwargs.copy() self.detail_label.setText(" ID: " + self.list_info["id"]) status_str = "" if self.list_info["status"]: diff --git a/modules/pyqt/pyqt_button_box_widget.py b/modules/pyqt/pyqt_button_box_widget.py index d2a72834..bf1425e9 100644 --- a/modules/pyqt/pyqt_button_box_widget.py +++ b/modules/pyqt/pyqt_button_box_widget.py @@ -26,21 +26,14 @@ def setup_ui(self): self.show() self.setAutoFillBackground(True) - self.start_button = QtWidgets.QPushButton( - QtGui.QIcon(self.config.gui.gui_config.icon_dir + "img/next_white.png"), "" - ) - self.lap_button = QtWidgets.QPushButton( - QtGui.QIcon(self.config.gui.gui_config.icon_dir + "img/lap_white.png"), "" - ) - self.menu_button = QtWidgets.QPushButton( - QtGui.QIcon(self.config.gui.gui_config.icon_dir + "img/menu.png"), "" - ) + self.start_button = QtWidgets.QPushButton(QtGui.QIcon("img/next_white.png"), "") + self.lap_button = QtWidgets.QPushButton(QtGui.QIcon("img/lap_white.png"), "") + self.menu_button = QtWidgets.QPushButton(QtGui.QIcon("img/menu.png"), "") self.scrollnext_button = QtWidgets.QPushButton( - QtGui.QIcon(self.config.gui.gui_config.icon_dir + "img/forward_black.svg"), - "", + QtGui.QIcon("img/forward_black.svg"), "" ) self.scrollprev_button = QtWidgets.QPushButton( - QtGui.QIcon(self.config.gui.gui_config.icon_dir + "img/back_black.svg"), "" + QtGui.QIcon("img/back_black.svg"), "" ) self.scrollprev_button.setFixedSize(60, 30) @@ -124,9 +117,7 @@ def gui_start_and_stop_quit(self): self.config.logger.start_and_stop_manual() def change_start_stop_button(self, status): - icon = QtGui.QIcon(self.config.gui.gui_config.icon_dir + "img/next_white.png") + icon = QtGui.QIcon("img/next_white.png") if status == "START": - icon = QtGui.QIcon( - self.config.gui.gui_config.icon_dir + "img/pause_white.png" - ) + icon = QtGui.QIcon("img/pause_white.png") self.start_button.setIcon(icon)