6953: remove "undo history warning" under CLI

Port my fix from gramps34.
In addition, the Check tool now has a hardwired dependency
on ProgressMeter. Make a nullifying mock locally and
only set it to the real thing only under GUI.

Tested with impex.sh (further stages after check still fail,
see bug #6878).

svn: r22899
This commit is contained in:
Vassilii Khachaturov 2013-08-21 17:24:41 +00:00
parent 949c41107a
commit f92f5d08bf
11 changed files with 50 additions and 39 deletions

View File

@ -1038,7 +1038,7 @@ class ToolManagedWindowBatch(tool.BatchTool, ToolManagedWindowBase):
# This constructor will ask a question, set self.fail: # This constructor will ask a question, set self.fail:
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if not self.fail: if not self.fail:
ToolManagedWindowBase.__init__(self, dbstate, uistate, ToolManagedWindowBase.__init__(self, dbstate, uistate,
options_class, name, callback) options_class, name, callback)

View File

@ -101,25 +101,26 @@ class Tool(object):
class BatchTool(Tool): class BatchTool(Tool):
""" """
Same as Tool, except the warning is displayed about the potential Same as Tool, except the warning is displayed about the potential
loss of undo history. Should be used for tools using batch transactions. loss of undo history when GUI is available.
Should be used for tools using batch transactions.
""" """
def __init__(self, dbstate, options_class, name): def __init__(self, dbstate, uistate, options_class, name):
# TODO: should we replace this with a callback? if uistate:
from ..dialog import QuestionDialog2 # TODO: should we replace this with a callback?
warn_dialog = QuestionDialog2( from ..dialog import QuestionDialog2
_('Undo history warning'), warn_dialog = QuestionDialog2(
_('Proceeding with this tool will erase the undo history ' _('Undo history warning'),
'for this session. In particular, you will not be able ' _('Proceeding with this tool will erase the undo history '
'to revert the changes made by this tool or any changes ' 'for this session. In particular, you will not be able '
'made prior to it.\n\n' 'to revert the changes made by this tool or any changes '
'If you think you may want to revert running this tool, ' 'made prior to it.\n\n'
'please stop here and backup your database.'), 'If you think you may want to revert running this tool, '
_('_Proceed with the tool'), _('_Stop')) 'please stop here and backup your database.'),
if not warn_dialog.run(): _('_Proceed with the tool'), _('_Stop'))
self.fail = True if not warn_dialog.run():
return self.fail = True
return
Tool.__init__(self, dbstate, options_class, name) Tool.__init__(self, dbstate, options_class, name)
self.fail = False self.fail = False

View File

@ -79,7 +79,7 @@ class ChangeNames(tool.BatchTool, ManagedWindow):
ManagedWindow.__init__(self,uistate,[],self.__class__) ManagedWindow.__init__(self,uistate,[],self.__class__)
self.set_window(Gtk.Window(),Gtk.Label(),'') self.set_window(Gtk.Window(),Gtk.Label(),'')
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail: if self.fail:
return return

View File

@ -56,7 +56,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, uistate, options_class, name, callback=None):
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail: if self.fail:
return return

View File

