diff --git a/src/data_recorder_dashboard.py b/src/data_recorder_dashboard.py index 90bb0e6..b1762e2 100644 --- a/src/data_recorder_dashboard.py +++ b/src/data_recorder_dashboard.py @@ -1,6 +1,7 @@ #! /usr/bin/python3 import logging +import logger from panel import Panel @@ -23,8 +24,8 @@ def __init__(self, recorder, export_directory="./"): self.recorder = recorder self.export_directory = export_directory - logging.config.fileConfig("gnss-ui/assets/log.ini") - self.logger = logging.getLogger("recorder") + + self.logger = logger.get_logger("recorder") self.set_css_classes(["recording_dashboard", "map_dashboard"]) @@ -32,33 +33,37 @@ def __init__(self, recorder, export_directory="./"): self.start_rec_button_icon = Gtk.Picture() self.start_rec_button_icon.set_filename( - "gnss-ui/assets/circle_dot_round_icon.svg" + self._get_resource_file("circle_dot_round_icon.svg") ) self.start_rec_button_icon_inactive = Gtk.Picture() self.start_rec_button_icon_inactive.set_filename( - "gnss-ui/assets/circle_dot_round_icon_inactive.svg" + self._get_resource_file("circle_dot_round_icon_inactive.svg") ) self.pause_rec_button_icon = Gtk.Picture() - self.pause_rec_button_icon.set_filename("gnss-ui/assets/circle_pause_icon.svg") + self.pause_rec_button_icon.set_filename( + self._get_resource_file("circle_pause_icon.svg") + ) self.stop_rec_button_icon = Gtk.Picture() - self.stop_rec_button_icon.set_filename("gnss-ui/assets/circle_stop_icon.svg") + self.stop_rec_button_icon.set_filename( + self._get_resource_file("circle_stop_icon.svg") + ) self.stop_rec_button_icon_inactive = Gtk.Picture() self.stop_rec_button_icon_inactive.set_filename( - "gnss-ui/assets/circle_stop_icon_inactive.svg" + self._get_resource_file("circle_stop_icon_inactive.svg") ) self.export_rec_button_icon = Gtk.Picture() self.export_rec_button_icon.set_filename( - "gnss-ui/assets/floppy_disk_storage_icon.svg" + self._get_resource_file("floppy_disk_storage_icon.svg") ) self.reset_button_icon = Gtk.Picture() self.reset_button_icon.set_filename( - "gnss-ui/assets/trash_can_delete_remove_icon.svg" + self._get_resource_file("trash_can_delete_remove_icon.svg") ) # start_pause_button diff --git a/src/data_recorder_panel.py b/src/data_recorder_panel.py index 2860976..0d9bd72 100644 --- a/src/data_recorder_panel.py +++ b/src/data_recorder_panel.py @@ -1,5 +1,6 @@ #! /usr/bin/python3 +import os import logging import logger @@ -30,7 +31,7 @@ def __init__(self, recorder, main_window, export_directory="~/.gnss-ui/"): self.selected_recording = None self.dialog = None self.recorder = recorder - self.export_directory = export_directory + self.export_directory = os.path.expanduser(export_directory) self.last_list_selected_ts = 0 @@ -49,34 +50,38 @@ def __init__(self, recorder, main_window, export_directory="~/.gnss-ui/"): self.icons_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) self.start_rec_button_icon = Gtk.Picture() - self.start_rec_button_icon.set_filename("gnss-ui/assets/record_icon.svg") + self.start_rec_button_icon.set_filename( + self._get_resource_file("record_icon.svg") + ) self.start_rec_button_icon_inactive = Gtk.Picture() self.start_rec_button_icon_inactive.set_filename( - "gnss-ui/assets/record_icon_inactive.svg" + self._get_resource_file("record_icon_inactive.svg") ) self.pause_rec_button_icon = Gtk.Picture() self.pause_rec_button_icon.set_filename( - "gnss-ui/assets/pause_recording_icon.svg" + self._get_resource_file("pause_recording_icon.svg") ) self.stop_rec_button_icon = Gtk.Picture() - self.stop_rec_button_icon.set_filename("gnss-ui/assets/stop_recording_icon.svg") + self.stop_rec_button_icon.set_filename( + self._get_resource_file("stop_recording_icon.svg") + ) self.stop_rec_button_icon_inactive = Gtk.Picture() self.stop_rec_button_icon_inactive.set_filename( - "gnss-ui/assets/stop_recording_icon_inactive.svg" + self._get_resource_file("stop_recording_icon_inactive.svg") ) self.export_rec_button_icon = Gtk.Picture() self.export_rec_button_icon.set_filename( - "gnss-ui/assets/floppy_disk_storage_icon.svg" + self._get_resource_file("floppy_disk_storage_icon.svg") ) self.reset_button_icon = Gtk.Picture() self.reset_button_icon.set_filename( - "gnss-ui/assets/trash_can_delete_remove_icon.svg" + self._get_resource_file("trash_can_delete_remove_icon.svg") ) # start_pause_button @@ -386,7 +391,7 @@ def update_recordings_table(self): for recording in recordings: recording_icon = Gtk.Picture() - recording_icon.set_filename("gnss-ui/assets/map_icon.svg") + recording_icon.set_filename(self._get_resource_file("map_icon.svg")) recording_icon.set_css_classes(["recording_icon"]) recording_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) diff --git a/src/gnss-ui.py b/src/gnss-ui.py index d4c6f85..09875b0 100755 --- a/src/gnss-ui.py +++ b/src/gnss-ui.py @@ -65,7 +65,7 @@ Gdk.Display.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER ) -APP_VERSION = "0.10.4" +APP_VERSION = "0.10.5" class PanelRefresher(threading.Thread): @@ -125,7 +125,7 @@ def __init__(self, *args, **kwargs): self.main_box.set_vexpand(True) self.bg_image = Gtk.Picture() - self.bg_image.set_filename("gnss-ui/assets/background.jpg") + self.bg_image.set_filename(self._get_resource_file("background.jpg")) self.bg_image.set_content_fit(Gtk.ContentFit.COVER) self.overlay_box = Gtk.Overlay() @@ -427,6 +427,16 @@ def show_settings_dialog(self, action, param): dialog = PreferencesDialog(self.config) # dialog.set_visible(True) + def _get_resource_file(self, resource_name): + for p in sys.path: + if p.find("gnss-ui/assets") != -1: + if os.path.exists(p + "/" + resource_name): + print(" resource file found: " + p + "/" + resource_name) + return p + "/" + resource_name + + print("no resource file found: " + resource_name) + return None + class MyApp(Adw.Application): def __init__(self, **kwargs): diff --git a/src/left_menu_panel.py b/src/left_menu_panel.py index 533926b..1d04464 100644 --- a/src/left_menu_panel.py +++ b/src/left_menu_panel.py @@ -37,7 +37,7 @@ def __init__( self.__set_icon( self.position_info_panel, self.position_icon, - "gnss-ui/assets/panel_icon_position_info(!).svg", + "panel_icon_position_info(!).svg", ) # Position @@ -54,7 +54,7 @@ def __init__( self.__set_icon( self.satellites_info_panel, self.satellites_icon, - "gnss-ui/assets/panel_icon_satellites_info2(!).svg", + "panel_icon_satellites_info2(!).svg", ) self.satellites_button = Gtk.Button(label="Satellites") self.satellites_button.set_tooltip_text("Toggle Satellites Panel") @@ -70,7 +70,7 @@ def __init__( self.__set_icon( self.satellites_radar_panel, self.satellites_radar_icon, - "gnss-ui/assets/panel_icon_satellites_radar(!).svg", + "panel_icon_satellites_radar(!).svg", ) self.satellites_radar_button = Gtk.Button(label="Satellites Radar") self.satellites_radar_button.set_tooltip_text("Toggle Satellites Radar Panel") @@ -86,7 +86,7 @@ def __init__( self.__set_icon( self.map_panel, self.map_icon, - "gnss-ui/assets/panel_icon_map(!).svg", + "panel_icon_map(!).svg", ) self.map_button = Gtk.Button(label="Map") self.map_button.set_tooltip_text("Toggle Map Panel") @@ -100,7 +100,7 @@ def __init__( self.__set_icon( self.recorder_panel, self.recorder_icon, - "gnss-ui/assets/panel_icon_recorder(!).svg", + "panel_icon_recorder(!).svg", ) self.recorder_button = Gtk.Button(label="Recorder") @@ -109,13 +109,13 @@ def __init__( self.recorder_button.set_child(self.recorder_icon) self.recorder_button.connect("clicked", self.on_recorder_button_pressed) self.append(self.recorder_button) - + # compass self.compass_icon = Gtk.Picture() self.__set_icon( self.compass_panel, self.compass_icon, - "gnss-ui/assets/panel_icon_compass(!).svg", + "panel_icon_compass(!).svg", ) self.compass_button = Gtk.Button(label="Compass") @@ -127,9 +127,11 @@ def __init__( def __set_icon(self, panel, icon, filename_pattern): if panel.get_visible(): - icon.set_filename(filename_pattern.replace("(!)", "")) + filename = filename_pattern.replace("(!)", "") else: - icon.set_filename(filename_pattern.replace("(!)", "_inactive")) + filename = filename_pattern.replace("(!)", "_inactive") + + icon.set_filename(self._get_resource_file(filename)) def on_position_info_button_pressed(self, button): self.position_info_panel.set_visible(not self.position_info_panel.get_visible()) @@ -137,7 +139,7 @@ def on_position_info_button_pressed(self, button): self.__set_icon( self.position_info_panel, self.position_icon, - "gnss-ui/assets/panel_icon_position_info(!).svg", + "panel_icon_position_info(!).svg", ) def on_satellites_info_button_pressed(self, button): @@ -147,7 +149,7 @@ def on_satellites_info_button_pressed(self, button): self.__set_icon( self.satellites_info_panel, self.satellites_icon, - "gnss-ui/assets/panel_icon_satellites_info2(!).svg", + "panel_icon_satellites_info2(!).svg", ) def on_satellites_radar_button_pressed(self, button): @@ -157,7 +159,7 @@ def on_satellites_radar_button_pressed(self, button): self.__set_icon( self.satellites_radar_panel, self.satellites_radar_icon, - "gnss-ui/assets/panel_icon_satellites_radar(!).svg", + "panel_icon_satellites_radar(!).svg", ) def on_map_button_pressed(self, button): @@ -165,7 +167,7 @@ def on_map_button_pressed(self, button): self.__set_icon( self.map_panel, self.map_icon, - "gnss-ui/assets/panel_icon_map(!).svg", + "panel_icon_map(!).svg", ) def on_recorder_button_pressed(self, button): @@ -173,7 +175,7 @@ def on_recorder_button_pressed(self, button): self.__set_icon( self.recorder_panel, self.recorder_icon, - "gnss-ui/assets/panel_icon_recorder(!).svg", + "panel_icon_recorder(!).svg", ) def on_compass_button_pressed(self, button): @@ -181,5 +183,5 @@ def on_compass_button_pressed(self, button): self.__set_icon( self.compass_panel, self.compass_icon, - "gnss-ui/assets/panel_icon_compass(!).svg", + "panel_icon_compass(!).svg", ) diff --git a/src/panel.py b/src/panel.py index 42f7ecd..418cf7e 100644 --- a/src/panel.py +++ b/src/panel.py @@ -2,14 +2,27 @@ import gi -gi.require_version('Gtk', '4.0') +import sys, os + +gi.require_version("Gtk", "4.0") from gi.repository import Gtk + class ScrolledPanel(Gtk.ScrolledWindow): - def __init__ (self): - super().__init__() #orientation = Gtk.Orientation.VERTICAL) + def __init__(self): + super().__init__() # orientation = Gtk.Orientation.VERTICAL) + class Panel(Gtk.Box): - def __init__ (self): - super().__init__(orientation = Gtk.Orientation.VERTICAL) \ No newline at end of file + def __init__(self): + super().__init__(orientation=Gtk.Orientation.VERTICAL) + + def _get_resource_file(self, resource_name): + for p in sys.path: + if p.find("gnss-ui/assets") != -1: + if os.path.exists(p + "/" + resource_name): + return p + "/" + resource_name + + print("no resource file found: " + resource_name) + return None diff --git a/src/shumate_map.py b/src/shumate_map.py index 8e32f76..db32fa5 100644 --- a/src/shumate_map.py +++ b/src/shumate_map.py @@ -94,7 +94,8 @@ def __init__( self.hint.set_css_classes(["map_hint"]) self.b1_icon = Gtk.Picture() - self.b1_icon.set_filename("gnss-ui/assets/center_icon.svg") + # self.b1_icon.set_filename("gnss-ui/assets/center_icon.svg") + self.b1_icon.set_filename(self._get_resource_file("center_icon.svg")) self.autocenter_map = autocenter_map self.b1 = Gtk.Button(label="Toggle Auto center") @@ -139,7 +140,9 @@ def __init__( self.marker.set_location(self.last_latitude, self.last_longitude) self.marker_icon = Gtk.Image() self.marker_icon.set_css_classes(["map_marker"]) - self.marker_icon.set_from_file("gnss-ui/assets/marker_icon_large.png") + # self.marker_icon.set_from_file("gnss-ui/assets/marker_icon_large.png") + self.marker_icon.set_from_file(self._get_resource_file("marker_icon_large.png")) + self.marker.set_child(self.marker_icon) self.marker_layer.add_marker(self.marker) @@ -151,7 +154,7 @@ def __init__( self.overlay.add_overlay(self.position_dashboard) self.overlay.add_overlay(self.satellites_radar_dashboard) self.overlay.add_overlay(self.compass_dashboard) - + if self.recorder_dashboard != None: self.overlay.add_overlay(self.recorder_dashboard) @@ -165,10 +168,14 @@ def on_autocenter_button_pressed(self, button): self.autocenter_map = not self.autocenter_map if self.autocenter_map == True: - self.b1_icon.set_filename("gnss-ui/assets/center_icon.svg") + # self.b1_icon.set_filename("gnss-ui/assets/center_icon.svg") + self.b1_icon.set_filename(self._get_resource_file("center_icon.svg")) self.go_to_location(self.last_latitude, self.last_longitude) else: - self.b1_icon.set_filename("gnss-ui/assets/center_icon_inactive.svg") + # self.b1_icon.set_filename("gnss-ui/assets/center_icon_inactive.svg") + self.b1_icon.set_filename( + self._get_resource_file("center_icon_inactive.svg") + ) def go_to_location(self, latitude, longitude): if math.isnan(latitude) or math.isnan(longitude):