From 79d876e35040b0805a4f966b121aac0475e4c216 Mon Sep 17 00:00:00 2001 From: Bastien Jacquet Date: Sun, 26 Oct 2014 15:24:21 +0100 Subject: [PATCH] And drag support to EditPersonRef when person is set --- gramps/gui/editors/editpersonref.py | 24 ++++++++++++++++++++++++ gramps/gui/glade/editpersonref.glade | 15 ++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/gramps/gui/editors/editpersonref.py b/gramps/gui/editors/editpersonref.py index 4ed96b103..308522804 100644 --- a/gramps/gui/editors/editpersonref.py +++ b/gramps/gui/editors/editpersonref.py @@ -102,6 +102,23 @@ class EditPersonRef(EditSecondary): DdTargets.PERSON_LINK.app_id) self.person_label.drag_dest_set_target_list(tglist) self.person_label.connect('drag_data_received', self.on_drag_persondata_received) + self._update_dnd_capability() + + def _update_dnd_capability(self): + self.label_event_box = self.top.get_object('person_event_box') + # Set the drag action from the label + if self.obj.ref: + self.label_event_box.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, + [], Gdk.DragAction.COPY) + tglist = Gtk.TargetList.new([]) + tglist.add(DdTargets.PERSON_LINK.atom_drag_type, + DdTargets.PERSON_LINK.target_flags, + DdTargets.PERSON_LINK.app_id) + self.label_event_box.drag_source_set_target_list(tglist) + self.label_event_box.drag_source_set_icon_stock('gramps-person') + self.label_event_box.connect('drag_data_get', self.drag_data_get) + else: + self.label_event_box.drag_source_unset() def _setup_fields(self): @@ -154,6 +171,7 @@ class EditPersonRef(EditSecondary): if person: self.obj.ref = person.get_handle() self.person_label.set_text(name_displayer.display(person)) + self._update_dnd_capability() def on_drag_persondata_received(self, widget, context, x, y, sel_data, info, time): @@ -165,6 +183,12 @@ class EditPersonRef(EditSecondary): person = self.db.get_person_from_handle(handle) self.update_person(person) + def drag_data_get(self, widget, context, sel_data, info, time): + # get the selected object, returning if not is defined + if info == DdTargets.PERSON_LINK.app_id: + data = (DdTargets.PERSON_LINK.drag_type, id(self), self.obj.ref, 0) + sel_data.set(DdTargets.PERSON_LINK.atom_drag_type, 8, pickle.dumps(data)) + def _create_tabbed_pages(self): """ Create the notebook tabs and inserts them into the main diff --git a/gramps/gui/glade/editpersonref.glade b/gramps/gui/glade/editpersonref.glade index d336540dd..fbfc6defa 100644 --- a/gramps/gui/glade/editpersonref.glade +++ b/gramps/gui/glade/editpersonref.glade @@ -176,11 +176,16 @@ Note: Use Events instead for relations connected to specific time frames or occa - - True - False - Use the select button to choose a person that has an association to the edited person. - 0 + + False + + + True + False + Use the select button to choose a person that has an association to the edited person. + 0 + + 1