@ -70,7 +70,6 @@ from gramps.gen.utils.db import family_name
from gramps.gen.utils.unknown import make_unknown from gramps.gen.utils.unknown import make_unknown
from gramps.gen.utils.file import (media_path_full, find_file, fix_encoding, from gramps.gen.utils.file import (media_path_full, find_file, fix_encoding,
get_unicode_path_from_file_chooser) get_unicode_path_from_file_chooser)
from gramps.gui.utils import ProgressMeter
from gramps.gui.managedwindow import ManagedWindow from gramps.gui.managedwindow import ManagedWindow
from gramps.gui.plug import tool from gramps.gui.plug import tool
@ -86,6 +85,12 @@ ngettext = glocale.translation.ngettext
# All except 09, 0A, 0D are replaced with space. # All except 09, 0A, 0D are replaced with space.
strip_dict = dict.fromkeys(list(range(9))+list(range(11,13))+list(range(14, 32)), " ") strip_dict = dict.fromkeys(list(range(9))+list(range(11,13))+list(range(14, 32)), " ")
class ProgressMeter(object):
def __init__(self, *args): pass
def set_pass(self, *args): pass
def step(self): pass
def close(self): pass
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Low Level repair # Low Level repair
@ -132,11 +137,15 @@ def cross_table_duplicates(db):
class Check(tool.BatchTool): class Check(tool.BatchTool):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, uistate, options_class, name, callback=None):
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail: if self.fail:
return return
cli = uistate is None cli = uistate is None
if uistate:
from gramps.gui.utils import ProgressMeter as PM
global ProgressMeter
ProgressMeter = PM
if self.db.readonly: if self.db.readonly:
# TODO: split plugin in a check and repair part to support # TODO: split plugin in a check and repair part to support
@ -2242,20 +2251,21 @@ class Report(ManagedWindow):
if cl: if cl:
print (text) print (text)
ManagedWindow.__init__(self, uistate, [], self) if uistate:
ManagedWindow.__init__(self, uistate, [], self)
topDialog = Glade() topDialog = Glade()
topDialog.get_object("close").connect('clicked', self.close) topDialog.get_object("close").connect('clicked', self.close)
window = topDialog.toplevel window = topDialog.toplevel
textwindow = topDialog.get_object("textwindow") textwindow = topDialog.get_object("textwindow")
textwindow.get_buffer().set_text(text) textwindow.get_buffer().set_text(text)
self.set_window(window, self.set_window(window,
#topDialog.get_widget("title"), #topDialog.get_widget("title"),
topDialog.get_object("title"), topDialog.get_object("title"),
_("Integrity Check Results")) _("Integrity Check Results"))
self.show() self.show()
def build_menu_names(self, obj): def build_menu_names(self, obj):
return (_('Check and Repair'), None) return (_('Check and Repair'), None)

View File

@ -69,7 +69,7 @@ class EventNames(tool.BatchTool, ManagedWindow):
""" """
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, uistate, options_class, name, callback=None):
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if not self.fail: if not self.fail:
uistate.set_busy_cursor(True) uistate.set_busy_cursor(True)

View File

@ -419,7 +419,7 @@ class ExtractCity(tool.BatchTool, ManagedWindow):
ManagedWindow.__init__(self, uistate, [], self.__class__) ManagedWindow.__init__(self, uistate, [], self.__class__)
self.set_window(Gtk.Window(), Gtk.Label(), '') self.set_window(Gtk.Window(), Gtk.Label(), '')
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if not self.fail: if not self.fail:
uistate.set_busy_cursor(True) uistate.set_busy_cursor(True)

View File

@ -97,7 +97,7 @@ class MergeCitations(tool.BatchTool,ManagedWindow):
self.dbstate = dbstate self.dbstate = dbstate
self.set_window(Gtk.Window(), Gtk.Label(), '') self.set_window(Gtk.Window(), Gtk.Label(), '')
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if not self.fail: if not self.fail:
uistate.set_busy_cursor(True) uistate.set_busy_cursor(True)

View File

@ -108,7 +108,7 @@ class PatchNames(tool.BatchTool, ManagedWindow):
ManagedWindow.__init__(self, uistate, [], self.__class__) ManagedWindow.__init__(self, uistate, [], self.__class__)
self.set_window(Gtk.Window(), Gtk.Label(), '') self.set_window(Gtk.Window(), Gtk.Label(), '')
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail: if self.fail:
return return

View File

@ -60,7 +60,7 @@ _parseformat = re.compile('.*%(\d+)[^\d]+')
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class ReorderIds(tool.BatchTool): class ReorderIds(tool.BatchTool):
def __init__(self, dbstate, uistate, options_class, name, callback=None): def __init__(self, dbstate, uistate, options_class, name, callback=None):
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail: if self.fail:
return return

View File

@ -115,7 +115,7 @@ class TestcaseGenerator(tool.BatchTool):
if dbstate.db.readonly: if dbstate.db.readonly:
return return
tool.BatchTool.__init__(self, dbstate, options_class, name) tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
if self.fail: if self.fail:
return return