-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
101 lines (93 loc) · 3.5 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import logging
from menu import Menu, ListMenu, TileMenu, MenuItem
from menu_bluetooth import BluetoothMenu
from menu_mopidy import MopidyMenu
from model_mopidy import Mopidy
from model_settings import Settings
from shapes import Point, Rectangle
logger = logging.getLogger(__name__)
class Model:
def __init__(self, view):
# vars
self.view = view
self.current_menu = None
# sub-models
self.settings = Settings(self)
self.mopidy = Mopidy(self)
# menu tree
self.root_menu = TileMenu(
model=self, name="Main Menu", background_bitmap="menu_main.bmp"
)
self.root_menu.add_children(
[
MopidyMenu(
model=self,
name="Songs",
uri="local:directory?type=track",
background_bitmap="menu_albums.bmp",
),
MopidyMenu(
model=self,
name="Albums",
uri="local:directory?type=album",
background_bitmap="menu_albums.bmp",
),
MopidyMenu(
model=self,
name="Artists",
uri="local:directory?type=artist&role=albumartist",
background_bitmap="menu_albums.bmp",
),
ListMenu(model=self, name="Playlists"),
ListMenu(
model=self,
name="Settings",
background_bitmap="menu_settings.bmp",
).add_children(
[
BluetoothMenu(
model=self,
name="Bluetooth",
background_bitmap="menu_settings_bluetooth.bmp",
),
MenuItem(
name="Theme",
value=self.settings.invert_value_callback,
callback=self.settings.invert_callback,
),
MenuItem(
name="Shutdown",
value="sudo shutdown now",
callback=self.settings.shutdown_callback,
),
MenuItem(
name="Reboot",
value="sudo reboot",
callback=self.settings.reboot_callback,
),
]
),
TileMenu(model=self, name="Now Playing"),
]
)
self.root_menu.child_locations = [
Rectangle(Point(0, 0), Point(82, 61)), # songs
Rectangle(Point(83, 0), Point(166, 61)), # albums
Rectangle(Point(167, 0), Point(250, 61)), # artists
Rectangle(Point(0, 62), Point(82, 122)), # playlists
Rectangle(Point(83, 62), Point(166, 122)), # settings
Rectangle(Point(167, 62), Point(250, 122)), # now playing
]
self.current_menu = self.root_menu
@property
def current_menu(self):
return self._current_menu
@current_menu.setter
def current_menu(self, other):
self._current_menu = other
if isinstance(other, Menu):
logger.info(f"navigate to {str(self.current_menu)}")
self.view.render_menu(
self.current_menu,
invert=self.settings.invert,
)