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,7 +77,6 @@ class Controller(UIMixin, SignalsMixins, Controller_Data):
event_system.subscribe("set_clipboard_data", self.set_clipboard_data)
def _load_glade_file(self):
self.builder = Gtk.Builder()
self.builder.add_from_file( settings_manager.get_glade_file() )
self.builder.expose_object("main_window", self.window)

View File

@ -35,13 +35,39 @@ class State:
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:
""" 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"
def _setup_controller_data(self) -> None:
self.window = settings_manager.get_main_window()
self.builder = None
self.builder = SFMBuilder()
self.core_widget = None
self._load_glade_file()
@ -88,7 +114,7 @@ class Controller_Data:
state.notebooks = self.notebooks
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.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.store = state.icon_grid.get_model()
state.message_dialog = MessageWidget()

View File

@ -68,7 +68,7 @@ class FileActionSignalsMixin:
wid, tid = tab_widget.split("|")
notebook = self.builder.get_object(f"window_{wid}")
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, tab_widget_label = self.get_store_and_label_from_notebook(notebook, f"{wid}|{tid}")

View File

@ -74,7 +74,7 @@ class KeyboardSignalsMixin:
def keyboard_close_tab(self):
wid, tid = self.fm_controller.get_active_wid_and_tid()
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)
tab = self.get_fm_window(wid).get_tab_by_id(tid)
watcher = tab.get_dir_watcher()

View File

@ -93,8 +93,8 @@ class GridMixin:
scroll.add(grid)
scroll.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()}", scroll)
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, use_gtk = False)
return scroll, grid.get_store()

View File

@ -17,7 +17,7 @@ from .grid_mixin import GridMixin
class TabMixin(GridMixin):
"""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:
wid, tid = self.fm_controller.get_active_wid_and_tid()
@ -60,7 +60,7 @@ class TabMixin(GridMixin):
tab_box = button.get_parent()
wid = int(notebook.get_name()[-1])
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]
store = icon_grid.get_store()
tab = self.get_fm_window(wid).get_tab_by_id(tid)
@ -69,6 +69,9 @@ class TabMixin(GridMixin):
watcher.cancel()
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.run_dispose()
icon_grid.destroy()

View File

@ -64,7 +64,7 @@ class FilesWidget(FileActionSignalsMixin, WindowMixin):
def _get_files_view_icon_grid(self, win_index = None, tid = None):
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):

View File

@ -59,7 +59,6 @@ class GridMixin:
icon = tab.create_icon(dir, file)
itr = store.get_iter(i)
store.set_value(itr, 0, icon)
return 1
def create_icons_generator(self, tab, dir, files):
for file in files:
@ -94,8 +93,8 @@ class GridMixin:
scroll.add(grid)
scroll.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()}", scroll)
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, use_gtk = False)
return scroll, grid.get_store()

View File

@ -17,7 +17,7 @@ from .grid_mixin import GridMixin
class TabMixin(GridMixin):
"""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:
wid, tid = self.fm_controller.get_active_wid_and_tid()
@ -62,7 +62,7 @@ class TabMixin(GridMixin):
tab_box = button.get_parent()
wid = int(notebook.get_name()[-1])
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]
store = icon_grid.get_model()
tab = self.get_fm_window(wid).get_tab_by_id(tid)
@ -71,6 +71,9 @@ class TabMixin(GridMixin):
watcher.cancel()
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.run_dispose()
icon_grid.destroy()