@@ -316,6 +316,13 @@ def selection(self, val):
316
316
self .__selection = val
317
317
#self.refresh_config_win()
318
318
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
+
319
326
def set_selection (self , sel ):
320
327
self .selection = sel
321
328
self ._put_cursor (0 )
@@ -3555,6 +3562,9 @@ class PyRadioKeyboardConfig():
3555
3562
_start = 0
3556
3563
_selection = 1
3557
3564
3565
+ # titles for search function
3566
+ _titles = None
3567
+
3558
3568
message = None
3559
3569
3560
3570
def __init__ (
@@ -3609,7 +3619,7 @@ def __init__(
3609
3619
self ._list [i ][- 2 ] = header_index
3610
3620
if logger .isEnabledFor (logging .DEBUG ):
3611
3621
for n in self ._list :
3612
- logger .debug (f'{ n } ' )
3622
+ logger .debug (f'list : { n } ' )
3613
3623
'''
3614
3624
3615
3625
# do not read keys.json to self._keys_to_classes
@@ -3630,7 +3640,33 @@ def __init__(
3630
3640
self ._keys_to_classes = self ._precompute_context_map (self ._classes )
3631
3641
# logger.error(f'{self._keys_to_classes = }')
3632
3642
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
3633
3648
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
3634
3670
3635
3671
def _precompute_context_map (self , results ):
3636
3672
"""
@@ -3681,17 +3717,18 @@ def _rename_keyboard_json_file(self, file_path):
3681
3717
return new_file_name
3682
3718
3683
3719
def _start_editing (self ):
3684
- self .existing_conflict = None
3685
3720
self ._win .addstr (self ._selection - self ._start + 2 , self .maxX - 8 , '[edit]' , curses .color_pair (6 ))
3686
3721
self ._win .refresh ()
3687
3722
self ._editing = True
3723
+ self ._cnf .inhibit_search = True
3688
3724
if logger .isEnabledFor (logging .DEBUG ):
3689
3725
logger .debug ('editing "{}"' .format (self ._list [self ._selection ]))
3690
3726
3691
3727
def _stop_editing (self ):
3692
3728
self ._win .addstr (self ._selection - self ._start + 2 , self .maxX - 8 , ' ' , curses .color_pair (6 ))
3693
3729
self ._win .refresh ()
3694
3730
self ._editing = False
3731
+ self ._cnf .inhibit_search = False
3695
3732
if logger .isEnabledFor (logging .DEBUG ):
3696
3733
logger .debug ('edited "{}"' .format (self ._list [self ._selection ]))
3697
3734
@@ -3891,6 +3928,10 @@ def _make_selection_visible(self):
3891
3928
elif chk > self ._number_of_lines :
3892
3929
self ._start = max (0 , int ((self ._selection - self ._number_of_lines ) / 2 ))
3893
3930
3931
+ def set_selection (self , sel ):
3932
+ self .selection = sel
3933
+ self ._go_to_line (self ._selection )
3934
+
3894
3935
def _go_to_line (self , a_line ):
3895
3936
self ._selection = a_line
3896
3937
self ._make_selection_visible ()
@@ -4018,6 +4059,7 @@ def _detect_conflict(self, modified_item):
4018
4059
"""
4019
4060
# reset self.existing_conflict ; None means no conflict
4020
4061
self .existing_conflict = None
4062
+ logger .error (f'2 { self .existing_conflict = } ' )
4021
4063
4022
4064
# Extract key and the new shortcut code from the modified item
4023
4065
key = modified_item [0 ] # Identifier for the shortcut (e.g., "reload", "mute")
@@ -4059,13 +4101,18 @@ def _detect_conflict(self, modified_item):
4059
4101
if key_in_context == key :
4060
4102
continue
4061
4103
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
4069
4116
4070
4117
if logger .isEnabledFor (logging .DEBUG ):
4071
4118
logger .debug ('\n -*-*-*-*-*-*-*-*- None 2\n \n ' )
@@ -4143,8 +4190,10 @@ def keypress(self, char):
4143
4190
l_char = None
4144
4191
self ._needs_update = False
4145
4192
if char == ord ('0' ):
4193
+ logger .error (f'{ self .existing_conflict = } ' )
4146
4194
if self .existing_conflict :
4147
4195
self ._editing = False
4196
+ self ._cnf .inhibit_search = False
4148
4197
if self ._selection == self .existing_conflict [0 ]:
4149
4198
self ._go_to_line (self .existing_conflict [1 ])
4150
4199
else :
0 commit comments