5598: implement User() class for tools

Let gui User take an optional uistate kwarg,
and use it in dbloader and viewmanager.

svn: r23008
This commit is contained in:
Vassilii Khachaturov 2013-09-03 14:17:27 +00:00
parent b37e4064f1
commit ceccf0c442
4 changed files with 12 additions and 4 deletions

View File

@ -253,7 +253,8 @@ class DbLoader(CLIDbLoader):
#an importer can return an object with info, object.info_text() #an importer can return an object with info, object.info_text()
#returns that info. Otherwise None is set to import_info #returns that info. Otherwise None is set to import_info
self.import_info = importer(self.dbstate.db, filename, 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 dirname = os.path.dirname(filename) + os.path.sep
config.set('paths.recent-import-dir', dirname) config.set('paths.recent-import-dir', dirname)
except UnicodeError as msg: except UnicodeError as msg:

View File

@ -56,5 +56,9 @@ class TestUser_prompt(unittest.TestCase):
MockQD.return_value.run.assert_called_once_with() MockQD.return_value.run.assert_called_once_with()
# TODO test that run's return is the one returned by prompt()... # 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__": if __name__ == "__main__":
unittest.main() unittest.main()

View File

@ -50,9 +50,10 @@ class User(user.User):
This class provides a means to interact with the user via GTK. This class provides a means to interact with the user via GTK.
It implements the interface in gramps.gen.user.User() 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) user.User.__init__(self, callback, error)
self.progress = None self.progress = None
self.uistate = uistate
def begin_progress(self, title, message, steps): def begin_progress(self, title, message, steps):
""" """

View File

@ -1319,13 +1319,15 @@ class ViewManager(CLIManager):
from gramps.plugins.export.exportpkg import PackageWriter from gramps.plugins.export.exportpkg import PackageWriter
writer = PackageWriter(self.dbstate.db, filename, writer = PackageWriter(self.dbstate.db, filename,
User(error=ErrorDialog, User(error=ErrorDialog,
callback=self.uistate.pulse_progressbar)) callback=self.uistate.pulse_progressbar,
uistate=self.uistate))
writer.export() writer.export()
else: else:
from gramps.plugins.export.exportxml import XmlWriter from gramps.plugins.export.exportxml import XmlWriter
writer = XmlWriter(self.dbstate.db, writer = XmlWriter(self.dbstate.db,
User(error=ErrorDialog, User(error=ErrorDialog,
callback=self.uistate.pulse_progressbar), callback=self.uistate.pulse_progressbar,
uistate=self.uistate),
strip_photos=0, compress=1) strip_photos=0, compress=1)
writer.write(filename) writer.write(filename)
self.uistate.set_busy_cursor(False) self.uistate.set_busy_cursor(False)