1919wallet = None
2020receive_qr_data = None
2121
22- # Settings screen implementation
2322# Settings screen implementation
2423class SettingsScreen ():
2524 def __init__ (self ):
@@ -34,7 +33,8 @@ def __init__(self):
3433 self .keyboard = None
3534 self .textarea = None
3635 self .msgbox = None
37- self .radio_group = None
36+ self .radio_container = None
37+ self .active_radio_index = 0 # Track active radio button index
3838 self .screen = self .create_ui ()
3939 self .update_setting_visibility () # Initialize visibility based on saved wallet_type
4040
@@ -116,6 +116,54 @@ def update_setting_visibility(self):
116116 else :
117117 setting ["cont" ].remove_flag (lv .obj .FLAG .HIDDEN )
118118
119+ def radio_event_handler (self , event ):
120+ code = event .get_code ()
121+ if code != lv .EVENT .CLICKED :
122+ return
123+ targetblob = event .get_target ()
124+ #target = self.radio_container
125+ #obj = e.get_target()
126+ target = lv .obj (targetblob )
127+ #pos = lvobj.get_pos() #
128+ if target == self .radio_container :
129+ print ("it's the container" )
130+ return # Ignore clicks on the container itself
131+ else :
132+ print ("it's not the container" )
133+ old_cb = self .radio_container .get_child (self .active_radio_index )
134+ old_cb .remove_state (lv .STATE .CHECKED )
135+ #target.add_state(lv.STATE.CHECKED)
136+ # 19 = lv.STATE.HOVERED, lv.STATE.CHECKED and lv.STATE.FOCUSED
137+ radio_index = - 1
138+ for childnr in range (2 ):
139+ child = self .radio_container .get_child (childnr )
140+ state = child .get_state ()
141+ print (f"state: { state } " )
142+ if state != lv .STATE .DEFAULT :
143+ print ("found checked child!" )
144+ radio_index = childnr
145+ break
146+ else :
147+ print ("skipping child..." )
148+ #self.active_radio_index = self.radio_container.get_child_by_id(target)
149+ self .active_radio_index = radio_index
150+ print (f"active_radio_index is now { self .active_radio_index } " )
151+
152+ def create_radio_button (self , parent , text , index ):
153+ cb = lv .checkbox (parent )
154+ cb .set_text (text )
155+ cb .add_flag (lv .obj .FLAG .EVENT_BUBBLE )
156+ # Add circular style to indicator for radio button appearance
157+ style_radio = lv .style_t ()
158+ style_radio .init ()
159+ style_radio .set_radius (lv .RADIUS_CIRCLE )
160+ cb .add_style (style_radio , lv .PART .INDICATOR )
161+ style_radio_chk = lv .style_t ()
162+ style_radio_chk .init ()
163+ style_radio_chk .set_bg_image_src (None )
164+ cb .add_style (style_radio_chk , lv .PART .INDICATOR | lv .STATE .CHECKED )
165+ return cb
166+
119167 def open_edit_popup (self , setting ):
120168 # Close existing msgbox and keyboard if open
121169 if self .msgbox :
@@ -139,17 +187,22 @@ def open_edit_popup(self, setting):
139187 content .set_flex_flow (lv .FLEX_FLOW .COLUMN )
140188
141189 if setting ["key" ] == "wallet_type" :
142- # Create radiobuttons for wallet_type
143- self .radio_group = lv .buttonmatrix (content )
144- self .radio_group .set_width (lv .pct (100 ))
145- buttons = ["LNBits" , "Nostr Wallet Connect" ]
146- self .radio_group .set_map (buttons + ["" ]) # Add empty string for matrix termination
147- self .radio_group .set_button_ctrl (0 , lv .buttonmatrix .CTRL .CHECKABLE )
148- self .radio_group .set_button_ctrl (1 , lv .buttonmatrix .CTRL .CHECKABLE )
190+ # Create container for radio buttons
191+ self .radio_container = lv .obj (content )
192+ self .radio_container .set_width (lv .pct (100 ))
193+ self .radio_container .set_height (lv .SIZE_CONTENT )
194+ self .radio_container .set_flex_flow (lv .FLEX_FLOW .COLUMN )
195+ self .radio_container .add_event_cb (self .radio_event_handler , lv .EVENT .CLICKED , None )
196+
197+ # Create radio buttons
198+ options = [("LNBits" , "lnbits" ), ("Nostr Wallet Connect" , "nwc" )]
149199 current_wallet = self .prefs .get_string ("wallet_type" , "lnbits" )
150- selected_idx = 0 if current_wallet == "lnbits" else 1
151- self .radio_group .set_button_ctrl (selected_idx , lv .buttonmatrix .CTRL .CHECKED )
152- self .radio_group .set_one_checked (True )
200+ self .active_radio_index = 0 if current_wallet == "lnbits" else 1
201+
202+ for i , (text , _ ) in enumerate (options ):
203+ cb = self .create_radio_button (self .radio_container , text , i )
204+ if i == self .active_radio_index :
205+ cb .add_state (lv .STATE .CHECKED )
153206 else :
154207 # Textarea for other settings
155208 self .textarea = lv .textarea (content )
@@ -187,8 +240,8 @@ def open_edit_popup(self, setting):
187240 cancel_btn .add_event_cb (self .close_popup , lv .EVENT .CLICKED , None )
188241
189242 def save_setting (self , setting ):
190- if setting ["key" ] == "wallet_type" and self .radio_group :
191- selected_idx = self .radio_group . get_selected_button ()
243+ if setting ["key" ] == "wallet_type" and self .radio_container :
244+ selected_idx = self .active_radio_index
192245 new_value = "lnbits" if selected_idx == 0 else "nwc"
193246 elif self .textarea :
194247 new_value = self .textarea .get_text ()
0 commit comments