* src/Exporter.py (Exporter): Callback support, busy cursor.

* src/ViewManager.py (ViewManager): Move progress bar handling
into DisplayState.
* src/DisplayState.py (DisplayState): Move progress bar here.
* src/Assistant.py (Assistant.set_busy_cursor): Add method.
* src/plugins/WritePkg.py: Callback support.
* src/GrampsDb/_WriteGedcom.py: Callback support.


svn: r6016
This commit is contained in:
Alex Roitman 2006-03-01 06:16:36 +00:00
parent 1ce3adb293
commit 632ad860df
7 changed files with 85 additions and 26 deletions

View File

@ -1,3 +1,12 @@
2006-02-28 Alex Roitman <shura@gramps-project.org>
* src/Exporter.py (Exporter): Callback support, busy cursor.
* src/ViewManager.py (ViewManager): Move progress bar handling
into DisplayState.
* src/DisplayState.py (DisplayState): Move progress bar here.
* src/Assistant.py (Assistant.set_busy_cursor): Add method.
* src/plugins/WritePkg.py: Callback support.
* src/GrampsDb/_WriteGedcom.py: Callback support.
2006-02-28 Don Allingham <don@gramps-project.org> 2006-02-28 Don Allingham <don@gramps-project.org>
* src/AddrEdit.py: remove already_exist check in favor of exception * src/AddrEdit.py: remove already_exist check in favor of exception
* src/AttrEdit.py: remove already_exist check in favor of exception * src/AttrEdit.py: remove already_exist check in favor of exception

View File

@ -139,6 +139,17 @@ class Assistant(gtk.Object):
self.window.add(vbox) self.window.add(vbox)
def set_busy_cursor(self,value):
if value:
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
self.window.set_sensitive(0)
else:
self.window.window.set_cursor(None)
self.window.set_sensitive(1)
while gtk.events_pending():
gtk.main_iteration()
def do_get_property(self, prop): def do_get_property(self, prop):
"""Return the gproperty's value.""" """Return the gproperty's value."""
raise AttributeError, 'unknown property %s' % prop.name raise AttributeError, 'unknown property %s' % prop.name

View File

@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2005 Donald N. Allingham # Copyright (C) 2000-2006 Donald N. Allingham
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -563,13 +563,14 @@ class DisplayState(GrampsDb.GrampsDBCallback):
__signals__ = { __signals__ = {
} }
def __init__(self,window,status,warnbtn,uimanager,dbstate): def __init__(self,window,status,progress,warnbtn,uimanager,dbstate):
self.dbstate = dbstate self.dbstate = dbstate
self.uimanager = uimanager self.uimanager = uimanager
self.window = window self.window = window
GrampsDb.GrampsDBCallback.__init__(self) GrampsDb.GrampsDBCallback.__init__(self)
self.status = status self.status = status
self.status_id = status.get_context_id('GRAMPS') self.status_id = status.get_context_id('GRAMPS')
self.progress = progress
self.phistory = History() self.phistory = History()
self.gwm = GrampsWindowManager(uimanager) self.gwm = GrampsWindowManager(uimanager)
self.widget = None self.widget = None
@ -618,6 +619,12 @@ class DisplayState(GrampsDb.GrampsDBCallback):
while gtk.events_pending(): while gtk.events_pending():
gtk.main_iteration() gtk.main_iteration()
def pulse_progressbar(self,value):
self.progress.set_fraction(min(value/100.0,1.0))
self.progress.set_text("%d%%" % value)
while gtk.events_pending():
gtk.main_iteration()
def status_text(self,text): def status_text(self,text):
self.status.pop(self.status_id) self.status.pop(self.status_id)
self.status.push(self.status_id,text) self.status.push(self.status_id,text)
@ -633,4 +640,3 @@ if __name__ == "__main__":
log = logging.getLogger() log = logging.getLogger()
log.setLevel(logging.WARN) log.setLevel(logging.WARN)
log.addHandler(rh) log.addHandler(rh)

View File

