From f92f5d08bfb1037459647b8dc522cb34f1eced4f Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Wed, 21 Aug 2013 17:24:41 +0000 Subject: [PATCH] 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 --- gramps/gui/plug/_windows.py | 2 +- gramps/gui/plug/tool.py | 35 ++++++++++++----------- gramps/plugins/tool/changenames.py | 2 +- gramps/plugins/tool/changetypes.py | 2 +- gramps/plugins/tool/check.py | 36 +++++++++++++++--------- gramps/plugins/tool/eventnames.py | 2 +- gramps/plugins/tool/extractcity.py | 2 +- gramps/plugins/tool/mergecitations.py | 2 +- gramps/plugins/tool/patchnames.py | 2 +- gramps/plugins/tool/reorderids.py | 2 +- gramps/plugins/tool/testcasegenerator.py | 2 +- 11 files changed, 50 insertions(+), 39 deletions(-) diff --git a/gramps/gui/plug/_windows.py b/gramps/gui/plug/_windows.py index 238563f4d..cddcf18c9 100644 --- a/gramps/gui/plug/_windows.py +++ b/gramps/gui/plug/_windows.py @@ -1038,7 +1038,7 @@ class ToolManagedWindowBatch(tool.BatchTool, ToolManagedWindowBase): # This constructor will ask a question, set self.fail: self.dbstate = dbstate self.uistate = uistate - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if not self.fail: ToolManagedWindowBase.__init__(self, dbstate, uistate, options_class, name, callback) diff --git a/gramps/gui/plug/tool.py b/gramps/gui/plug/tool.py index 176ad1633..8d67632cb 100644 --- a/gramps/gui/plug/tool.py +++ b/gramps/gui/plug/tool.py @@ -101,25 +101,26 @@ class Tool(object): class BatchTool(Tool): """ 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): - # TODO: should we replace this with a callback? - from ..dialog import QuestionDialog2 - warn_dialog = QuestionDialog2( - _('Undo history warning'), - _('Proceeding with this tool will erase the undo history ' - 'for this session. In particular, you will not be able ' - 'to revert the changes made by this tool or any changes ' - 'made prior to it.\n\n' - 'If you think you may want to revert running this tool, ' - 'please stop here and backup your database.'), - _('_Proceed with the tool'), _('_Stop')) - if not warn_dialog.run(): - self.fail = True - return + def __init__(self, dbstate, uistate, options_class, name): + if uistate: + # TODO: should we replace this with a callback? + from ..dialog import QuestionDialog2 + warn_dialog = QuestionDialog2( + _('Undo history warning'), + _('Proceeding with this tool will erase the undo history ' + 'for this session. In particular, you will not be able ' + 'to revert the changes made by this tool or any changes ' + 'made prior to it.\n\n' + 'If you think you may want to revert running this tool, ' + 'please stop here and backup your database.'), + _('_Proceed with the tool'), _('_Stop')) + if not warn_dialog.run(): + self.fail = True + return Tool.__init__(self, dbstate, options_class, name) self.fail = False diff --git a/gramps/plugins/tool/changenames.py b/gramps/plugins/tool/changenames.py index c776b80e2..b420f68b0 100644 --- a/gramps/plugins/tool/changenames.py +++ b/gramps/plugins/tool/changenames.py @@ -79,7 +79,7 @@ class ChangeNames(tool.BatchTool, ManagedWindow): ManagedWindow.__init__(self,uistate,[],self.__class__) 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: return diff --git a/gramps/plugins/tool/changetypes.py b/gramps/plugins/tool/changetypes.py index ac827253b..93a19797d 100644 --- a/gramps/plugins/tool/changetypes.py +++ b/gramps/plugins/tool/changetypes.py @@ -56,7 +56,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow): 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: return diff --git a/gramps/plugins/tool/check.py b/gramps/plugins/tool/check.py index 2f7422994..49e1e7d90 100644 --- a/gramps/plugins/tool/check.py +++ b/gramps/plugins/tool/check.py @@ -70,7 +70,6 @@ from gramps.gen.utils.db import family_name from gramps.gen.utils.unknown import make_unknown from gramps.gen.utils.file import (media_path_full, find_file, fix_encoding, get_unicode_path_from_file_chooser) -from gramps.gui.utils import ProgressMeter from gramps.gui.managedwindow import ManagedWindow from gramps.gui.plug import tool @@ -86,6 +85,12 @@ ngettext = glocale.translation.ngettext # All except 09, 0A, 0D are replaced with space. 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 @@ -132,11 +137,15 @@ def cross_table_duplicates(db): class Check(tool.BatchTool): 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: return cli = uistate is None + if uistate: + from gramps.gui.utils import ProgressMeter as PM + global ProgressMeter + ProgressMeter = PM if self.db.readonly: # TODO: split plugin in a check and repair part to support @@ -2242,20 +2251,21 @@ class Report(ManagedWindow): if cl: print (text) - ManagedWindow.__init__(self, uistate, [], self) + if uistate: + ManagedWindow.__init__(self, uistate, [], self) - topDialog = Glade() - topDialog.get_object("close").connect('clicked', self.close) - window = topDialog.toplevel - textwindow = topDialog.get_object("textwindow") - textwindow.get_buffer().set_text(text) + topDialog = Glade() + topDialog.get_object("close").connect('clicked', self.close) + window = topDialog.toplevel + textwindow = topDialog.get_object("textwindow") + textwindow.get_buffer().set_text(text) - self.set_window(window, - #topDialog.get_widget("title"), - topDialog.get_object("title"), - _("Integrity Check Results")) + self.set_window(window, + #topDialog.get_widget("title"), + topDialog.get_object("title"), + _("Integrity Check Results")) - self.show() + self.show() def build_menu_names(self, obj): return (_('Check and Repair'), None) diff --git a/gramps/plugins/tool/eventnames.py b/gramps/plugins/tool/eventnames.py index 9e181d9af..5ece3fe03 100644 --- a/gramps/plugins/tool/eventnames.py +++ b/gramps/plugins/tool/eventnames.py @@ -69,7 +69,7 @@ class EventNames(tool.BatchTool, ManagedWindow): """ 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: uistate.set_busy_cursor(True) diff --git a/gramps/plugins/tool/extractcity.py b/gramps/plugins/tool/extractcity.py index 603cf4bb3..27d100a52 100644 --- a/gramps/plugins/tool/extractcity.py +++ b/gramps/plugins/tool/extractcity.py @@ -419,7 +419,7 @@ class ExtractCity(tool.BatchTool, ManagedWindow): ManagedWindow.__init__(self, uistate, [], self.__class__) 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: uistate.set_busy_cursor(True) diff --git a/gramps/plugins/tool/mergecitations.py b/gramps/plugins/tool/mergecitations.py index 1badae0c1..0374141e2 100644 --- a/gramps/plugins/tool/mergecitations.py +++ b/gramps/plugins/tool/mergecitations.py @@ -97,7 +97,7 @@ class MergeCitations(tool.BatchTool,ManagedWindow): self.dbstate = dbstate 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: uistate.set_busy_cursor(True) diff --git a/gramps/plugins/tool/patchnames.py b/gramps/plugins/tool/patchnames.py index ba26a6210..ffedd6e2d 100644 --- a/gramps/plugins/tool/patchnames.py +++ b/gramps/plugins/tool/patchnames.py @@ -108,7 +108,7 @@ class PatchNames(tool.BatchTool, ManagedWindow): ManagedWindow.__init__(self, uistate, [], self.__class__) 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: return diff --git a/gramps/plugins/tool/reorderids.py b/gramps/plugins/tool/reorderids.py index c61681530..4ec040be0 100644 --- a/gramps/plugins/tool/reorderids.py +++ b/gramps/plugins/tool/reorderids.py @@ -60,7 +60,7 @@ _parseformat = re.compile('.*%(\d+)[^\d]+') #------------------------------------------------------------------------- class ReorderIds(tool.BatchTool): 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: return diff --git a/gramps/plugins/tool/testcasegenerator.py b/gramps/plugins/tool/testcasegenerator.py index 30b3499cc..0a70cebe1 100644 --- a/gramps/plugins/tool/testcasegenerator.py +++ b/gramps/plugins/tool/testcasegenerator.py @@ -115,7 +115,7 @@ class TestcaseGenerator(tool.BatchTool): if dbstate.db.readonly: return - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if self.fail: return