diff --git a/gramps/gui/dialog.py b/gramps/gui/dialog.py
index 91ce7bb77..c52f88e52 100644
--- a/gramps/gui/dialog.py
+++ b/gramps/gui/dialog.py
@@ -340,55 +340,68 @@ class MissingMediaDialog(object):
return True
class MultiSelectDialog(object):
- def __init__(self, msg1, msg2, task1, task2, task3, parent=None):
+ def __init__(self, msg1_func, msg2_func, items, lookup,
+ cancel_func=None, no_func=None, yes_func=None,
+ parent=None):
+ """
+ """
self.xml = Glade(toplevel='multiselectdialog')
self.top = self.xml.toplevel
self.top.set_icon(ICON)
- self.top.set_title("%s - Gramps" % msg1)
-
- self.task1 = task1
- self.task2 = task2
- self.task3 = task3
- self.default_action = 0
- self.last_action = 0
+
+ self.msg1_func = msg1_func
+ self.msg2_func = msg2_func
+ self.items = items
+ self.lookup = lookup
+ self.cancel_func = cancel_func
+ self.no_func = no_func
+ self.yes_func = yes_func
label1 = self.xml.get_object('label6')
- label1.set_text('%s' % msg1)
- label1.set_use_markup(True)
-
label2 = self.xml.get_object('label5')
- label2.set_text(msg2)
- label2.set_use_markup(True)
-
check_button = self.xml.get_object('apply_to_rest')
if parent:
self.top.set_transient_for(parent)
- self.top.show()
self.top.connect('delete_event', self.warn)
- response = Gtk.ResponseType.DELETE_EVENT
- # Need some magic here, because an attempt to close the dialog
- # with the X button not only emits the 'delete_event' signal
- # but also exits with the RESPONSE_DELETE_EVENT
- while response == Gtk.ResponseType.DELETE_EVENT:
- response = self.top.run()
+ default_action = 0
+ for selected in items:
+ item = self.lookup(selected)
+ if default_action == 0:
+ msg1 = self.msg1_func(item)
+ msg2 = self.msg2_func(item)
+
+ self.top.set_title("%s - Gramps" % msg1)
+ label1.set_text('%s' % msg1)
+ label1.set_use_markup(True)
+ label2.set_text(msg2)
+ label2.set_use_markup(True)
+ self.top.show()
+
+ # Need some magic here, because an attempt to close the dialog
+ # with the X button not only emits the 'delete_event' signal
+ # but also exits with the RESPONSE_DELETE_EVENT
+ response = Gtk.ResponseType.DELETE_EVENT
+ while response == Gtk.ResponseType.DELETE_EVENT:
+ response = self.top.run()
- if check_button.get_active():
- self.default_action = response
- else:
- self.default_action = 0
- self.last_action = response
- if response == 1:
- if self.task1:
- self.task1()
- elif response == 2:
- if self.task2:
- self.task2()
- elif response == 3:
- if self.task3:
- self.task3()
+ if check_button.get_active():
+ default_action = response
+ else:
+ response = default_action
+ ### Now do it
+ if response == 1: # Cancel
+ if self.cancel_func:
+ self.cancel_func()
+ break
+ elif response == 2: # No
+ if self.no_func:
+ self.no_func()
+ elif response == 3: # Yes
+ if self.yes_func:
+ self.yes_func()
self.top.destroy()
def warn(self, obj, obj2):
diff --git a/gramps/plugins/lib/libpersonview.py b/gramps/plugins/lib/libpersonview.py
index ce7b16917..5c9209e47 100644
--- a/gramps/plugins/lib/libpersonview.py
+++ b/gramps/plugins/lib/libpersonview.py
@@ -51,7 +51,7 @@ from gramps.gui.views.listview import ListView, TEXT, MARKUP, ICON
from gramps.gui.actiongroup import ActionGroup
from gramps.gen.utils.string import data_recover_msg
from gramps.gen.display.name import displayer as name_displayer
-from gramps.gui.dialog import ErrorDialog, MultiSelectDialog
+from gramps.gui.dialog import ErrorDialog, MultiSelectDialog, QuestionDialog
from gramps.gen.errors import WindowActiveError
from gramps.gui.views.bookmarks import PersonBookmarks
from gramps.gen.config import config
@@ -286,34 +286,39 @@ class BasePersonView(ListView):
"""
Remove a person from the database.
"""
- self._multi_select_dialog = None
- for sel in self.selected_handles():
- person = self.dbstate.db.get_person_from_handle(sel)
- self.active_person = person
- if (self._multi_select_dialog and
- self._multi_select_dialog.default_action != 0):
- # Repeat previous choice
- if self._multi_select_dialog.default_action == 1: # Cancel
- break
- elif self._multi_select_dialog.default_action == 2: # No
- break
- elif self._multi_select_dialog.default_action == 3: # Yes
- self.delete_person_response()
- elif (self._multi_select_dialog and
- self._multi_select_dialog.last_action == 1): # Cancel
- # Cancel the rest of the operations
- break
- else:
- # Ask to delete; option to cancel, delete rest
- name = name_displayer.display(person) + (" [%s]" % person.gramps_id)
- msg = _('Deleting the person will remove the person '
- 'from the database.')
- self._multi_select_dialog = MultiSelectDialog(_('Delete %s?') % name,
- msg,
- None, # Cancel function
- None, # No function
- self.delete_person_response) # Yes
- self._multi_select_dialog = None
+ handles = self.selected_handles()
+ if len(handles) == 1:
+ person = self._lookup_person(handles[0])
+ name = self._message1_format(person)
+ msg = self._message2_format(person)
+ msg = "%s %s" % (msg, data_recover_msg)
+ QuestionDialog(_('Delete %s?') % name,
+ msg,
+ _('_Delete Person'),
+ self.delete_person_response)
+ else:
+ # Ask to delete; option to cancel, delete rest
+ MultiSelectDialog(self._message1_format,
+ self._message2_format,
+ handles,
+ self._lookup_person,
+ yes_func=self.delete_person_response) # Yes
+
+ def _message1_format(self, person):
+ return _('Delete %s?') % (name_displayer.display(person) +
+ (" [%s]" % person.gramps_id))
+
+ def _message2_format(self, person):
+ return _('Deleting the person will remove the person '
+ 'from the database.')
+
+ def _lookup_person(self, handle):
+ """
+ Get the next person from handle.
+ """
+ person = self.dbstate.db.get_person_from_handle(handle)
+ self.active_person = person
+ return person
def delete_person_response(self):
"""