1010
1111from . import base
1212from . import pref
13+ from . import _const
1314from . import database
1415from . import editmeta
1516
@@ -48,7 +49,27 @@ def search_for_files(self, command_line, widget_proxy, live):
4849
4950 self .parent .after_search_now_filter_view = True
5051 self .parent .wMain .values = self .parent .value .get ()
51- self .parent .wMain .display ()
52+ self .parent .display ()
53+ if self .parent .wMain .values :
54+ self .parent .wMain .set_current_status ()
55+ else : # search didn't match
56+ self .parent .wStatus2 .value = ' '
57+ self .parent .display ()
58+
59+
60+ def special_handler (handler ):
61+ """Decorator which accepts a handler as param and executes it
62+ only if the window is not empty(if there are files to display)
63+ If the handler requires the status line to be updated(like with
64+ movement handlers like h_cursor_line_up to show metadata preview
65+ of file under cursor), that is also done
66+ """
67+ def wrapper (self , char ):
68+ if self .values :
69+ handler (self , char )
70+ if handler .__name__ in _const .HANDLERS_REQUIRING_STATUS_UDPATE :
71+ self .set_current_status ()
72+ return wrapper
5273
5374
5475class ClidMultiline (npy .MultiLine ):
@@ -70,7 +91,6 @@ class ClidMultiline(npy.MultiLine):
7091 self.parent refers to ClidInterface -> class
7192 self.parent.value refers to database.Mp3DataBase -> class
7293 """
73-
7494 def __init__ (self , * args , ** kwargs ):
7595 super ().__init__ (* args , ** kwargs )
7696 self .allow_filtering = False # does NOT refer to search invoked with '/'
@@ -79,49 +99,45 @@ def __init__(self, *args, **kwargs):
7999 smooth = self .parent .parentApp .settings ['smooth_scroll' ] # is smooth scroll enabled ?
80100 self .slow_scroll = True if smooth == 'true' else False
81101
82- def set_up_handlers (self ):
83- super ().set_up_handlers ()
84102 self .handlers .update ({
85103 'u' : self .h_reload_files ,
86104 '2' : self .h_switch_to_settings ,
87105 curses .ascii .SP : self .h_multi_select ,
88106 curses .ascii .ESC : self .h_revert_escape ,
89107 })
90108
91- self .h_cursor_line_down = self . handler_with_status_updating (self .h_cursor_line_down )
92- self .h_cursor_line_up = self . handler_with_status_updating (self .h_cursor_line_up )
93- self .h_cursor_page_down = self . handler_with_status_updating (self .h_cursor_page_down )
94- self .h_cursor_page_up = self . handler_with_status_updating (self .h_cursor_page_up )
109+ # self.h_cursor_line_up = special_handler (self.h_cursor_line_up )
110+ # self.h_cursor_line_down = special_handler (self.h_cursor_line_down )
111+ # self.h_cursor_page_up = special_handler (self.h_cursor_page_up )
112+ # self.h_cursor_page_down = special_handler (self.h_cursor_page_down )
95113
114+ # Movement Handlers
115+ @special_handler
116+ def h_cursor_page_up (self , char ):
117+ super ().h_cursor_page_up (char )
96118
97- def run_only_if_window_is_not_empty (handler ):
98- """Decorator which accepts a handler as param and executes it
99- only if the window is not empty(if there are files to display)
100- """
101- def wrapper (self , char ):
102- if self .values :
103- handler (self , char )
104- return wrapper
105-
106- @staticmethod
107- def handler_with_status_updating (handler ):
108- """Decorator which adds status line updating(set status line's value
109- according to tags of file undef cursor) and `run_only_if_window_is_not_empty`
110- functionality to movement handler(up, down, page up, etc)
111- """
112- def wrapper (self , char ):
113- if self .values :
114- handler (self , char )
115- self .set_status (self .get_selected ())
116- return wrapper
119+ @special_handler
120+ def h_cursor_page_down (self , char ):
121+ super ().h_cursor_page_down (char )
122+
123+ @special_handler
124+ def h_cursor_line_up (self , char ):
125+ super ().h_cursor_line_up (char )
126+
127+ @special_handler
128+ def h_cursor_line_down (self , char ):
129+ super ().h_cursor_line_down (char )
117130
118131 @property
119132 def _relative_index_of_space_selected_values (self ):
120- return [self .values .index (file ) for file in self .space_selected_values if file in self .values ]
121-
122- def set_status (self , filename , ** kwargs ):
123- """Set the the value of self.parent.wStatus2 with metadata of file under cursor."""
124- self .parent .wStatus2 .value = self .parent .value .parse_meta_for_status (filename = filename , ** kwargs )
133+ return [self .values .index (file ) for file in self .space_selected_values \
134+ if file in self .values ]
135+
136+ def set_current_status (self , * args , ** kwargs ):
137+ """Show metadata(preview) of file under cursor in the status line"""
138+ s = self .parent .value .parse_meta_for_status (
139+ filename = self .get_selected (), * args , ** kwargs )
140+ self .parent .wStatus2 .value = s
125141 self .parent .display ()
126142
127143 def get_selected (self ):
@@ -154,7 +170,7 @@ def h_switch_to_settings(self, char):
154170 self .parent .parentApp .switchForm ("SETTINGS" )
155171
156172
157- @run_only_if_window_is_not_empty
173+ @special_handler
158174 def h_select (self , char ):
159175 app = self .parent .parentApp
160176 file_dict = self .parent .value .file_dict
@@ -171,7 +187,7 @@ def h_select(self, char):
171187 self .parent .parentApp .current_files = [file_dict [file_under_cursor ]]
172188 self .parent .parentApp .switchForm ("SINGLEEDIT" )
173189
174- @run_only_if_window_is_not_empty
190+ @special_handler
175191 def h_multi_select (self , char ):
176192 """Add or remove current line from list of lines
177193 to be highlighted, when <Space> is pressed.
0 commit comments