* 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:
parent
1ce3adb293
commit
632ad860df
@ -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>
|
||||
* src/AddrEdit.py: remove already_exist check in favor of exception
|
||||
* src/AttrEdit.py: remove already_exist check in favor of exception
|
||||
|
@ -139,6 +139,17 @@ class Assistant(gtk.Object):
|
||||
|
||||
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):
|
||||
"""Return the gproperty's value."""
|
||||
raise AttributeError, 'unknown property %s' % prop.name
|
||||
|
@ -1,7 +1,7 @@
|
||||
#
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -563,13 +563,14 @@ class DisplayState(GrampsDb.GrampsDBCallback):
|
||||
__signals__ = {
|
||||
}
|
||||
|
||||
def __init__(self,window,status,warnbtn,uimanager,dbstate):
|
||||
def __init__(self,window,status,progress,warnbtn,uimanager,dbstate):
|
||||
self.dbstate = dbstate
|
||||
self.uimanager = uimanager
|
||||
self.window = window
|
||||
GrampsDb.GrampsDBCallback.__init__(self)
|
||||
self.status = status
|
||||
self.status_id = status.get_context_id('GRAMPS')
|
||||
self.progress = progress
|
||||
self.phistory = History()
|
||||
self.gwm = GrampsWindowManager(uimanager)
|
||||
self.widget = None
|
||||
@ -618,6 +619,12 @@ class DisplayState(GrampsDb.GrampsDBCallback):
|
||||
while gtk.events_pending():
|
||||
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):
|
||||
self.status.pop(self.status_id)
|
||||
self.status.push(self.status_id,text)
|
||||
@ -633,4 +640,3 @@ if __name__ == "__main__":
|
||||
log = logging.getLogger()
|
||||
log.setLevel(logging.WARN)
|
||||
log.addHandler(rh)
|
||||
|
||||
|
@ -67,7 +67,7 @@ class Exporter:
|
||||
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.
|
||||
Some page elements are left empty, since their contents depends
|
||||
@ -75,7 +75,7 @@ class Exporter:
|
||||
"""
|
||||
self.dbstate = dbstate
|
||||
self.uistate = uistate
|
||||
self.callback = callback
|
||||
self.callback = self.uistate.pulse_progressbar
|
||||
if self.dbstate.active:
|
||||
self.person = self.dbstate.active
|
||||
else:
|
||||
@ -163,6 +163,7 @@ class Exporter:
|
||||
filename = self.chooser.get_filename()
|
||||
GrampsKeys.save_last_export_dir(os.path.split(filename)[0])
|
||||
ix = self.get_selected_format_index()
|
||||
self.pre_save()
|
||||
if self.exports[ix][3]:
|
||||
success = self.exports[ix][0](self.dbstate.db,
|
||||
filename,self.person,
|
||||
@ -172,8 +173,19 @@ class Exporter:
|
||||
success = self.exports[ix][0](self.dbstate.db,
|
||||
filename,self.person,
|
||||
self.callback)
|
||||
self.post_save()
|
||||
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):
|
||||
if success:
|
||||
conclusion_title = _('Your data has been saved')
|
||||
|
@ -444,12 +444,18 @@ class GedcomWriterOptionBox:
|
||||
|
||||
|
||||
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.person = person
|
||||
self.option_box = option_box
|
||||
self.cl = cl
|
||||
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.slist = {}
|
||||
@ -490,7 +496,8 @@ class GedcomWriter:
|
||||
self.plist[p] = 1
|
||||
else:
|
||||
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
|
||||
except Errors.FilterError, msg:
|
||||
(m1,m2) = msg.messages()
|
||||
@ -501,11 +508,23 @@ class GedcomWriter:
|
||||
self.slist = {}
|
||||
for key in self.plist.keys():
|
||||
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():
|
||||
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
|
||||
|
||||
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):
|
||||
self.restrict = 0
|
||||
self.private = 0
|
||||
@ -538,7 +557,8 @@ class GedcomWriter:
|
||||
p = self.db.get_person_from_handle(key)
|
||||
add_persons_sources(self.db,p,self.slist,self.private)
|
||||
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
|
||||
|
||||
def writeln(self,text):
|
||||
@ -610,16 +630,20 @@ class GedcomWriter:
|
||||
self.writeln('2 CONT Not Provided')
|
||||
|
||||
pkeys = self.plist.keys()
|
||||
self.total = len(pkeys) + len(self.flist.keys()) \
|
||||
+ len(self.slist.keys())
|
||||
self.oldval = 0
|
||||
self.count = 0
|
||||
|
||||
sorted = []
|
||||
for key in pkeys:
|
||||
person = self.db.get_person_from_handle (key)
|
||||
data = (person.get_gramps_id (), person)
|
||||
sorted.append (data)
|
||||
sorted.sort()
|
||||
index = 0.0
|
||||
for (gramps_id, person) in sorted:
|
||||
self.write_person(person)
|
||||
index = index + 1
|
||||
self.update()
|
||||
|
||||
self.write_families()
|
||||
if self.source_refs:
|
||||
@ -744,6 +768,7 @@ class GedcomWriter:
|
||||
self.write_photo(photo,1)
|
||||
|
||||
self.write_change(1,family.get_change_time())
|
||||
self.update()
|
||||
|
||||
def write_sources(self):
|
||||
index = 0.0
|
||||
@ -776,6 +801,7 @@ class GedcomWriter:
|
||||
self.write_long_text("NOTE",1,self.cnvtxt(source.get_note()))
|
||||
index = index + 1
|
||||
self.write_change(1,source.get_change_time())
|
||||
self.update()
|
||||
|
||||
def write_person(self,person):
|
||||
self.writeln("0 @%s@ INDI" % person.get_gramps_id())
|
||||
@ -1321,7 +1347,7 @@ class GedcomWriter:
|
||||
def exportData(database,filename,person,option_box,callback=None):
|
||||
ret = 0
|
||||
try:
|
||||
gw = GedcomWriter(database,person,0,filename,option_box)
|
||||
gw = GedcomWriter(database,person,0,filename,option_box,callback)
|
||||
ret = gw.export_data(filename)
|
||||
except Errors.DatabaseError,msg:
|
||||
ErrorDialog(_("Export failed"),str(msg))
|
||||
|
@ -223,7 +223,7 @@ class ViewManager:
|
||||
|
||||
self.notebook.connect('switch-page',self.change_page)
|
||||
self.uistate = DisplayState.DisplayState(self.window, self.statusbar,
|
||||
self.warnbtn,
|
||||
self.progress, self.warnbtn,
|
||||
self.uimanager, self.state)
|
||||
|
||||
toolbar = self.uimanager.get_widget('/ToolBar')
|
||||
@ -760,7 +760,7 @@ class ViewManager:
|
||||
def load_database(self,name,callback=None,mode="w"):
|
||||
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
||||
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
|
||||
self.progress.hide()
|
||||
return self.post_load(name,callback)
|
||||
@ -856,12 +856,6 @@ class ViewManager:
|
||||
import ScratchPad
|
||||
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):
|
||||
self.state.db.undo()
|
||||
|
||||
@ -870,7 +864,7 @@ class ViewManager:
|
||||
|
||||
def export_data(self,obj):
|
||||
import Exporter
|
||||
Exporter.Exporter(self.state,self.uistate,self.pulse_progressbar)
|
||||
Exporter.Exporter(self.state,self.uistate)
|
||||
|
||||
def import_data(self,obj):
|
||||
choose = gtk.FileChooserDialog(_('GRAMPS: Import database'),
|
||||
@ -961,7 +955,7 @@ class ViewManager:
|
||||
dialog.destroy()
|
||||
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
||||
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.progress.hide()
|
||||
self.window.window.set_cursor(None)
|
||||
|
@ -58,7 +58,7 @@ from QuestionDialog import MissingMediaDialog
|
||||
def writeData(database,filename,person,callback=None):
|
||||
ret = 0
|
||||
try:
|
||||
writer = PackageWriter(database,filename)
|
||||
writer = PackageWriter(database,filename,callback)
|
||||
ret = writer.export()
|
||||
|
||||
except:
|
||||
@ -73,8 +73,9 @@ def writeData(database,filename,person,callback=None):
|
||||
#-------------------------------------------------------------------------
|
||||
class PackageWriter:
|
||||
|
||||
def __init__(self,database,filename):
|
||||
def __init__(self,database,filename,callback):
|
||||
self.db = database
|
||||
self.callback = callback
|
||||
|
||||
if os.path.splitext(filename)[1] != ".gpkg":
|
||||
filename = filename + ".gpkg"
|
||||
@ -182,7 +183,7 @@ class PackageWriter:
|
||||
|
||||
# Write XML now
|
||||
g = StringIO()
|
||||
gfile = XmlWriter(self.db,None,2)
|
||||
gfile = XmlWriter(self.db,self.callback,2)
|
||||
gfile.write_handle(g)
|
||||
tarinfo = tarfile.TarInfo('data.gramps')
|
||||
tarinfo.size = len(g.getvalue())
|
||||
|
Loading…
Reference in New Issue
Block a user