Verbesserungen für Clock-Seite, neue allgemeine display_new Methode
This commit is contained in:
parent
e7a96390f2
commit
f47379b6d3
|
@ -397,7 +397,9 @@ class Frontend(Gtk.Window):
|
|||
self.keylock = False
|
||||
self.pages = profile
|
||||
self.pageno = 1
|
||||
self.pageno_last = 1
|
||||
self.curpage = self.pages[self.pageno]
|
||||
self.curpage.display_new()
|
||||
|
||||
print("Wische von 2 nach 1 für Programmende")
|
||||
|
||||
|
@ -556,6 +558,7 @@ class Frontend(Gtk.Window):
|
|||
else:
|
||||
self.pageno = len(self.pages) - 1
|
||||
self.curpage = self.pages[self.pageno]
|
||||
self.curpage.display_new()
|
||||
elif selected == 4:
|
||||
if not self.curpage.handle_key(4):
|
||||
if self.pageno < len(self.pages) - 1:
|
||||
|
@ -564,6 +567,7 @@ class Frontend(Gtk.Window):
|
|||
self.pageno = 1
|
||||
# hoch / eine Seite zurück
|
||||
self.curpage = self.pages[self.pageno]
|
||||
self.curpage.display_new()
|
||||
elif selected == 5:
|
||||
# Ok/Menü
|
||||
if self.button_clicked == 4:
|
||||
|
@ -737,6 +741,9 @@ if __name__ == "__main__":
|
|||
history = History("press", 75)
|
||||
boatdata.addHistory(history, "press")
|
||||
|
||||
# Zeitzonenoffset, aus Kompatibilitätsgründen zum OBP60
|
||||
cfg['tzoffset'] = config.getint('settings', 'timezone')
|
||||
|
||||
# Tracker data
|
||||
cfg['tracker']['type'] = config.get('tracker', 'type').upper()
|
||||
cfg['tracker']['host'] = config.get('tracker', 'host')
|
||||
|
|
|
@ -15,7 +15,7 @@ import os
|
|||
import cairo
|
||||
import math
|
||||
from .page import Page
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone, timedelta
|
||||
import astral
|
||||
|
||||
class Clock(Page):
|
||||
|
@ -27,8 +27,11 @@ class Clock(Page):
|
|||
self.mode = ('A', 'D', 'T') # (A)nalog (D)igital (T)imer
|
||||
self.modeindex = 1
|
||||
self.utc = True
|
||||
self.location = astral.Location(('Norderstedt', 'Germany', 53.710105, 10.0574378, 'UTC'))
|
||||
self.location.astral = astral.Astral()
|
||||
self.tzoffset = cfg['tzoffset']
|
||||
self.bv_lat = boatdata.getRef("LAT")
|
||||
self.bv_lon = boatdata.getRef("LON")
|
||||
# Eine beliebiger Ort damit irgendetwas gesetzt ist
|
||||
self.set_location('Norderstedt', 'Germany', 53.710105, 10.0574378)
|
||||
self.bgimg = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "unknown.png"))
|
||||
|
||||
def handle_key(self, buttonid):
|
||||
|
@ -43,6 +46,25 @@ class Clock(Page):
|
|||
return True
|
||||
return False
|
||||
|
||||
def set_location(self, city, country, lat, lon):
|
||||
try:
|
||||
# Astral ab Debian 13
|
||||
self.location = astral.LocationInfo((city, country, lat, lon, 'UTC'))
|
||||
except AttributeError:
|
||||
# Astral bis Debian 12 (Version 1.6.1)
|
||||
self.location = astral.Location((city, country, lat, lon, 'UTC'))
|
||||
self.location.astral = astral.Astral()
|
||||
|
||||
def display_new(self):
|
||||
"""
|
||||
Position für Sonnenauf- und Untergang neu ermitteln
|
||||
Machen wir hier einmal je Seitenaufruf, besser wäre es
|
||||
in regelmäßigen Zeitabständen. Das kann dann später implementiert
|
||||
werden.
|
||||
"""
|
||||
if self.bv_lat.valid and self.bv_lon.valid:
|
||||
self.set_location('Ship', 'World', self.bv_lat.getValue, self.bv_lon.getValue, 'UTC')
|
||||
|
||||
def draw(self, ctx):
|
||||
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
|
||||
|
||||
|
@ -56,6 +78,10 @@ class Clock(Page):
|
|||
|
||||
def draw_digital(self, ctx):
|
||||
|
||||
# TODO
|
||||
# Sonnenauf- und Untergang
|
||||
# Zeitzone
|
||||
|
||||
ts = datetime.now()
|
||||
|
||||
ctx.set_font_size(20)
|
||||
|
@ -86,14 +112,15 @@ class Clock(Page):
|
|||
def draw_analog(self, ctx):
|
||||
|
||||
ts = datetime.now()
|
||||
if self.utc:
|
||||
pass
|
||||
# Location ist in UTC definiert
|
||||
sunrise = self.location.sunrise(ts)
|
||||
sunset = self.location.sunset(ts)
|
||||
#print(sunrise)
|
||||
#print(sunset)
|
||||
|
||||
# Datum und Uhrzeit
|
||||
# Sonnenaufgang
|
||||
# Sonnenuntergang
|
||||
if not self.utc:
|
||||
td = timedelta(hours=self.tzoffset)
|
||||
sunrise += td
|
||||
sunset += td
|
||||
|
||||
# Wochentag
|
||||
# ts.strftime('%a')
|
||||
|
@ -112,17 +139,21 @@ class Clock(Page):
|
|||
|
||||
ctx.set_font_size(16)
|
||||
|
||||
# Datum links oben
|
||||
ctx.move_to(10, 65)
|
||||
ctx.show_text(ts.strftime("%d.%m.%Y"))
|
||||
# Uhrzeit links unten
|
||||
ctx.move_to(10, 250)
|
||||
ctx.show_text(ts.strftime("%H:%M"))
|
||||
# Sonnenaufgang rechts oben
|
||||
ctx.move_to(335, 65)
|
||||
ctx.show_text(sunrise.strftime("%H:%M"))
|
||||
# Sonnenuntergang rechts unten
|
||||
ctx.move_to(335, 250)
|
||||
ctx.show_text(sunset.strftime("%H:%M"))
|
||||
ctx.stroke()
|
||||
|
||||
# Horizontal separators
|
||||
# Horizontale Trennlinien
|
||||
ctx.rectangle(0, 149, 60, 3)
|
||||
ctx.rectangle(340, 149, 60, 3)
|
||||
ctx.fill()
|
||||
|
|
|
@ -126,6 +126,13 @@ class Page():
|
|||
ctx.restore()
|
||||
self.hbled = not self.hbled
|
||||
|
||||
def display_new(self):
|
||||
"""
|
||||
Aufruf jedenfalls bei Seitenwechsel.
|
||||
Überladen in spezialisierten Seiten bei Bedarf
|
||||
"""
|
||||
pass
|
||||
|
||||
def draw_header(self, ctx):
|
||||
"""
|
||||
Mögliche Zeichen für aktivierte Funktionen (max. 8)
|
||||
|
|
Loading…
Reference in New Issue