Skip to content

Commit c115926

Browse files
Piggy: order functions logically
1 parent f877281 commit c115926

1 file changed

Lines changed: 45 additions & 52 deletions

File tree

  • internal_filesystem/apps/com.lightningpiggy.displaywallet/assets

internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,6 @@ def __init__(self):
1515
self.receive_qr = None
1616
self.payments_label = None
1717

18-
def settings_button_tap(self, event):
19-
settings_activity = SettingsActivity()
20-
settings_activity.onCreate()
21-
22-
def main_ui_set_defaults(self):
23-
self.balance_label.set_text(lv.SYMBOL.REFRESH)
24-
self.payments_label.set_text(lv.SYMBOL.REFRESH)
25-
self.receive_qr.update("EMPTY", len("EMPTY"))
26-
27-
def qr_clicked_cb(self, event):
28-
if not self.receive_qr_data:
29-
return
30-
print("QR clicked")
31-
qr_screen = lv.obj()
32-
big_receive_qr = lv.qrcode(qr_screen)
33-
big_receive_qr.set_size(240) # TODO: make this dynamic
34-
big_receive_qr.set_dark_color(lv.color_black())
35-
big_receive_qr.set_light_color(lv.color_white())
36-
big_receive_qr.center()
37-
big_receive_qr.set_style_border_color(lv.color_white(), 0)
38-
big_receive_qr.set_style_border_width(3, 0);
39-
big_receive_qr.update(self.receive_qr_data, len(self.receive_qr_data))
40-
mpos.ui.load_screen(qr_screen)
41-
42-
4318
def onCreate(self):
4419
main_screen = lv.obj()
4520
main_screen.set_style_pad_all(10, 0)
@@ -69,14 +44,6 @@ def onCreate(self):
6944
snap_label.center()
7045
settings_button.add_event_cb(self.settings_button_tap,lv.EVENT.CLICKED,None)
7146
mpos.ui.setContentView(self, main_screen)
72-
73-
def redraw_balance_cb(self):
74-
# this gets called from another thread (the wallet) so make sure it happens in the LVGL thread using lv.async_call():
75-
lv.async_call(lambda l: self.balance_label.set_text(str(self.wallet.last_known_balance)), None)
76-
77-
def redraw_payments_cb(self):
78-
# this gets called from another thread (the wallet) so make sure it happens in the LVGL thread using lv.async_call():
79-
lv.async_call(lambda l: self.payments_label.set_text(str(self.wallet.payment_list)), None)
8047

8148
def onStart(self, main_screen):
8249
self.main_ui_set_defaults()
@@ -120,6 +87,38 @@ def onStop(self, main_screen):
12087
if self.wallet:
12188
self.wallet.stop()
12289

90+
def redraw_balance_cb(self):
91+
# this gets called from another thread (the wallet) so make sure it happens in the LVGL thread using lv.async_call():
92+
lv.async_call(lambda l: self.balance_label.set_text(str(self.wallet.last_known_balance)), None)
93+
94+
def redraw_payments_cb(self):
95+
# this gets called from another thread (the wallet) so make sure it happens in the LVGL thread using lv.async_call():
96+
lv.async_call(lambda l: self.payments_label.set_text(str(self.wallet.payment_list)), None)
97+
98+
99+
def settings_button_tap(self, event):
100+
settings_activity = SettingsActivity()
101+
settings_activity.onCreate()
102+
103+
def main_ui_set_defaults(self):
104+
self.balance_label.set_text(lv.SYMBOL.REFRESH)
105+
self.payments_label.set_text(lv.SYMBOL.REFRESH)
106+
self.receive_qr.update("EMPTY", len("EMPTY"))
107+
108+
def qr_clicked_cb(self, event):
109+
if not self.receive_qr_data:
110+
return
111+
print("QR clicked")
112+
qr_screen = lv.obj()
113+
big_receive_qr = lv.qrcode(qr_screen)
114+
big_receive_qr.set_size(240) # TODO: make this dynamic
115+
big_receive_qr.set_dark_color(lv.color_black())
116+
big_receive_qr.set_light_color(lv.color_white())
117+
big_receive_qr.center()
118+
big_receive_qr.set_style_border_color(lv.color_white(), 0)
119+
big_receive_qr.set_style_border_width(3, 0);
120+
big_receive_qr.update(self.receive_qr_data, len(self.receive_qr_data))
121+
mpos.ui.load_screen(qr_screen)
123122

