Backup: Add a modal status popup
This is used to prevent the user closing Gramps during a backup. Fixes #12846, #12475, #12538
This commit is contained in:
parent
118b89e247
commit
b5e88c13f2
@ -99,6 +99,61 @@ class CLIDialog:
|
||||
pass
|
||||
vbox = CLIVbox()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Popup class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
class Popup:
|
||||
"""
|
||||
Popup a message for Gramps.
|
||||
|
||||
The Popup is used to display a message
|
||||
This class must be closed when no longer needed.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, title, message, parent=None):
|
||||
"""
|
||||
Specify the title and the message to display.
|
||||
"""
|
||||
from gi.repository import Gtk
|
||||
self.__popup = None
|
||||
if has_display():
|
||||
self.__popup = Gtk.Dialog()
|
||||
self.__popup.connect('delete_event', self.do_nothing)
|
||||
self.__popup.set_title(title)
|
||||
self.__popup.set_size_request(400, 100)
|
||||
self.__popup.vbox.set_spacing(10)
|
||||
self.__popup.vbox.set_border_width(24)
|
||||
self.__mesg = Gtk.Label(label=message)
|
||||
self.__mesg.set_use_markup(True)
|
||||
self.__popup.vbox.add(self.__mesg)
|
||||
if not parent: # if we don't have an explicit parent,
|
||||
# try to find one
|
||||
for win in Gtk.Window.list_toplevels():
|
||||
if win.is_active():
|
||||
parent = win
|
||||
break
|
||||
# if we still don't have a parent, give up
|
||||
if parent:
|
||||
self.__popup.set_transient_for(parent)
|
||||
self.__popup.set_modal(True)
|
||||
self.__popup.show_all()
|
||||
else: # This class is useful only in gui mode
|
||||
return
|
||||
|
||||
def destroy(self):
|
||||
if self.__popup:
|
||||
self.__popup.destroy()
|
||||
|
||||
def do_nothing(self, widget, value):
|
||||
"""
|
||||
Avoid to close the Popup
|
||||
"""
|
||||
return True
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Progress meter class
|
||||
|
@ -73,7 +73,7 @@ from gramps.gen.plug import REPORT
|
||||
from gramps.gen.plug.report._constants import standalone_categories
|
||||
from .plug import (PluginWindows, ReportPluginDialog, ToolPluginDialog)
|
||||
from .plug.report import report, BookSelector
|
||||
from .utils import AvailableUpdates
|
||||
from .utils import (AvailableUpdates, Popup)
|
||||
from .pluginmanager import GuiPluginManager
|
||||
from gramps.gen.relationship import get_relationship_calculator
|
||||
from .displaystate import DisplayState, RecentDocsMenu
|
||||
@ -1209,6 +1209,10 @@ class ViewManager(CLIManager):
|
||||
if(self.dbstate.db.is_open() and
|
||||
self.dbstate.db.has_changed > self.prev_has_changed):
|
||||
self.prev_has_changed = self.dbstate.db.has_changed
|
||||
message = _("Please, wait before closing gramps")
|
||||
message = '<span size="larger" weight="bold">%s</span>' % message
|
||||
pgr_title = _("Autobackup...")
|
||||
popup = Popup(pgr_title, message, parent=self.window)
|
||||
self.uistate.set_busy_cursor(True)
|
||||
self.uistate.progress.show()
|
||||
self.uistate.push_message(self.dbstate, _("Autobackup..."))
|
||||
@ -1218,6 +1222,7 @@ class ViewManager(CLIManager):
|
||||
self.uistate.push_message(self.dbstate,
|
||||
_("Error saving backup data"))
|
||||
self.uistate.set_busy_cursor(False)
|
||||
popup.destroy()
|
||||
self.uistate.progress.hide()
|
||||
|
||||
def __backup(self):
|
||||
@ -1782,6 +1787,10 @@ class QuickBackup(ManagedWindow): # TODO move this class into its own module
|
||||
position = self.window.get_position() # crock
|
||||
window.hide()
|
||||
self.window.move(position[0], position[1])
|
||||
message = _("Please, wait before closing gramps")
|
||||
message = '<span size="larger" weight="bold">%s</span>' % message
|
||||
pgr_title = _("Making backup...")
|
||||
popup = Popup(pgr_title, message, parent=self.window)
|
||||
self.uistate.set_busy_cursor(True)
|
||||
self.uistate.pulse_progressbar(0)
|
||||
self.uistate.progress.show()
|
||||
@ -1796,6 +1805,7 @@ class QuickBackup(ManagedWindow): # TODO move this class into its own module
|
||||
strip_photos=0, compress=1)
|
||||
writer.write(filename)
|
||||
self.uistate.set_busy_cursor(False)
|
||||
popup.destroy()
|
||||
self.uistate.progress.hide()
|
||||
self.uistate.push_message(self.dbstate,
|
||||
_("Backup saved to '%s'") % filename)
|
||||
|
Loading…
Reference in New Issue
Block a user