From ceccf0c4428e43b3a5988cd64461195be352d311 Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Tue, 3 Sep 2013 14:17:27 +0000 Subject: [PATCH] 5598: implement User() class for tools Let gui User take an optional uistate kwarg, and use it in dbloader and viewmanager. svn: r23008 --- gramps/gui/dbloader.py | 3 ++- gramps/gui/test/user_test.py | 4 ++++ gramps/gui/user.py | 3 ++- gramps/gui/viewmanager.py | 6 ++++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gramps/gui/dbloader.py b/gramps/gui/dbloader.py index aab1fe157..3f8898513 100644 --- a/gramps/gui/dbloader.py +++ b/gramps/gui/dbloader.py @@ -253,7 +253,8 @@ class DbLoader(CLIDbLoader): #an importer can return an object with info, object.info_text() #returns that info. Otherwise None is set to import_info self.import_info = importer(self.dbstate.db, filename, - User(callback=self._pulse_progress)) + User(callback=self._pulse_progress, + uistate=self.uistate)) dirname = os.path.dirname(filename) + os.path.sep config.set('paths.recent-import-dir', dirname) except UnicodeError as msg: diff --git a/gramps/gui/test/user_test.py b/gramps/gui/test/user_test.py index 7b778df24..60d139693 100644 --- a/gramps/gui/test/user_test.py +++ b/gramps/gui/test/user_test.py @@ -56,5 +56,9 @@ class TestUser_prompt(unittest.TestCase): MockQD.return_value.run.assert_called_once_with() # TODO test that run's return is the one returned by prompt()... +class TestUser_init_accepts_uistate(unittest.TestCase): + def test(self): + user.User(uistate = None) + if __name__ == "__main__": unittest.main() diff --git a/gramps/gui/user.py b/gramps/gui/user.py index 7a0b3f70b..f52880cf7 100644 --- a/gramps/gui/user.py +++ b/gramps/gui/user.py @@ -50,9 +50,10 @@ class User(user.User): This class provides a means to interact with the user via GTK. It implements the interface in gramps.gen.user.User() """ - def __init__(self, callback=None, error=None): + def __init__(self, callback=None, error=None, uistate=None): user.User.__init__(self, callback, error) self.progress = None + self.uistate = uistate def begin_progress(self, title, message, steps): """ diff --git a/gramps/gui/viewmanager.py b/gramps/gui/viewmanager.py index 2eac42a08..43beaee8f 100644 --- a/gramps/gui/viewmanager.py +++ b/gramps/gui/viewmanager.py @@ -1319,13 +1319,15 @@ class ViewManager(CLIManager): from gramps.plugins.export.exportpkg import PackageWriter writer = PackageWriter(self.dbstate.db, filename, User(error=ErrorDialog, - callback=self.uistate.pulse_progressbar)) + callback=self.uistate.pulse_progressbar, + uistate=self.uistate)) writer.export() else: from gramps.plugins.export.exportxml import XmlWriter writer = XmlWriter(self.dbstate.db, User(error=ErrorDialog, - callback=self.uistate.pulse_progressbar), + callback=self.uistate.pulse_progressbar, + uistate=self.uistate), strip_photos=0, compress=1) writer.write(filename) self.uistate.set_busy_cursor(False)