generated from itdominator/Python-With-Gtk-Template
added event trapping
This commit is contained in:
parent
4055076a44
commit
e37e2e548f
@ -3,8 +3,10 @@
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
gi.require_version('GtkSource', '4')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
@ -40,8 +42,11 @@ class DragArea(GtkSource.View):
|
||||
...
|
||||
|
||||
def add_fixed_base_widgets(self, name = None, date = None, update_header_callback = None):
|
||||
entry = Gtk.Entry(text = name)
|
||||
date_label = Gtk.Label(label = date)
|
||||
entry = Gtk.Entry(text = name)
|
||||
wrapped_entry = self.wrap_widget_in_trap( entry )
|
||||
date_label = Gtk.Label(label = date)
|
||||
wrapped_date = self.wrap_widget_in_trap( date_label )
|
||||
|
||||
|
||||
ctx = entry.get_style_context()
|
||||
ctx.add_class("drag-area-title")
|
||||
@ -50,18 +55,41 @@ class DragArea(GtkSource.View):
|
||||
entry.set_width_chars(25)
|
||||
entry.set_max_length(25)
|
||||
|
||||
# self.put(entry, 30, 30)
|
||||
# self.put(date_label, 30, 65)
|
||||
self.add_child_in_window(entry, Gtk.TextWindowType.WIDGET, 30, 30)
|
||||
self.add_child_in_window(date_label, Gtk.TextWindowType.WIDGET, 30, 65)
|
||||
# self.put(wrapped_entry, 30, 30)
|
||||
# self.put(wrapped_date, 30, 65)
|
||||
self.add_child_in_window(wrapped_entry, Gtk.TextWindowType.WIDGET, 30, 30)
|
||||
self.add_child_in_window(wrapped_date, Gtk.TextWindowType.WIDGET, 30, 65)
|
||||
|
||||
def add_or_select_widget(self, widget = None, eve = None):
|
||||
dynamic_widget = DynamicWidget(self._move_callback, eve.x, eve.y)
|
||||
dynamic_widget_wrapped = self.wrap_widget_in_trap(dynamic_widget)
|
||||
|
||||
self._children_content.append(dynamic_widget)
|
||||
# self.put(dynamic_widget, eve.x, eve.y)
|
||||
self.add_child_in_window(dynamic_widget, Gtk.TextWindowType.WIDGET, eve.x, eve.y)
|
||||
self.add_child_in_window(dynamic_widget_wrapped, Gtk.TextWindowType.WIDGET, eve.x, eve.y)
|
||||
|
||||
def _move_callback(self, widget = None, x = None, y = None):
|
||||
# self.move(widget, x, y)
|
||||
self.move_child(widget, x, y)
|
||||
# self.move(widget.get_parent(), x, y)
|
||||
self.move_child(widget.get_parent(), x, y)
|
||||
|
||||
|
||||
def wrap_widget_in_trap(self, widget):
|
||||
eve_trap_box = Gtk.EventBox()
|
||||
|
||||
eve_trap_box.connect("enter-notify-event", self._enter_event)
|
||||
eve_trap_box.connect("motion-notify-event", self._motion_event)
|
||||
eve_trap_box.connect("button-release-event", self._release_event)
|
||||
|
||||
eve_trap_box.add(widget)
|
||||
eve_trap_box.show()
|
||||
|
||||
return eve_trap_box
|
||||
|
||||
def _enter_event(self, widget = None, eve = None):
|
||||
...
|
||||
|
||||
def _motion_event(self, widget = None, eve = None):
|
||||
...
|
||||
|
||||
def _release_event(self, widget = None, eve = None):
|
||||
return True
|
||||
|
@ -48,22 +48,13 @@ class Page(Gtk.ScrolledWindow):
|
||||
|
||||
def _load_widgets(self):
|
||||
self._drag_area = DragArea()
|
||||
eve_box = Gtk.EventBox()
|
||||
viewport = Gtk.Viewport()
|
||||
|
||||
# eve_box.connect("button-press-event", self._press_event)
|
||||
# eve_box.connect("motion-notify-event", self._motion_event)
|
||||
# eve_box.connect("button-release-event", self._release_event)
|
||||
# eve_box.add(self._drag_area)
|
||||
# eve_box.set_above_child(False)
|
||||
# eve_box.set_visible_window(False)
|
||||
# viewport.add(eve_box)
|
||||
|
||||
self._drag_area.connect("button-press-event", self._press_event)
|
||||
self._drag_area.connect("motion-notify-event", self._motion_event)
|
||||
self.connect("motion-notify-event", self._motion_event)
|
||||
self._drag_area.connect("button-release-event", self._release_event)
|
||||
viewport.add(self._drag_area)
|
||||
|
||||
viewport.add(self._drag_area)
|
||||
self.add(viewport)
|
||||
|
||||
def get_tab_widget(self):
|
||||
@ -85,7 +76,6 @@ class Page(Gtk.ScrolledWindow):
|
||||
if parts[0] == "date":
|
||||
self._date = parts[1].strip()
|
||||
|
||||
|
||||
def _add_fixed_base_widgets(self):
|
||||
self._drag_area.add_fixed_base_widgets(self._name, self._date, self._update_header)
|
||||
|
||||
@ -94,7 +84,6 @@ class Page(Gtk.ScrolledWindow):
|
||||
self._tab_widget.set_tab_label(self._name)
|
||||
settings.update_manifest(self._manifest_pth, self._name, self._date)
|
||||
|
||||
|
||||
def _press_event(self, widget = None, eve = None):
|
||||
self.mouse_held = True
|
||||
|
||||
@ -108,7 +97,4 @@ 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)
|
||||
self._drag_area.add_or_select_widget(widget, eve)
|
||||
|
Loading…
Reference in New Issue
Block a user