Skip to content

Commit

Permalink
remove non-needed path manipulation + clean code and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptosiek committed Sep 27, 2023
1 parent d78b74a commit cbf101a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 85 deletions.
44 changes: 9 additions & 35 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions modules/gui_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
6 changes: 0 additions & 6 deletions modules/helper/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 3 additions & 5 deletions modules/pyqt/menu/pyqt_course_menu_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
25 changes: 9 additions & 16 deletions modules/pyqt/menu/pyqt_menu_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions modules/pyqt/menu/pyqt_sensor_menu_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"]:
Expand Down
23 changes: 7 additions & 16 deletions modules/pyqt/pyqt_button_box_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit cbf101a

Please sign in to comment.