2023-04-03 04:42:09 +00:00
|
|
|
# Python imports
|
2023-04-07 03:45:02 +00:00
|
|
|
import uuid
|
|
|
|
import pickle
|
2023-04-03 04:42:09 +00:00
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
# Application imports
|
|
|
|
from .dynamic_header_widget import DynamicHeaderWidget
|
|
|
|
|
|
|
|
|
2023-04-05 22:35:23 +00:00
|
|
|
|
|
|
|
class DynamicWidgetException(Exception):
|
|
|
|
...
|
|
|
|
|
|
|
|
|
2023-04-03 04:42:09 +00:00
|
|
|
class DynamicWidget(Gtk.Box):
|
|
|
|
def __init__(self, move_callback, x, y):
|
|
|
|
super(DynamicWidget, self).__init__()
|
|
|
|
|
2023-04-07 03:45:02 +00:00
|
|
|
self.uuid = str(uuid.uuid4())
|
2023-04-08 02:04:40 +00:00
|
|
|
self._header_widget = DynamicHeaderWidget(move_callback, x, y)
|
|
|
|
self._body_widget = None
|
2023-04-03 04:42:09 +00:00
|
|
|
|
|
|
|
self._setup_styling()
|
|
|
|
self._setup_signals()
|
|
|
|
self._subscribe_to_events()
|
|
|
|
self._load_widgets()
|
|
|
|
|
|
|
|
self.show_all()
|
|
|
|
|
|
|
|
|
|
|
|
def _setup_styling(self):
|
|
|
|
self.set_orientation(1)
|
2023-04-05 03:23:07 +00:00
|
|
|
self.set_size_request(256, 45)
|
2023-04-03 04:42:09 +00:00
|
|
|
ctx = self.get_style_context()
|
|
|
|
ctx.add_class("dynamic-widget")
|
|
|
|
|
|
|
|
def _setup_signals(self):
|
|
|
|
...
|
|
|
|
|
|
|
|
def _subscribe_to_events(self):
|
|
|
|
...
|
|
|
|
|
|
|
|
def _load_widgets(self):
|
2023-04-05 22:35:23 +00:00
|
|
|
try:
|
|
|
|
self.add(self._header_widget)
|
2023-04-08 02:04:40 +00:00
|
|
|
self._body_widget = event_system.emit_and_await("get_widget_type")
|
|
|
|
if not self._body_widget:
|
2023-04-05 22:35:23 +00:00
|
|
|
raise Exception("No widget detected... Will not insert anything.")
|
|
|
|
|
2023-04-08 02:04:40 +00:00
|
|
|
self.add(self._body_widget)
|
2023-04-05 22:35:23 +00:00
|
|
|
except DynamicWidgetException as e:
|
|
|
|
logger.debug(e)
|
2023-04-07 03:45:02 +00:00
|
|
|
|
|
|
|
def save(self):
|
2023-04-08 02:04:40 +00:00
|
|
|
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
|
|
|
|
|
2023-04-07 03:45:02 +00:00
|
|
|
path = f"{settings.get_active_page()}/{self.uuid}"
|
2023-04-08 02:04:40 +00:00
|
|
|
with open(path, "wb") as f:
|
|
|
|
pickle.dump(save_collection, f, protocol=pickle.HIGHEST_PROTOCOL, fix_imports=True, buffer_callback=None)
|