Debian Codegraph @

s_tui/sturwid/ui_elements.py

raw symbols SCIP
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2017-2025 Alex Manuskin, Gil Tsuker
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18
19 import urwid
20
21 DEFAULT_PALETTE = [
22 ("body", "default", "default", "standout"),
23 (
24 "header",
25 "default",
26 "dark red",
27 ),
28 ("screen edge", "light blue", "brown"),
29 ("main shadow", "dark gray", "black"),
30 ("line", "default", "light gray", "standout"),
31 ("menu button", "light gray", "black"),
32 ("bg background", "default", "default"),
33 ("overheat dark", "white", "light red", "standout"),
34 ("bold text", "default,bold", "default", "bold"),
35 ("under text", "default,underline", "default", "underline"),
36 ("util light", "default", "light green"),
37 ("util light smooth", "light green", "default"),
38 ("util dark", "default", "dark green"),
39 ("util dark smooth", "dark green", "default"),
40 ("high temp dark", "default", "dark red"),
41 ("high temp dark smooth", "dark red", "default"),
42 ("high temp light", "default", "light red"),
43 ("high temp light smooth", "light red", "default"),
44 ("power dark", "default", "light gray", "standout"),
45 ("power dark smooth", "light gray", "default"),
46 ("power light", "default", "white", "standout"),
47 ("power light smooth", "white", "default"),
48 ("temp dark", "default", "dark cyan", "standout"),
49 ("temp dark smooth", "dark cyan", "default"),
50 ("temp light", "default", "light cyan", "standout"),
51 ("temp light smooth", "light cyan", "default"),
52 ("freq dark", "default", "dark magenta", "standout"),
53 ("freq dark smooth", "dark magenta", "default"),
54 ("freq light", "default", "light magenta", "standout"),
55 ("freq light smooth", "light magenta", "default"),
56 ("fan dark", "default", "dark blue", "standout"),
57 ("fan dark smooth", "dark blue", "default"),
58 ("fan light", "default", "light blue", "standout"),
59 ("fan light smooth", "light blue", "default"),
60 ("button normal", "dark green", "default", "standout"),
61 ("button select", "white", "dark green"),
62 ("line", "default", "default", "standout"),
63 ("pg normal", "white", "default", "standout"),
64 ("pg complete", "white", "dark magenta"),
65 ("high temp txt", "light red", "default"),
66 ("throttle txt", "yellow", "default"),
67 ("freq throttle dark", "default", "brown", "standout"),
68 ("freq throttle dark smooth", "brown", "default"),
69 ("freq throttle light", "default", "yellow", "standout"),
70 ("freq throttle light smooth", "yellow", "default"),
71 ("pg smooth", "dark magenta", "default"),
72 ]
73
74
75 class ViListBox(urwid.ListBox):
76 # Catch key presses in box and pass them as arrow keys
77 def keypress(self, size, key):
78 if key == "j":
79 key = "down"
80 elif key == "k":
81 key = "up"
82 elif key == "h":
83 key = "left"
84 elif key == "l":
85 key = "right"
86 elif key == "G":
87 key = "page down"
88 elif key == "g":
89 key = "page up"
90 elif key == "x":
91 key = "enter"
92 elif key == "q":
93 key = "q"
94 return super().keypress(size, key)
95
96
97 def radio_button(group, label, fn):
98 """Inheriting radio button of urwid"""
99 w = urwid.RadioButton(group, label, False, on_state_change=fn)
100 w = urwid.AttrMap(w, "button normal", "button select")
101 return w
102
103
104 def button(t, fn, data=None):
105 w = urwid.Button(t, fn, data)
106 w = urwid.AttrMap(w, "button normal", "button select")
107 return w