WIP pickling of widgets

This commit is contained in:
itdominator 2023-04-06 22:45:02 -05:00
parent 749a862885
commit a23c13a259
5 changed files with 33 additions and 4 deletions

View File

@ -68,6 +68,8 @@ class DragArea(GtkSource.View):
# self.put(dynamic_widget, eve.x, eve.y) # self.put(dynamic_widget, eve.x, eve.y)
self.add_child_in_window(dynamic_widget_wrapped, Gtk.TextWindowType.WIDGET, eve.x, eve.y) self.add_child_in_window(dynamic_widget_wrapped, Gtk.TextWindowType.WIDGET, eve.x, eve.y)
dynamic_widget.save()
def _move_callback(self, widget = None, x = None, y = None): def _move_callback(self, widget = None, x = None, y = None):
# self.move(widget.get_parent(), x, y) # self.move(widget.get_parent(), x, y)
self.move_child(widget.get_parent(), x, y) self.move_child(widget.get_parent(), x, y)

View File

@ -31,9 +31,10 @@ class Pages(Gtk.Notebook):
def _setup_styling(self): def _setup_styling(self):
self.set_tab_pos(1) # NOTE: LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 self.set_tab_pos(1) # NOTE: LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3
self.set_scrollable(True)
def _setup_signals(self): def _setup_signals(self):
self.set_scrollable(True) self.connect("switch-page", self._switch_page_update)
def _load_widgets(self): def _load_widgets(self):
start_box = Gtk.Box() start_box = Gtk.Box()
@ -81,6 +82,10 @@ class Pages(Gtk.Notebook):
page.show_all() page.show_all()
self.set_current_page(page_num) self.set_current_page(page_num)
def _switch_page_update(self, notebook, page, page_num):
path = page.get_manifest_pth().replace("MANIFEST", "")
settings.set_active_page(path)
def get_tab_widget(self): def get_tab_widget(self):
return self._tab_widget return self._tab_widget

View File

@ -31,10 +31,10 @@ class Sections(Gtk.Notebook):
self.set_scrollable(True) self.set_scrollable(True)
def _setup_signals(self): def _setup_signals(self):
event_system.subscribe("create_section_view", self.create_section_view) self.connect("switch-page", self._switch_page_update)
def _subscribe_to_events(self): def _subscribe_to_events(self):
... event_system.subscribe("create_section_view", self.create_section_view)
def _load_widgets(self): def _load_widgets(self):
start_box = Gtk.Box() start_box = Gtk.Box()
@ -103,5 +103,9 @@ class Sections(Gtk.Notebook):
pages_view.show_all() pages_view.show_all()
self.set_current_page(page_num) self.set_current_page(page_num)
def _switch_page_update(self, notebook, page, page_num):
path = page.get_section_pth()
settings.set_active_section(path)
def show_widgets_selection(self, widget = None, eve = None): def show_widgets_selection(self, widget = None, eve = None):
event_system.emit("show_widget_types") event_system.emit("show_widget_types")

View File

@ -1,4 +1,6 @@
# Python imports # Python imports
import uuid
import pickle
# Lib imports # Lib imports
import gi import gi
@ -19,6 +21,7 @@ class DynamicWidget(Gtk.Box):
super(DynamicWidget, self).__init__() super(DynamicWidget, self).__init__()
self._header_widget = DynamicHeaderWidget(move_callback, x, y) self._header_widget = DynamicHeaderWidget(move_callback, x, y)
self.uuid = str(uuid.uuid4())
self._setup_styling() self._setup_styling()
self._setup_signals() self._setup_signals()
@ -50,3 +53,9 @@ class DynamicWidget(Gtk.Box):
self.add(widget) self.add(widget)
except DynamicWidgetException as e: except DynamicWidgetException as e:
logger.debug(e) logger.debug(e)
def save(self):
path = f"{settings.get_active_page()}/{self.uuid}"
logger.debug("Widget save stub...")
# with open(path, "wb") as f:
# pickle.dump(self, f, protocol=pickle.HIGHEST_PROTOCOL, fix_imports=True, buffer_callback=None)

View File

@ -84,6 +84,8 @@ class Settings(StartCheckMixin):
self._debug = False self._debug = False
self._dirty_start = False self._dirty_start = False
self._active_notebook = None self._active_notebook = None
self._active_section = None
self._active_page = None
self.load_settings() self.load_settings()
@ -166,8 +168,15 @@ class Settings(StartCheckMixin):
def set_main_window(self, window): self._main_window = window def set_main_window(self, window): self._main_window = window
def set_builder(self, builder) -> any: self._builder = builder def set_builder(self, builder) -> any: self._builder = builder
def set_active_notebook(self, path: str): self._active_notebook = path
def get_active_notebook(self) -> str: return self._active_notebook def get_active_notebook(self) -> str: return self._active_notebook
def get_active_section(self) -> str: return self._active_section
def get_active_page(self) -> str: return self._active_page
def set_active_notebook(self, path: str): self._active_notebook = path
def set_active_section(self, path: str): self._active_section = path
def set_active_page(self, path: str): self._active_page = path
def get_monitor_data(self) -> list: def get_monitor_data(self) -> list:
screen = self._main_window.get_screen() screen = self._main_window.get_screen()