Skip to content

Commit 357447e

Browse files
committed
add family DnD
1 parent eaeab92 commit 357447e

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
@@ -1360,8 +1360,8 @@ def motion_notify_event(self, item, target, event):
13601360
if self._in_drag and (event.type == Gdk.EventType.MOTION_NOTIFY):
13611361
# start drag when cursor moved more then 5
13621362
# to separate it from simple click
1363-
if ((abs(self._last_x - event.x) > 5)
1364-
or (abs(self._last_y - event.y) > 5)):
1363+
if ((abs(self._last_x - event.x_root) > 5)
1364+
or (abs(self._last_y - event.y_root) > 5)):
13651365
self.uistate.set_busy_cursor(False)
13661366
# Remove all single click events
13671367
for click_item in self.click_events:
@@ -1379,18 +1379,29 @@ def motion_notify_event(self, item, target, event):
13791379

13801380
# setup targets
13811381
tglist = Gtk.TargetList.new([])
1382-
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
1383-
DdTargets.PERSON_LINK.target_flags,
1384-
DdTargets.PERSON_LINK.app_id)
1385-
# allow drag to a text document, info on drag_get will be 0L !
1386-
tglist.add_text_targets(0)
1382+
if self.drag_person is not None:
1383+
tglist.add(DdTargets.PERSON_LINK.atom_drag_type,
1384+
DdTargets.PERSON_LINK.target_flags,
1385+
DdTargets.PERSON_LINK.app_id,
1386+
)
1387+
# allow drag to a text document, info on drag_get will be 0
1388+
tglist.add_text_targets(0)
1389+
if self.drag_family is not None:
1390+
tglist.add(DdTargets.FAMILY_LINK.atom_drag_type,
1391+
DdTargets.FAMILY_LINK.target_flags,
1392+
DdTargets.FAMILY_LINK.app_id,
1393+
)
1394+
# allow drag to a text document, info on drag_get will be 1
1395+
tglist.add_text_targets(1)
13871396

1388-
# start drag
13891397
drag_widget = self.get_widget()
1398+
# change event window
1399+
event.window = drag_widget.get_window()
1400+
# start drag
13901401
drag_widget.drag_begin_with_coordinates(
13911402
tglist,
13921403
Gdk.DragAction.COPY,
1393-
Gdk.ModifierType.BUTTON1_MASK,
1404+
Gdk.KEY_Pointer_Button1,
13941405
event,
13951406
x, y)
13961407
return True
@@ -1435,9 +1446,22 @@ def select_node(self, item, target, event):
14351446
if event.type != getattr(Gdk.EventType, "BUTTON_PRESS"):
14361447
return False
14371448

1449+
if button == 1 and node_class: # left mouse
1450+
# set drag mode, it will be applyed on motion event
1451+
self.drag_person = None
1452+
self.drag_family = None
1453+
if node_class == 'node':
1454+
self.drag_person = self.dbstate.db.get_person_from_handle(
1455+
handle)
1456+
if node_class == 'familynode':
1457+
self.drag_family = self.dbstate.db.get_family_from_handle(
1458+
handle)
1459+
self._in_drag = True
1460+
self._last_x = event.x_root
1461+
self._last_y = event.y_root
1462+
14381463
if button == 1 and node_class == 'node': # left mouse
14391464
self.uistate.set_busy_cursor(True)
1440-
self.drag_person = self.dbstate.db.get_person_from_handle(handle)
14411465
if handle == self.active_person_handle:
14421466
# Find a parent of the active person so that they can become
14431467
# the active person, if no parents then leave as the current
@@ -1457,11 +1481,6 @@ def select_node(self, item, target, event):
14571481
context = GLib.main_context_default()
14581482
self.click_events.append(context.find_source_by_id(click_event_id))
14591483

1460-
# go to drag mode, applyed on motion event
1461-
self._in_drag = True
1462-
self._last_x = event.x
1463-
self._last_y = event.y
1464-
14651484
elif button == 3 and node_class: # right mouse
14661485
if node_class == 'node':
14671486
self.menu = PopupMenu(self, 'person', handle)
@@ -1481,8 +1500,12 @@ def cb_drag_begin(self, widget, context):
14811500
"""
14821501
Called on start drag.
14831502
"""
1484-
# set icon for person drag
1485-
Gtk.drag_set_icon_name(context, 'gramps-person', 0, 0)
1503+
tgs = [x.name() for x in context.list_targets()]
1504+
# set icon depending on person or family drag
1505+
if DdTargets.PERSON_LINK.drag_type in tgs:
1506+
Gtk.drag_set_icon_name(context, 'gramps-person', 0, 0)
1507+
if DdTargets.FAMILY_LINK.drag_type in tgs:
1508+
Gtk.drag_set_icon_name(context, 'gramps-family', 0, 0)
14861509

14871510
def cb_drag_end(self, widget, context):
14881511
"""
@@ -1493,17 +1516,39 @@ def cb_drag_end(self, widget, context):
14931516
def cb_drag_data_get(self, widget, context, sel_data, info, time):
14941517
"""
14951518
Returned parameters after drag.
1496-
Specified for 'person-link', for others return text info about person.
1519+
Specified for 'person-link' and 'family-link',
1520+
also to return text info about person or family.
14971521
"""
14981522
tgs = [x.name() for x in context.list_targets()]
1523+
14991524
if info == DdTargets.PERSON_LINK.app_id:
15001525
data = (DdTargets.PERSON_LINK.drag_type,
15011526
id(widget), self.drag_person.handle, 0)
15021527
sel_data.set(sel_data.get_target(), 8, pickle.dumps(data))
1503-
elif ('TEXT' in tgs or 'text/plain' in tgs) and info == 0:
1504-
format_helper = FormattingHelper(self.dbstate)
1505-
sel_data.set_text(
1506-
format_helper.format_person(self.drag_person, 11),-1)
1528+
elif info == DdTargets.FAMILY_LINK.app_id:
1529+
data = (DdTargets.FAMILY_LINK.drag_type,
1530+
id(widget), self.drag_family.handle, 0)
1531+
sel_data.set(sel_data.get_target(), 8, pickle.dumps(data))
1532+
elif ('TEXT' in tgs or 'text/plain' in tgs):
1533+
if info == 0:
1534+
format_helper = FormattingHelper(self.dbstate)
1535+
sel_data.set_text(
1536+
format_helper.format_person(self.drag_person, 11),-1)
1537+
if info == 1:
1538+
f_handle = self.drag_family.get_father_handle()
1539+
m_handle = self.drag_family.get_mother_handle()
1540+
if f_handle:
1541+
father = self.dbstate.db.get_person_from_handle(f_handle)
1542+
father = displayer.display(father)
1543+
else:
1544+
father = '...'
1545+
if m_handle:
1546+
mother = self.dbstate.db.get_person_from_handle(m_handle)
1547+
mother = displayer.display(mother)
1548+
else:
1549+
mother = '...'
1550+
sel_data.set_text(
1551+
_('Family of %s and %s') % (father, mother), -1)
15071552

15081553
def find_a_parent(self, handle):
15091554
"""

0 commit comments

Comments
 (0)