WIP dargging and generation

This commit is contained in:
itdominator 2023-04-04 22:23:07 -05:00
parent 449f8b54ce
commit d2b878722d
5 changed files with 82 additions and 60 deletions

View File

@ -13,6 +13,7 @@ from .dynamic_widget import DynamicWidget
class DragArea(GtkSource.View): class DragArea(GtkSource.View):
# class DragArea(Gtk.Fixed):
def __init__(self): def __init__(self):
super(DragArea, self).__init__() super(DragArea, self).__init__()
@ -30,7 +31,7 @@ class DragArea(GtkSource.View):
self.set_cursor_visible(False) self.set_cursor_visible(False)
def _setup_signals(self): def _setup_signals(self):
self.connect("button-release-event", self.add_or_select_widget) ...
def _subscribe_to_events(self): def _subscribe_to_events(self):
... ...
@ -42,30 +43,25 @@ class DragArea(GtkSource.View):
entry = Gtk.Entry(text = name) entry = Gtk.Entry(text = name)
date_label = Gtk.Label(label = date) date_label = Gtk.Label(label = date)
ctx = entry.get_style_context()
ctx.add_class("drag-area-title")
entry.connect("changed", update_header_callback) entry.connect("changed", update_header_callback)
entry.set_width_chars(25) entry.set_width_chars(25)
entry.set_max_length(25) entry.set_max_length(25)
# PRIVATE = 0, WIDGET = 1, TEXT = 2, LEFT = 3, RIGHT = 4, TOP = 5, BOTTOM = 6 # self.put(entry, 30, 30)
self.add_child_in_window(entry, Gtk.TextWindowType.TEXT, 30, 30) # self.put(date_label, 30, 65)
self.add_child_in_window(date_label, Gtk.TextWindowType.TEXT, 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): def add_or_select_widget(self, widget = None, eve = None):
dynamic_widget = DynamicWidget(self._move_callback, eve.x, eve.y) dynamic_widget = DynamicWidget(self._move_callback, eve.x, eve.y)
self._children_content.append(dynamic_widget) self._children_content.append(dynamic_widget)
self.add_child_in_window(dynamic_widget, Gtk.TextWindowType.TEXT, eve.x, eve.y) # self.put(dynamic_widget, eve.x, eve.y)
self.get_page_content() self.add_child_in_window(dynamic_widget, Gtk.TextWindowType.WIDGET, eve.x, eve.y)
def get_page_content(self, widget = None, eve = None): def _move_callback(self, widget = None, x = None, y = None):
# PRIVATE = 0, WIDGET = 1, TEXT = 2, LEFT = 3, RIGHT = 4, TOP = 5, BOTTOM = 6 # self.move(widget, x, y)
text_window = self.get_window(Gtk.TextWindowType.TEXT) self.move_child(widget, x, y)
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)

View File

@ -18,6 +18,10 @@ class DynamicHeaderWidget(Gtk.Box):
self._move_callback = move_callback self._move_callback = move_callback
self._current_x = x self._current_x = x
self._current_y = y 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_styling()
self._setup_signals() self._setup_signals()
@ -37,48 +41,41 @@ class DynamicHeaderWidget(Gtk.Box):
... ...
def _load_widgets(self): def _load_widgets(self):
drag_eve = Gtk.EventBox()
hresize_eve = Gtk.EventBox()
self.is_dragging = False self.is_dragging = False
drag_eve = Gtk.Button(label = "....")
hresize_eve = Gtk.Button(label = "< >")
label1 = Gtk.Label(label="") drag_eve.set_hexpand(True)
label2 = Gtk.Label(label="....") drag_eve.connect("button-press-event", self._press_event)
label3 = Gtk.Label(label="< >") 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(drag_eve)
self.add(hresize_eve) self.add(hresize_eve)
def _toggle_drag_start(self, widget = None, eve = None): def _press_event(self, widget = None, eve = None):
self.is_dragging = not self.is_dragging 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: 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 += offset_x
self._current_x = x self._current_y += offset_y
self._current_y = 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

View File

@ -25,10 +25,9 @@ class DynamicWidget(Gtk.Box):
def _setup_styling(self): def _setup_styling(self):
self.set_orientation(1) self.set_orientation(1)
self.set_size_request(120, 45) self.set_size_request(256, 45)
ctx = self.get_style_context() ctx = self.get_style_context()
ctx.add_class("dynamic-widget") ctx.add_class("dynamic-widget")
...
def _setup_signals(self): def _setup_signals(self):
... ...

View File

@ -11,18 +11,20 @@ from .pages_tab_widget import PagesTabWidget
# class Page(Gtk.Box):
class Page(Gtk.ScrolledWindow): class Page(Gtk.ScrolledWindow):
def __init__(self, close_tab, section_pth, manifest_pth): def __init__(self, close_tab, section_pth, manifest_pth):
super(Page, self).__init__() 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._manifest_pth = settings.generate_page_manifest(section_pth) if not manifest_pth else manifest_pth
self._close_tab = close_tab self._close_tab = close_tab
self._drag_area = None self._drag_area = None
self._name = None self._name = None
self._date = None self._date = None
self.mouse_held = False
self.was_dragging = False
self._setup_styling() self._setup_styling()
self._setup_signals() self._setup_signals()
self._subscribe_to_events() self._subscribe_to_events()
@ -46,9 +48,22 @@ class Page(Gtk.ScrolledWindow):
def _load_widgets(self): def _load_widgets(self):
self._drag_area = DragArea() self._drag_area = DragArea()
eve_box = Gtk.EventBox()
viewport = Gtk.Viewport() 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) viewport.add(self._drag_area)
self.add(viewport) self.add(viewport)
def get_tab_widget(self): def get_tab_widget(self):
@ -74,8 +89,24 @@ class Page(Gtk.ScrolledWindow):
def _add_fixed_base_widgets(self): def _add_fixed_base_widgets(self):
self._drag_area.add_fixed_base_widgets(self._name, self._date, self._update_header) self._drag_area.add_fixed_base_widgets(self._name, self._date, self._update_header)
def _update_header(self, widget = None, eve = None): def _update_header(self, widget = None, eve = None):
self._name = widget.get_text() self._name = widget.get_text()
self._tab_widget.set_tab_label(self._name) self._tab_widget.set_tab_label(self._name)
settings.update_manifest(self._manifest_pth, self._name, self._date) 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)

View File

@ -32,7 +32,6 @@ class Pages(Gtk.Notebook):
def _setup_styling(self): def _setup_styling(self):
self.set_tab_pos(1) # NOTE: LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 self.set_tab_pos(1) # NOTE: LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3
def _setup_signals(self): def _setup_signals(self):
self.set_scrollable(True) self.set_scrollable(True)