@@ -316,6 +316,13 @@ def selection(self, val):
316316 self .__selection = val
317317 #self.refresh_config_win()
318318
319+ def get_previous_search (self , string ):
320+ sel = self .__selection - 1
321+ if sel in self ._headers and \
322+ string in list (self ._config_options .values ())[sel ][0 ].lower ():
323+ sel -= 1
324+ return sel
325+
319326 def set_selection (self , sel ):
320327 self .selection = sel
321328 self ._put_cursor (0 )
@@ -3555,6 +3562,9 @@ class PyRadioKeyboardConfig():
35553562 _start = 0
35563563 _selection = 1
35573564
3565+ # titles for search function
3566+ _titles = None
3567+
35583568 message = None
35593569
35603570 def __init__ (
@@ -3609,7 +3619,7 @@ def __init__(
36093619 self ._list [i ][- 2 ] = header_index
36103620 if logger .isEnabledFor (logging .DEBUG ):
36113621 for n in self ._list :
3612- logger .debug (f'{ n } ' )
3622+ logger .debug (f'list : { n } ' )
36133623 '''
36143624
36153625 # do not read keys.json to self._keys_to_classes
@@ -3630,7 +3640,33 @@ def __init__(
36303640 self ._keys_to_classes = self ._precompute_context_map (self ._classes )
36313641 # logger.error(f'{self._keys_to_classes = }')
36323642 self ._needs_update = False
3643+ # logger.error('\n\ntitles\n{}\n\n'.format(self.titles()))
3644+
3645+ @property
3646+ def editing (self ):
3647+ return self ._editing
36333648
3649+ @property
3650+ def selection (self ):
3651+ return self ._selection
3652+
3653+ @selection .setter
3654+ def selection (self , value ):
3655+ self ._selection = value
3656+ if self ._selection in self ._headers :
3657+ self ._selection += 1
3658+
3659+ def get_previous_search (self , string ):
3660+ sel = self ._selection - 1
3661+ if string .lower () in self ._list [sel ][- 1 ].lower () and \
3662+ sel in self ._headers :
3663+ sel -= 1
3664+ return sel
3665+
3666+ def titles (self ):
3667+ if self ._titles is None :
3668+ self ._titles = [x [- 1 ] for x in self ._list ]
3669+ return self ._titles
36343670
36353671 def _precompute_context_map (self , results ):
36363672 """
@@ -3681,17 +3717,18 @@ def _rename_keyboard_json_file(self, file_path):
36813717 return new_file_name
36823718
36833719 def _start_editing (self ):
3684- self .existing_conflict = None
36853720 self ._win .addstr (self ._selection - self ._start + 2 , self .maxX - 8 , '[edit]' , curses .color_pair (6 ))
36863721 self ._win .refresh ()
36873722 self ._editing = True
3723+ self ._cnf .inhibit_search = True
36883724 if logger .isEnabledFor (logging .DEBUG ):
36893725 logger .debug ('editing "{}"' .format (self ._list [self ._selection ]))
36903726
36913727 def _stop_editing (self ):
36923728 self ._win .addstr (self ._selection - self ._start + 2 , self .maxX - 8 , ' ' , curses .color_pair (6 ))
36933729 self ._win .refresh ()
36943730 self ._editing = False
3731+ self ._cnf .inhibit_search = False
36953732 if logger .isEnabledFor (logging .DEBUG ):
36963733 logger .debug ('edited "{}"' .format (self ._list [self ._selection ]))
36973734
@@ -3891,6 +3928,10 @@ def _make_selection_visible(self):
38913928 elif chk > self ._number_of_lines :
38923929 self ._start = max (0 , int ((self ._selection - self ._number_of_lines ) / 2 ))
38933930
3931+ def set_selection (self , sel ):
3932+ self .selection = sel
3933+ self ._go_to_line (self ._selection )
3934+
38943935 def _go_to_line (self , a_line ):
38953936 self ._selection = a_line
38963937 self ._make_selection_visible ()
@@ -4018,6 +4059,7 @@ def _detect_conflict(self, modified_item):
40184059 """
40194060 # reset self.existing_conflict ; None means no conflict
40204061 self .existing_conflict = None
4062+ logger .error (f'2 { self .existing_conflict = } ' )
40214063
40224064 # Extract key and the new shortcut code from the modified item
40234065 key = modified_item [0 ] # Identifier for the shortcut (e.g., "reload", "mute")
@@ -4059,13 +4101,18 @@ def _detect_conflict(self, modified_item):
40594101 if key_in_context == key :
40604102 continue
40614103
4062- idx , chk = [(i , x ) for i , x in enumerate (self ._list ) if x [0 ] == key_in_context ][0 ]
4063- if logger .isEnabledFor (logging .DEBUG ):
4064- logger .debug ('\n \n item with key - {0}: {1}\n \n ' .format (idx , chk ))
4065- # Check if the new shortcut code matches the existing shortcut code for any other key
4066- if chk [3 ] == new_shortcut_code :
4067- self .existing_conflict = (modified_item [- 3 ], idx ) # Return the first conflicting key and index
4068- return
4104+ try :
4105+ idx , chk = [(i , x ) for i , x in enumerate (self ._list ) if x [0 ] == key_in_context ][0 ]
4106+ if logger .isEnabledFor (logging .DEBUG ):
4107+ logger .debug ('\n \n item with key - {}: {}, new_shortcut_code = {}\n \n ' .format (idx , chk , new_shortcut_code ))
4108+
4109+ # Check if the new shortcut code matches the existing shortcut code for any other key
4110+ if chk [3 ] == new_shortcut_code :
4111+ self .existing_conflict = (modified_item [- 3 ], idx ) # Return the first conflicting key and index
4112+ logger .debug (f'{ self .existing_conflict = } ' )
4113+ return
4114+ except IndexError :
4115+ pass
40694116
40704117 if logger .isEnabledFor (logging .DEBUG ):
40714118 logger .debug ('\n -*-*-*-*-*-*-*-*- None 2\n \n ' )
@@ -4143,8 +4190,10 @@ def keypress(self, char):
41434190 l_char = None
41444191 self ._needs_update = False
41454192 if char == ord ('0' ):
4193+ logger .error (f'{ self .existing_conflict = } ' )
41464194 if self .existing_conflict :
41474195 self ._editing = False
4196+ self ._cnf .inhibit_search = False
41484197 if self ._selection == self .existing_conflict [0 ]:
41494198 self ._go_to_line (self .existing_conflict [1 ])
41504199 else :
0 commit comments