-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathACLIB_UIDebug.py
More file actions
104 lines (79 loc) · 3.67 KB
/
ACLIB_UIDebug.py
File metadata and controls
104 lines (79 loc) · 3.67 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
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
102
103
104
from memory.ac_data import ACData
from memory.ac_meta import ACMeta
from ui.color import RED, TRANSPARENT, BLACK, WHITE, YELLOW
from ui.gui.aclib_widget import ACLIBListBox
from ui.gui.font import Font
from ui.gui.layout import ACGrid
from ui.gui.ac_widget import ACApp, ACLabel, ACWidget
from time import time
from util.log import console
def set_render(widget: ACWidget, no_render=False):
widget.no_render = no_render
if widget.child:
set_render(widget.child, no_render)
if hasattr(widget, 'children'):
for child in widget.children:
set_render(child)
class UIDebug(ACApp):
def __init__(self, data: ACData = None, meta: ACMeta = None):
super().__init__('ACLIB UIDebug', 200, 200, 550, 80)
self.hide_decoration()
self.background_color = BLACK
self._data = data
self._active_widgets = []
self._timer = time()
self._font = Font('Roboto Mono', WHITE)
self._grid = ACGrid(4, 4, self)
self._widget_label = ACLabel(self._grid, 'Widget:', font=self._font)
self._widget_text = ACLabel(self._grid, '', font=self._font)
self._position_label = ACLabel(self._grid, 'Position:', font=self._font)
self._position_text = ACLabel(self._grid, '', font=self._font)
self._size_label = ACLabel(self._grid, 'Size:', font=self._font)
self._size_text = ACLabel(self._grid, '', font=self._font)
self._property_name = ACLIBListBox(self._grid, 4)
self._property_value = ACLIBListBox(self._grid, 4)
col, row = 0, 0
self._grid.add(self._widget_label, col, row)
self._grid.add(self._position_label, col, row + 1)
self._grid.add(self._size_label, col, row + 2)
col, row = 1, 0
self._grid.add(self._widget_text, col, row)
self._grid.add(self._position_text, col, row + 1)
self._grid.add(self._size_text, col, row + 2)
col, row = 2, 0
self._grid.add(self._property_name, col, row, 1, 4)
col, row = 3, 0
self._grid.add(self._property_value, col, row, 1, 4)
self._data.on(ACData.EVENT.READY, self.init)
self.on(ACWidget.EVENT.DISMISSED, self.dismissed)
def _reset_active(self):
for widget, border_color, no_render in self._active_widgets:
widget.border_color = border_color
widget.no_render = no_render
self._active_widgets = []
self._property_name.clear()
self._property_value.clear()
def init(self):
for _, widget in ACWidget.IDS.items():
widget.on(ACWidget.EVENT.ON_MOUSE_DOWN, self.get_info)
def get_info(self, widget: ACWidget, *args):
if self.active:
# Children of the widget should also be highlighted.
# It is expected that the next click takes at least 10ms
# (otherwise it would be a pretty sick reaction time for the clicker).
if time() - self._timer > 0.01:
self._reset_active()
self._timer = time()
# Store the state of the widget.
self._active_widgets.append((widget, widget.border_color, widget.no_render))
# Highlight newly selected widgets.
set_render(widget, False)
widget.border_color = RED
# Set Properties
self._widget_text.text = widget.__class__.__name__
self._position_text.text = str(widget.position)
self._size_text.text = str(widget.size)
# self._property_name.add(ACLabel(self._property_name, 'Name'))
# self._property_value.add(ACLabel(self._property_value, widget.__class__.__name__))
def dismissed(self, *args):
self._reset_active()