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,37 +82,42 @@ class EventNames(tool.BatchTool, ManagedWindow):
self.change = False self.change = False
counter = 0 counter = 0
for person in self.db.iter_people(): with self.user.progress(
for event_ref in person.get_event_ref_list(): _("Extract Event Description"), '',
if event_ref.get_role() == EventRoleType.PRIMARY: 2) as step:
event_handle = event_ref.ref for person in self.db.iter_people():
event = self.db.get_event_from_handle(event_handle) for event_ref in person.get_event_ref_list():
if event.get_description() == "": if event_ref.get_role() == EventRoleType.PRIMARY:
person_event_name(event, person) event_handle = event_ref.ref
self.db.commit_event(event, trans) event = self.db.get_event_from_handle(event_handle)
self.change = True if event.get_description() == "":
counter += 1 person_event_name(event, person)
self.db.commit_event(event, trans)
self.change = True
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():
if event_ref.get_role() == EventRoleType.FAMILY: if event_ref.get_role() == EventRoleType.FAMILY:
event_handle = event_ref.ref event_handle = event_ref.ref
event = self.db.get_event_from_handle(event_handle) event = self.db.get_event_from_handle(event_handle)
if event.get_description() == "": if event.get_description() == "":
family_event_name(event, family, self.db) family_event_name(event, family, self.db)
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]
) )
#------------------------------------------------------------------------ #------------------------------------------------------------------------