Anker-Konfigurationsseite, erste Versuche mit Menü

This commit is contained in:
Thomas Hooge 2025-07-21 19:59:40 +02:00
parent 664d6c7d49
commit 986d222a98
6 changed files with 175 additions and 30 deletions

48
cfgmenu.py Normal file
View File

@ -0,0 +1,48 @@
"""
Menüsystem für Konfiguration(en)
"""
class MenuItem():
def __init__(self, itmname):
self.name = itmname
self.label = None
self.value = None
self.steps = (1,)
def setValue(self, val):
self.value = val
class Menu():
def __init__(self):
title = None
x = 0
y = 0
w = 100
h = 20
items = []
itm_active = -1 # nothing activated
self._index = -1
def addItem(self, label):
itm = MenuItem(label)
items.append(itm)
class MenuIter():
def __init__(self, menu):
self._items = menu.items
self._class_size = len(self._items)
self._index = 0
def __iter__(self):
return self
def __next__(self):
if self._index < self._class_size:
itm = items[self._index]
self._index += 1
return itm
raise StopIteration

BIN
images/arrow_dn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

BIN
images/arrow_up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B

View File

@ -409,7 +409,7 @@ class Frontend(Gtk.Window):
self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.BLANK_CURSOR))
def run(self):
GLib.timeout_add_seconds(2, self.on_timer)
GLib.timeout_add_seconds(1, self.on_timer)
self.show_all()
Gtk.main()

View File

