forked from DedFishy/FWMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout_manager.py
More file actions
70 lines (57 loc) · 2.34 KB
/
layout_manager.py
File metadata and controls
70 lines (57 loc) · 2.34 KB
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
from typing import Callable
import numpy as np
from matrix import Matrix
from widget import Widget
from widget_layout_object import WidgetObjectLayout
class LayoutManager:
widgets: list[WidgetObjectLayout] = []
matrix: Matrix
flush_callback: Callable
selected_layout_file_path = ""
selected_layout_file_name = ""
def __init__(self, matrix: Matrix, flush_callback: Callable):
self.matrix = matrix
self.flush_callback = flush_callback
def add_widget(self, widget: Widget, color=None):
widget_object_layout = WidgetObjectLayout(widget, self, color)
self.widgets.append(widget_object_layout)
return widget_object_layout
def generate_layout_dict(self):
return {
"widgets": [
{
"position": widget.widget.position,
"rotation": widget.widget.rotation,
"color": widget.color,
"import_name": widget.widget.import_name, # type: ignore
"configuration": {field: widget.widget.configuration[field].value for field in widget.widget.configuration.keys()}
} for widget in self.widgets
]
}
def remove_all(self):
self.widgets = []
def remove(self, widget):
self.widgets.remove(widget)
self.render()
def get_desired_spf(self):
spf = -1
for widget in self.widgets:
desired = widget.widget.get_desired_spf()
#print(desired)
if desired == -1: desired = 30
if desired < spf or spf == -1:
spf = desired
return spf
def render(self):
self.matrix.fill(0)
for widget in self.widgets:
self.render_widget(widget)
def render_widget(self, widget: WidgetObjectLayout):
widget_pixels_untyped: np.matrix|list = widget.widget.get_frame()
if type(widget_pixels_untyped) == list:
widget_pixels: np.matrix = np.matrix(widget_pixels_untyped)
elif type(widget_pixels_untyped) == np.matrix:
widget_pixels = widget_pixels_untyped
if widget.widget.allow_rotation and widget.widget.rotation != 0:
widget_pixels = np.rot90(widget_pixels, widget.widget.rotation // 90) # type: ignore
self.matrix.impose(widget_pixels, widget.widget.position)