Fensterposition merken

This commit is contained in:
Thomas Hooge 2025-07-03 12:47:56 +02:00
parent e94f6df408
commit 5c2f058888
3 changed files with 56 additions and 23 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*~ *~
__pycache__ __pycache__
nmea2000

View File

@ -7,8 +7,12 @@ histpath = ~/.local/lib/obp60
guistyle = fullscreen guistyle = fullscreen
mouseptr = off mouseptr = off
[gui]
win_x = -1
win_y = -1
[bme280] [bme280]
enabled = true enabled = false
port = 1 port = 1
address = 0x76 address = 0x76
@ -96,3 +100,4 @@ type=Rudder
[page10] [page10]
type = SkyView type = SkyView

View File

@ -284,9 +284,12 @@ class Frontend(Gtk.Window):
super().__init__() super().__init__()
self.owndev = device self.owndev = device
self.boatdata = boatdata self.boatdata = boatdata
self._config = cfg['_config']
self._cfgfile = cfg['cfgfile']
self._fullscreen = cfg['guistyle'] == 'fullscreen' self._fullscreen = cfg['guistyle'] == 'fullscreen'
self._mouseptr = cfg['mouseptr'] self._mouseptr = cfg['mouseptr']
self.connect("delete-event", self.on_delete)
self.connect("destroy", self.on_destroy) self.connect("destroy", self.on_destroy)
if self._fullscreen: if self._fullscreen:
@ -306,6 +309,8 @@ class Frontend(Gtk.Window):
self.button_w = 160 self.button_w = 160
self.button_h = 64 self.button_h = 64
else: else:
if cfg['win_x'] >= 0 and cfg['win_y'] >= 0:
self.move(cfg['win_x'], cfg['win_y'])
self.button_round = True self.button_round = True
# Runde Tasten wie beim Original-Gerät # Runde Tasten wie beim Original-Gerät
self.button = { # Mittelpunkt self.button = { # Mittelpunkt
@ -442,7 +447,6 @@ class Frontend(Gtk.Window):
# Falls der Rückgabewert "True" ist, hat die Seite die Taste # Falls der Rückgabewert "True" ist, hat die Seite die Taste
# verarbeitet, die Funktion hier wird damit unterdrückt. # verarbeitet, die Funktion hier wird damit unterdrückt.
# TODO # TODO
print("release")
if self.button_round: if self.button_round:
if (event.x < self.button[1][0] - self.button_radius or event.x > self.button[6][0] + self.button_radius): if (event.x < self.button[1][0] - self.button_radius or event.x > self.button[6][0] + self.button_radius):
return True return True
@ -475,7 +479,7 @@ class Frontend(Gtk.Window):
if self.button_clicked == 2: if self.button_clicked == 2:
# Programmende bei Klicken auf 2 und loslassen auf 1 # Programmende bei Klicken auf 2 und loslassen auf 1
self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH)) self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH))
Gtk.main_quit() self.on_destroy(self)
elif self.button_clicked == 6: elif self.button_clicked == 6:
# Klick auf 6 und loslassen auf 1 ist Tastatursperre # Klick auf 6 und loslassen auf 1 ist Tastatursperre
self.keylock = True self.keylock = True
@ -513,7 +517,22 @@ class Frontend(Gtk.Window):
self.curpage.backlight = not self.curpage.backlight self.curpage.backlight = not self.curpage.backlight
return True return True
def on_delete(self, widget, event):
# Einhängepunkt für zukünftige Erweiterungen
# Hier kann der Vorgang noch durch z.B. Benutzerinteraktion
# abgebrochen werden
print("Window delete event")
return False
def on_destroy(self, widget): def on_destroy(self, widget):
# Letzte Fensterposition speichern
position = self.get_position()
if not self._config.has_section('gui'):
config.add_section('gui')
self._config.set('gui', 'win_x', str(position[0]))
self._config.set('gui', 'win_y', str(position[1]))
with open(self._cfgfile, 'w') as fh:
self._config.write(fh)
Gtk.main_quit() Gtk.main_quit()
def init_profile(config, cfg, boatdata): def init_profile(config, cfg, boatdata):
@ -588,12 +607,20 @@ if __name__ == "__main__":
# Basiskonfiguration aus Datei lesen # Basiskonfiguration aus Datei lesen
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(os.path.join(sys.path[0], cfg['cfgfile'])) config.read(os.path.join(sys.path[0], cfg['cfgfile']))
cfg['_config'] = config # Objekt zum späteren schreiben
cfg['deviceid'] = config.getint('system', 'deviceid') cfg['deviceid'] = config.getint('system', 'deviceid')
cfg['simulation'] = config.getboolean('system', 'simulation') cfg['simulation'] = config.getboolean('system', 'simulation')
cfg['histpath'] = os.path.expanduser(config.get('system', 'histpath')) cfg['histpath'] = os.path.expanduser(config.get('system', 'histpath'))
cfg['guistyle'] = config.get('system', 'guistyle') cfg['guistyle'] = config.get('system', 'guistyle')
cfg['mouseptr'] = config.getboolean('system', 'mouseptr')
print("Setting GUI style to '{}'".format(cfg['guistyle'])) print("Setting GUI style to '{}'".format(cfg['guistyle']))
cfg['mouseptr'] = config.getboolean('system', 'mouseptr')
try:
cfg['win_x'] = config.getint('gui', 'win_x')
cfg['win_y'] = config.getint('gui', 'win_y')
except (configparser.NoSectionError, configparser.NoOptionError):
# Keine vorgegebene Position
cfg['win_x'] = -1
cfg['win_y'] = -1
cfg['gps'] = config.getboolean('gps', 'enabled') cfg['gps'] = config.getboolean('gps', 'enabled')
if cfg['gps']: if cfg['gps']: