generated from itdominator/Python-With-Gtk-Template
Added section title update logic
This commit is contained in:
parent
c2655dd4b3
commit
1306bed11d
|
@ -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()
|
||||
|
|
|
@ -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)
|
|
@ -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
|
||||
|
|
|
@ -47,6 +47,7 @@ class TabHeaderTemplate(Gtk.Box):
|
|||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
eve_box = Gtk.EventBox()
|
||||
label = Gtk.Label()
|
||||
close = Gtk.Button()
|
||||
icon = Gtk.Image(stock=Gtk.STOCK_CLOSE)
|
||||
|
@ -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"):
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue