From d2b878722de51adb6fdee3f2dcd696582b9b6783 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Tue, 4 Apr 2023 22:23:07 -0500 Subject: [PATCH] WIP dargging and generation --- src/core/widgets/drag_area_widget.py | 32 +++++------ src/core/widgets/dynamic_header_widget.py | 69 +++++++++++------------ src/core/widgets/dynamic_widget.py | 3 +- src/core/widgets/page_widget.py | 37 +++++++++++- src/core/widgets/pages/pages_widget.py | 1 - 5 files changed, 82 insertions(+), 60 deletions(-) diff --git a/src/core/widgets/drag_area_widget.py b/src/core/widgets/drag_area_widget.py index e9b9e91..0aa400e 100644 --- a/src/core/widgets/drag_area_widget.py +++ b/src/core/widgets/drag_area_widget.py @@ -13,6 +13,7 @@ from .dynamic_widget import DynamicWidget class DragArea(GtkSource.View): +# class DragArea(Gtk.Fixed): def __init__(self): super(DragArea, self).__init__() @@ -30,7 +31,7 @@ class DragArea(GtkSource.View): self.set_cursor_visible(False) def _setup_signals(self): - self.connect("button-release-event", self.add_or_select_widget) + ... def _subscribe_to_events(self): ... @@ -42,30 +43,25 @@ class DragArea(GtkSource.View): entry = Gtk.Entry(text = name) date_label = Gtk.Label(label = date) + ctx = entry.get_style_context() + ctx.add_class("drag-area-title") + entry.connect("changed", update_header_callback) entry.set_width_chars(25) entry.set_max_length(25) - # PRIVATE = 0, WIDGET = 1, TEXT = 2, LEFT = 3, RIGHT = 4, TOP = 5, BOTTOM = 6 - self.add_child_in_window(entry, Gtk.TextWindowType.TEXT, 30, 30) - self.add_child_in_window(date_label, Gtk.TextWindowType.TEXT, 30, 65) + # 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) def add_or_select_widget(self, widget = None, eve = None): dynamic_widget = DynamicWidget(self._move_callback, eve.x, eve.y) self._children_content.append(dynamic_widget) - self.add_child_in_window(dynamic_widget, Gtk.TextWindowType.TEXT, eve.x, eve.y) - self.get_page_content() + # self.put(dynamic_widget, eve.x, eve.y) + self.add_child_in_window(dynamic_widget, Gtk.TextWindowType.WIDGET, eve.x, eve.y) - def get_page_content(self, widget = None, eve = None): - # PRIVATE = 0, WIDGET = 1, TEXT = 2, LEFT = 3, RIGHT = 4, TOP = 5, BOTTOM = 6 - text_window = self.get_window(Gtk.TextWindowType.TEXT) - logger.info(text_window) - - # NOTE: Probably should use something similar to pass to custom widget content container - def _move_callback(self, widget = None, x = None, y = None, call_back = None): - logger.info(widget) - logger.info(x) - logger.info(y) - logger.info(call_back) - # self.move_child(widget, x, y) + def _move_callback(self, widget = None, x = None, y = None): + # self.move(widget, x, y) + self.move_child(widget, x, y) diff --git a/src/core/widgets/dynamic_header_widget.py b/src/core/widgets/dynamic_header_widget.py index 2bf80ac..5b77523 100644 --- a/src/core/widgets/dynamic_header_widget.py +++ b/src/core/widgets/dynamic_header_widget.py @@ -18,6 +18,10 @@ class DynamicHeaderWidget(Gtk.Box): self._move_callback = move_callback self._current_x = x self._current_y = y + self._drag_start_x = 0 + self._drag_start_y = 0 + self._prior_time = 0 + self._update_block = False self._setup_styling() self._setup_signals() @@ -37,48 +41,41 @@ class DynamicHeaderWidget(Gtk.Box): ... def _load_widgets(self): - drag_eve = Gtk.EventBox() - hresize_eve = Gtk.EventBox() self.is_dragging = False + drag_eve = Gtk.Button(label = "....") + hresize_eve = Gtk.Button(label = "< >") - label1 = Gtk.Label(label="") - label2 = Gtk.Label(label="....") - label3 = Gtk.Label(label="< >") + drag_eve.set_hexpand(True) + drag_eve.connect("button-press-event", self._press_event) + drag_eve.connect("motion-notify-event", self._motion_event) + drag_eve.connect("button-release-event", self._release_event) - drag_eve.set_above_child(True) - hresize_eve.set_above_child(True) - label1.set_hexpand(True) - label2.set_hexpand(True) - label3.set_hexpand(True) - label2.set_yalign(0.5) - label3.set_yalign(0.5) - label3.set_xalign(1.0) - - drag_eve.add(label2) - hresize_eve.add(label3) - - URI_TARGET_TYPE = 80 - uri_target = Gtk.TargetEntry.new('text/uri-list', Gtk.TargetFlags(0), URI_TARGET_TYPE) - targets = [ uri_target ] - flags = Gtk.DestDefaults.ALL - action = Gdk.DragAction.COPY - drag_eve.drag_dest_set(flags, targets, action) - - drag_eve.connect("button-press-event", self._toggle_drag_start) - drag_eve.connect("motion-notify-event", self._do_drag_motion_call) - drag_eve.connect("button-release-event", self._toggle_drag_start) - - self.add(label1) self.add(drag_eve) self.add(hresize_eve) - def _toggle_drag_start(self, widget = None, eve = None): - self.is_dragging = not self.is_dragging + def _press_event(self, widget = None, eve = None): + self.is_dragging = True + self._drag_start_x = eve.x + self._drag_start_y = eve.y + + def _motion_event(self, widget = None, eve = None): + if self._update_block: + self._drag_start_x = eve.x + self._drag_start_y = eve.y + return - def _do_drag_motion_call(self, widget = None, eve = None): if self.is_dragging: - self._move_callback(self.get_parent(), self._current_x, self._current_y, self.set_current_xy) + offset_x = eve.x - self._drag_start_x + offset_y = eve.y - self._drag_start_y - def set_current_xy(self, x, y): - self._current_x = x - self._current_y = y + self._current_x += offset_x + self._current_y += offset_y + + self._update_block = True + self._move_callback(self.get_parent(), self._current_x, self._current_y) + self._update_block = False + + def _release_event(self, widget = None, eve = None): + self.is_dragging = False + self._drag_start_x = 0 + self._drag_start_y = 0 diff --git a/src/core/widgets/dynamic_widget.py b/src/core/widgets/dynamic_widget.py index 3d51ec3..e750f53 100644 --- a/src/core/widgets/dynamic_widget.py +++ b/src/core/widgets/dynamic_widget.py @@ -25,10 +25,9 @@ class DynamicWidget(Gtk.Box): def _setup_styling(self): self.set_orientation(1) - self.set_size_request(120, 45) + self.set_size_request(256, 45) ctx = self.get_style_context() ctx.add_class("dynamic-widget") - ... def _setup_signals(self): ... diff --git a/src/core/widgets/page_widget.py b/src/core/widgets/page_widget.py index ebc3e33..3bd3e14 100644 --- a/src/core/widgets/page_widget.py +++ b/src/core/widgets/page_widget.py @@ -11,18 +11,20 @@ from .pages_tab_widget import PagesTabWidget - -# class Page(Gtk.Box): class Page(Gtk.ScrolledWindow): def __init__(self, close_tab, section_pth, manifest_pth): super(Page, self).__init__() + self._window = settings.get_main_window() self._manifest_pth = settings.generate_page_manifest(section_pth) if not manifest_pth else manifest_pth self._close_tab = close_tab self._drag_area = None self._name = None self._date = None + self.mouse_held = False + self.was_dragging = False + self._setup_styling() self._setup_signals() self._subscribe_to_events() @@ -46,9 +48,22 @@ 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._drag_area.connect("button-release-event", self._release_event) viewport.add(self._drag_area) + self.add(viewport) def get_tab_widget(self): @@ -74,8 +89,24 @@ class Page(Gtk.ScrolledWindow): def _add_fixed_base_widgets(self): self._drag_area.add_fixed_base_widgets(self._name, self._date, self._update_header) - def _update_header(self, widget = None, eve = None): self._name = widget.get_text() 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 + + def _motion_event(self, widget = None, eve = None): + if self.mouse_held and not self.was_dragging: + self.was_dragging = True + + def _release_event(self, widget = None, eve = None): + self.mouse_held = False + if self.was_dragging: + self.was_dragging = False + return + + if "DragArea" in f"{self._window.get_focus()}": + self._drag_area.add_or_select_widget(widget, eve) diff --git a/src/core/widgets/pages/pages_widget.py b/src/core/widgets/pages/pages_widget.py index f9b5a71..9271564 100644 --- a/src/core/widgets/pages/pages_widget.py +++ b/src/core/widgets/pages/pages_widget.py @@ -32,7 +32,6 @@ class Pages(Gtk.Notebook): def _setup_styling(self): self.set_tab_pos(1) # NOTE: LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 - def _setup_signals(self): self.set_scrollable(True)