And drag support to EditPersonRef when person is set

This commit is contained in:
Bastien Jacquet 2014-10-26 15:24:21 +01:00 committed by Nick Hall
parent ea3afbb35c
commit 79d876e350
2 changed files with 34 additions and 5 deletions

View File

@ -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

View File

@ -176,11 +176,16 @@ Note: Use Events instead for relations connected to specific time frames or occa
</packing>
</child>
<child>
<object class="GtkLabel" id="person">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Use the select button to choose a person that has an association to the edited person.</property>
<property name="xalign">0</property>
<object class="GtkEventBox" id="person_event_box">
<property name="visible-window">False</property>
<child>
<object class="GtkLabel" id="person">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Use the select button to choose a person that has an association to the edited person.</property>
<property name="xalign">0</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>