@ -17,7 +17,7 @@ Daten
- Zeitpunkt des Ankeraus
Darstellung:
- Modi:
- Modi: Normal / Konfiguration
- Anker oben / unten
- Nord ist oben
@ -31,6 +31,7 @@ import os
import cairo
import math
import time
from cfgmenu import Menu
from .page import Page
class Anchor(Page):
@ -67,43 +68,86 @@ class Anchor(Page):
self.alarm = False # Alarm ist ausgelöst und aktiv
self.wind_angle = -1
# Menüsteuerung für Konfiguration
self._mnu = {
# Lfd. Name, curr unit steps type: numeric, on/off
# TODO Das sollte eine Klasse werden!
'chain': [1, "Chain out", 0, "m", (1, 5, 10), (0, 200)],
'chainmax': [2, "Chain max", 0, "m", (1, 5, 10), (0, 200)],
'zoom': [3, "Zoom", 50, "", (1,), (1, 8)],
'range': [4, "Alarm range", 35, "m", (1, 5, 10), (0, 200)]
}
self._mnu_title = "Options"
self._mnu_x = 20
self._mnu_y = 80
self._mnu_w = 120
self._mnu_h = 20
self._mnu_sel = 1
self.mnu_step = 1
def handle_key(self, buttonid):
if buttonid == 1:
if self.mode == 'N':
self.mode = 'C'
self.buttonlabel[2] = '#UP'
self.buttonlabel[3] = '#DOWN'
self.buttonlabel[4] = '[ - ]'
self.buttonlabel[5] = '[ + ]'
self.buttonlabel[6] = 'STEP'
else:
self.mode = 'N'
self.buttonlabel[2] = 'RISE' if self.anchor_set else 'DROP'
self.buttonlabel[3] = '#PREV'
self.buttonlabel[4] = '#NEXT'
self.buttonlabel[5] = 'ALARM' if not self.alarm_enabled else 'OFF'
return True
if self.mode == 'N':
# Normal
if buttonid == 2:
if not self.anchor_set:
self.anchor_lat = self._bd.lat
self.anchor_lon = self._bd.lon
self.anchor_set = True
self.anchor_ts = time.time()
self.buttonlabel[2] = 'RISE'
self.buttonlabel[5] = 'ALARM'
else:
self.anchor_set = False
self.alarm = False
self.alarm_enabled = False
self.anchor_ts = None
self.buttonlabel[2] = 'DROP'
self.buttonlabel[5] = ''
return True
elif buttonid == 5:
# Bei aktivem Alarm kann mit dieser Taste der Alarm zurückgesetzt
# werden. Die Tastenbeschriftung wechselt zwischen ALARM und OFF.
if self.alarm:
self.alarm = False
self.buttonlabel[5] = 'ALARM'
if self.alarm_enabled:
self.alarm_enabled = False
self.buttonlabel[5] = 'ALARM'
else:
self.alarm_enabled = True
self.buttonlabel[5] = 'OFF'
return True
else:
# Konfiguration
if buttonid == 2:
if self._mnu_sel == 1:
self._mnu_sel = len(self._mnu)
else:
self._mnu_sel -= 1
elif buttonid == 3:
if self._mnu_sel == len(self._mnu):
self._mnu_sel = 1
else:
self._mnu_sel += 1
return True
if buttonid == 2:
if not self.anchor_set:
self.anchor_lat = self._bd.lat
self.anchor_lon = self._bd.lon
self.anchor_set = True
self.anchor_ts = time.time()
self.buttonlabel[2] = 'RISE'
self.buttonlabel[5] = 'ALARM'
else:
self.anchor_set = False
self.alarm = False
self.alarm_enabled = False
self.anchor_ts = None
self.buttonlabel[2] = 'DROP'
self.buttonlabel[5] = ''
if buttonid == 5:
# Bei aktivem Alarm kann mit dieser Taste der Alarm zurückgesetzt
# werden. Die Tastenbeschriftung wechselt zwischen ALARM und OFF.
if self.alarm:
self.alarm = False
self.buttonlabel[5] = 'ALARM'
if self.alarm_enabled:
self.alarm_enabled = False
self.buttonlabel[5] = 'ALARM'
else:
self.alarm_enabled = True
self.buttonlabel[5] = 'OFF'
return False
def draw(self, ctx):
def draw_normal(self, ctx):
"""
value1 = LAT
@ -208,3 +252,35 @@ class Anchor(Page):
for point in wind[1:]:
ctx.line_to(*point)
ctx.fill()
def draw_config(self, ctx):
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
ctx.set_font_size(20)
ctx.move_to(2, 50)
ctx.show_text("Anchor configuration")
# Menüwerte initialisieren
self._mnu["chain"][2] = self.chain
self._mnu["chainmax"][2] = self.chain_length
# Menü zeichnen
ctx.save()
ctx.set_font_size(16)
#ctx.rectangle(100, 100, 50, 50)
#ctx.clip()
for m in self._mnu.items():
#ctx.move_to(self._mnu_x, self._mnu_y + 24 + m[1][0] * 16)
#ctx.show_text(m[1][1])
inverted = (m[1][0] == self._mnu_sel)
self.draw_text_boxed(ctx, self._mnu_x, self._mnu_y + self._mnu_h * (m[1][0] - 1), self._mnu_w, self._mnu_h, m[1][1], inverted)
ctx.move_to(self._mnu_x + self._mnu_w + 20 , self._mnu_y + self._mnu_h * (m[1][0] - 1))
ctx.show_text(str(m[1][2]) + m[1][3])
ctx.stroke()
ctx.restore()
def draw(self, ctx):
if self.mode == 'N':
self.draw_normal(ctx)
else:
self.draw_config(ctx)

View File

@ -77,6 +77,8 @@ class Page():
self.icon = {}
self.icon['PREV'] = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "arrow_l1.png"))
self.icon['NEXT'] = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "arrow_r1.png"))
self.icon['UP'] = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "arrow_up.png"))
self.icon['DOWN'] = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "arrow_dn.png"))
self.icon['ILUM'] = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "lighton.png"))
self.sym_lock = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "lock.png"))
self.sym_swipe = cairo.ImageSurface.create_from_png(os.path.join(cfg['imgpath'], "swipe3.png"))
@ -276,3 +278,22 @@ class Page():
ctx.move_to(x - w, y)
ctx.show_text(content)
ctx.stroke()
def draw_text_boxed(self, ctx, x, y, w, h, content, inverted=False):
ctx.set_line_width(1)
if inverted:
ctx.set_source_rgb(*self.fgcolor)
ctx.rectangle(x, y + 0.5, w, h)
ctx.fill()
else:
ctx.set_source_rgb(*self.bgcolor)
ctx.rectangle(x, y + 0.5, w, h)
ctx.stroke()
if inverted:
ctx.set_source_rgb(*self.bgcolor)
else:
ctx.set_source_rgb(*self.fgcolor)
ctx.move_to(x + 4, y + h - 5 + 0.5)
ctx.show_text(content)
ctx.stroke()