7822: Yes To All button; added MultiSelectDialog, and use in remove multiple people

This commit is contained in:
Doug Blank 2015-05-24 11:05:45 -04:00
parent b363360ac8
commit 2835f51fb6
3 changed files with 249 additions and 10 deletions

View File

@ -339,6 +339,66 @@ class MissingMediaDialog(object):
self.top) self.top)
return True return True
class MultiSelectDialog(object):
def __init__(self, msg1, msg2, task1, task2, task3, 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
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.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()
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()
self.top.destroy()
def warn(self, obj, obj2):
WarningDialog(
_("Attempt to force closing the dialog"),
_("Please do not force closing this important dialog.\n"
"Instead select one of the available options"),
self.top)
return True
class MessageHideDialog(object): class MessageHideDialog(object):
def __init__(self, title, message, key, parent=None): def __init__(self, title, message, key, parent=None):

View File

@ -397,6 +397,169 @@
<action-widget response="3">button11</action-widget> <action-widget response="3">button11</action-widget>
</action-widgets> </action-widgets>
</object> </object>
<object class="GtkDialog" id="multiselectdialog">
<property name="can_focus">False</property>
<property name="default_width">600</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="vbox143">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="hbuttonbox50">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button183">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Cancel the rest of the operations</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button184">
<property name="label" translatable="yes">_No</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Do not apply the operation to this item</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button185">
<property name="label" translatable="yes">_Yes</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Apply the operation to this item</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="table82">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="margin_top">24</property>
<property name="margin_bottom">24</property>
<property name="hexpand">True</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
<property name="ellipsize">start</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkImage" id="image8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="pixel_size">48</property>
<property name="icon_name">dialog-warning</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="hexpand">True</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="apply_to_rest">
<property name="label" translatable="yes">_Use this answer for the rest of the items</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If you check this button, your next answer will apply to the rest of the selected items</property>
<property name="halign">center</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="1">button183</action-widget>
<action-widget response="2">button184</action-widget>
<action-widget response="3">button185</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="optiondialog"> <object class="GtkDialog" id="optiondialog">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>

View File

@ -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, QuestionDialog from gramps.gui.dialog import ErrorDialog, MultiSelectDialog
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,18 +286,34 @@ class BasePersonView(ListView):
""" """
Remove a person from the database. Remove a person from the database.
""" """
self._multi_select_dialog = None
for sel in self.selected_handles(): for sel in self.selected_handles():
person = self.dbstate.db.get_person_from_handle(sel) person = self.dbstate.db.get_person_from_handle(sel)
self.active_person = person self.active_person = person
name = name_displayer.display(person) if (self._multi_select_dialog and
self._multi_select_dialog.default_action != 0):
msg = _('Deleting the person will remove the person ' # Repeat previous choice
'from the database.') if self._multi_select_dialog.default_action == 1: # Cancel
msg = "%s %s" % (msg, data_recover_msg) break
QuestionDialog(_('Delete %s?') % name, elif self._multi_select_dialog.default_action == 2: # No
msg, break
_('_Delete Person'), elif self._multi_select_dialog.default_action == 3: # Yes
self.delete_person_response) 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
def delete_person_response(self): def delete_person_response(self):
""" """