5098: refactor to use user.info and user.progress

svn: r23100
This commit is contained in:
Vassilii Khachaturov 2013-09-12 21:21:53 +00:00
parent 85c1a9a0fd
commit 4ff73e9d8a

View File

@ -56,6 +56,7 @@ class ChangeTypes(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 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 self.fail: if self.fail:
@ -67,7 +68,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow):
self.__class__) self.__class__)
self.init_gui() self.init_gui()
else: else:
self.run_tool(cli=True) self.run_tool()
def init_gui(self): def init_gui(self):
# Draw dialog and make it handle everything # Draw dialog and make it handle everything
@ -104,7 +105,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow):
def build_menu_names(self, obj): def build_menu_names(self, obj):
return (self.title,None) return (self.title,None)
def run_tool(self,cli=False): def run_tool(self, parent_window = None):
# Run tool and return results # Run tool and return results
# These are English names, no conversion needed # These are English names, no conversion needed
fromtype = self.options.handler.options_dict['fromtype'] fromtype = self.options.handler.options_dict['fromtype']
@ -114,20 +115,16 @@ class ChangeTypes(tool.BatchTool, ManagedWindow):
with DbTxn(_('Change types'), self.db, batch=True) as self.trans: with DbTxn(_('Change types'), self.db, batch=True) as self.trans:
self.db.disable_signals() self.db.disable_signals()
if not cli: with self.user.progress(
progress = ProgressMeter(_('Analyzing Events'),'') _('Analyzing Events'), '',
progress.set_pass('',self.db.get_number_of_events()) self.db.get_number_of_events()) as step:
for event_handle in self.db.get_event_handles():
for event_handle in self.db.get_event_handles(): event = self.db.get_event_from_handle(event_handle)
event = self.db.get_event_from_handle(event_handle) if event.get_type().xml_str() == fromtype:
if event.get_type().xml_str() == fromtype: event.type.set_from_xml_str(totype)
event.type.set_from_xml_str(totype) modified += 1
modified += 1 self.db.commit_event(event,self.trans)
self.db.commit_event(event,self.trans) step()
if not cli:
progress.step()
if not cli:
progress.close()
self.db.enable_signals() self.db.enable_signals()
self.db.request_rebuild() self.db.request_rebuild()
@ -137,8 +134,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow):
msg = glocale.translation.ngettext("%d event record was modified." msg = glocale.translation.ngettext("%d event record was modified."
, "%d event records were modified.", modified) % modified , "%d event records were modified.", modified) % modified
if cli: self.user.info(_('Change types'), msg, parent_window)
print("Done: ", msg)
return (bool(modified),msg) return (bool(modified),msg)
def on_apply_clicked(self, obj): def on_apply_clicked(self, obj):
@ -151,8 +147,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow):
the_type.set(self.auto2.get_child().get_text()) the_type.set(self.auto2.get_child().get_text())
self.options.handler.options_dict['totype'] = the_type.xml_str() self.options.handler.options_dict['totype'] = the_type.xml_str()
modified,msg = self.run_tool(cli=False) self.run_tool(self.window)
OkDialog(_('Change types'), msg, self.window)
# Save options # Save options
self.options.handler.save_options() self.options.handler.save_options()