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__
nmea2000

View File

@ -7,8 +7,12 @@ histpath = ~/.local/lib/obp60
guistyle = fullscreen
mouseptr = off
[gui]
win_x = -1
win_y = -1
[bme280]
enabled = true
enabled = false
port = 1
address = 0x76
@ -59,40 +63,41 @@ number_of_pages = 10
start_page = 1
[page1]
type=Clock
type = Clock
[page2]
type=Barograph
type = Barograph
[page3]
type=Anchor
type = Anchor
[page4]
type=Autobahn
type = Autobahn
[page5]
type=ApparentWind
type = ApparentWind
[page6]
type=TwoValues
value1=LAT
value2=LON
type = TwoValues
value1 = LAT
value2 = LON
[page7]
type=ThreeValues
value1=COG
value2=STW
value3=DBT
type = ThreeValues
value1 = COG
value2 = STW
value3 = DBT
[page8]
type=FourValues
value1=AWA
value2=AWS
value3=COG
value4=STW
type = FourValues
value1 = AWA
value2 = AWS
value3 = COG
value4 = STW
[page9]
type=Rudder
type = Rudder
[page10]
type=SkyView
type = SkyView

View File

@ -284,9 +284,12 @@ class Frontend(Gtk.Window):
super().__init__()
self.owndev = device
self.boatdata = boatdata
self._config = cfg['_config']
self._cfgfile = cfg['cfgfile']
self._fullscreen = cfg['guistyle'] == 'fullscreen'
self._mouseptr = cfg['mouseptr']
self.connect("delete-event", self.on_delete)
self.connect("destroy", self.on_destroy)
if self._fullscreen:
@ -306,6 +309,8 @@ class Frontend(Gtk.Window):
self.button_w = 160
self.button_h = 64
else:
if cfg['win_x'] >= 0 and cfg['win_y'] >= 0:
self.move(cfg['win_x'], cfg['win_y'])
self.button_round = True
# Runde Tasten wie beim Original-Gerät
self.button = { # Mittelpunkt
@ -442,7 +447,6 @@ class Frontend(Gtk.Window):
# Falls der Rückgabewert "True" ist, hat die Seite die Taste
# verarbeitet, die Funktion hier wird damit unterdrückt.
# TODO
print("release")
if self.button_round:
if (event.x < self.button[1][0] - self.button_radius or event.x > self.button[6][0] + self.button_radius):
return True
@ -475,7 +479,7 @@ class Frontend(Gtk.Window):
if self.button_clicked == 2:
# Programmende bei Klicken auf 2 und loslassen auf 1
self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH))
Gtk.main_quit()
self.on_destroy(self)
elif self.button_clicked == 6:
# Klick auf 6 und loslassen auf 1 ist Tastatursperre
self.keylock = True
@ -513,7 +517,22 @@ class Frontend(Gtk.Window):
self.curpage.backlight = not self.curpage.backlight
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):
# 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()
def init_profile(config, cfg, boatdata):
@ -588,12 +607,20 @@ if __name__ == "__main__":
# Basiskonfiguration aus Datei lesen
config = configparser.ConfigParser()
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['simulation'] = config.getboolean('system', 'simulation')
cfg['histpath'] = os.path.expanduser(config.get('system', 'histpath'))
cfg['guistyle'] = config.get('system', 'guistyle')
cfg['mouseptr'] = config.getboolean('system', 'mouseptr')
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')
if cfg['gps']: