extending builder; format cleanup; dereference attempt

This commit is contained in:
itdominator 2023-09-27 21:03:49 -05:00
parent 8046fec794
commit 39aa0eeea4
10 changed files with 59 additions and 29 deletions

View File

@ -77,8 +77,7 @@ class Controller(UIMixin, SignalsMixins, Controller_Data):
event_system.subscribe("set_clipboard_data", self.set_clipboard_data) event_system.subscribe("set_clipboard_data", self.set_clipboard_data)
def _load_glade_file(self): def _load_glade_file(self):
self.builder = Gtk.Builder() self.builder.add_from_file( settings_manager.get_glade_file() )
self.builder.add_from_file(settings_manager.get_glade_file())
self.builder.expose_object("main_window", self.window) self.builder.expose_object("main_window", self.window)
self.core_widget = self.builder.get_object("core_widget") self.core_widget = self.builder.get_object("core_widget")

View File

@ -35,13 +35,39 @@ class State:
user_pass_dialog: type = None user_pass_dialog: type = None
class SFMBuilder(Gtk.Builder):
"""docstring for SFMBuilder."""
def __init__(self):
super(SFMBuilder, self).__init__()
self.objects = {}
def get_object(self, id: str, use_gtk: bool = True) -> any:
if not use_gtk:
return self.objects[id]
return super(SFMBuilder, self).get_object(id)
def expose_object(self, id: str, object: any, use_gtk: bool = True) -> None:
if not use_gtk:
self.objects[id] = object
else:
super(SFMBuilder, self).expose_object(id, object)
def dereference_object(self, id: str) -> None:
del self.objects[id]
class Controller_Data: class Controller_Data:
""" Controller_Data contains most of the state of the app at ay given time. It also has some support methods. """ """ Controller_Data contains most of the state of the app at ay given time. It also has some support methods. """
__slots__ = "settings", "builder", "logger", "keybindings", "trashman", "fm_controller", "window", "window1", "window2", "window3", "window4" __slots__ = "settings", "builder", "logger", "keybindings", "trashman", "fm_controller", "window", "window1", "window2", "window3", "window4"
def _setup_controller_data(self) -> None: def _setup_controller_data(self) -> None:
self.window = settings_manager.get_main_window() self.window = settings_manager.get_main_window()
self.builder = None self.builder = SFMBuilder()
self.core_widget = None self.core_widget = None
self._load_glade_file() self._load_glade_file()
@ -88,7 +114,7 @@ class Controller_Data:
state.notebooks = self.notebooks state.notebooks = self.notebooks
state.wid, state.tid = self.fm_controller.get_active_wid_and_tid() state.wid, state.tid = self.fm_controller.get_active_wid_and_tid()
state.tab = self.get_fm_window(state.wid).get_tab_by_id(state.tid) state.tab = self.get_fm_window(state.wid).get_tab_by_id(state.tid)
state.icon_grid = self.builder.get_object(f"{state.wid}|{state.tid}|icon_grid") state.icon_grid = self.builder.get_object(f"{state.wid}|{state.tid}|icon_grid", use_gtk = False)
# state.icon_grid = event_system.emit_and_await("get_files_view_icon_grid", (state.wid, state.tid)) # state.icon_grid = event_system.emit_and_await("get_files_view_icon_grid", (state.wid, state.tid))
state.store = state.icon_grid.get_model() state.store = state.icon_grid.get_model()
state.message_dialog = MessageWidget() state.message_dialog = MessageWidget()
@ -110,7 +136,7 @@ class Controller_Data:
event_system.emit("update_state_info_plugins", state) # NOTE: Need to remove after we convert plugins to use emit_and_await event_system.emit("update_state_info_plugins", state) # NOTE: Need to remove after we convert plugins to use emit_and_await
return state return state
def format_to_uris(self, store, wid, tid, treePaths, use_just_path=False): def format_to_uris(self, store, wid, tid, treePaths, use_just_path = False):
tab = self.get_fm_window(wid).get_tab_by_id(tid) tab = self.get_fm_window(wid).get_tab_by_id(tid)
dir = tab.get_current_directory() dir = tab.get_current_directory()
uris = [] uris = []

View File

@ -35,7 +35,7 @@ class FileActionSignalsMixin:
# NOTE: Too lazy to impliment a proper update handler and so just regen store and update tab. # NOTE: Too lazy to impliment a proper update handler and so just regen store and update tab.
# Use a lock system to prevent too many update calls for certain instances but user can manually refresh if they have urgency # Use a lock system to prevent too many update calls for certain instances but user can manually refresh if they have urgency
def dir_watch_updates(self, file_monitor, file, other_file=None, eve_type=None, data=None): def dir_watch_updates(self, file_monitor, file, other_file = None, eve_type = None, data = None):
if eve_type in [Gio.FileMonitorEvent.CREATED, Gio.FileMonitorEvent.DELETED, if eve_type in [Gio.FileMonitorEvent.CREATED, Gio.FileMonitorEvent.DELETED,
Gio.FileMonitorEvent.RENAMED, Gio.FileMonitorEvent.MOVED_IN, Gio.FileMonitorEvent.RENAMED, Gio.FileMonitorEvent.MOVED_IN,
Gio.FileMonitorEvent.MOVED_OUT]: Gio.FileMonitorEvent.MOVED_OUT]:
@ -68,7 +68,7 @@ class FileActionSignalsMixin:
wid, tid = tab_widget.split("|") wid, tid = tab_widget.split("|")
notebook = self.builder.get_object(f"window_{wid}") notebook = self.builder.get_object(f"window_{wid}")
tab = self.get_fm_window(wid).get_tab_by_id(tid) tab = self.get_fm_window(wid).get_tab_by_id(tid)
icon_grid = self.builder.get_object(f"{wid}|{tid}|icon_grid") icon_grid = self.builder.get_object(f"{wid}|{tid}|icon_grid", use_gtk = False)
store = icon_grid.get_model() store = icon_grid.get_model()
_store, tab_widget_label = self.get_store_and_label_from_notebook(notebook, f"{wid}|{tid}") _store, tab_widget_label = self.get_store_and_label_from_notebook(notebook, f"{wid}|{tid}")
@ -82,7 +82,7 @@ class FileActionSignalsMixin:
self.set_bottom_labels(tab) self.set_bottom_labels(tab)
def do_file_search(self, widget, eve=None): def do_file_search(self, widget, eve = None):
if not self.ctrl_down and not self.shift_down and not self.alt_down: if not self.ctrl_down and not self.shift_down and not self.alt_down:
target = widget.get_name() target = widget.get_name()
notebook = self.builder.get_object(target) notebook = self.builder.get_object(target)

View File

@ -74,7 +74,7 @@ class KeyboardSignalsMixin:
def keyboard_close_tab(self): def keyboard_close_tab(self):
wid, tid = self.fm_controller.get_active_wid_and_tid() wid, tid = self.fm_controller.get_active_wid_and_tid()
notebook = self.builder.get_object(f"window_{wid}") notebook = self.builder.get_object(f"window_{wid}")
scroll = self.builder.get_object(f"{wid}|{tid}") scroll = self.builder.get_object(f"{wid}|{tid}", use_gtk = False)
page = notebook.page_num(scroll) page = notebook.page_num(scroll)
tab = self.get_fm_window(wid).get_tab_by_id(tid) tab = self.get_fm_window(wid).get_tab_by_id(tid)
watcher = tab.get_dir_watcher() watcher = tab.get_dir_watcher()

View File

@ -81,7 +81,7 @@ class GridMixin:
def create_tab_widget(self, tab): def create_tab_widget(self, tab):
return TabHeaderWidget(tab, self.close_tab) return TabHeaderWidget(tab, self.close_tab)
def create_scroll_and_store(self, tab, wid, use_tree_view=False): def create_scroll_and_store(self, tab, wid, use_tree_view = False):
scroll = Gtk.ScrolledWindow() scroll = Gtk.ScrolledWindow()
if not use_tree_view: if not use_tree_view:
@ -93,8 +93,8 @@ class GridMixin:
scroll.add(grid) scroll.add(grid)
scroll.set_name(f"{wid}|{tab.get_id()}") scroll.set_name(f"{wid}|{tab.get_id()}")
grid.set_name(f"{wid}|{tab.get_id()}") grid.set_name(f"{wid}|{tab.get_id()}")
self.builder.expose_object(f"{wid}|{tab.get_id()}|icon_grid", grid) self.builder.expose_object(f"{wid}|{tab.get_id()}|icon_grid", grid, use_gtk = False)
self.builder.expose_object(f"{wid}|{tab.get_id()}", scroll) self.builder.expose_object(f"{wid}|{tab.get_id()}", scroll, use_gtk = False)
return scroll, grid.get_store() return scroll, grid.get_store()

View File

@ -17,7 +17,7 @@ from .grid_mixin import GridMixin
class TabMixin(GridMixin): class TabMixin(GridMixin):
"""docstring for TabMixin""" """docstring for TabMixin"""
def create_tab(self, wid=None, tid=None, path=None): def create_tab(self, wid: int = None, tid: int = None, path: str = None):
if not wid: if not wid:
wid, tid = self.fm_controller.get_active_wid_and_tid() wid, tid = self.fm_controller.get_active_wid_and_tid()
@ -60,7 +60,7 @@ class TabMixin(GridMixin):
tab_box = button.get_parent() tab_box = button.get_parent()
wid = int(notebook.get_name()[-1]) wid = int(notebook.get_name()[-1])
tid = self.get_id_from_tab_box(tab_box) tid = self.get_id_from_tab_box(tab_box)
scroll = self.builder.get_object(f"{wid}|{tid}") scroll = self.builder.get_object(f"{wid}|{tid}", use_gtk = False)
icon_grid = scroll.get_children()[0] icon_grid = scroll.get_children()[0]
store = icon_grid.get_store() store = icon_grid.get_store()
tab = self.get_fm_window(wid).get_tab_by_id(tid) tab = self.get_fm_window(wid).get_tab_by_id(tid)
@ -69,6 +69,9 @@ class TabMixin(GridMixin):
watcher.cancel() watcher.cancel()
self.get_fm_window(wid).delete_tab_by_id(tid) self.get_fm_window(wid).delete_tab_by_id(tid)
self.builder.dereference_object(f"{wid}|{tid}|icon_grid")
self.builder.dereference_object(f"{wid}|{tid}")
store.clear() store.clear()
# store.run_dispose() # store.run_dispose()
icon_grid.destroy() icon_grid.destroy()
@ -112,7 +115,7 @@ class TabMixin(GridMixin):
if not settings_manager.is_trace_debug(): if not settings_manager.is_trace_debug():
self.fm_controller.save_state() self.fm_controller.save_state()
def on_tab_switch_update(self, notebook, content=None, index=None): def on_tab_switch_update(self, notebook, content = None, index = None):
self.selected_files.clear() self.selected_files.clear()
wid, tid = content.get_children()[0].get_name().split("|") wid, tid = content.get_children()[0].get_name().split("|")
self.fm_controller.set_wid_and_tid(wid, tid) self.fm_controller.set_wid_and_tid(wid, tid)
@ -131,7 +134,7 @@ class TabMixin(GridMixin):
def get_tab_icon_grid_from_notebook(self, notebook): def get_tab_icon_grid_from_notebook(self, notebook):
return notebook.get_children()[1].get_children()[0] return notebook.get_children()[1].get_children()[0]
def refresh_tab(data=None): def refresh_tab(data = None):
state = self.get_current_state() state = self.get_current_state()
state.tab.load_directory() state.tab.load_directory()
self.load_store(state.tab, state.store) self.load_store(state.tab, state.store)
@ -148,7 +151,7 @@ class TabMixin(GridMixin):
if not settings_manager.is_trace_debug(): if not settings_manager.is_trace_debug():
self.fm_controller.save_state() self.fm_controller.save_state()
def do_action_from_bar_controls(self, widget, eve=None): def do_action_from_bar_controls(self, widget, eve = None):
action = widget.get_name() action = widget.get_name()
wid, tid = self.fm_controller.get_active_wid_and_tid() wid, tid = self.fm_controller.get_active_wid_and_tid()
notebook = self.builder.get_object(f"window_{wid}") notebook = self.builder.get_object(f"window_{wid}")

View File

@ -54,7 +54,7 @@ class FilesWidget(FileActionSignalsMixin, WindowMixin):
self.files_view.set_group_name("files_widget") self.files_view.set_group_name("files_widget")
self.builder.expose_object(f"{self.NAME}", self.files_view) self.builder.expose_object(f"{self.NAME}", self.files_view)
def _load_files_view_state(self, win_name=None, tabs=None): def _load_files_view_state(self, win_name = None, tabs = None):
if win_name == self.NAME: if win_name == self.NAME:
if tabs: if tabs:
for tab in tabs: for tab in tabs:
@ -62,9 +62,9 @@ class FilesWidget(FileActionSignalsMixin, WindowMixin):
else: else:
self.create_new_tab_notebook(None, self.INDEX, None) self.create_new_tab_notebook(None, self.INDEX, None)
def _get_files_view_icon_grid(self, win_index=None, tid=None): def _get_files_view_icon_grid(self, win_index = None, tid = None):
if win_index == str(self.INDEX): if win_index == str(self.INDEX):
return self.builder.get_object(f"{self.INDEX}|{tid}|icon_grid") return self.builder.get_object(f"{self.INDEX}|{tid}|icon_grid", use_gtk = False)
def set_fm_controller(self, _fm_controller): def set_fm_controller(self, _fm_controller):

View File

@ -59,7 +59,6 @@ class GridMixin:
icon = tab.create_icon(dir, file) icon = tab.create_icon(dir, file)
itr = store.get_iter(i) itr = store.get_iter(i)
store.set_value(itr, 0, icon) store.set_value(itr, 0, icon)
return 1
def create_icons_generator(self, tab, dir, files): def create_icons_generator(self, tab, dir, files):
for file in files: for file in files:
@ -82,7 +81,7 @@ class GridMixin:
def create_tab_widget(self, tab): def create_tab_widget(self, tab):
return TabHeaderWidget(tab, self.close_tab) return TabHeaderWidget(tab, self.close_tab)
def create_scroll_and_store(self, tab, wid, use_tree_view=False): def create_scroll_and_store(self, tab, wid, use_tree_view = False):
scroll = Gtk.ScrolledWindow() scroll = Gtk.ScrolledWindow()
if not use_tree_view: if not use_tree_view:
@ -94,8 +93,8 @@ class GridMixin:
scroll.add(grid) scroll.add(grid)
scroll.set_name(f"{wid}|{tab.get_id()}") scroll.set_name(f"{wid}|{tab.get_id()}")
grid.set_name(f"{wid}|{tab.get_id()}") grid.set_name(f"{wid}|{tab.get_id()}")
self.builder.expose_object(f"{wid}|{tab.get_id()}|icon_grid", grid) self.builder.expose_object(f"{wid}|{tab.get_id()}|icon_grid", grid, use_gtk = False)
self.builder.expose_object(f"{wid}|{tab.get_id()}", scroll) self.builder.expose_object(f"{wid}|{tab.get_id()}", scroll, use_gtk = False)
return scroll, grid.get_store() return scroll, grid.get_store()

View File

@ -17,7 +17,7 @@ from .grid_mixin import GridMixin
class TabMixin(GridMixin): class TabMixin(GridMixin):
"""docstring for TabMixin""" """docstring for TabMixin"""
def create_tab(self, wid=None, tid=None, path=None): def create_tab(self, wid: int = None, tid: int = None, path: str = None):
if not wid: if not wid:
wid, tid = self.fm_controller.get_active_wid_and_tid() wid, tid = self.fm_controller.get_active_wid_and_tid()
@ -62,7 +62,7 @@ class TabMixin(GridMixin):
tab_box = button.get_parent() tab_box = button.get_parent()
wid = int(notebook.get_name()[-1]) wid = int(notebook.get_name()[-1])
tid = self.get_id_from_tab_box(tab_box) tid = self.get_id_from_tab_box(tab_box)
scroll = self.builder.get_object(f"{wid}|{tid}") scroll = self.builder.get_object(f"{wid}|{tid}", use_gtk = False)
icon_grid = scroll.get_children()[0] icon_grid = scroll.get_children()[0]
store = icon_grid.get_model() store = icon_grid.get_model()
tab = self.get_fm_window(wid).get_tab_by_id(tid) tab = self.get_fm_window(wid).get_tab_by_id(tid)
@ -71,6 +71,9 @@ class TabMixin(GridMixin):
watcher.cancel() watcher.cancel()
self.get_fm_window(wid).delete_tab_by_id(tid) self.get_fm_window(wid).delete_tab_by_id(tid)
self.builder.dereference_object(f"{wid}|{tid}|icon_grid")
self.builder.dereference_object(f"{wid}|{tid}")
store.clear() store.clear()
# store.run_dispose() # store.run_dispose()
icon_grid.destroy() icon_grid.destroy()
@ -114,7 +117,7 @@ class TabMixin(GridMixin):
if not settings_manager.is_trace_debug(): if not settings_manager.is_trace_debug():
self.fm_controller.save_state() self.fm_controller.save_state()
def on_tab_switch_update(self, notebook, content=None, index=None): def on_tab_switch_update(self, notebook, content = None, index = None):
self.selected_files.clear() self.selected_files.clear()
wid, tid = content.get_children()[0].get_name().split("|") wid, tid = content.get_children()[0].get_name().split("|")
self.fm_controller.set_wid_and_tid(wid, tid) self.fm_controller.set_wid_and_tid(wid, tid)
@ -133,7 +136,7 @@ class TabMixin(GridMixin):
def get_tab_icon_grid_from_notebook(self, notebook): def get_tab_icon_grid_from_notebook(self, notebook):
return notebook.get_children()[1].get_children()[0] return notebook.get_children()[1].get_children()[0]
def refresh_tab(data=None): def refresh_tab(data = None):
state = self.get_current_state() state = self.get_current_state()
state.tab.load_directory() state.tab.load_directory()
self.load_store(state.tab, state.store) self.load_store(state.tab, state.store)
@ -150,7 +153,7 @@ class TabMixin(GridMixin):
if not settings_manager.is_trace_debug(): if not settings_manager.is_trace_debug():
self.fm_controller.save_state() self.fm_controller.save_state()
def do_action_from_bar_controls(self, widget, eve=None): def do_action_from_bar_controls(self, widget, eve = None):
action = widget.get_name() action = widget.get_name()
wid, tid = self.fm_controller.get_active_wid_and_tid() wid, tid = self.fm_controller.get_active_wid_and_tid()
notebook = self.builder.get_object(f"window_{wid}") notebook = self.builder.get_object(f"window_{wid}")