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

53 lines
1.2 KiB
Python

# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .dynamic_header_widget import DynamicHeaderWidget
class DynamicWidgetException(Exception):
...
class DynamicWidget(Gtk.Box):
def __init__(self, move_callback, x, y):
super(DynamicWidget, self).__init__()
self._header_widget = DynamicHeaderWidget(move_callback, x, y)
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_orientation(1)
self.set_size_request(256, 45)
ctx = self.get_style_context()
ctx.add_class("dynamic-widget")
def _setup_signals(self):
...
def _subscribe_to_events(self):
...
def _load_widgets(self):
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)