* src/plugins/BookReport.py, src/plugins/FtmStyleDescendants.py,
src/plugins/FtmStyleAncestors.py: Further work on option handling. Start parse/save cycle. svn: r1681
This commit is contained in:
parent
f342e1edea
commit
52e494be76
@ -1,3 +1,8 @@
|
|||||||
|
2003-06-09 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
|
* src/plugins/BookReport.py, src/plugins/FtmStyleDescendants.py,
|
||||||
|
src/plugins/FtmStyleAncestors.py: Further work on option handling.
|
||||||
|
Start parse/save cycle.
|
||||||
|
|
||||||
2003-06-09 Alex Roitman <shura@alex.neuro.umn.edu>
|
2003-06-09 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
* src/ReadXML.py, src/plugins/Check.py, src/plugins/WriteCD.py,
|
* src/ReadXML.py, src/plugins/Check.py, src/plugins/WriteCD.py,
|
||||||
src/plugins/WritePkg.py: Proper use of dialog.run() in file
|
src/plugins/WritePkg.py: Proper use of dialog.run() in file
|
||||||
|
@ -27,6 +27,16 @@
|
|||||||
import os
|
import os
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# SAX interface
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
try:
|
||||||
|
from xml.sax import make_parser,handler,SAXParseException
|
||||||
|
except:
|
||||||
|
from _xmlplus.sax import make_parser,handler,SAXParseException
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# internationalization
|
# internationalization
|
||||||
@ -65,6 +75,7 @@ class BookReportSelector:
|
|||||||
def __init__(self,db,person):
|
def __init__(self,db,person):
|
||||||
self.db = db
|
self.db = db
|
||||||
self.person = person
|
self.person = person
|
||||||
|
self.file = os.path.expanduser("~/.gramps/books.xml")
|
||||||
|
|
||||||
base = os.path.dirname(__file__)
|
base = os.path.dirname(__file__)
|
||||||
glade_file = os.path.join(base,"book.glade")
|
glade_file = os.path.join(base,"book.glade")
|
||||||
@ -72,11 +83,6 @@ class BookReportSelector:
|
|||||||
self.xml = gtk.glade.XML(glade_file,"top")
|
self.xml = gtk.glade.XML(glade_file,"top")
|
||||||
self.top = self.xml.get_widget("top")
|
self.top = self.xml.get_widget("top")
|
||||||
|
|
||||||
if person:
|
|
||||||
self.default_name = person.getPrimaryName().getSurname().upper()
|
|
||||||
else:
|
|
||||||
self.default_name = ""
|
|
||||||
|
|
||||||
self.xml.signal_autoconnect({
|
self.xml.signal_autoconnect({
|
||||||
"on_add_clicked" : self.on_add_clicked,
|
"on_add_clicked" : self.on_add_clicked,
|
||||||
"on_remove_clicked" : self.on_remove_clicked,
|
"on_remove_clicked" : self.on_remove_clicked,
|
||||||
@ -118,6 +124,8 @@ class BookReportSelector:
|
|||||||
self.av_model = ListModel.ListModel(self.avail_tree,av_titles)
|
self.av_model = ListModel.ListModel(self.avail_tree,av_titles)
|
||||||
self.bk_model = ListModel.ListModel(self.book_tree,bk_titles)
|
self.bk_model = ListModel.ListModel(self.book_tree,bk_titles)
|
||||||
self.draw_avail_list()
|
self.draw_avail_list()
|
||||||
|
self.bookmap = {}
|
||||||
|
self.parse()
|
||||||
|
|
||||||
def close(self,obj):
|
def close(self,obj):
|
||||||
self.top.destroy()
|
self.top.destroy()
|
||||||
@ -152,10 +160,6 @@ class BookReportSelector:
|
|||||||
self.bk_model.add(data)
|
self.bk_model.add(data)
|
||||||
for book_item in Plugins._bkitems:
|
for book_item in Plugins._bkitems:
|
||||||
if book_item[0] == data[0]:
|
if book_item[0] == data[0]:
|
||||||
#get_options = book_item[4]
|
|
||||||
#get_style = book_item[5]
|
|
||||||
#store_item = list(book_item)
|
|
||||||
#[ book_item[0], book_item[1], book_item[2], book_item[3], get_options(), get_style() ]
|
|
||||||
self.item_storage[newkey] = list(book_item)
|
self.item_storage[newkey] = list(book_item)
|
||||||
|
|
||||||
def on_remove_clicked(self,obj):
|
def on_remove_clicked(self,obj):
|
||||||
@ -217,8 +221,14 @@ class BookReportSelector:
|
|||||||
self.on_add_clicked(obj)
|
self.on_add_clicked(obj)
|
||||||
|
|
||||||
def on_book_ok_clicked(self,obj):
|
def on_book_ok_clicked(self,obj):
|
||||||
|
item_list = self.build_item_list()
|
||||||
|
if item_list:
|
||||||
|
BookReportDialog(self.db,self.person,item_list)
|
||||||
|
self.top.destroy()
|
||||||
|
|
||||||
|
def build_item_list(self):
|
||||||
|
item_list = []
|
||||||
if self.bk_model.count:
|
if self.bk_model.count:
|
||||||
item_list = []
|
|
||||||
for row in range(self.bk_model.count):
|
for row in range(self.bk_model.count):
|
||||||
self.bk_model.select_row(row)
|
self.bk_model.select_row(row)
|
||||||
store,iter = self.bk_model.get_selected()
|
store,iter = self.bk_model.get_selected()
|
||||||
@ -226,15 +236,120 @@ class BookReportSelector:
|
|||||||
key = data[self.bk_ncols-1]
|
key = data[self.bk_ncols-1]
|
||||||
book_item = self.item_storage[key]
|
book_item = self.item_storage[key]
|
||||||
item_list.append(book_item)
|
item_list.append(book_item)
|
||||||
BookReportDialog(self.db,self.person,item_list)
|
return item_list
|
||||||
self.top.destroy()
|
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
"""
|
||||||
|
Saves the current BookReportSelector selections to the associated file.
|
||||||
|
"""
|
||||||
|
f = open(self.file,"w")
|
||||||
|
f.write("<?xml version=\"1.0\"?>\n")
|
||||||
|
f.write('<booklist>\n')
|
||||||
|
|
||||||
|
# Write old entries first
|
||||||
|
for name in self.bookmap.keys():
|
||||||
|
f.write('<book name="%s" database="%s">\n' %
|
||||||
|
(name,self.db.getSavePath()))
|
||||||
|
item_list = self.bookmap[name]
|
||||||
|
for book_item in item_list:
|
||||||
|
f.write(' <item name="%s">\n' % book_item[0])
|
||||||
|
options = book_item[4]
|
||||||
|
for opt_index in range(len(options)):
|
||||||
|
f.write(' <option number="%d" value="%s"/>\n' % (
|
||||||
|
opt_index,options[opt_index]) )
|
||||||
|
f.write(' <style name="%s"/>\n' % book_item[5] )
|
||||||
|
f.write(' </item>\n')
|
||||||
|
f.write('</book>\n')
|
||||||
|
|
||||||
|
item_list = self.build_item_list()
|
||||||
|
if not item_list:
|
||||||
|
f.write('</booklist>\n')
|
||||||
|
f.close()
|
||||||
|
return
|
||||||
|
|
||||||
|
# Write current book now
|
||||||
|
f.write('<book name="New Book" database="%s">\n' % self.db.getSavePath())
|
||||||
|
for book_item in item_list:
|
||||||
|
f.write(' <item name="%s">\n' % book_item[0])
|
||||||
|
options = book_item[4]
|
||||||
|
for opt_index in range(len(options)):
|
||||||
|
f.write(' <option number="%d" value="%s"/>\n' % (
|
||||||
|
opt_index,options[opt_index]) )
|
||||||
|
f.write(' <style name="%s"/>\n' % book_item[5].get_name() )
|
||||||
|
f.write(' </item>\n')
|
||||||
|
f.write('</book>\n')
|
||||||
|
|
||||||
|
f.write('</booklist>\n')
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def parse(self):
|
||||||
|
"""
|
||||||
|
Loads the BookReportSelector selections from the associated file,
|
||||||
|
if it exists.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
p = make_parser()
|
||||||
|
p.setContentHandler(BookParser(self.bookmap))
|
||||||
|
p.parse('file://' + self.file)
|
||||||
|
except (IOError,OSError,SAXParseException):
|
||||||
|
pass
|
||||||
|
|
||||||
def on_save_clicked(self,obj):
|
def on_save_clicked(self,obj):
|
||||||
pass
|
self.save()
|
||||||
|
|
||||||
def on_open_clicked(self,obj):
|
def on_open_clicked(self,obj):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# BookParser
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
class BookParser(handler.ContentHandler):
|
||||||
|
"""
|
||||||
|
SAX parsing class for the Books XML file.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self,bookmap):
|
||||||
|
"""
|
||||||
|
Creates a BookParser class that populates the passed bookmap.
|
||||||
|
|
||||||
|
bookmap - BookList to be loaded from the file.
|
||||||
|
"""
|
||||||
|
handler.ContentHandler.__init__(self)
|
||||||
|
self.bookmap = bookmap
|
||||||
|
self.b = None
|
||||||
|
self.i = None
|
||||||
|
self.o = None
|
||||||
|
self.s = None
|
||||||
|
self.bname = None
|
||||||
|
self.iname = None
|
||||||
|
|
||||||
|
def startElement(self,tag,attrs):
|
||||||
|
"""
|
||||||
|
Overridden class that handles the start of a XML element
|
||||||
|
"""
|
||||||
|
if tag == "book":
|
||||||
|
self.bname = attrs['name']
|
||||||
|
self.b = []
|
||||||
|
elif tag == "item":
|
||||||
|
self.iname = attrs['name']
|
||||||
|
self.o = []
|
||||||
|
elif tag == "option":
|
||||||
|
self.o.append(attrs['value'])
|
||||||
|
elif tag == "style":
|
||||||
|
self.s = attrs['name']
|
||||||
|
|
||||||
|
def endElement(self,tag):
|
||||||
|
"Overridden class that handles the start of a XML element"
|
||||||
|
if tag == "item":
|
||||||
|
self.i = [ self.iname, None, None, None, self.o, self.s ]
|
||||||
|
self.b.append(self.i)
|
||||||
|
elif tag == "book":
|
||||||
|
self.bookmap[self.bname] = self.b
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# The final dialog - paper, format, target, etc.
|
# The final dialog - paper, format, target, etc.
|
||||||
|
@ -852,8 +852,9 @@ class FtmAncestorBareReportDialog(Report.BareReportDialog):
|
|||||||
def __init__(self,database,person,opt,stl):
|
def __init__(self,database,person,opt,stl):
|
||||||
|
|
||||||
self.options = opt
|
self.options = opt
|
||||||
|
self.db = database
|
||||||
if self.options[0]:
|
if self.options[0]:
|
||||||
self.person = self.options[0]
|
self.person = self.db.getPerson(self.options[0])
|
||||||
else:
|
else:
|
||||||
self.person = person
|
self.person = person
|
||||||
Report.BareReportDialog.__init__(self,database,self.person)
|
Report.BareReportDialog.__init__(self,database,self.person)
|
||||||
@ -899,8 +900,9 @@ class FtmAncestorBareReportDialog(Report.BareReportDialog):
|
|||||||
self.parse_style_frame()
|
self.parse_style_frame()
|
||||||
self.parse_report_options_frame()
|
self.parse_report_options_frame()
|
||||||
|
|
||||||
self.person = self.new_person
|
if self.new_person:
|
||||||
self.options = [ self.person, self.max_gen, self.pg_brk ]
|
self.person = self.new_person
|
||||||
|
self.options = [ self.person.getId(), self.max_gen, self.pg_brk ]
|
||||||
self.style = self.selected_style
|
self.style = self.selected_style
|
||||||
|
|
||||||
|
|
||||||
@ -914,7 +916,7 @@ def write_book_item(database,person,doc,options,newpage=0):
|
|||||||
All user dialog has already been handled and the output file opened."""
|
All user dialog has already been handled and the output file opened."""
|
||||||
try:
|
try:
|
||||||
if options[0]:
|
if options[0]:
|
||||||
person = options[0]
|
person = database.getPerson(options[0])
|
||||||
max_gen = options[1]
|
max_gen = options[1]
|
||||||
pg_brk = options[2]
|
pg_brk = options[2]
|
||||||
MyReport = FtmAncestorReport(database, person,
|
MyReport = FtmAncestorReport(database, person,
|
||||||
|
@ -1260,8 +1260,9 @@ class FtmDescendantBareReportDialog(Report.BareReportDialog):
|
|||||||
def __init__(self,database,person,opt,stl):
|
def __init__(self,database,person,opt,stl):
|
||||||
|
|
||||||
self.options = opt
|
self.options = opt
|
||||||
|
self.db = database
|
||||||
if self.options[0]:
|
if self.options[0]:
|
||||||
self.person = self.options[0]
|
self.person = self.db.getPerson(self.options[0])
|
||||||
else:
|
else:
|
||||||
self.person = person
|
self.person = person
|
||||||
Report.BareReportDialog.__init__(self,database,self.person)
|
Report.BareReportDialog.__init__(self,database,self.person)
|
||||||
@ -1307,8 +1308,9 @@ class FtmDescendantBareReportDialog(Report.BareReportDialog):
|
|||||||
self.parse_style_frame()
|
self.parse_style_frame()
|
||||||
self.parse_report_options_frame()
|
self.parse_report_options_frame()
|
||||||
|
|
||||||
self.person = self.new_person
|
if self.new_person:
|
||||||
self.options = [ self.person, self.max_gen, self.pg_brk ]
|
self.person = self.new_person
|
||||||
|
self.options = [ self.person.getId(), self.max_gen, self.pg_brk ]
|
||||||
self.style = self.selected_style
|
self.style = self.selected_style
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
@ -1321,9 +1323,9 @@ def write_book_item(database,person,doc,options,newpage=0):
|
|||||||
All user dialog has already been handled and the output file opened."""
|
All user dialog has already been handled and the output file opened."""
|
||||||
try:
|
try:
|
||||||
if options[0]:
|
if options[0]:
|
||||||
person = options[0]
|
person = database.getPerson(options[0])
|
||||||
max_gen = options[1]
|
max_gen = int(options[1])
|
||||||
pg_brk = options[2]
|
pg_brk = int(options[2])
|
||||||
MyReport = FtmDescendantReport(database, person,
|
MyReport = FtmDescendantReport(database, person,
|
||||||
max_gen, pg_brk, doc, None, newpage )
|
max_gen, pg_brk, doc, None, newpage )
|
||||||
MyReport.write_report()
|
MyReport.write_report()
|
||||||
|
Loading…
Reference in New Issue
Block a user