-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathui.py
More file actions
273 lines (229 loc) · 8.44 KB
/
ui.py
File metadata and controls
273 lines (229 loc) · 8.44 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# This file was generated by SquareLine Studio
# SquareLine Studio version: SquareLine Studio 1.5.0
# LVGL version: 8.3.11
# Project name: esp32-50
import lvgl as lv
#import tempui.ui.ui_images as ui_images
import lvgl_panel_utils as utils
# dispp = lv.display_get_default()
# theme = lv.theme_default_init(dispp, lv.palette_main(lv.PALETTE.BLUE), lv.palette_main(lv.PALETTE.RED), False, lv.font_default())
# dispp.set_theme(theme)
def ui_theme_set(idx):
return
def SetFlag( obj, flag, value):
if (value):
obj.add_flag(flag)
else:
obj.remove_flag(flag)
return
_ui_comp_table = {}
_ui_comp_prev = None
_ui_name_prev = None
_ui_child_prev = None
_ui_comp_table.clear()
def _ui_comp_del_event(e):
target = e.get_target()
_ui_comp_table[id(target)].remove()
def ui_comp_get_child(comp, child_name):
return _ui_comp_table[id(comp)][child_name]
def ui_comp_get_root_from_child(child, compname):
for component in _ui_comp_table:
if _ui_comp_table[component]["_CompName"]==compname:
for part in _ui_comp_table[component]:
if id(_ui_comp_table[component][part]) == id(child):
return _ui_comp_table[component]
return None
def SetBarProperty(target, id, val):
if id == 'Value_with_anim': target.set_value(val, lv.ANIM.ON)
if id == 'Value': target.set_value(val, lv.ANIM.OFF)
return
def SetPanelProperty(target, id, val):
if id == 'Position_X': target.set_x(val)
if id == 'Position_Y': target.set_y(val)
if id == 'Width': target.set_width(val)
if id == 'Height': target.set_height(val)
return
def SetDropdownProperty(target, id, val):
if id == 'Selected':
target.set_selected(val)
return
def SetImageProperty(target, id, val, val2):
if id == 'Image': target.set_src(val)
if id == 'Angle': target.set_angle(val2)
if id == 'Zoom': target.set_zoom(val2)
return
def SetLabelProperty(target, id, val):
if id == 'Text': target.set_text(val)
return
def SetRollerProperty(target, id, val):
if id == 'Selected':
target.set_selected(val, lv.ANIM.OFF)
if id == 'Selected_with_anim':
target.set_selected(val, lv.ANIM.ON)
return
def SetSliderProperty(target, id, val):
if id == 'Value_with_anim': target.set_value(val, lv.ANIM.ON)
if id == 'Value': target.set_value(val, lv.ANIM.OFF)
return
def ChangeScreen( src, fademode, speed, delay):
print("Change screen to: "+str([name for name in globals() if globals()[name] is src]))
lv.screen_load_anim(src, fademode, speed, delay, False)
return
def DeleteScreen(src):
return
def IncrementArc( trg, val):
trg.set_value(trg.get_value()+val)
lv.event_send(trg,lv.EVENT.VALUE_CHANGED, None)
return
def IncrementBar( trg, val, anim):
trg.set_value(trg.get_value()+val,anim)
return
def IncrementSlider( trg, val, anim):
trg.set_value(trg.get_value()+val,anim)
lv.event_send(trg,lv.EVENT.VALUE_CHANGED, None)
return
def KeyboardSetTarget( keyboard, textarea):
keyboard.set_textarea(textarea)
return
def ModifyFlag( obj, flag, value):
if (value=="TOGGLE"):
if ( obj.has_flag(flag) ):
obj.remove_flag(flag)
else:
obj.add_flag(flag)
return
if (value=="ADD"):
obj.add_flag(flag)
else:
obj.remove_flag(flag)
return
def ModifyState( obj, state, value):
if (value=="TOGGLE"):
if ( obj.has_state(state) ):
obj.clear_state(state)
else:
obj.add_state(state)
return
if (value=="ADD"):
obj.add_state(state)
else:
obj.clear_state(state)
return
def TextAreaMoveCursor( trg, val):
if val=="UP" : trg.cursor_up()
if val=="RIGHT" : trg.cursor_right()
if val=="DOWN" : trg.cursor_down()
if val=="LEFT" : trg.cursor_left()
trg.add_state(lv.STATE.FOCUSED)
return
def set_opacity(obj, v):
obj.set_style_opa(v, lv.STATE.DEFAULT|lv.PART.MAIN)
return
def SetTextValueArc( trg, src, prefix, postfix):
trg.set_text(prefix+str(src.get_value())+postfix)
return
def SetTextValueSlider( trg, src, prefix, postfix):
trg.set_text(prefix+str(src.get_value())+postfix)
return
def SetTextValueChecked( trg, src, txton, txtoff):
if src.has_state(lv.STATE.CHECKED):
trg.set_text(txton)
else:
trg.set_text(txtoff)
return
def StepSpinbox( trg, val):
if val==1 : trg.increment()
if val==-1 : trg.decrement()
lv.event_send(trg,lv.EVENT.VALUE_CHANGED, None)
return
def SwitchTheme(val):
ui_theme_set(val)
return
# COMPONENTS
ui____initial_actions0 = lv.obj()
def Button1_eventhandler(event_struct):
event = event_struct.get_code()
if event == lv.EVENT.RELEASED and True:
print("pin38.value(1)")
ui_Label1.set_text("1")
ui_Label2.set_text("0")
#ChangeScreen( ui_Screen1, lv.SCR_LOAD_ANIM.FADE_ON, 500, 0)
return
def Button2_eventhandler(event_struct):
event = event_struct.get_code()
if event == lv.EVENT.RELEASED and True:
print("pin38.value(0)")
ui_Label1.set_text("0")
ui_Label2.set_text("1")
#ChangeScreen( ui_Screen1, lv.SCR_LOAD_ANIM.FADE_ON, 500, 0)
return
ui_Screen1 = lv.screen_active() #lv.obj()
SetFlag(ui_Screen1, lv.obj.FLAG.SCROLLABLE, False)
ui_Screen1.set_style_bg_color(lv.color_hex(0xFF66EE), lv.PART.MAIN | lv.STATE.DEFAULT )
ui_Screen1.set_style_bg_opa(255, lv.PART.MAIN| lv.STATE.DEFAULT )
#ui_Screen1.set_style_bg_image_src( ui_images.TemporaryImage, lv.PART.MAIN | lv.STATE.DEFAULT )
ui_Image2 = lv.image(ui_Screen1)
#ui_Image2.set_src(ui_images.ui_img_background1_png)
ui_Image2.set_src(utils.lvgl_get_image_desc("background1.png"))
ui_Image2.set_width(lv.SIZE_CONTENT) # 329
ui_Image2.set_height(lv.SIZE_CONTENT) # 244
ui_Image2.set_x(-171)
ui_Image2.set_y(-12)
if (lv.image.ALIGN.CENTER == lv.image.ALIGN.STRETCH ):
ui_Image2.set_inner_align(lv.image.ALIGN.TILE) # LVGL9.1 bug fix patch CENTER, 1, 1
ui_Image2.set_inner_align(lv.image.ALIGN.CENTER) # LVGL9.1 bug fix patch 1, 1
ui_Image2.set_align( lv.ALIGN.CENTER) # LVGL9.1 bug fix patch CENTER, 1, 1ui_Image2.set_align( lv.ALIGN.CENTER)
SetFlag(ui_Image2, lv.obj.FLAG.ADV_HITTEST, True)
SetFlag(ui_Image2, lv.obj.FLAG.SCROLLABLE, False)
ui_Label1 = lv.label(ui_Screen1)
ui_Label1.set_text("Temp\n")
ui_Label1.set_width(50)
ui_Label1.set_height(25)
ui_Label1.set_x(-120)
ui_Label1.set_y(-89)
ui_Label1.set_align( lv.ALIGN.CENTER)
ui_Label2 = lv.label(ui_Screen1)
ui_Label2.set_text("Humi")
ui_Label2.set_width(50)
ui_Label2.set_height(25)
ui_Label2.set_x(-120)
ui_Label2.set_y(60)
ui_Label2.set_align( lv.ALIGN.CENTER)
ui_Button1 = lv.button(ui_Screen1)
ui_Button1.set_width(100)
ui_Button1.set_height(50)
ui_Button1.set_x(205)
ui_Button1.set_y(-91)
ui_Button1.set_align( lv.ALIGN.CENTER)
SetFlag(ui_Button1, lv.obj.FLAG.SCROLLABLE, False)
SetFlag(ui_Button1, lv.obj.FLAG.SCROLL_ON_FOCUS, True)
ui_Button1.set_style_bg_color(lv.color_hex(0xFFFFFF), lv.PART.MAIN | lv.STATE.DEFAULT )
ui_Button1.set_style_bg_opa(255, lv.PART.MAIN| lv.STATE.DEFAULT )
#ui_Button1.set_style_bg_image_src( ui_images.ui_img_on_png, lv.PART.MAIN | lv.STATE.DEFAULT )
ui_Button1.set_style_bg_image_src(utils.lvgl_get_image_desc("on.png"), lv.PART.MAIN | lv.STATE.DEFAULT )
ui_Button1.set_style_bg_color(lv.color_hex(0xEE6611), lv.PART.MAIN | lv.STATE.PRESSED )
ui_Button1.set_style_bg_opa(255, lv.PART.MAIN| lv.STATE.PRESSED )
ui_Button1.add_event_cb(Button1_eventhandler, lv.EVENT.ALL, None)
ui_Button2 = lv.button(ui_Screen1)
ui_Button2.set_width(100)
ui_Button2.set_height(50)
ui_Button2.set_x(200)
ui_Button2.set_y(62)
ui_Button2.set_align( lv.ALIGN.CENTER)
SetFlag(ui_Button2, lv.obj.FLAG.SCROLLABLE, False)
SetFlag(ui_Button2, lv.obj.FLAG.SCROLL_ON_FOCUS, True)
ui_Button2.set_style_bg_color(lv.color_hex(0xFFFFFF), lv.PART.MAIN | lv.STATE.DEFAULT )
ui_Button2.set_style_bg_opa(255, lv.PART.MAIN| lv.STATE.DEFAULT )
#ui_Button2.set_style_bg_image_src( ui_images.ui_img_off_png, lv.PART.MAIN | lv.STATE.DEFAULT )
ui_Button2.set_style_bg_image_src(utils.lvgl_get_image_desc("off.png"), lv.PART.MAIN | lv.STATE.DEFAULT )
ui_Button2.set_style_bg_color(lv.color_hex(0xEE6611), lv.PART.MAIN | lv.STATE.PRESSED )
ui_Button2.set_style_bg_opa(255, lv.PART.MAIN| lv.STATE.PRESSED )
ui_Button2.add_event_cb(Button2_eventhandler, lv.EVENT.ALL, None)
ui_Time = lv.label(ui_Screen1)
ui_Time.set_text("Donnerstag 01.01.2025 17:28:32")
ui_Time.set_width(220)
ui_Time.set_height(lv.SIZE_CONTENT) # 1
ui_Time.set_x(250)
ui_Time.set_y(-205)
ui_Time.set_align( lv.ALIGN.CENTER)
#lv.screen_load(ui_Screen1)