generated from itdominator/Python-With-Gtk-Template
WIP saving of widget through pickle process
This commit is contained in:
parent
a23c13a259
commit
8ccb8f0709
|
@ -47,7 +47,6 @@ class DragArea(GtkSource.View):
|
||||||
date_label = Gtk.Label(label = date)
|
date_label = Gtk.Label(label = date)
|
||||||
wrapped_date = self.wrap_widget_in_trap( date_label )
|
wrapped_date = self.wrap_widget_in_trap( date_label )
|
||||||
|
|
||||||
|
|
||||||
ctx = entry.get_style_context()
|
ctx = entry.get_style_context()
|
||||||
ctx.add_class("drag-area-title")
|
ctx.add_class("drag-area-title")
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,9 @@ class DynamicWidget(Gtk.Box):
|
||||||
def __init__(self, move_callback, x, y):
|
def __init__(self, move_callback, x, y):
|
||||||
super(DynamicWidget, self).__init__()
|
super(DynamicWidget, self).__init__()
|
||||||
|
|
||||||
self._header_widget = DynamicHeaderWidget(move_callback, x, y)
|
|
||||||
self.uuid = str(uuid.uuid4())
|
self.uuid = str(uuid.uuid4())
|
||||||
|
self._header_widget = DynamicHeaderWidget(move_callback, x, y)
|
||||||
|
self._body_widget = None
|
||||||
|
|
||||||
self._setup_styling()
|
self._setup_styling()
|
||||||
self._setup_signals()
|
self._setup_signals()
|
||||||
|
@ -46,16 +47,21 @@ class DynamicWidget(Gtk.Box):
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
try:
|
try:
|
||||||
self.add(self._header_widget)
|
self.add(self._header_widget)
|
||||||
widget = event_system.emit_and_await("get_widget_type")
|
self._body_widget = event_system.emit_and_await("get_widget_type")
|
||||||
if not widget:
|
if not self._body_widget:
|
||||||
raise Exception("No widget detected... Will not insert anything.")
|
raise Exception("No widget detected... Will not insert anything.")
|
||||||
|
|
||||||
self.add(widget)
|
self.add(self._body_widget)
|
||||||
except DynamicWidgetException as e:
|
except DynamicWidgetException as e:
|
||||||
logger.debug(e)
|
logger.debug(e)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
save_collection = self._body_widget.get_saveable_data()
|
||||||
|
save_collection["w"] = self._header_widget._current_w
|
||||||
|
save_collection["h"] = self._header_widget._current_h
|
||||||
|
save_collection["x"] = self._header_widget._current_x
|
||||||
|
save_collection["y"] = self._header_widget._current_y
|
||||||
|
|
||||||
path = f"{settings.get_active_page()}/{self.uuid}"
|
path = f"{settings.get_active_page()}/{self.uuid}"
|
||||||
logger.debug("Widget save stub...")
|
with open(path, "wb") as f:
|
||||||
# with open(path, "wb") as f:
|
pickle.dump(save_collection, f, protocol=pickle.HIGHEST_PROTOCOL, fix_imports=True, buffer_callback=None)
|
||||||
# pickle.dump(self, f, protocol=pickle.HIGHEST_PROTOCOL, fix_imports=True, buffer_callback=None)
|
|
||||||
|
|
|
@ -6,10 +6,10 @@ gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
from utils.widget_save_load_controller import WidgetSaveLoadController
|
||||||
|
|
||||||
|
|
||||||
|
class TextAreaWidget(WidgetSaveLoadController, Gtk.TextView):
|
||||||
class TextAreaWidget(Gtk.TextView):
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(TextAreaWidget, self).__init__()
|
super(TextAreaWidget, self).__init__()
|
||||||
|
|
||||||
|
@ -35,7 +35,20 @@ class TextAreaWidget(Gtk.TextView):
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
def get_buffer_text(self):
|
||||||
|
start, end = self.buffer.get_start_iter(), self.buffer.get_end_iter()
|
||||||
|
return self.buffer.get_slice(start, end, True)
|
||||||
|
|
||||||
|
def load_saveable_data(self, data):
|
||||||
|
self.save_collection = data
|
||||||
|
self.buffer.set_text(self.save_collection["data"])
|
||||||
|
|
||||||
|
def get_saveable_data(self):
|
||||||
|
self.save_collection["data"] = self.get_buffer_text()
|
||||||
|
self.save_collection["widget_type"] = str(type(self).__name__)
|
||||||
|
return self.save_collection
|
||||||
|
|
||||||
def new(self):
|
def new(self):
|
||||||
widget = TextAreaWidget()
|
widget = TextAreaWidget()
|
||||||
widget.buffer.set_text("Poo")
|
widget.buffer.set_text("Lorem ipsum dolor")
|
||||||
return widget
|
return widget
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SaveLoadControllerException(Exception):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
class WidgetSaveLoadController:
|
||||||
|
def __init__(self):
|
||||||
|
super(WidgetSaveLoadController, self).__init__()
|
||||||
|
self.saveable_data = []
|
||||||
|
self.save_collection = {
|
||||||
|
"width": -1,
|
||||||
|
"height": -1,
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"data": None,
|
||||||
|
"widget_type": None
|
||||||
|
}
|
||||||
|
|
||||||
|
def register_saveable_data(self, data):
|
||||||
|
self.saveable_data.append(data)
|
||||||
|
|
||||||
|
def load_saveable_data(self, data):
|
||||||
|
self.save_collection = data
|
||||||
|
|
||||||
|
def get_saveable_data(self):
|
||||||
|
return self.save_collection
|
Loading…
Reference in New Issue