* src/plugins/ExportVCard.py: Bring to new API.
* src/plugins/ExportVCalendar.py: Bring to new API. svn: r6596
This commit is contained in:
parent
424c170b37
commit
cd6e3a59a6
@ -1,4 +1,6 @@
|
|||||||
2006-05-09 Alex Roitman <shura@gramps-project.org>
|
2006-05-09 Alex Roitman <shura@gramps-project.org>
|
||||||
|
* src/plugins/ExportVCard.py: Bring to new API.
|
||||||
|
* src/plugins/ExportVCalendar.py: Bring to new API.
|
||||||
* src/plugins/WriteFtree.py: Bring to new API.
|
* src/plugins/WriteFtree.py: Bring to new API.
|
||||||
* src/Filters/_FilterMenu.py (build_filter_menu): Return the menu.
|
* src/Filters/_FilterMenu.py (build_filter_menu): Return the menu.
|
||||||
* src/plugins/WriteGeneWeb.py: Bring to new API.
|
* src/plugins/WriteGeneWeb.py: Bring to new API.
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import os
|
import os
|
||||||
from time import localtime
|
from time import localtime
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -54,9 +55,8 @@ log = logging.getLogger(".ExportVCal")
|
|||||||
from Filters import GenericFilter, Rules, build_filter_menu
|
from Filters import GenericFilter, Rules, build_filter_menu
|
||||||
import const
|
import const
|
||||||
import Utils
|
import Utils
|
||||||
from RelLib import Date
|
from RelLib import Date, EventType
|
||||||
import Errors
|
import Errors
|
||||||
from gettext import gettext as _
|
|
||||||
from QuestionDialog import ErrorDialog
|
from QuestionDialog import ErrorDialog
|
||||||
from PluginUtils import register_export
|
from PluginUtils import register_export
|
||||||
|
|
||||||
@ -124,12 +124,18 @@ class CalendarWriterOptionBox:
|
|||||||
|
|
||||||
|
|
||||||
class CalendarWriter:
|
class CalendarWriter:
|
||||||
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.flist = {}
|
self.flist = {}
|
||||||
@ -161,6 +167,16 @@ class CalendarWriter:
|
|||||||
for family_handle in p.get_family_handle_list():
|
for family_handle in p.get_family_handle_list():
|
||||||
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):
|
||||||
for p in self.db.get_person_handles(sort_handles=False):
|
for p in self.db.get_person_handles(sort_handles=False):
|
||||||
self.plist[p] = 1
|
self.plist[p] = 1
|
||||||
@ -191,11 +207,17 @@ class CalendarWriter:
|
|||||||
self.writeln("BEGIN:VCALENDAR");
|
self.writeln("BEGIN:VCALENDAR");
|
||||||
self.writeln("PRODID:-//GNU//Gramps//EN");
|
self.writeln("PRODID:-//GNU//Gramps//EN");
|
||||||
self.writeln("VERSION:1.0");
|
self.writeln("VERSION:1.0");
|
||||||
|
|
||||||
|
self.count = 0
|
||||||
|
self.oldval = 0
|
||||||
|
self.total = len(self.plist) + len(self.flist)
|
||||||
for key in self.plist:
|
for key in self.plist:
|
||||||
self.write_person(key)
|
self.write_person(key)
|
||||||
|
self.update()
|
||||||
|
|
||||||
for key in self.flist:
|
for key in self.flist:
|
||||||
self.write_family(key)
|
self.write_family(key)
|
||||||
|
self.update()
|
||||||
|
|
||||||
self.writeln("");
|
self.writeln("");
|
||||||
self.writeln("END:VCALENDAR");
|
self.writeln("END:VCALENDAR");
|
||||||
@ -208,7 +230,7 @@ class CalendarWriter:
|
|||||||
if family:
|
if family:
|
||||||
for event_ref in family.get_event_ref_list():
|
for event_ref in family.get_event_ref_list():
|
||||||
event = self.db.get_event_from_handle(event_ref.ref)
|
event = self.db.get_event_from_handle(event_ref.ref)
|
||||||
if int(event.get_type()) == RelLib.EventType.MARRIAGE:
|
if event.get_type() == EventType.MARRIAGE:
|
||||||
m_date = event.get_date_object()
|
m_date = event.get_date_object()
|
||||||
place_handle = event.get_place_handle()
|
place_handle = event.get_place_handle()
|
||||||
text = _("Marriage of %s") % Utils.family_name(family,self.db)
|
text = _("Marriage of %s") % Utils.family_name(family,self.db)
|
||||||
@ -308,9 +330,9 @@ class CalendarWriter:
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def exportData(database,filename,person,option_box):
|
def exportData(database,filename,person,option_box,callback=None):
|
||||||
ret = 0
|
ret = 0
|
||||||
cw = CalendarWriter(database,person,0,filename,option_box)
|
cw = CalendarWriter(database,person,0,filename,option_box,callback)
|
||||||
ret = cw.export_data(filename)
|
ret = cw.export_data(filename)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import os
|
import os
|
||||||
|
from gettext import gettext as _
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -54,7 +55,6 @@ from Filters import GenericFilter, Rules, build_filter_menu
|
|||||||
import const
|
import const
|
||||||
from RelLib import Date
|
from RelLib import Date
|
||||||
import Errors
|
import Errors
|
||||||
from gettext import gettext as _
|
|
||||||
from QuestionDialog import ErrorDialog
|
from QuestionDialog import ErrorDialog
|
||||||
from PluginUtils import register_export
|
from PluginUtils import register_export
|
||||||
|
|
||||||
@ -121,12 +121,18 @@ class CardWriterOptionBox:
|
|||||||
self.cfilter = self.filter_menu.get_active().get_data("filter")
|
self.cfilter = self.filter_menu.get_active().get_data("filter")
|
||||||
|
|
||||||
class CardWriter:
|
class CardWriter:
|
||||||
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 = {}
|
||||||
|
|
||||||
@ -147,6 +153,15 @@ class CardWriter:
|
|||||||
ErrorDialog(m1,m2)
|
ErrorDialog(m1,m2)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
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):
|
||||||
for p in self.db.get_person_handles(sort_handles=False):
|
for p in self.db.get_person_handles(sort_handles=False):
|
||||||
@ -168,13 +183,16 @@ class CardWriter:
|
|||||||
ErrorDialog(_("Could not create %s") % filename)
|
ErrorDialog(_("Could not create %s") % filename)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
self.count = 0
|
||||||
|
self.oldval = 0
|
||||||
|
self.total = len(self.plist)
|
||||||
for key in self.plist:
|
for key in self.plist:
|
||||||
self.write_person(key)
|
self.write_person(key)
|
||||||
|
self.update()
|
||||||
|
|
||||||
self.g.close()
|
self.g.close()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def write_person(self, person_handle):
|
def write_person(self, person_handle):
|
||||||
person = self.db.get_person_from_handle(person_handle)
|
person = self.db.get_person_from_handle(person_handle)
|
||||||
if person:
|
if person:
|
||||||
@ -227,9 +245,9 @@ class CardWriter:
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def exportData(database,filename,person,option_box):
|
def exportData(database,filename,person,option_box,callback=None):
|
||||||
ret = 0
|
ret = 0
|
||||||
cw = CardWriter(database,person,0,filename,option_box)
|
cw = CardWriter(database,person,0,filename,option_box,callback)
|
||||||
ret = cw.export_data(filename)
|
ret = cw.export_data(filename)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user