Refined MultiSelectDialog to do all of the work
This commit is contained in:
parent
015f882826
commit
dfb45bdc5d
@ -340,55 +340,68 @@ class MissingMediaDialog(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
class MultiSelectDialog(object):
|
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.xml = Glade(toplevel='multiselectdialog')
|
||||||
|
|
||||||
self.top = self.xml.toplevel
|
self.top = self.xml.toplevel
|
||||||
self.top.set_icon(ICON)
|
self.top.set_icon(ICON)
|
||||||
self.top.set_title("%s - Gramps" % msg1)
|
|
||||||
|
|
||||||
self.task1 = task1
|
self.msg1_func = msg1_func
|
||||||
self.task2 = task2
|
self.msg2_func = msg2_func
|
||||||
self.task3 = task3
|
self.items = items
|
||||||
self.default_action = 0
|
self.lookup = lookup
|
||||||
self.last_action = 0
|
self.cancel_func = cancel_func
|
||||||
|
self.no_func = no_func
|
||||||
|
self.yes_func = yes_func
|
||||||
|
|
||||||
label1 = self.xml.get_object('label6')
|
label1 = self.xml.get_object('label6')
|
||||||
label1.set_text('<span weight="bold" size="larger">%s</span>' % msg1)
|
|
||||||
label1.set_use_markup(True)
|
|
||||||
|
|
||||||
label2 = self.xml.get_object('label5')
|
label2 = self.xml.get_object('label5')
|
||||||
label2.set_text(msg2)
|
|
||||||
label2.set_use_markup(True)
|
|
||||||
|
|
||||||
check_button = self.xml.get_object('apply_to_rest')
|
check_button = self.xml.get_object('apply_to_rest')
|
||||||
|
|
||||||
if parent:
|
if parent:
|
||||||
self.top.set_transient_for(parent)
|
self.top.set_transient_for(parent)
|
||||||
self.top.show()
|
|
||||||
self.top.connect('delete_event', self.warn)
|
self.top.connect('delete_event', self.warn)
|
||||||
response = Gtk.ResponseType.DELETE_EVENT
|
|
||||||
|
|
||||||
# Need some magic here, because an attempt to close the dialog
|
default_action = 0
|
||||||
# with the X button not only emits the 'delete_event' signal
|
for selected in items:
|
||||||
# but also exits with the RESPONSE_DELETE_EVENT
|
item = self.lookup(selected)
|
||||||
while response == Gtk.ResponseType.DELETE_EVENT:
|
if default_action == 0:
|
||||||
response = self.top.run()
|
msg1 = self.msg1_func(item)
|
||||||
|
msg2 = self.msg2_func(item)
|
||||||
|
|
||||||
if check_button.get_active():
|
self.top.set_title("%s - Gramps" % msg1)
|
||||||
self.default_action = response
|
label1.set_text('<span weight="bold" size="larger">%s</span>' % msg1)
|
||||||
else:
|
label1.set_use_markup(True)
|
||||||
self.default_action = 0
|
label2.set_text(msg2)
|
||||||
self.last_action = response
|
label2.set_use_markup(True)
|
||||||
if response == 1:
|
self.top.show()
|
||||||
if self.task1:
|
|
||||||
self.task1()
|
# Need some magic here, because an attempt to close the dialog
|
||||||
elif response == 2:
|
# with the X button not only emits the 'delete_event' signal
|
||||||
if self.task2:
|
# but also exits with the RESPONSE_DELETE_EVENT
|
||||||
self.task2()
|
response = Gtk.ResponseType.DELETE_EVENT
|
||||||
elif response == 3:
|
while response == Gtk.ResponseType.DELETE_EVENT:
|
||||||
if self.task3:
|
response = self.top.run()
|
||||||
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()
|
self.top.destroy()
|
||||||
|
|
||||||
def warn(self, obj, obj2):
|
def warn(self, obj, obj2):
|
||||||
|
@ -51,7 +51,7 @@ from gramps.gui.views.listview import ListView, TEXT, MARKUP, ICON
|
|||||||
from gramps.gui.actiongroup import ActionGroup
|
from gramps.gui.actiongroup import ActionGroup
|
||||||
from gramps.gen.utils.string import data_recover_msg
|
from gramps.gen.utils.string import data_recover_msg
|
||||||
from gramps.gen.display.name import displayer as name_displayer
|
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.gen.errors import WindowActiveError
|
||||||
from gramps.gui.views.bookmarks import PersonBookmarks
|
from gramps.gui.views.bookmarks import PersonBookmarks
|
||||||
from gramps.gen.config import config
|
from gramps.gen.config import config
|
||||||
@ -286,34 +286,39 @@ class BasePersonView(ListView):
|
|||||||
"""
|
"""
|
||||||
Remove a person from the database.
|
Remove a person from the database.
|
||||||
"""
|
"""
|
||||||
self._multi_select_dialog = None
|
handles = self.selected_handles()
|
||||||
for sel in self.selected_handles():
|
if len(handles) == 1:
|
||||||
person = self.dbstate.db.get_person_from_handle(sel)
|
person = self._lookup_person(handles[0])
|
||||||
self.active_person = person
|
name = self._message1_format(person)
|
||||||
if (self._multi_select_dialog and
|
msg = self._message2_format(person)
|
||||||
self._multi_select_dialog.default_action != 0):
|
msg = "%s %s" % (msg, data_recover_msg)
|
||||||
# Repeat previous choice
|
QuestionDialog(_('Delete %s?') % name,
|
||||||
if self._multi_select_dialog.default_action == 1: # Cancel
|
msg,
|
||||||
break
|
_('_Delete Person'),
|
||||||
elif self._multi_select_dialog.default_action == 2: # No
|
self.delete_person_response)
|
||||||
break
|
else:
|
||||||
elif self._multi_select_dialog.default_action == 3: # Yes
|
# Ask to delete; option to cancel, delete rest
|
||||||
self.delete_person_response()
|
MultiSelectDialog(self._message1_format,
|
||||||
elif (self._multi_select_dialog and
|
self._message2_format,
|
||||||
self._multi_select_dialog.last_action == 1): # Cancel
|
handles,
|
||||||
# Cancel the rest of the operations
|
self._lookup_person,
|
||||||
break
|
yes_func=self.delete_person_response) # Yes
|
||||||
else:
|
|
||||||
# Ask to delete; option to cancel, delete rest
|
def _message1_format(self, person):
|
||||||
name = name_displayer.display(person) + (" [%s]" % person.gramps_id)
|
return _('Delete %s?') % (name_displayer.display(person) +
|
||||||
msg = _('Deleting the person will remove the person '
|
(" [%s]" % person.gramps_id))
|
||||||
'from the database.')
|
|
||||||
self._multi_select_dialog = MultiSelectDialog(_('Delete %s?') % name,
|
def _message2_format(self, person):
|
||||||
msg,
|
return _('Deleting the person will remove the person '
|
||||||
None, # Cancel function
|
'from the database.')
|
||||||
None, # No function
|
|
||||||
self.delete_person_response) # Yes
|
def _lookup_person(self, handle):
|
||||||
self._multi_select_dialog = None
|
"""
|
||||||
|
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):
|
def delete_person_response(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user