Coherence/src/core/widgets/template/dynamic_widget_template.py

62 lines
1.5 KiB
Python
Raw Normal View History

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__()
self._header_widget = DynamicHeaderWidget(move_callback, x, y)
2023-04-07 03:45:02 +00:00
self.uuid = str(uuid.uuid4())
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)
widget = event_system.emit_and_await("get_widget_type")
if not widget:
raise Exception("No widget detected... Will not insert anything.")
self.add(widget)
except DynamicWidgetException as e:
logger.debug(e)
2023-04-07 03:45:02 +00:00
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)