develop #12

Merged
itdominator merged 6 commits from develop into master 2023-09-30 19:36:35 +00:00
10 changed files with 59 additions and 29 deletions
Showing only changes of commit 39aa0eeea4 - Show all commits

View File

@ -77,7 +77,6 @@ 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)

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()

View File

@ -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}")

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

@ -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()

View File

@ -64,7 +64,7 @@ class FilesWidget(FileActionSignalsMixin, WindowMixin):
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:
@ -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()