From d025ffd97a3296819138642117fe3a510615d951 Mon Sep 17 00:00:00 2001 From: piotrj Date: Sat, 10 Feb 2024 15:59:48 +0100 Subject: [PATCH] dialogs stack improvements nuitka update --- requirements.txt | 2 +- src/dude.py | 116 ++++++++++++++++++++++++++++------------------- 2 files changed, 71 insertions(+), 47 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2b72f05..f6ec147 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ pyinstaller==6.3.0 appdirs==1.4.4 send2trash==1.8.2 zstandard==0.22.0 -nuitka==2.0.1 +nuitka==2.0.2 diff --git a/src/dude.py b/src/dude.py index 76afb18..07cef21 100755 --- a/src/dude.py +++ b/src/dude.py @@ -200,27 +200,34 @@ class Gui: MAX_PATHS=8 sel_path_full='' - actions_processing=False - ##################################################### - def block(func): - def block_wrapp(self,*args,**kwargs): + block_processing_stack=['init'] + + def processing_off(self,caller_id=None): + self.block_processing_stack.append(caller_id) + + disable = lambda menu : self.menubar_entryconfig(menu, state="disabled") + + _ = {disable(menu) for menu in ("File","Navigation","Help") } - prev_active=self.actions_processing - self.actions_processing=False + self.menubar_config(cursor='watch') + self.main_config(cursor='watch') - prev_cursor=self.menubar_cget('cursor') + def processing_on(self,caller_id=None): + self.block_processing_stack.pop() - if prev_cursor=='watch': - print('nested call:',func) + if not self.block_processing_stack: + norm = lambda menu : self.menubar_entryconfig(menu, state="normal") - self_menubar_config = self.menubar_config - self_main_config = self.main_config + _ = {norm(menu) for menu in ("File","Navigation","Help") } - self.menu_disable() + self.main_config(cursor='') + self.menubar_config(cursor='') - self_menubar_config(cursor='watch') - self_main_config(cursor='watch') + ##################################################### + def block(func): + def block_wrapp(self,*args,**kwargs): + self.processing_off(f'block_wrapp:{func.__name__}') try: res=func(self,*args,**kwargs) @@ -231,11 +238,7 @@ def block_wrapp(self,*args,**kwargs): self.get_info_dialog_on_main().show('INTERNAL ERROR block_wrapp',f'{func.__name__}\n' + str(e)) res=None - self.actions_processing=prev_active - - self.menu_enable() - self_main_config(cursor=prev_cursor) - self_menubar_config(cursor=prev_cursor) + self.processing_on() return res return block_wrapp @@ -589,7 +592,21 @@ def __init__(self,cwd,paths_to_add=None,exclude=None,exclude_regexp=None,norun=N self_main_unbind_class('Treeview', '<>') self_main_unbind_class('Treeview', '<>') - self.vsb1 = Scrollbar(frame_groups, orient='vertical', command=self_groups_tree.yview,takefocus=False) + def mouse_scroll(event): + if self.block_processing_stack: + return "break" + + self_groups_tree.bind('', mouse_scroll) + self_groups_tree.bind('', mouse_scroll) + self_groups_tree.bind('', mouse_scroll) + + def self_groups_tree_yview(*args): + if self.block_processing_stack: + return "break" + else: + self_groups_tree.yview(*args) + + self.vsb1 = Scrollbar(frame_groups, orient='vertical', command=self_groups_tree_yview,takefocus=False) self_groups_tree.configure(yscrollcommand=self.vsb1.set) @@ -636,7 +653,17 @@ def __init__(self,cwd,paths_to_add=None,exclude=None,exclude_regexp=None,norun=N self_folder_tree_heading('file', text='File \u25B2') - self.vsb2 = Scrollbar(frame_folder, orient='vertical', command=self_folder_tree.yview,takefocus=False) + self_folder_tree.bind('', mouse_scroll) + self_folder_tree.bind('', mouse_scroll) + self_folder_tree.bind('', mouse_scroll) + + def self_folder_tree_yview(*args): + if self.block_processing_stack: + return "break" + else: + self_folder_tree.yview(*args) + + self.vsb2 = Scrollbar(frame_folder, orient='vertical', command=self_folder_tree_yview,takefocus=False) #,bg=self.bg_color self.folder_tree_configure(yscrollcommand=self.vsb2.set) @@ -812,7 +839,7 @@ def file_cascade_post(): item_actions_state=('disabled','normal')[self.sel_item is not None] self.file_cascade.delete(0,'end') - if self.actions_processing: + if not self.block_processing_stack: self_file_cascade_add_command = self.file_cascade.add_command self_file_cascade_add_separator = self.file_cascade.add_separator @@ -838,7 +865,7 @@ def navi_cascade_post(): self.popup_folder_unpost() self.navi_cascade.delete(0,'end') - if self.actions_processing: + if not self.block_processing_stack: item_actions_state=('disabled','normal')[self.sel_item is not None] self_navi_cascade_add_command = self.navi_cascade.add_command @@ -870,7 +897,7 @@ def help_cascade_post(): self.popup_folder_unpost() self.help_cascade.delete(0,'end') - if self.actions_processing: + if not self.block_processing_stack: self_help_cascade_add_command = self.help_cascade.add_command self_help_cascade_add_separator = self.help_cascade.add_separator @@ -977,12 +1004,14 @@ def help_cascade_post(): gc_collect() gc_enable() - self.actions_processing=True + self.processing_on() self_main.mainloop() ####################################################################### def pre_show(self,on_main_window_dialog=True,new_widget=None): + self.processing_off(f'pre_show:{new_widget}') + self.menubar_unpost() self.hide_tooltip() self.popup_groups_unpost() @@ -992,15 +1021,11 @@ def pre_show(self,on_main_window_dialog=True,new_widget=None): if new_widget: self.main_locked_by_child=new_widget - self.actions_processing=False - self.menu_disable() - self.menubar_config(cursor="watch") - def post_close(self,on_main_window_dialog=True): if on_main_window_dialog: - self.actions_processing=True - self.menu_enable() - self.menubar_config(cursor="") + self.main_locked_by_child=None + + self.processing_on() def pre_show_settings(self,on_main_window_dialog=True,new_widget=None): _ = {var.set(self.cfg_get_bool(key)) for var,key in self.settings} @@ -1193,7 +1218,7 @@ def get_info_dialog_on_scan(self): if not self.info_dialog_on_scan_created: self.status("Creating dialog ...") - self.info_dialog_on_scan = LabelDialog(self.scan_dialog.widget,self.main_icon_tuple,self.bg_color,pre_show=self.pre_show,post_close=self.post_close) + self.info_dialog_on_scan = LabelDialog(self.scan_dialog.widget,self.main_icon_tuple,self.bg_color,pre_show=lambda new_widget : self.pre_show(on_main_window_dialog=False,new_widget=new_widget),post_close=self.post_close) self.info_dialog_on_scan_created = True @@ -1206,7 +1231,7 @@ def get_exclude_dialog_on_scan(self): if not self.exclude_dialog_on_scan_created: self.status("Creating dialog ...") - self.exclude_dialog_on_scan = EntryDialogQuestion(self.scan_dialog.widget,self.main_icon_tuple,self.bg_color,pre_show=self.pre_show,post_close=self.post_close) + self.exclude_dialog_on_scan = EntryDialogQuestion(self.scan_dialog.widget,self.main_icon_tuple,self.bg_color,pre_show=lambda new_widget : self.pre_show(on_main_window_dialog=False,new_widget=new_widget),post_close=self.post_close) self.exclude_dialog_on_scan_created = True @@ -1220,7 +1245,7 @@ def get_progress_dialog_on_scan(self): if not self.progress_dialog_on_scan_created: self.status("Creating dialog ...") - self.progress_dialog_on_scan = ProgressDialog(self.scan_dialog.widget,self.main_icon_tuple,self.bg_color,pre_show=self.pre_show,post_close=self.post_close) + self.progress_dialog_on_scan = ProgressDialog(self.scan_dialog.widget,self.main_icon_tuple,self.bg_color,pre_show=lambda new_widget : self.pre_show(on_main_window_dialog=False,new_widget=new_widget),post_close=self.post_close) self.progress_dialog_on_scan.command_on_close = self.progress_dialog_abort self.progress_dialog_on_scan.abort_button.bind("", lambda event : self.widget_leave()) @@ -1478,11 +1503,11 @@ def motion_on_widget(self,event,message=None): self.tooltip_show_after_widget = event.widget.after(1, self.show_tooltip_widget(event)) def motion_on_groups_tree(self,event): - if self.actions_processing: + if not self.block_processing_stack: self.tooltip_show_after_groups = event.widget.after(1, self.show_tooltip_groups(event)) def motion_on_folder_tree(self,event): - if self.actions_processing: + if not self.block_processing_stack: self.tooltip_show_after_folder = event.widget.after(1, self.show_tooltip_folder(event)) def configure_tooltip(self,widget): @@ -1681,7 +1706,7 @@ def reset_sels(self): self.sel_kind = None def delete_window_wrapper(self): - if self.actions_processing: + if not self.block_processing_stack: self.exit() else: self.status('WM_DELETE_WINDOW NOT exiting ...') @@ -1937,8 +1962,7 @@ def goto_first_last_dir_entry(self,index): @catched def key_press(self,event): - if self.actions_processing: - + if not self.block_processing_stack: self.main_unbind_class('Treeview','') self.hide_tooltip() @@ -2154,7 +2178,7 @@ def tree_on_mouse_button_press(self,event,toggle=False): self.popup_groups_unpost() self.popup_folder_unpost() - if self.actions_processing: + if not self.block_processing_stack: tree=event.widget region = tree.identify("region", event.x, event.y) @@ -2289,7 +2313,7 @@ def context_menu_show(self,event): if tree.identify("region", event.x, event.y) == 'heading': return - if not self.actions_processing: + if self.block_processing_stack: return tree.focus_set() @@ -3276,7 +3300,7 @@ def initial_focus(self): @block @logwrapper def groups_show(self): - self.menu_disable() + #self.menu_disable() self_idfunc=self.idfunc = (lambda i,d : '%s-%s' % (i,d)) if len(dude_core.devs)>1 else (lambda i,d : str(i)) self_status=self.status @@ -3366,7 +3390,7 @@ def groups_show(self): self.initial_focus() self.calc_mark_stats_groups() - self.menu_enable() + #self.menu_enable() self_status('') @block @@ -4229,6 +4253,7 @@ def process_files_confirm(self,action,processed_items,remaining_items,scope_titl _ = {l_warning(line) for line in message} l_warning('###########################################################################################') l_warning('Confirmed.') + return False @block @@ -4302,7 +4327,6 @@ def process_files_core(self,action,processed_items,remaining_items): abort_on_error=self.cfg_get_bool(CFG_ABORT_ON_ERROR) erase_empty_dirs=self.cfg_get_bool(CFG_ERASE_EMPTY_DIRS) - self_groups_tree_item_to_data = self.groups_tree_item_to_data dude_core_delete_file_wrapper = dude_core.delete_file_wrapper @@ -4703,7 +4727,7 @@ def enter_dir(self,fullpath,sel): self.folder_tree_sel_change(item) def double_left_button(self,event): - if self.actions_processing: + if not self.block_processing_stack: tree=event.widget if tree.identify("region", event.x, event.y) != 'heading': if item:=tree.identify('item',event.x,event.y):