diff --git a/gramps/gui/editors/editpersonref.py b/gramps/gui/editors/editpersonref.py
index 91aef118d..d5c91d64f 100644
--- a/gramps/gui/editors/editpersonref.py
+++ b/gramps/gui/editors/editpersonref.py
@@ -48,9 +48,9 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
from gramps.gen.display.name import displayer as name_displayer
from .editsecondary import EditSecondary
+from .objectentries import PersonEntry
from gramps.gen.lib import NoteType
from ..widgets import MonitoredEntry, PrivacyButton
-from ..selectors import SelectorFactory
from .displaytabs import CitationEmbedList, NoteTab
from ..glade import Glade
from ..ddtargets import DdTargets
@@ -94,32 +94,17 @@ class EditPersonRef(EditSecondary):
self.setup_configs('interface.person-ref', 600, 350)
self.person_label = self.top.get_object('person')
-
- #allow for drop:
- self.person_label.drag_dest_set(Gtk.DestDefaults.MOTION |
- Gtk.DestDefaults.DROP,
- [DdTargets.PERSON_LINK.target()],
- Gdk.DragAction.COPY)
- 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,
- [DdTargets.PERSON_LINK.target()], Gdk.DragAction.COPY)
- self.label_event_box.drag_source_set_icon_name('gramps-person')
- self.label_event_box.connect('drag_data_get', self.drag_data_get)
- else:
- self.label_event_box.drag_source_unset()
+ self.share_btn = self.top.get_object('select')
+ self.add_del_btn = self.top.get_object('add_del')
def _setup_fields(self):
- if self.obj.ref:
- p = self.dbstate.db.get_person_from_handle(self.obj.ref)
- self.person_label.set_text(name_displayer.display(p))
+ self.person_field = PersonEntry(self.dbstate, self.uistate, self.track,
+ self.top.get_object("person"),
+ self.top.get_object("person_event_box"),
+ self.obj.set_reference_handle,
+ self.obj.get_reference_handle,
+ self.add_del_btn, self.share_btn)
self.street = MonitoredEntry(
self.top.get_object("relationship"),
@@ -135,7 +120,6 @@ class EditPersonRef(EditSecondary):
def _connect_signals(self):
self.define_cancel_button(self.top.get_object('cancel'))
self.define_ok_button(self.top.get_object('ok'),self.save)
- self.top.get_object('select').connect('clicked',self._select_person)
self.define_help_button(self.top.get_object('help'),
WIKI_HELP_PAGE, WIKI_HELP_SEC)
@@ -156,35 +140,6 @@ class EditPersonRef(EditSecondary):
if self.obj.ref in handles:
self.close()
- def _select_person(self, obj):
- SelectPerson = SelectorFactory('Person')
-
- sel = SelectPerson(self.dbstate, self.uistate, self.track)
- person = sel.run()
- self.update_person(person)
-
- def update_person(self, person):
- 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):
- """
- Handle the standard gtk interface for drag_data_received.
- """
- if sel_data and sel_data.get_data():
- (drag_type, idval, handle, val) = pickle.loads(sel_data.get_data())
- 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/editors/objectentries.py b/gramps/gui/editors/objectentries.py
index 54a19788e..670281326 100644
--- a/gramps/gui/editors/objectentries.py
+++ b/gramps/gui/editors/objectentries.py
@@ -44,7 +44,8 @@ from gi.repository import Pango
# Gramps modules
#
#-------------------------------------------------------------------------
-from gramps.gen.lib import (Place, Source, Media, Note)
+from gramps.gen.lib import (Person, Place, Source, Media, Note)
+from .editperson import EditPerson
from .editplace import EditPlace
from .editsource import EditSource
from .editmedia import EditMedia
@@ -53,6 +54,7 @@ from ..selectors import SelectorFactory
from ..ddtargets import DdTargets
from gramps.gen.errors import WindowActiveError
from gramps.gen.display.place import displayer as place_displayer
+from gramps.gen.display.name import displayer as name_displayer
#-------------------------------------------------------------------------
#
@@ -283,6 +285,53 @@ class ObjEntry:
self.add_edt.set_tooltip_text(self.ADD_STR)
self._update_dnd_capability()
+class PersonEntry(ObjEntry):
+ """
+ Handles the selection of a existing or new Person. Supports Drag and Drop
+ to select a person.
+ """
+ EMPTY_TEXT = "%s" % _('To select a person, use drag-and-drop '
+ 'or use the buttons')
+ EMPTY_TEXT_RED = "%s" % _('No person given, click button to select one')
+ EDIT_STR = _('Edit person')
+ SHARE_STR = _('Select an existing person')
+ ADD_STR = _('Add a new person')
+ DEL_STR = _('Remove person')
+ _DND_TYPE = DdTargets.PERSON_LINK
+ _DND_ICON = 'gramps-person'
+
+ def __init__(self, dbstate, uistate, track, label, label_event_box, set_val,
+ get_val, add_edt, share, skip=[]):
+ ObjEntry.__init__(self, dbstate, uistate, track, label, label_event_box, set_val,
+ get_val, add_edt, share)
+ self.skip = skip
+
+ def get_from_handle(self, handle):
+ """ return the object given the hande
+ """
+ return self.db.get_person_from_handle(handle)
+
+ def get_label(self, person):
+ person_name = name_displayer.display(person)
+ return "%s \u2068[%s]\u200e\u2069" % (person_name, person.gramps_id)
+
+ def call_editor(self, obj=None):
+ if obj is None:
+ person = Person()
+ func = self.obj_added
+ else:
+ person = obj
+ func = self.after_edit
+ try:
+ EditPerson(self.dbstate, self.uistate, self.track,
+ person, func)
+ except WindowActiveError:
+ pass
+
+ def call_selector(self):
+ cls = SelectorFactory('Person')
+ return cls(self.dbstate, self.uistate, self.track, skip=self.skip)
+
class PlaceEntry(ObjEntry):
"""
Handles the selection of a existing or new Place. Supports Drag and Drop
diff --git a/gramps/gui/glade/editpersonref.glade b/gramps/gui/glade/editpersonref.glade
index 89ffb1321..58f32c0d1 100644
--- a/gramps/gui/glade/editpersonref.glade
+++ b/gramps/gui/glade/editpersonref.glade
@@ -1,30 +1,30 @@
-
+