@ -67,7 +67,7 @@ class Exporter:
name. name.
""" """
def __init__(self,dbstate,uistate,callback=None): def __init__(self,dbstate,uistate):
""" """
Set up the window, the druid, and build all the druid's pages. Set up the window, the druid, and build all the druid's pages.
Some page elements are left empty, since their contents depends Some page elements are left empty, since their contents depends
@ -75,7 +75,7 @@ class Exporter:
""" """
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.callback = callback self.callback = self.uistate.pulse_progressbar
if self.dbstate.active: if self.dbstate.active:
self.person = self.dbstate.active self.person = self.dbstate.active
else: else:
@ -163,6 +163,7 @@ class Exporter:
filename = self.chooser.get_filename() filename = self.chooser.get_filename()
GrampsKeys.save_last_export_dir(os.path.split(filename)[0]) GrampsKeys.save_last_export_dir(os.path.split(filename)[0])
ix = self.get_selected_format_index() ix = self.get_selected_format_index()
self.pre_save()
if self.exports[ix][3]: if self.exports[ix][3]:
success = self.exports[ix][0](self.dbstate.db, success = self.exports[ix][0](self.dbstate.db,
filename,self.person, filename,self.person,
@ -172,8 +173,19 @@ class Exporter:
success = self.exports[ix][0](self.dbstate.db, success = self.exports[ix][0](self.dbstate.db,
filename,self.person, filename,self.person,
self.callback) self.callback)
self.post_save()
return success return success
def pre_save(self):
self.uistate.set_busy_cursor(1)
self.w.set_busy_cursor(1)
self.uistate.progress.show()
def post_save(self):
self.uistate.set_busy_cursor(0)
self.w.set_busy_cursor(0)
self.uistate.progress.hide()
def build_conclusion(self,success): def build_conclusion(self,success):
if success: if success:
conclusion_title = _('Your data has been saved') conclusion_title = _('Your data has been saved')

View File

@ -444,12 +444,18 @@ class GedcomWriterOptionBox:
class GedcomWriter: class GedcomWriter:
def __init__(self,database,person,cl=0,filename="",option_box=None): def __init__(self,database,person,cl=0,filename="",option_box=None,
callback=None):
self.db = database self.db = database
self.person = person self.person = person
self.option_box = option_box self.option_box = option_box
self.cl = cl self.cl = cl
self.filename = filename self.filename = filename
self.callback = callback
if '__call__' in dir(self.callback): # callback is really callable
self.update = self.update_real
else:
self.update = self.update_empty
self.plist = {} self.plist = {}
self.slist = {} self.slist = {}
@ -490,7 +496,8 @@ class GedcomWriter:
self.plist[p] = 1 self.plist[p] = 1
else: else:
try: try:
for p in self.option_box.cfilter.apply(self.db, self.db.get_person_handles(sort_handles=False)): for p in self.option_box.cfilter.apply(self.db,
self.db.get_person_handles(sort_handles=False)):
self.plist[p] = 1 self.plist[p] = 1
except Errors.FilterError, msg: except Errors.FilterError, msg:
(m1,m2) = msg.messages() (m1,m2) = msg.messages()
@ -501,11 +508,23 @@ class GedcomWriter:
self.slist = {} self.slist = {}
for key in self.plist.keys(): for key in self.plist.keys():
p = self.db.get_person_from_handle(key) p = self.db.get_person_from_handle(key)
add_persons_sources(self.db,p,self.slist,self.option_box.private) add_persons_sources(self.db,p,self.slist,
self.option_box.private)
for family_handle in p.get_family_handle_list(): for family_handle in p.get_family_handle_list():
add_familys_sources(self.db,family_handle,self.slist,self.option_box.private) add_familys_sources(self.db,family_handle,
self.slist,self.option_box.private)
self.flist[family_handle] = 1 self.flist[family_handle] = 1
def update_empty(self):
pass
def update_real(self):
self.count += 1
newval = int(100*self.count/self.total)
if newval != self.oldval:
self.callback(newval)
self.oldval = newval
def cl_setup(self): def cl_setup(self):
self.restrict = 0 self.restrict = 0
self.private = 0 self.private = 0
@ -538,7 +557,8 @@ class GedcomWriter:
p = self.db.get_person_from_handle(key) p = self.db.get_person_from_handle(key)
add_persons_sources(self.db,p,self.slist,self.private) add_persons_sources(self.db,p,self.slist,self.private)
for family_handle in p.get_family_handle_list(): for family_handle in p.get_family_handle_list():
add_familys_sources(self.db,family_handle,self.slist,self.private) add_familys_sources(self.db,family_handle,
self.slist,self.private)
self.flist[family_handle] = 1 self.flist[family_handle] = 1
def writeln(self,text): def writeln(self,text):
@ -610,16 +630,20 @@ class GedcomWriter:
self.writeln('2 CONT Not Provided') self.writeln('2 CONT Not Provided')
pkeys = self.plist.keys() pkeys = self.plist.keys()
self.total = len(pkeys) + len(self.flist.keys()) \
+ len(self.slist.keys())
self.oldval = 0
self.count = 0
sorted = [] sorted = []
for key in pkeys: for key in pkeys:
person = self.db.get_person_from_handle (key) person = self.db.get_person_from_handle (key)
data = (person.get_gramps_id (), person) data = (person.get_gramps_id (), person)
sorted.append (data) sorted.append (data)
sorted.sort() sorted.sort()
index = 0.0
for (gramps_id, person) in sorted: for (gramps_id, person) in sorted:
self.write_person(person) self.write_person(person)
index = index + 1 self.update()
self.write_families() self.write_families()
if self.source_refs: if self.source_refs:
@ -744,6 +768,7 @@ class GedcomWriter:
self.write_photo(photo,1) self.write_photo(photo,1)
self.write_change(1,family.get_change_time()) self.write_change(1,family.get_change_time())
self.update()
def write_sources(self): def write_sources(self):
index = 0.0 index = 0.0
@ -776,6 +801,7 @@ class GedcomWriter:
self.write_long_text("NOTE",1,self.cnvtxt(source.get_note())) self.write_long_text("NOTE",1,self.cnvtxt(source.get_note()))
index = index + 1 index = index + 1
self.write_change(1,source.get_change_time()) self.write_change(1,source.get_change_time())
self.update()
def write_person(self,person): def write_person(self,person):
self.writeln("0 @%s@ INDI" % person.get_gramps_id()) self.writeln("0 @%s@ INDI" % person.get_gramps_id())
@ -1321,7 +1347,7 @@ class GedcomWriter:
def exportData(database,filename,person,option_box,callback=None): def exportData(database,filename,person,option_box,callback=None):
ret = 0 ret = 0
try: try:
gw = GedcomWriter(database,person,0,filename,option_box) gw = GedcomWriter(database,person,0,filename,option_box,callback)
ret = gw.export_data(filename) ret = gw.export_data(filename)
except Errors.DatabaseError,msg: except Errors.DatabaseError,msg:
ErrorDialog(_("Export failed"),str(msg)) ErrorDialog(_("Export failed"),str(msg))

View File

@ -223,7 +223,7 @@ class ViewManager:
self.notebook.connect('switch-page',self.change_page) self.notebook.connect('switch-page',self.change_page)
self.uistate = DisplayState.DisplayState(self.window, self.statusbar, self.uistate = DisplayState.DisplayState(self.window, self.statusbar,
self.warnbtn, self.progress, self.warnbtn,
self.uimanager, self.state) self.uimanager, self.state)
toolbar = self.uimanager.get_widget('/ToolBar') toolbar = self.uimanager.get_widget('/ToolBar')
@ -760,7 +760,7 @@ class ViewManager:
def load_database(self,name,callback=None,mode="w"): def load_database(self,name,callback=None,mode="w"):
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
self.progress.show() self.progress.show()
if not self.state.db.load(name,self.pulse_progressbar,mode): if not self.state.db.load(name,self.uistate.pulse_progressbar,mode):
return False return False
self.progress.hide() self.progress.hide()
return self.post_load(name,callback) return self.post_load(name,callback)
@ -856,12 +856,6 @@ class ViewManager:
import ScratchPad import ScratchPad
ScratchPad.ScratchPadWindow(self.state, self) ScratchPad.ScratchPadWindow(self.state, self)
def pulse_progressbar(self,value):
self.progress.set_fraction(min(value/100.0,1.0))
self.progress.set_text("%d%%" % value)
while gtk.events_pending():
gtk.main_iteration()
def undo(self,obj): def undo(self,obj):
self.state.db.undo() self.state.db.undo()
@ -870,7 +864,7 @@ class ViewManager:
def export_data(self,obj): def export_data(self,obj):
import Exporter import Exporter
Exporter.Exporter(self.state,self.uistate,self.pulse_progressbar) Exporter.Exporter(self.state,self.uistate)
def import_data(self,obj): def import_data(self,obj):
choose = gtk.FileChooserDialog(_('GRAMPS: Import database'), choose = gtk.FileChooserDialog(_('GRAMPS: Import database'),
@ -961,7 +955,7 @@ class ViewManager:
dialog.destroy() dialog.destroy()
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
self.progress.show() self.progress.show()
importer(self.state.db,filename,self.pulse_progressbar) importer(self.state.db,filename,self.uistate.pulse_progressbar)
self.uistate.clear_history() self.uistate.clear_history()
self.progress.hide() self.progress.hide()
self.window.window.set_cursor(None) self.window.window.set_cursor(None)

View File

@ -58,7 +58,7 @@ from QuestionDialog import MissingMediaDialog
def writeData(database,filename,person,callback=None): def writeData(database,filename,person,callback=None):
ret = 0 ret = 0
try: try:
writer = PackageWriter(database,filename) writer = PackageWriter(database,filename,callback)
ret = writer.export() ret = writer.export()
except: except:
@ -73,8 +73,9 @@ def writeData(database,filename,person,callback=None):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class PackageWriter: class PackageWriter:
def __init__(self,database,filename): def __init__(self,database,filename,callback):
self.db = database self.db = database
self.callback = callback
if os.path.splitext(filename)[1] != ".gpkg": if os.path.splitext(filename)[1] != ".gpkg":
filename = filename + ".gpkg" filename = filename + ".gpkg"
@ -182,7 +183,7 @@ class PackageWriter:
# Write XML now # Write XML now
g = StringIO() g = StringIO()
gfile = XmlWriter(self.db,None,2) gfile = XmlWriter(self.db,self.callback,2)
gfile.write_handle(g) gfile.write_handle(g)
tarinfo = tarfile.TarInfo('data.gramps') tarinfo = tarfile.TarInfo('data.gramps')
tarinfo.size = len(g.getvalue()) tarinfo.size = len(g.getvalue())