124123
# Used to list and edit all settings:
125124
class SettingsActivity(Activity):
@@ -175,10 +174,6 @@ def onCreate(self):
175174
)
176175
mpos.ui.setContentView(self, screen)
177176

178-
def startSettingActivity(self, setting):
179-
sa = SettingActivity(setting)
180-
sa.onCreate()
181-
182177
def onResume(self, screen):
183178
wallet_type = self.prefs.get_string("wallet_type", "lnbits")
184179
# update setting visibility based on wallet_type:
@@ -194,6 +189,9 @@ def onResume(self, screen):
194189
else:
195190
setting["cont"].remove_flag(lv.obj.FLAG.HIDDEN)
196191

192+
def startSettingActivity(self, setting):
193+
sa = SettingActivity(setting)
194+
sa.onCreate()
197195

198196

199197
# Used to edit one setting:
@@ -204,14 +202,6 @@ def __init__(self, setting):
204202
self.setting = setting
205203

206204
def onCreate(self):
207-
# Initialize keyboard (hidden initially)
208-
self.keyboard = lv.keyboard(lv.layer_sys())
209-
self.keyboard.set_size(lv.pct(100), lv.pct(40))
210-
self.keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0)
211-
self.keyboard.add_flag(lv.obj.FLAG.HIDDEN)
212-
self.keyboard.add_event_cb(self.keyboard_cb, lv.EVENT.READY, None)
213-
self.keyboard.add_event_cb(self.keyboard_cb, lv.EVENT.CANCEL, None)
214-
215205
settings_screen_detail = lv.obj()
216206
settings_screen_detail.set_style_pad_all(10, 0)
217207
settings_screen_detail.set_flex_flow(lv.FLEX_FLOW.COLUMN)
@@ -263,6 +253,15 @@ def onCreate(self):
263253
self.textarea.add_event_cb(self.show_keyboard, lv.EVENT.CLICKED, None)
264254
self.textarea.add_event_cb(self.show_keyboard, lv.EVENT.FOCUSED, None)
265255
self.textarea.add_event_cb(self.hide_keyboard, lv.EVENT.DEFOCUSED, None)
256+
# Initialize keyboard (hidden initially)
257+
self.keyboard = lv.keyboard(lv.layer_sys())
258+
self.keyboard.set_size(lv.pct(100), lv.pct(40))
259+
self.keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0)
260+
self.keyboard.add_flag(lv.obj.FLAG.HIDDEN)
261+
self.keyboard.add_event_cb(self.keyboard_cb, lv.EVENT.READY, None)
262+
self.keyboard.add_event_cb(self.keyboard_cb, lv.EVENT.CANCEL, None)
263+
self.keyboard.set_textarea(self.textarea)
264+
266265
# Button container
267266
btn_cont = lv.obj(settings_screen_detail)
268267
btn_cont.set_width(lv.pct(100))
@@ -283,7 +282,7 @@ def onCreate(self):
283282
cancel_label = lv.label(cancel_btn)
284283
cancel_label.set_text("Cancel")
285284
cancel_label.center()
286-
cancel_btn.add_event_cb(self.close_popup, lv.EVENT.CLICKED, None)
285+
cancel_btn.add_event_cb(lambda e: mpos.ui.back_screen(), lv.EVENT.CLICKED, None)
287286
mpos.ui.setContentView(self, settings_screen_detail)
288287

289288
def hide_keyboard(self, event=None):
@@ -293,7 +292,6 @@ def hide_keyboard(self, event=None):
293292
def show_keyboard(self, event):
294293
print("showing keyboard")
295294
self.keyboard.remove_flag(lv.obj.FLAG.HIDDEN)
296-
self.keyboard.set_textarea(self.textarea)
297295

298296
def keyboard_cb(self, event=None):
299297
print("keyboard_cb: Keyboard event triggered")
@@ -354,10 +352,5 @@ def save_setting(self, setting):
354352
editor.put_string(setting["key"], new_value)
355353
editor.commit()
356354
setting["value_label"].set_text(new_value if new_value else "Not set")
357-
self.close_popup(None)
358-
359-
def close_popup(self, event):
360-
if self.keyboard:
361-
self.hide_keyboard()
362355
mpos.ui.back_screen()
363356

0 commit comments

Comments
 (0)