From f84e8791417822605f951df65583602dbefbab89 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Tue, 16 May 2023 21:26:00 -0500 Subject: [PATCH] added images to plugin menu options, added testing for generators, attempted mitigation of memory leak --- plugins/disk_usage/du_usage.glade | 24 ++++++++++++++++--- plugins/disk_usage/plugin.py | 14 +++++++---- plugins/trasher/plugin.py | 10 ++++---- .../core/fs_actions/file_system_actions.py | 14 +++++++++-- .../solarfm/core/mixins/ui/grid_mixin.py | 21 ++++++++++++---- .../solarfm/core/mixins/ui/tab_mixin.py | 9 ++++--- .../core/widgets/files_view/grid_mixin.py | 21 ++++++++++++---- .../core/widgets/files_view/tab_mixin.py | 11 ++++----- .../shellfm/windows/tabs/icons/icon.py | 2 +- .../usr/share/solarfm/contexct_menu.json | 2 ++ 10 files changed, 95 insertions(+), 33 deletions(-) diff --git a/plugins/disk_usage/du_usage.glade b/plugins/disk_usage/du_usage.glade index 1b609dc..221b878 100644 --- a/plugins/disk_usage/du_usage.glade +++ b/plugins/disk_usage/du_usage.glade @@ -60,9 +60,11 @@ False vertical - + True False + 5 + 5 5 5 5 @@ -76,6 +78,22 @@ 0 + + + True + False + 5 + 5 + 5 + 5 + center + + + False + True + 1 + + True @@ -91,7 +109,7 @@ - + Disk Usage @@ -113,7 +131,7 @@ True True - 1 + 2 diff --git a/plugins/disk_usage/plugin.py b/plugins/disk_usage/plugin.py index 3811661..d2cc67f 100644 --- a/plugins/disk_usage/plugin.py +++ b/plugins/disk_usage/plugin.py @@ -32,10 +32,14 @@ class Plugin(PluginBase): self._builder.add_from_file(self._GLADE_FILE) self._connect_builder_signals(self, self._builder) - self._du_dialog = self._builder.get_object("du_dialog") - self._du_store = self._builder.get_object("du_store") + self._du_dialog = self._builder.get_object("du_dialog") + self._du_tree_view = self._builder.get_object("du_tree_view") + self._du_store = self._builder.get_object("du_store") self._current_dir_lbl = self._builder.get_object("current_dir_lbl") + self._current_dir_lbl.set_line_wrap(False) + self._current_dir_lbl.set_ellipsize(1) # NONE = 0¶, START = 1¶, MIDDLE = 2¶, END = 3¶ + self._event_system.subscribe("show_du_menu", self._show_du_menu) def generate_reference_ui_element(self): @@ -49,7 +53,9 @@ class Plugin(PluginBase): self._event_system.emit("get_current_state") def _set_current_dir_lbl(self, widget=None, eve=None): - self._current_dir_lbl.set_label(f"Current Directory:\n{self._fm_state.tab.get_current_directory()}") + path = self._fm_state.tab.get_current_directory() + self._current_dir_lbl.set_label(path) + self._current_dir_lbl.set_tooltip_text(path) def _show_du_menu(self, widget=None, eve=None): self._fm_state = None @@ -72,7 +78,7 @@ class Plugin(PluginBase): # NOTE: Last entry is curret dir. Move to top of list and pop off... size, file = parts[-1].split("\t") - self._du_store.append([size, file.split("/")[-1]]) + self._du_tree_view.set_title(f"Disk Usage: {file.split('/')[-1]} ( {size} )") parts.pop() for part in parts: diff --git a/plugins/trasher/plugin.py b/plugins/trasher/plugin.py index ba9ac51..287ce8a 100644 --- a/plugins/trasher/plugin.py +++ b/plugins/trasher/plugin.py @@ -39,19 +39,21 @@ class Plugin(PluginBase): trash_a = Gtk.MenuItem("Trash Actions") trash_menu = Gtk.Menu() - self.restore = Gtk.MenuItem("Restore From Trash") + self.restore = Gtk.ImageMenuItem("Restore From Trash") + self.restore.set_image( Gtk.Image.new_from_icon_name("gtk-undelete", 3) ) self.restore.connect("activate", self.restore_trash_files) - self.empty = Gtk.MenuItem("Empty Trash") + self.empty = Gtk.ImageMenuItem("Empty Trash") + self.empty.set_image( Gtk.Image.new_from_icon_name("gtk-delete", 3) ) self.empty.connect("activate", self.empty_trash) trash = Gtk.ImageMenuItem("Trash") - trash.set_image( Gtk.Image.new_from_icon_name("user-trash", 16) ) + trash.set_image( Gtk.Image.new_from_icon_name("user-trash", 3) ) trash.connect("activate", self.trash_files) trash.set_always_show_image(True) go_to = Gtk.ImageMenuItem("Go To Trash") - go_to.set_image( Gtk.Image.new_from_icon_name("user-trash", 16) ) + go_to.set_image( Gtk.Image.new_from_icon_name("gtk-go-forward", 3) ) go_to.connect("activate", self.go_to_trash) go_to.set_always_show_image(True) diff --git a/src/versions/solarfm-0.0.1/solarfm/core/fs_actions/file_system_actions.py b/src/versions/solarfm-0.0.1/solarfm/core/fs_actions/file_system_actions.py index dc0bd56..603c9b6 100644 --- a/src/versions/solarfm-0.0.1/solarfm/core/fs_actions/file_system_actions.py +++ b/src/versions/solarfm-0.0.1/solarfm/core/fs_actions/file_system_actions.py @@ -47,6 +47,8 @@ class FileSystemActions(HandlerMixin, CRUDMixin): event_system.subscribe("paste_files", self.paste_files) event_system.subscribe("move_files", self.move_files) event_system.subscribe("copy_name", self.copy_name) + event_system.subscribe("copy_path", self.copy_path) + event_system.subscribe("copy_path_name", self.copy_path_name) event_system.subscribe("create_files", self.create_files) event_system.subscribe("rename_files", self.rename_files) @@ -79,8 +81,16 @@ class FileSystemActions(HandlerMixin, CRUDMixin): def copy_path(self): state = event_system.emit_and_await("get_current_state") - dir = state.tab.get_current_directory() - event_system.emit("set_clipboard_data", (file_name,)) + path = state.tab.get_current_directory() + print(path) + event_system.emit("set_clipboard_data", (path,)) + + def copy_path_name(self): + state = event_system.emit_and_await("get_current_state") + if len(state.uris) == 1: + file = state.uris[0].replace("file://") + print(file) + event_system.emit("set_clipboard_data", (file,)) def open_files(self): state = event_system.emit_and_await("get_current_state") diff --git a/src/versions/solarfm-0.0.1/solarfm/core/mixins/ui/grid_mixin.py b/src/versions/solarfm-0.0.1/solarfm/core/mixins/ui/grid_mixin.py index 3dcc163..2725424 100644 --- a/src/versions/solarfm-0.0.1/solarfm/core/mixins/ui/grid_mixin.py +++ b/src/versions/solarfm-0.0.1/solarfm/core/mixins/ui/grid_mixin.py @@ -14,11 +14,10 @@ from ...widgets.icon_tree_widget import IconTreeWidget - class GridMixin: """docstring for GridMixin""" - def load_store(self, tab, store, save_state = False): + def load_store(self, tab, store, save_state = False, use_generator = False): store.clear() dir = tab.get_current_directory() files = tab.get_files() @@ -27,19 +26,33 @@ class GridMixin: store.append([None, file[0]]) Gtk.main_iteration() - for i, file in enumerate(files): - self.create_icon(i, tab, store, dir, file[0]) + if use_generator: + # NOTE: tab > icon > _get_system_thumbnail_gtk_thread must not be used + # as the attempted promotion back to gtk threading stalls the generator. (We're already in main gtk thread) + for i, icon in enumerate( self.create_icons_generator(tab, dir, files) ): + self.load_icon(i, store, icon) + else: + for i, file in enumerate(files): + self.create_icon(i, tab, store, dir, file[0]) # NOTE: Not likely called often from here but it could be useful if save_state and not trace_debug: self.fm_controller.save_state() + def create_icons_generator(self, tab, dir, files): + for file in files: + icon = tab.create_icon(dir, file[0]) + yield icon @daemon_threaded def create_icon(self, i, tab, store, dir, file): icon = tab.create_icon(dir, file) GLib.idle_add(self.update_store, *(i, store, icon,)) + @daemon_threaded + def load_icon(self, i, store, icon): + GLib.idle_add(self.update_store, *(i, store, icon,)) + def update_store(self, i, store, icon): itr = store.get_iter(i) store.set_value(itr, 0, icon) diff --git a/src/versions/solarfm-0.0.1/solarfm/core/mixins/ui/tab_mixin.py b/src/versions/solarfm-0.0.1/solarfm/core/mixins/ui/tab_mixin.py index d75fac0..59d3892 100644 --- a/src/versions/solarfm-0.0.1/solarfm/core/mixins/ui/tab_mixin.py +++ b/src/versions/solarfm-0.0.1/solarfm/core/mixins/ui/tab_mixin.py @@ -50,8 +50,6 @@ class TabMixin(GridMixin): self.set_file_watcher(tab) - - def close_tab(self, button, eve = None): notebook = button.get_parent().get_parent() if notebook.get_n_pages() == 1: @@ -63,7 +61,6 @@ class TabMixin(GridMixin): scroll = self.builder.get_object(f"{wid}|{tid}") icon_grid = scroll.get_children()[0] store = icon_grid.get_model() - page_num = notebook.page_num(scroll) tab = self.get_fm_window(wid).get_tab_by_id(tid) watcher = tab.get_dir_watcher() @@ -71,12 +68,14 @@ class TabMixin(GridMixin): self.get_fm_window(wid).delete_tab_by_id(tid) store.clear() + # store.run_dispose() icon_grid.destroy() + # icon_grid.run_dispose() scroll.destroy() + scroll.run_dispose() tab_box.destroy() - notebook.remove_page(page_num) + tab_box.run_dispose() - del page_num del store del icon_grid del scroll diff --git a/src/versions/solarfm-0.0.1/solarfm/core/widgets/files_view/grid_mixin.py b/src/versions/solarfm-0.0.1/solarfm/core/widgets/files_view/grid_mixin.py index 9e7fc42..2725424 100644 --- a/src/versions/solarfm-0.0.1/solarfm/core/widgets/files_view/grid_mixin.py +++ b/src/versions/solarfm-0.0.1/solarfm/core/widgets/files_view/grid_mixin.py @@ -14,11 +14,10 @@ from ...widgets.icon_tree_widget import IconTreeWidget - class GridMixin: """docstring for GridMixin""" - def load_store(self, tab, store, save_state=False): + def load_store(self, tab, store, save_state = False, use_generator = False): store.clear() dir = tab.get_current_directory() files = tab.get_files() @@ -27,19 +26,33 @@ class GridMixin: store.append([None, file[0]]) Gtk.main_iteration() - for i, file in enumerate(files): - self.create_icon(i, tab, store, dir, file[0]) + if use_generator: + # NOTE: tab > icon > _get_system_thumbnail_gtk_thread must not be used + # as the attempted promotion back to gtk threading stalls the generator. (We're already in main gtk thread) + for i, icon in enumerate( self.create_icons_generator(tab, dir, files) ): + self.load_icon(i, store, icon) + else: + for i, file in enumerate(files): + self.create_icon(i, tab, store, dir, file[0]) # NOTE: Not likely called often from here but it could be useful if save_state and not trace_debug: self.fm_controller.save_state() + def create_icons_generator(self, tab, dir, files): + for file in files: + icon = tab.create_icon(dir, file[0]) + yield icon @daemon_threaded def create_icon(self, i, tab, store, dir, file): icon = tab.create_icon(dir, file) GLib.idle_add(self.update_store, *(i, store, icon,)) + @daemon_threaded + def load_icon(self, i, store, icon): + GLib.idle_add(self.update_store, *(i, store, icon,)) + def update_store(self, i, store, icon): itr = store.get_iter(i) store.set_value(itr, 0, icon) diff --git a/src/versions/solarfm-0.0.1/solarfm/core/widgets/files_view/tab_mixin.py b/src/versions/solarfm-0.0.1/solarfm/core/widgets/files_view/tab_mixin.py index 21c3bd1..6e643d6 100644 --- a/src/versions/solarfm-0.0.1/solarfm/core/widgets/files_view/tab_mixin.py +++ b/src/versions/solarfm-0.0.1/solarfm/core/widgets/files_view/tab_mixin.py @@ -63,23 +63,21 @@ class TabMixin(GridMixin): scroll = self.builder.get_object(f"{wid}|{tid}") icon_grid = scroll.get_children()[0] store = icon_grid.get_model() - page_num = notebook.page_num(scroll) tab = self.get_fm_window(wid).get_tab_by_id(tid) watcher = tab.get_dir_watcher() watcher.cancel() self.get_fm_window(wid).delete_tab_by_id(tid) - icon_grid = scroll.get_children()[0] - store = icon_grid.get_model() - store.clear() + store.run_dispose() icon_grid.destroy() + icon_grid.run_dispose() scroll.destroy() + scroll.run_dispose() tab_box.destroy() - notebook.remove_page(page_num) + tab_box.run_dispose() - del page_num del store del icon_grid del scroll @@ -89,6 +87,7 @@ class TabMixin(GridMixin): if not settings.is_trace_debug(): self.fm_controller.save_state() + self.set_window_title() # NOTE: Not actually getting called even tho set in the glade file... diff --git a/src/versions/solarfm-0.0.1/solarfm/shellfm/windows/tabs/icons/icon.py b/src/versions/solarfm-0.0.1/solarfm/shellfm/windows/tabs/icons/icon.py index 160737e..be17d8c 100644 --- a/src/versions/solarfm-0.0.1/solarfm/shellfm/windows/tabs/icons/icon.py +++ b/src/versions/solarfm-0.0.1/solarfm/shellfm/windows/tabs/icons/icon.py @@ -50,7 +50,7 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): if not thumbnl: # TODO: Detect if not in a thread and use directly for speed get_system_thumbnail - # thumbnl = self.get_system_thumbnail(full_path, full_path, self.sys_icon_wh[0]) + # thumbnl = self.get_system_thumbnail(full_path, self.sys_icon_wh[0]) thumbnl = self._get_system_thumbnail_gtk_thread(full_path, self.sys_icon_wh[0]) if not thumbnl: raise IconException("No known icons found.") diff --git a/user_config/usr/share/solarfm/contexct_menu.json b/user_config/usr/share/solarfm/contexct_menu.json index 9e9323b..c17be4c 100644 --- a/user_config/usr/share/solarfm/contexct_menu.json +++ b/user_config/usr/share/solarfm/contexct_menu.json @@ -11,6 +11,8 @@ "Cut": ["STOCK_CUT", "cut"], "Copy": ["STOCK_COPY", "copy"], "Copy Name": ["STOCK_COPY", "copy_name"], + "Copy Path": ["STOCK_COPY", "copy_path"], + "Copy Path+Name": ["STOCK_COPY", "copy_path_name"], "Paste": ["STOCK_PASTE", "paste"] }, "Plugins": {}