5598: refactor GUI tools to enable CLI operation

evname now a CLI tool

svn: r23111
This commit is contained in:
Vassilii Khachaturov 2013-09-13 09:00:59 +00:00
parent 2abca1d071
commit f8698d12f3
2 changed files with 30 additions and 29 deletions

View File

@ -44,21 +44,19 @@ _ = glocale.translation.gettext
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gui.managedwindow import ManagedWindow
from gramps.gen.lib import EventRoleType from gramps.gen.lib import EventRoleType
from gramps.gen.db import DbTxn from gramps.gen.db import DbTxn
from gramps.gen.utils.db import family_name from gramps.gen.utils.db import family_name
from gramps.gui.plug import tool from gramps.gui.plug import tool
from gramps.gen.display.name import displayer as name_displayer from gramps.gen.display.name import displayer as name_displayer
from gramps.gui.dialog import OkDialog
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# EventNames # EventNames
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class EventNames(tool.BatchTool, ManagedWindow): class EventNames(tool.BatchTool):
""" """
Look for events that do not have a description, and build the description Look for events that do not have a description, and build the description
from the item that contains it. from the item that contains it.
@ -69,13 +67,11 @@ class EventNames(tool.BatchTool, ManagedWindow):
""" """
def __init__(self, dbstate, user, options_class, name, callback=None): def __init__(self, dbstate, user, options_class, name, callback=None):
uistate = user.uistate self.user = user
tool.BatchTool.__init__(self, dbstate, user, options_class, name) tool.BatchTool.__init__(self, dbstate, user, options_class, name)
if not self.fail: if not self.fail:
uistate.set_busy_cursor(True)
self.run() self.run()
uistate.set_busy_cursor(False)
def run(self): def run(self):
""" """
@ -86,6 +82,9 @@ class EventNames(tool.BatchTool, ManagedWindow):
self.change = False self.change = False
counter = 0 counter = 0
with self.user.progress(
_("Extract Event Description"), '',
2) as step:
for person in self.db.iter_people(): for person in self.db.iter_people():
for event_ref in person.get_event_ref_list(): for event_ref in person.get_event_ref_list():
if event_ref.get_role() == EventRoleType.PRIMARY: if event_ref.get_role() == EventRoleType.PRIMARY:
@ -96,6 +95,7 @@ class EventNames(tool.BatchTool, ManagedWindow):
self.db.commit_event(event, trans) self.db.commit_event(event, trans)
self.change = True self.change = True
counter += 1 counter += 1
step()
for family in self.db.iter_families(): for family in self.db.iter_families():
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
@ -107,16 +107,17 @@ class EventNames(tool.BatchTool, ManagedWindow):
self.db.commit_event(event, trans) self.db.commit_event(event, trans)
self.change = True self.change = True
counter += 1 counter += 1
step()
self.db.enable_signals() self.db.enable_signals()
self.db.request_rebuild() self.db.request_rebuild()
if self.change == True: if self.change == True:
OkDialog(_('Modifications made'), self.user.info(_('Modifications made'),
glocale.translation.ngettext("%s event description has been added", glocale.translation.ngettext("%s event description has been added",
"%s event descriptions have been added", counter) % counter) "%s event descriptions have been added", counter) % counter)
else: else:
OkDialog(_('No modifications made'), self.user.info(_('No modifications made'),
_("No event description has been added.")) _("No event description has been added."))
#------------------------------------------------------------------------- #-------------------------------------------------------------------------

View File

@ -181,7 +181,7 @@ authors_email = ["don@gramps-project.org"],
category = TOOL_DBPROC, category = TOOL_DBPROC,
toolclass = 'EventNames', toolclass = 'EventNames',
optionclass = 'EventNamesOptions', optionclass = 'EventNamesOptions',
tool_modes = [TOOL_MODE_GUI] tool_modes = [TOOL_MODE_GUI, TOOL_MODE_CLI]
) )
#------------------------------------------------------------------------ #------------------------------------------------------------------------