generated from itdominator/Python-With-Gtk-Template
WIP widget selection and cleanup
This commit is contained in:
parent
d2b878722d
commit
4055076a44
|
@ -59,8 +59,8 @@ class Controller(SignalsMixins, ControllerData):
|
|||
event_system.subscribe("load_notebook_data", self._load_notebook_data)
|
||||
|
||||
def _load_widgets(self):
|
||||
MessageWidget()
|
||||
CreateNotebookWidget()
|
||||
MessageWidget()
|
||||
|
||||
def load_glade_file(self):
|
||||
self.builder = Gtk.Builder()
|
||||
|
|
|
@ -8,7 +8,7 @@ from gi.repository import Gtk
|
|||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
from .dynamic_widget import DynamicWidget
|
||||
from .template.dynamic_widget_template import DynamicWidget
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -108,5 +108,7 @@ class Page(Gtk.ScrolledWindow):
|
|||
self.was_dragging = False
|
||||
return
|
||||
|
||||
logger.debug(self._window.get_focus().__class__)
|
||||
|
||||
if "DragArea" in f"{self._window.get_focus()}":
|
||||
self._drag_area.add_or_select_widget(widget, eve)
|
||||
|
|
|
@ -8,7 +8,7 @@ from gi.repository import Gtk
|
|||
|
||||
# Application imports
|
||||
from ..pages.pages_widget import Pages
|
||||
|
||||
from ..widget_selector.widget_selector_grid import WidgetSelector
|
||||
|
||||
|
||||
class Sections(Gtk.Notebook):
|
||||
|
@ -45,6 +45,16 @@ class Sections(Gtk.Notebook):
|
|||
add_btn.set_always_show_image(True)
|
||||
add_btn.connect("released", self.create_section_view)
|
||||
|
||||
widgets_btn = Gtk.Button()
|
||||
widgets_btn.set_image( Gtk.Image.new_from_icon_name("gtk-cdrom", 4) )
|
||||
widgets_btn.set_always_show_image(True)
|
||||
widgets_btn.connect("released", self.show_widgets_selection)
|
||||
|
||||
widget_selector = WidgetSelector()
|
||||
widget_selector.set_relative_to(widgets_btn)
|
||||
widget_selector.set_position(3)
|
||||
|
||||
start_box.add(widgets_btn)
|
||||
end_box.add(add_btn)
|
||||
|
||||
start_box.show_all()
|
||||
|
@ -65,6 +75,19 @@ class Sections(Gtk.Notebook):
|
|||
if response == -8:
|
||||
self.remove_page(page_num)
|
||||
|
||||
def _load_section_manifest(self, manifest_pth = None):
|
||||
if manifest_pth:
|
||||
self._manifest_pth = manifest_pth
|
||||
|
||||
with open(self._manifest_pth, "r") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
parts = line.split("=")
|
||||
if parts[0] == "name":
|
||||
self._name = parts[1].strip()
|
||||
if parts[0] == "date":
|
||||
self._date = parts[1].strip()
|
||||
|
||||
def create_section_view(self, widget = None, eve = None, manifest_pth = None):
|
||||
self._manifest_pth = manifest_pth
|
||||
if not manifest_pth:
|
||||
|
@ -80,16 +103,5 @@ class Sections(Gtk.Notebook):
|
|||
pages_view.show_all()
|
||||
self.set_current_page(page_num)
|
||||
|
||||
|
||||
def _load_section_manifest(self, manifest_pth = None):
|
||||
if manifest_pth:
|
||||
self._manifest_pth = manifest_pth
|
||||
|
||||
with open(self._manifest_pth, "r") as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
parts = line.split("=")
|
||||
if parts[0] == "name":
|
||||
self._name = parts[1].strip()
|
||||
if parts[0] == "date":
|
||||
self._date = parts[1].strip()
|
||||
def show_widgets_selection(self, widget = None, eve = None):
|
||||
event_system.emit("show_widget_types")
|
||||
|
|
|
@ -33,6 +33,8 @@ class DynamicHeaderWidget(Gtk.Box):
|
|||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(0)
|
||||
ctx = self.get_style_context()
|
||||
ctx.add_class("dynamic-header-widget")
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
|
@ -9,6 +9,11 @@ from gi.repository import Gtk
|
|||
from .dynamic_header_widget import DynamicHeaderWidget
|
||||
|
||||
|
||||
|
||||
class DynamicWidgetException(Exception):
|
||||
...
|
||||
|
||||
|
||||
class DynamicWidget(Gtk.Box):
|
||||
def __init__(self, move_callback, x, y):
|
||||
super(DynamicWidget, self).__init__()
|
||||
|
@ -36,6 +41,12 @@ class DynamicWidget(Gtk.Box):
|
|||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
label = Gtk.Label(label="Test")
|
||||
self.add(self._header_widget)
|
||||
self.add(label)
|
||||
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)
|
|
@ -0,0 +1,3 @@
|
|||
"""
|
||||
Widgets Selector Module
|
||||
"""
|
|
@ -0,0 +1,111 @@
|
|||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from .widgets import *
|
||||
|
||||
|
||||
|
||||
widgets_list = []
|
||||
for item in dir():
|
||||
if "Widget" in f"{item}":
|
||||
widgets_list.append(item)
|
||||
|
||||
|
||||
class WidgetSelectorGrid(Gtk.Grid):
|
||||
|
||||
def __init__(self):
|
||||
super(WidgetSelectorGrid, self).__init__()
|
||||
|
||||
self._seleced_widget_type = Gtk.Label(label="NO WIDGET SELECTED!")
|
||||
self._row = 0
|
||||
self._col = 0
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
self.set_column_homogeneous(True)
|
||||
self.set_row_homogeneous(False)
|
||||
self.set_column_spacing(10)
|
||||
self.set_row_spacing(10)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("register_widget_type", self._register_widget_type)
|
||||
event_system.subscribe("get_widget_type", self._get_widget_type)
|
||||
event_system.subscribe("set_widget_type", self._set_widget_type)
|
||||
|
||||
def _load_widgets(self):
|
||||
for widget in widgets_list:
|
||||
self._register_widget_type(globals()[widget])
|
||||
|
||||
def _register_widget_type(self, Widget):
|
||||
widget = Widget()
|
||||
|
||||
selection = Gtk.EventBox()
|
||||
selection.set_above_child(True)
|
||||
selection.add(widget)
|
||||
selection.connect("button-release-event", self._set_widget_type_eve)
|
||||
|
||||
self.attach(selection, self._col, self._row, 1, 1)
|
||||
|
||||
self._col += 1
|
||||
if self._col > 4:
|
||||
self._col = 0
|
||||
self._row += 1
|
||||
|
||||
def _get_widget_type(self):
|
||||
logger.debug(self._seleced_widget_type)
|
||||
return self._seleced_widget_type.new()
|
||||
|
||||
def _set_widget_type_eve(self, widget = None, eve = None):
|
||||
self._seleced_widget_type = widget.get_children()[0]
|
||||
|
||||
def _set_widget_type(self, type):
|
||||
self._seleced_widget_type = type
|
||||
|
||||
|
||||
class WidgetSelector(Gtk.Popover):
|
||||
def __init__(self):
|
||||
super(WidgetSelector, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_size_request(256, 480)
|
||||
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("show_widget_types", self._show_widget_types)
|
||||
|
||||
def _load_widgets(self):
|
||||
scroll_win = Gtk.ScrolledWindow()
|
||||
viewport = Gtk.Viewport()
|
||||
|
||||
viewport.add(WidgetSelectorGrid())
|
||||
scroll_win.add(viewport)
|
||||
self.add(scroll_win)
|
||||
|
||||
scroll_win.show_all()
|
||||
|
||||
def _show_widget_types(self):
|
||||
self.show()
|
|
@ -0,0 +1,4 @@
|
|||
"""
|
||||
Widgets Selector Widgets
|
||||
"""
|
||||
from .text_area import TextAreaWidget
|
|
@ -0,0 +1,41 @@
|
|||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class TextAreaWidget(Gtk.TextView):
|
||||
def __init__(self):
|
||||
super(TextAreaWidget, self).__init__()
|
||||
|
||||
self.buffer = self.get_buffer()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
|
||||
def new(self):
|
||||
widget = TextAreaWidget()
|
||||
widget.buffer.set_text("Poo")
|
||||
return widget
|
|
@ -75,8 +75,8 @@ class Settings(StartCheckMixin):
|
|||
keybindings.configure(bindings)
|
||||
|
||||
self._main_window = None
|
||||
self._main_window_w = 800
|
||||
self._main_window_h = 600
|
||||
self._main_window_w = 1200
|
||||
self._main_window_h = 800
|
||||
self._builder = None
|
||||
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
|
||||
|
||||
|
|
|
@ -55,32 +55,25 @@ notebook > header > tabs > tab:checked {
|
|||
border: 2px solid rgba(255, 255, 255, 0.24);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* * {
|
||||
background: rgba(0, 0, 0, 0.14);
|
||||
color: rgba(255, 255, 255, 1);
|
||||
} */
|
||||
|
||||
/* * selection {
|
||||
background-color: rgba(116, 0, 0, 0.65);
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
} */
|
||||
|
||||
/* Rubberband coloring */
|
||||
/* .rubberband,
|
||||
rubberband,
|
||||
flowbox rubberband,
|
||||
treeview.view rubberband,
|
||||
.content-view rubberband,
|
||||
.content-view .rubberband,
|
||||
XfdesktopIconView.view .rubberband {
|
||||
border: 1px solid #6c6c6c;
|
||||
background-color: rgba(21, 158, 167, 0.57);
|
||||
.sourceview > * {
|
||||
background-color: rgba(0, 0, 0, 0.0);
|
||||
}
|
||||
|
||||
XfdesktopIconView.view:active {
|
||||
background-color: rgba(172, 102, 21, 1);
|
||||
} */
|
||||
|
||||
|
||||
.dynamic-header-widget {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.dynamic-widget {
|
||||
border: 2px solid rgba(45, 45, 45, 0.84);
|
||||
}
|
||||
|
||||
.label-widget:selected:hover {
|
||||
background-color: rgba(0, 116, 0, 0.64);
|
||||
}
|
||||
|
||||
.drag-area-title {
|
||||
background-color: rgba(0, 0, 0, 0.0);
|
||||
border-bottom: 2px solid rgba(255, 255, 255, 0.24);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue