Skip to content

Commit 32f9106

Browse files
committed
add family DnD
1 parent d5a2f26 commit 32f9106

File tree

1 file changed

+67
-22
lines changed

1 file changed

+67
-22
lines changed

GraphView/graphview.py

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,8 +1451,8 @@ def motion_notify_event(self, _item, _target, event):
14511451
if self._in_drag and (event.type == Gdk.EventType.MOTION_NOTIFY):
14521452
# start drag when cursor moved more then 5
14531453
# to separate it from simple click
1454-
if ((abs(self._last_x - event.x) > 5)
1455-
or (abs(self._last_y - event.y) > 5)):
1454+
if ((abs(self._last_x - event.x_root) > 5)
1455+
or (abs(self._last_y - event.y_root) > 5)):
14561456
self.uistate.set_busy_cursor(False)
14571457
# Remove all single click events
14581458
for click_item in self.click_events:
@@ -1470,18 +1470,29 @@ def motion_notify_event(self, _item, _target, event):
14701470

14711471
# setup targets
14721472
tglist = Gtk.TargetList.new([])
1473-
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
1474-
DdTargets.PERSON_LINK.target_flags,
1475-
DdTargets.PERSON_LINK.app_id)
1476-
# allow drag to a text document, info on drag_get will be 0L !
1477-
tglist.add_text_targets(0)
1473+
if self.drag_person is not None:
1474+
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
1475+
DdTargets.PERSON_LINK.target_flags,
1476+
DdTargets.PERSON_LINK.app_id,
1477+
)
1478+
# allow drag to a text document, info on drag_get will be 0
1479+
tglist.add_text_targets(0)
1480+
if self.drag_family is not None:
1481+
tglist.add(DdTargets.FAMILY_LINK.atom_drag_type,
1482+
DdTargets.FAMILY_LINK.target_flags,
1483+
DdTargets.FAMILY_LINK.app_id,
1484+
)
1485+
# allow drag to a text document, info on drag_get will be 1
1486+
tglist.add_text_targets(1)
14781487

1479-
# start drag
14801488
drag_widget = self.get_widget()
1489+
# change event window
1490+
event.window = drag_widget.get_window()
1491+
# start drag
14811492
drag_widget.drag_begin_with_coordinates(
14821493
tglist,
14831494
Gdk.DragAction.COPY,
1484-
Gdk.ModifierType.BUTTON1_MASK,
1495+
Gdk.KEY_Pointer_Button1,
14851496
event,
14861497
x, y)
14871498
return True
@@ -1526,9 +1537,22 @@ def select_node(self, item, target, event):
15261537
if event.type != getattr(Gdk.EventType, "BUTTON_PRESS"):
15271538
return False
15281539

1540+
if button == 1 and node_class: # left mouse
1541+
# set drag mode, it will be applyed on motion event
1542+
self.drag_person = None
1543+
self.drag_family = None
1544+
if node_class == 'node':
1545+
self.drag_person = self.dbstate.db.get_person_from_handle(
1546+
handle)
1547+
if node_class == 'familynode':
1548+
self.drag_family = self.dbstate.db.get_family_from_handle(
1549+
handle)
1550+
self._in_drag = True
1551+
self._last_x = event.x_root
1552+
self._last_y = event.y_root
1553+
15291554
if button == 1 and node_class == 'node': # left mouse
15301555
self.uistate.set_busy_cursor(True)
1531-
self.drag_person = self.dbstate.db.get_person_from_handle(handle)
15321556
if handle == self.active_person_handle:
15331557
# Find a parent of the active person so that they can become
15341558
# the active person, if no parents then leave as the current
@@ -1548,11 +1572,6 @@ def select_node(self, item, target, event):
15481572
context = GLib.main_context_default()
15491573
self.click_events.append(context.find_source_by_id(click_event_id))
15501574

1551-
# go to drag mode, applyed on motion event
1552-
self._in_drag = True
1553-
self._last_x = event.x
1554-
self._last_y = event.y
1555-
15561575
elif button == 3 and node_class: # right mouse
15571576
if node_class == 'node':
15581577
self.menu = PopupMenu(self, 'person', handle)
@@ -1572,8 +1591,12 @@ def cb_drag_begin(self, widget, context):
15721591
"""
15731592
Called on start drag.
15741593
"""
1575-
# set icon for person drag
1576-
Gtk.drag_set_icon_name(context, 'gramps-person', 0, 0)
1594+
tgs = [x.name() for x in context.list_targets()]
1595+
# set icon depending on person or family drag
1596+
if DdTargets.PERSON_LINK.drag_type in tgs:
1597+
Gtk.drag_set_icon_name(context, 'gramps-person', 0, 0)
1598+
if DdTargets.FAMILY_LINK.drag_type in tgs:
1599+
Gtk.drag_set_icon_name(context, 'gramps-family', 0, 0)
15771600

15781601
def cb_drag_end(self, widget, context):
15791602
"""
@@ -1584,17 +1607,39 @@ def cb_drag_end(self, widget, context):
15841607
def cb_drag_data_get(self, widget, context, sel_data, info, time):
15851608
"""
15861609
Returned parameters after drag.
1587-
Specified for 'person-link', for others return text info about person.
1610+
Specified for 'person-link' and 'family-link',
1611+
also to return text info about person or family.
15881612
"""
15891613
tgs = [x.name() for x in context.list_targets()]
1614+
15901615
if info == DdTargets.PERSON_LINK.app_id:
15911616
data = (DdTargets.PERSON_LINK.drag_type,
15921617
id(widget), self.drag_person.handle, 0)
15931618
sel_data.set(sel_data.get_target(), 8, pickle.dumps(data))
1594-
elif ('TEXT' in tgs or 'text/plain' in tgs) and info == 0:
1595-
format_helper = FormattingHelper(self.dbstate)
1596-
sel_data.set_text(
1597-
format_helper.format_person(self.drag_person, 11),-1)
1619+
elif info == DdTargets.FAMILY_LINK.app_id:
1620+
data = (DdTargets.FAMILY_LINK.drag_type,
1621+
id(widget), self.drag_family.handle, 0)
1622+
sel_data.set(sel_data.get_target(), 8, pickle.dumps(data))
1623+
elif ('TEXT' in tgs or 'text/plain' in tgs):
1624+
if info == 0:
1625+
format_helper = FormattingHelper(self.dbstate)
1626+
sel_data.set_text(
1627+
format_helper.format_person(self.drag_person, 11),-1)
1628+
if info == 1:
1629+
f_handle = self.drag_family.get_father_handle()
1630+
m_handle = self.drag_family.get_mother_handle()
1631+
if f_handle:
1632+
father = self.dbstate.db.get_person_from_handle(f_handle)
1633+
father = displayer.display(father)
1634+
else:
1635+
father = '...'
1636+
if m_handle:
1637+
mother = self.dbstate.db.get_person_from_handle(m_handle)
1638+
mother = displayer.display(mother)
1639+
else:
1640+
mother = '...'
1641+
sel_data.set_text(
1642+
_('Family of %s and %s') % (father, mother), -1)
15981643

15991644
def find_a_parent(self, handle):
16001645
"""

0 commit comments

Comments
 (0)