Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-ingenious committed Jul 12, 2024
1 parent a3d0031 commit 33aefed
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 45 deletions.
23 changes: 14 additions & 9 deletions src/data_recorder_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/python3

import logging
import logger

from panel import Panel

Expand All @@ -23,42 +24,46 @@ 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"])

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/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
Expand Down
23 changes: 14 additions & 9 deletions src/data_recorder_panel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/python3

import os
import logging

import logger
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions src/gnss-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
32 changes: 17 additions & 15 deletions src/left_menu_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -127,17 +127,19 @@ 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())
self.gnss_info_panel.set_visible(not self.gnss_info_panel.get_visible())
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):
Expand All @@ -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):
Expand All @@ -157,29 +159,29 @@ 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):
self.map_panel.set_visible(not self.map_panel.get_visible())
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):
self.recorder_panel.set_visible(not self.recorder_panel.get_visible())
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):
self.compass_panel.set_visible(not self.compass_panel.get_visible())
self.__set_icon(
self.compass_panel,
self.compass_icon,
"gnss-ui/assets/panel_icon_compass(!).svg",
"panel_icon_compass(!).svg",
)
23 changes: 18 additions & 5 deletions src/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
17 changes: 12 additions & 5 deletions src/shumate_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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):
Expand Down

0 comments on commit 33aefed

Please sign in to comment.