From 1306bed11d7d1650f4a4d9517580910bc04c5ad3 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 8 Apr 2023 19:45:57 -0500 Subject: [PATCH] Added section title update logic --- src/core/controller.py | 4 +- .../dialogs/section_header_updater_widget.py | 61 +++++++++++++++++++ src/core/widgets/pages/pages_widget.py | 19 ++++-- .../widgets/template/tab_header_template.py | 11 ++-- .../widget_selector/widget_selector_grid.py | 5 +- 5 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 src/core/widgets/dialogs/section_header_updater_widget.py diff --git a/src/core/controller.py b/src/core/controller.py index ecd1fdb..1f63f5f 100644 --- a/src/core/controller.py +++ b/src/core/controller.py @@ -13,6 +13,7 @@ from gi.repository import GLib from .mixins.signals_mixins import SignalsMixins from .controller_data import ControllerData from .widgets.dialogs.message_widget import MessageWidget +from .widgets.dialogs.section_header_updater_widget import SectionHeaderUpdater from .widgets.create_notebook_widget import CreateNotebookWidget from .widgets.sections.sections_widget import Sections @@ -43,8 +44,6 @@ class Controller(SignalsMixins, ControllerData): if settings.get_active_notebook(): self._load_notebook_data() - logger.info(f"Made it past {self.__class__} loading...") - def _setup_styling(self): ... @@ -61,6 +60,7 @@ class Controller(SignalsMixins, ControllerData): def _load_widgets(self): CreateNotebookWidget() MessageWidget() + SectionHeaderUpdater() def load_glade_file(self): self.builder = Gtk.Builder() diff --git a/src/core/widgets/dialogs/section_header_updater_widget.py b/src/core/widgets/dialogs/section_header_updater_widget.py new file mode 100644 index 0000000..f2fab74 --- /dev/null +++ b/src/core/widgets/dialogs/section_header_updater_widget.py @@ -0,0 +1,61 @@ +# Python imports + +# Lib imports +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +# Application imports + + + +class SectionHeaderUpdater(Gtk.Popover): + def __init__(self): + super(SectionHeaderUpdater, self).__init__() + + self._label = None + self._data = None + self._entry = None + self._is_setting_up = False + + self._setup_styling() + self._setup_signals() + self._subscribe_to_events() + self._load_widgets() + + + def _setup_styling(self): + self.set_size_request(128, 56) + self.set_position(3) + + def _setup_signals(self): + ... + + def _subscribe_to_events(self): + event_system.subscribe("update_section_title", self._update_section_title) + + def _load_widgets(self): + self._entry = Gtk.Entry() + self.add(self._entry) + self._entry.connect("changed", self.update_section_title) + self._entry.show() + + def _update_section_title(self, label, data = []): + self._is_setting_up = True + self._label = label + self._data = data + + self._entry.set_text(label.get_text()) + self.set_relative_to(label) + self.show() + + def update_section_title(self, widget = None, eve = None): + if self._is_setting_up: + self._is_setting_up = False + return + + manifest_pth, name, date = self._data + name = widget.get_text() + + self._label.set_label(name) + settings.update_manifest(manifest_pth, name, date) diff --git a/src/core/widgets/pages/pages_widget.py b/src/core/widgets/pages/pages_widget.py index 34ac1ef..5664d74 100644 --- a/src/core/widgets/pages/pages_widget.py +++ b/src/core/widgets/pages/pages_widget.py @@ -34,7 +34,9 @@ class Pages(Gtk.Notebook): self.set_scrollable(True) def _setup_signals(self): + label = self._tab_widget.get_children()[0] self.connect("switch-page", self._switch_page_update) + label.connect("button-release-event", self._change_section_name) def _load_widgets(self): start_box = Gtk.Box() @@ -86,11 +88,12 @@ class Pages(Gtk.Notebook): path = page.get_manifest_pth().replace("MANIFEST", "") settings.set_active_page(path) - def get_tab_widget(self): - return self._tab_widget - - def get_section_pth(self): - return self._section_pth + def _change_section_name(self, widget = None, eve = None): + if eve.button == 1: # NOTE: If left click + label = widget.get_children()[0] # NOTE: Pull from event box + parent = self.get_parent() + data = [parent._manifest_pth, parent._name, parent._date] + event_system.emit("update_section_title", (label, data)) def _text_search(self, widget = None, eve = None): ... @@ -111,3 +114,9 @@ class Pages(Gtk.Notebook): _page = os.path.join(path, page) manifest = os.path.join(_page, "MANIFEST") self.create_page_view(None, None, manifest) + + def get_tab_widget(self): + return self._tab_widget + + def get_section_pth(self): + return self._section_pth diff --git a/src/core/widgets/template/tab_header_template.py b/src/core/widgets/template/tab_header_template.py index 15e1c0a..accfabc 100644 --- a/src/core/widgets/template/tab_header_template.py +++ b/src/core/widgets/template/tab_header_template.py @@ -47,9 +47,10 @@ class TabHeaderTemplate(Gtk.Box): ... def _load_widgets(self): - label = Gtk.Label() - close = Gtk.Button() - icon = Gtk.Image(stock=Gtk.STOCK_CLOSE) + eve_box = Gtk.EventBox() + label = Gtk.Label() + close = Gtk.Button() + icon = Gtk.Image(stock=Gtk.STOCK_CLOSE) # NOTE: Setup with settings and from file label.set_xalign(0.0) @@ -58,12 +59,14 @@ class TabHeaderTemplate(Gtk.Box): label.set_hexpand(True) label.set_label(self.LABEL) + close.set_always_show_image(True) close.set_hexpand(False) close.set_image( Gtk.Image.new_from_icon_name("gtk-close", 4) ) close.connect("released", self._close_tab, *(self._container,)) - self.add(label) + eve_box.add(label) + self.add(eve_box) self.add(close) def set_tab_label(self, label = "untitled"): diff --git a/src/core/widgets/widget_selector/widget_selector_grid.py b/src/core/widgets/widget_selector/widget_selector_grid.py index f0dd6a9..d5343e9 100644 --- a/src/core/widgets/widget_selector/widget_selector_grid.py +++ b/src/core/widgets/widget_selector/widget_selector_grid.py @@ -67,11 +67,10 @@ class WidgetSelectorGrid(Gtk.Grid): self._row += 1 def _get_widget_type(self): - logger.debug(self._seleced_widget_type) try: - return self._seleced_widget_type().new() - except Exception: return self._seleced_widget_type.new() + except Exception: + return self._seleced_widget_type().new() def _set_widget_type_eve(self, widget = None, eve = None): self._seleced_widget_type = widget.get_children()[0]