svn: r6291
This commit is contained in:
Don Allingham 2006-04-08 00:53:44 +00:00
parent c475f4f2b8
commit 3e1de4dcc6
3 changed files with 218 additions and 183 deletions

View File

@ -58,7 +58,7 @@ interfaces should be derived from the core classes.
""" """
__author__ = "Donald N. Allingham" __author__ = "Donald N. Allingham"
__version__ = "Revision:$Id$" __revision__ = "Revision:$Id$"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -101,33 +101,41 @@ except:
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
FONT_SANS_SERIF = 0 FONT_SANS_SERIF = 0
FONT_SERIF = 1 FONT_SERIF = 1
FONT_MONOSPACE = 2 FONT_MONOSPACE = 2
#-------------------------------------------------------------------------
# #
# Page orientation # Page orientation
# #
#-------------------------------------------------------------------------
PAPER_PORTRAIT = 0 PAPER_PORTRAIT = 0
PAPER_LANDSCAPE = 1 PAPER_LANDSCAPE = 1
#-------------------------------------------------------------------------
# #
# Paragraph alignment # Paragraph alignment
# #
PARA_ALIGN_CENTER = 0 #-------------------------------------------------------------------------
PARA_ALIGN_LEFT = 1 PARA_ALIGN_CENTER = 0
PARA_ALIGN_RIGHT = 2 PARA_ALIGN_LEFT = 1
PARA_ALIGN_JUSTIFY= 3 PARA_ALIGN_RIGHT = 2
PARA_ALIGN_JUSTIFY = 3
#-------------------------------------------------------------------------
# #
# Text vs. Graphics mode # Text vs. Graphics mode
# #
TEXT_MODE = 0 #-------------------------------------------------------------------------
TEXT_MODE = 0
GRAPHICS_MODE = 1 GRAPHICS_MODE = 1
#-------------------------------------------------------------------------
# #
# Line style # Line style
# #
SOLID = 0 #-------------------------------------------------------------------------
SOLID = 0
DASHED = 1 DASHED = 1
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@ -140,10 +148,7 @@ def cnv2color(text):
converts a hex value in the form of #XXXXXX into a tuple of integers converts a hex value in the form of #XXXXXX into a tuple of integers
representing the RGB values representing the RGB values
""" """
c0 = int(text[1:3], 16) return (int(text[1:3], 16), int(text[3:5], 16), int(text[5:7], 16))
c1 = int(text[3:5], 16)
c2 = int(text[5:7], 16)
return (c0, c1, c2)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -548,13 +553,19 @@ class ParagraphStyle:
self.right_border = 0 self.right_border = 0
self.left_border = 0 self.left_border = 0
self.pad = 0 self.pad = 0
self.bgcolor = (255,255,255) self.bgcolor = (255, 255, 255)
self.description = "" self.description = ""
def set_description(self, text): def set_description(self, text):
"""
Sets the desciption of the paragraph
"""
self.description = text self.description = text
def get_description(self): def get_description(self):
"""
Returns the desciption of the paragraph
"""
return self.description return self.description
def set(self, rmargin=None, lmargin=None, first_indent=None, def set(self, rmargin=None, lmargin=None, first_indent=None,
@ -681,7 +692,7 @@ class ParagraphStyle:
"Returns 1 if a left border is specified" "Returns 1 if a left border is specified"
return self.left_border return self.left_border
def set_right_border(self ,val): def set_right_border(self, val):
""" """
Sets the presence or absence of rigth border. Sets the presence or absence of rigth border.
@ -800,7 +811,7 @@ class StyleSheetList:
""" """
defstyle.set_name('default') defstyle.set_name('default')
self.map = { "default" : defstyle } self.map = { "default" : defstyle }
self.file = os.path.join(const.home_dir,filename) self.file = os.path.join(const.home_dir, filename)
self.parse() self.parse()
def delete_style_sheet(self, name): def delete_style_sheet(self, name):
@ -846,48 +857,49 @@ class StyleSheetList:
""" """
Saves the current StyleSheet definitions to the associated file. Saves the current StyleSheet definitions to the associated file.
""" """
f = open(self.file,"w") xml_file = open(self.file,"w")
f.write("<?xml version=\"1.0\"?>\n") xml_file.write("<?xml version=\"1.0\"?>\n")
f.write('<stylelist>\n') xml_file.write('<stylelist>\n')
for name in self.map.keys(): for name in self.map.keys():
if name == "default": if name == "default":
continue continue
sheet = self.map[name] sheet = self.map[name]
f.write('<sheet name="%s">\n' % name) xml_file.write('<sheet name="%s">\n' % name)
for p_name in sheet.get_names(): for p_name in sheet.get_names():
p = sheet.get_style(p_name) para = sheet.get_style(p_name)
f.write('<style name="%s">\n' % p_name) xml_file.write('<style name="%s">\n' % p_name)
font = p.get_font() font = para.get_font()
f.write('<font face="%d" ' % font.get_type_face()) xml_file.write('<font face="%d" ' % font.get_type_face())
f.write('size="%d" ' % font.get_size()) xml_file.write('size="%d" ' % font.get_size())
f.write('italic="%d" ' % font.get_italic()) xml_file.write('italic="%d" ' % font.get_italic())
f.write('bold="%d" ' % font.get_bold()) xml_file.write('bold="%d" ' % font.get_bold())
f.write('underline="%d" ' % font.get_underline()) xml_file.write('underline="%d" ' % font.get_underline())
f.write('color="#%02x%02x%02x"/>\n' % font.get_color()) xml_file.write('color="#%02x%02x%02x"/>\n' % font.get_color())
f.write('<para ') xml_file.write('<para ')
rm = float(p.get_right_margin()) rmargin = float(para.get_right_margin())
lm = float(p.get_left_margin()) lmargin = float(para.get_left_margin())
fi = float(p.get_first_indent()) findent = float(para.get_first_indent())
tm = float(p.get_top_margin()) tmargin = float(para.get_top_margin())
bm = float(p.get_bottom_margin()) bmargin = float(para.get_bottom_margin())
pa = float(p.get_padding()) padding = float(para.get_padding())
f.write('rmargin="%s" ' % Utils.gformat(rm)) xml_file.write('rmargin="%s" ' % Utils.gformat(rmargin))
f.write('lmargin="%s" ' % Utils.gformat(lm)) xml_file.write('lmargin="%s" ' % Utils.gformat(lmargin))
f.write('first="%s" ' % Utils.gformat(fi)) xml_file.write('first="%s" ' % Utils.gformat(findent))
f.write('tmargin="%s" ' % Utils.gformat(tm)) xml_file.write('tmargin="%s" ' % Utils.gformat(tmargin))
f.write('bmargin="%s" ' % Utils.gformat(bm)) xml_file.write('bmargin="%s" ' % Utils.gformat(bmargin))
f.write('pad="%s" ' % Utils.gformat(pa)) xml_file.write('pad="%s" ' % Utils.gformat(padding))
f.write('bgcolor="#%02x%02x%02x" ' % p.get_background_color()) bg_color = para.get_background_color()
f.write('level="%d" ' % p.get_header_level()) xml_file.write('bgcolor="#%02x%02x%02x" ' % bg_color)
f.write('align="%d" ' % p.get_alignment()) xml_file.write('level="%d" ' % para.get_header_level())
f.write('tborder="%d" ' % p.get_top_border()) xml_file.write('align="%d" ' % para.get_alignment())
f.write('lborder="%d" ' % p.get_left_border()) xml_file.write('tborder="%d" ' % para.get_top_border())
f.write('rborder="%d" ' % p.get_right_border()) xml_file.write('lborder="%d" ' % para.get_left_border())
f.write('bborder="%d"/>\n' % p.get_bottom_border()) xml_file.write('rborder="%d" ' % para.get_right_border())
f.write('</style>\n') xml_file.write('bborder="%d"/>\n' % para.get_bottom_border())
f.write('</sheet>\n') xml_file.write('</style>\n')
f.write('</stylelist>\n') xml_file.write('</sheet>\n')
f.close() xml_file.write('</stylelist>\n')
xml_file.close()
def parse(self): def parse(self):
""" """
@ -895,9 +907,9 @@ class StyleSheetList:
""" """
try: try:
if os.path.isfile(self.file): if os.path.isfile(self.file):
p = make_parser() parser = make_parser()
p.setContentHandler(SheetParser(self)) parser.setContentHandler(SheetParser(self))
p.parse(self.file) parser.parse(self.file)
except (IOError,OSError,SAXParseException): except (IOError,OSError,SAXParseException):
pass pass
@ -911,7 +923,7 @@ class StyleSheet:
A collection of named paragraph styles. A collection of named paragraph styles.
""" """
def __init__(self,obj=None): def __init__(self, obj=None):
""" """
Creates a new empty StyleSheet. Creates a new empty StyleSheet.
@ -926,9 +938,15 @@ class StyleSheet:
self.style_list[style_name] = ParagraphStyle(style) self.style_list[style_name] = ParagraphStyle(style)
def set_name(self, name): def set_name(self, name):
"""
Sets the name of the StyleSheet
"""
self.name = name self.name = name
def get_name(self): def get_name(self):
"""
Returns the name of the StyleSheet
"""
return self.name return self.name
def clear(self): def clear(self):
@ -1027,9 +1045,9 @@ class SheetParser(handler.ContentHandler):
"Overridden class that handles the start of a XML element" "Overridden class that handles the start of a XML element"
if tag == "style": if tag == "style":
self.p.set_font(self.f) self.p.set_font(self.f)
self.s.add_style(self.pname,self.p) self.s.add_style(self.pname, self.p)
elif tag == "sheet": elif tag == "sheet":
self.sheetlist.set_style_sheet(self.sname,self.s) self.sheetlist.set_style_sheet(self.sname, self.s)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -1037,7 +1055,16 @@ class SheetParser(handler.ContentHandler):
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class GraphicsStyle: class GraphicsStyle:
"""
Defines the properties of graphics objects, such as line width,
color, fill, ect.
"""
def __init__(self, obj=None): def __init__(self, obj=None):
"""
Initialize the object with default values, unless a source
object is specified. In that case, make a copy of the source
object.
"""
if obj: if obj:
self.height = obj.height self.height = obj.height
self.width = obj.width self.width = obj.width
@ -1055,14 +1082,20 @@ class GraphicsStyle:
self.shadow = 0 self.shadow = 0
self.shadow_space = 0.2 self.shadow_space = 0.2
self.lwidth = 0.5 self.lwidth = 0.5
self.color = (0,0,0) self.color = (0, 0, 0)
self.fill_color = (255,255,255) self.fill_color = (255, 255, 255)
self.lstyle = SOLID self.lstyle = SOLID
def set_line_width(self, val): def set_line_width(self, val):
"""
sets the line width
"""
self.lwidth = val self.lwidth = val
def get_line_width(self): def get_line_width(self):
"""
Returns the name of the StyleSheet
"""
return self.lwidth return self.lwidth
def get_line_style(self): def get_line_style(self):
@ -1122,7 +1155,7 @@ class BaseDoc:
such as OpenOffice, AbiWord, and LaTeX are derived from this base such as OpenOffice, AbiWord, and LaTeX are derived from this base
class, providing a common interface to all document generators. class, providing a common interface to all document generators.
""" """
def __init__(self, styles, paper_type ,template, def __init__(self, styles, paper_type, template,
orientation=PAPER_PORTRAIT): orientation=PAPER_PORTRAIT):
""" """
Creates a BaseDoc instance, which provides a document generation Creates a BaseDoc instance, which provides a document generation
@ -1180,7 +1213,7 @@ class BaseDoc:
def print_requested(self): def print_requested(self):
self.print_req = 1 self.print_req = 1
def set_owner(self,owner): def set_owner(self, owner):
""" """
Sets the name of the owner of the document. Sets the name of the owner of the document.
@ -1226,7 +1259,7 @@ class BaseDoc:
def get_bottom_margin(self): def get_bottom_margin(self):
return self.bmargin return self.bmargin
def creator(self,name): def creator(self, name):
"Returns the owner name" "Returns the owner name"
self.name = name self.name = name
@ -1279,7 +1312,7 @@ class BaseDoc:
def string_width(self, fontstyle, text): def string_width(self, fontstyle, text):
"Determine the width need for text in given font" "Determine the width need for text in given font"
return FontScale.string_width(fontstyle,text) return FontScale.string_width(fontstyle, text)
def line_break(self): def line_break(self):
"Forces a line break within a paragraph" "Forces a line break within a paragraph"
@ -1430,48 +1463,48 @@ class BaseDoc:
p = [] p = []
degreestoradians = pi/180.0 degreestoradians = pi / 180.0
radiansdelta = degreestoradians/2 radiansdelta = degreestoradians / 2
sangle = start_angle*degreestoradians sangle = start_angle * degreestoradians
eangle = end_angle*degreestoradians eangle = end_angle * degreestoradians
while eangle<sangle: while eangle < sangle:
eangle = eangle+2*pi eangle = eangle + 2 * pi
angle = sangle angle = sangle
if short_radius == 0: if short_radius == 0:
p.append((centerx, centery)) p.append((centerx, centery))
else: else:
origx = (centerx + cos(angle)*short_radius) origx = (centerx + cos(angle) * short_radius)
origy = (centery + sin(angle)*short_radius) origy = (centery + sin(angle) * short_radius)
p.append((origx, origy)) p.append((origx, origy))
while angle<eangle: while angle < eangle:
x = centerx + cos(angle)*radius x = centerx + cos(angle) * radius
y = centery + sin(angle)*radius y = centery + sin(angle) * radius
p.append((x, y)) p.append((x, y))
angle = angle+radiansdelta angle = angle + radiansdelta
x = centerx + cos(eangle)*radius x = centerx + cos(eangle) * radius
y = centery + sin(eangle)*radius y = centery + sin(eangle) * radius
p.append((x, y)) p.append((x, y))
if short_radius: if short_radius:
x = centerx + cos(eangle)*short_radius x = centerx + cos(eangle) * short_radius
y = centery + sin(eangle)*short_radius y = centery + sin(eangle) * short_radius
p.append((x, y)) p.append((x, y))
angle = eangle angle = eangle
while angle>=sangle: while angle >= sangle:
x = centerx + cos(angle)*short_radius x = centerx + cos(angle) * short_radius
y = centery + sin(angle)*short_radius y = centery + sin(angle) * short_radius
p.append((x, y)) p.append((x, y))
angle = angle-radiansdelta angle = angle - radiansdelta
self.draw_path(style, p) self.draw_path(style, p)
delta = (eangle - sangle)/2.0 delta = (eangle - sangle) / 2.0
rad = short_radius + (radius-short_radius)/2.0 rad = short_radius + (radius - short_radius) / 2.0
return ( (centerx + cos(sangle+delta) * rad), return ( (centerx + cos(sangle + delta) * rad),
(centery + sin(sangle+delta) * rad)) (centery + sin(sangle + delta) * rad))
def start_path(self, style, x, y): def start_path(self, style, x, y):
pass pass

View File

@ -63,7 +63,7 @@ import GrampsWidgets
from _EditPrimary import EditPrimary from _EditPrimary import EditPrimary
from QuestionDialog import WarningDialog, ErrorDialog, QuestionDialog2 from QuestionDialog import WarningDialog, ErrorDialog, QuestionDialog2
from DisplayTabs import NoteTab, GalleryTab, WebEmbedList, LdsEmbedList from DisplayTabs import *
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -5,7 +5,7 @@
# #
# 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
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License,or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
@ -14,8 +14,8 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not,write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation,Inc.,59 Temple Place,Suite 330,Boston,MA 02111-1307 USA
# #
# $Id$ # $Id$
@ -91,16 +91,16 @@ _MARKER_COL= 20
# #
# python 2.3 has a bug in the unicode sorting using locale.strcoll. Seems # python 2.3 has a bug in the unicode sorting using locale.strcoll. Seems
# to have a buffer overrun. We can convince it to do the right thing by # to have a buffer overrun. We can convince it to do the right thing by
# forcing the string to be nul terminated, sorting, then stripping off the # forcing the string to be nul terminated,sorting,then stripping off the
# nul. # nul.
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
if sys.version_info[0:2] == (2,3): if sys.version_info[0:2] == (2, 3):
def locale_sort(mylist): def locale_sort(mylist):
mylist = map(lambda x: x + "\x00", mylist) mylist = map(lambda x: x + "\x00",mylist)
mylist.sort(locale.strcoll) mylist.sort(locale.strcoll)
return map(lambda x: x[:-1], mylist) return map(lambda x: x[:-1],mylist)
else: else:
def locale_sort(mylist): def locale_sort(mylist):
mylist.sort(locale.strcoll) mylist.sort(locale.strcoll)
@ -113,7 +113,7 @@ else:
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class PeopleModel(gtk.GenericTreeModel): class PeopleModel(gtk.GenericTreeModel):
def __init__(self,db,data_filter=None,invert_result=False,skip=[]): def __init__(self, db, data_filter=None, invert_result=False, skip=[]):
gtk.GenericTreeModel.__init__(self) gtk.GenericTreeModel.__init__(self)
self.db = db self.db = db
@ -125,13 +125,13 @@ class PeopleModel(gtk.GenericTreeModel):
self.prev_handle = None self.prev_handle = None
self.prev_data = None self.prev_data = None
self.temp_top_path2iter = [] self.temp_top_path2iter = []
self.rebuild_data(data_filter,skip) self.rebuild_data(data_filter, skip)
def rebuild_data(self,data_filter=None,skip=[]): def rebuild_data(self, data_filter=None, skip=[]):
self.calculate_data(data_filter,skip) self.calculate_data(data_filter, skip)
self.assign_data() self.assign_data()
def calculate_data(self,dfilter=None,skip=[]): def calculate_data(self, dfilter=None, skip=[]):
if dfilter: if dfilter:
self.dfilter = dfilter self.dfilter = dfilter
self.temp_iter2path = {} self.temp_iter2path = {}
@ -150,7 +150,7 @@ class PeopleModel(gtk.GenericTreeModel):
node = cursor.first() node = cursor.first()
while node: while node:
handle,d = node handle, d = node
if not (handle in skip or (dfilter and not dfilter.match(handle))): if not (handle in skip or (dfilter and not dfilter.match(handle))):
name_data = d[_NAME_COL] name_data = d[_NAME_COL]
self.sortnames[handle] = nsn(name_data) self.sortnames[handle] = nsn(name_data)
@ -168,15 +168,15 @@ class PeopleModel(gtk.GenericTreeModel):
def clear_cache(self): def clear_cache(self):
self.prev_handle = None self.prev_handle = None
def build_sub_entry(self,name): def build_sub_entry(self, name):
self.prev_handle = None self.prev_handle = None
slist = [ (locale.strxfrm(self.sortnames[x]),x) \ slist = [ (locale.strxfrm(self.sortnames[x]), x) \
for x in self.temp_sname_sub[name] ] for x in self.temp_sname_sub[name] ]
slist.sort() slist.sort()
val = 0 val = 0
for (junk,person_handle) in slist: for (junk, person_handle) in slist:
tpl = (name,val) tpl = (name, val)
self.temp_iter2path[person_handle] = tpl self.temp_iter2path[person_handle] = tpl
self.temp_path2iter[tpl] = person_handle self.temp_path2iter[tpl] = person_handle
val += 1 val += 1
@ -194,33 +194,32 @@ class PeopleModel(gtk.GenericTreeModel):
def on_get_n_columns(self): def on_get_n_columns(self):
return len(COLUMN_DEFS) return len(COLUMN_DEFS)
def on_get_path(self, node): def on_get_path(self,node):
'''returns the tree path (a tuple of indices at the various '''returns the tree path (a tuple of indices at the various
levels) for a particular node.''' levels) for a particular node.'''
try: try:
return (self.top_path2iter.index(node),) return (self.top_path2iter.index(node), )
except: except:
(surname,index) = self.iter2path[node] (surname, index) = self.iter2path[node]
return (self.top_path2iter.index(surname),index) return (self.top_path2iter.index(surname), index)
def is_visable(self,handle): def is_visable(self, handle):
return self.iter2path.has_key(handle) return self.iter2path.has_key(handle)
def on_get_column_type(self,index): def on_get_column_type(self, index):
# return column data-type, from table return COLUMN_DEFS[index][COLUMN_DEF_TYPE]
return COLUMN_DEFS[index][COLUMN_DEF_TYPE]
def on_get_iter(self, path): def on_get_iter(self,path):
try: try:
if len(path)==1: # Top Level if len(path)==1: # Top Level
return self.top_path2iter[path[0]] return self.top_path2iter[path[0]]
else: # Sublevel else: # Sublevel
surname = self.top_path2iter[path[0]] surname = self.top_path2iter[path[0]]
return self.path2iter[(surname,path[1])] return self.path2iter[(surname, path[1])]
except: except:
return None return None
def on_get_value(self,node,col): def on_get_value(self, node, col):
# test for header or data row-type # test for header or data row-type
if self.sname_sub.has_key(node): if self.sname_sub.has_key(node):
# Header rows dont get the background color set # Header rows dont get the background color set
@ -229,25 +228,26 @@ class PeopleModel(gtk.GenericTreeModel):
# test for 'header' column being empty (most are) # test for 'header' column being empty (most are)
if not COLUMN_DEFS[col][COLUMN_DEF_HEADER]: if not COLUMN_DEFS[col][COLUMN_DEF_HEADER]:
return u'' return u''
# return values for 'header' row, calling a function # return values for 'header' row,calling a function
# according to column_defs table # according to column_defs table
val = COLUMN_DEFS[col][COLUMN_DEF_HEADER](self,node) val = COLUMN_DEFS[col][COLUMN_DEF_HEADER](self, node)
return val return val
else: else:
# return values for 'data' row, calling a function # return values for 'data' row,calling a function
# according to column_defs table # according to column_defs table
try: try:
if node != self.prev_handle: if node != self.prev_handle:
self.prev_data = self.db.get_raw_person_data(str(node)) self.prev_data = self.db.get_raw_person_data(str(node))
self.prev_handle = node self.prev_handle = node
return COLUMN_DEFS[col][COLUMN_DEF_LIST](self,self.prev_data,node) return COLUMN_DEFS[col][COLUMN_DEF_LIST](self,
self.prev_data, node)
except: except:
if col == _MARKER_COL: if col == _MARKER_COL:
return None return None
else: else:
return u'error' return u'error'
def on_iter_next(self, node): def on_iter_next(self,node):
'''returns the next node at this level of the tree''' '''returns the next node at this level of the tree'''
try: try:
path = self.top_path2iter.index(node) path = self.top_path2iter.index(node)
@ -255,17 +255,17 @@ class PeopleModel(gtk.GenericTreeModel):
return None return None
return self.top_path2iter[path+1] return self.top_path2iter[path+1]
except: except:
(surname,val) = self.iter2path[node] (surname, val) = self.iter2path[node]
return self.path2iter.get((surname,val+1)) return self.path2iter.get((surname, val+1))
def on_iter_children(self,node): def on_iter_children(self, node):
"""Return the first child of the node""" """Return the first child of the node"""
if node == None: if node == None:
return self.top_path2iter[0] return self.top_path2iter[0]
else: else:
return self.path2iter.get((node,0)) return self.path2iter.get((node, 0))
def on_iter_has_child(self, node): def on_iter_has_child(self,node):
'''returns true if this node has children''' '''returns true if this node has children'''
if node == None: if node == None:
return len(self.sname_sub) return len(self.sname_sub)
@ -273,7 +273,7 @@ class PeopleModel(gtk.GenericTreeModel):
return True return True
return False return False
def on_iter_n_children(self,node): def on_iter_n_children(self, node):
if node == None: if node == None:
return len(self.sname_sub) return len(self.sname_sub)
try: try:
@ -281,61 +281,62 @@ class PeopleModel(gtk.GenericTreeModel):
except: except:
return 0 return 0
def on_iter_nth_child(self,node,n): def on_iter_nth_child(self, node, n):
try: try:
if node == None: if node == None:
return self.top_path2iter[n] return self.top_path2iter[n]
try: try:
return self.path2iter[(node,n)] return self.path2iter[(node, n)]
except: except:
return None return None
except IndexError: except IndexError:
return None return None
def on_iter_parent(self, node): def on_iter_parent(self,node):
'''returns the parent of this node''' '''returns the parent of this node'''
path = self.iter2path.get(node) path = self.iter2path.get(node)
if path: if path:
return path[0] return path[0]
return None return None
def column_sort_name(self,data,node): def column_sort_name(self, data, node):
n = Name() n = Name()
n.unserialize(data[_NAME_COL]) n.unserialize(data[_NAME_COL])
return NameDisplay.displayer.sort_string(n) return NameDisplay.displayer.sort_string(n)
def column_spouse(self,data,node): def column_spouse(self, data, node):
spouses_names = u"" spouses_names = u""
handle = data[0] handle = data[0]
for family_handle in data[_FAMILY_COL]: for family_handle in data[_FAMILY_COL]:
family = self.db.get_family_from_handle(family_handle) family = self.db.get_family_from_handle(family_handle)
for spouse_id in [family.get_father_handle(), family.get_mother_handle()]: for spouse_id in [family.get_father_handle(),
family.get_mother_handle()]:
if not spouse_id: if not spouse_id:
continue continue
if spouse_id == handle: if spouse_id == handle:
continue continue
spouse = self.db.get_person_from_handle(spouse_id) spouse = self.db.get_person_from_handle(spouse_id)
if len(spouses_names) > 0: if len(spouses_names) > 0:
spouses_names += ", " spouses_names += ","
spouses_names += NameDisplay.displayer.display(spouse) spouses_names += NameDisplay.displayer.display(spouse)
return spouses_names return spouses_names
def column_name(self,data,node): def column_name(self, data, node):
n = Name() n = Name()
n.unserialize(data[_NAME_COL]) n.unserialize(data[_NAME_COL])
return NameDisplay.displayer.sorted_name(n) return NameDisplay.displayer.sorted_name(n)
def column_id(self,data,node): def column_id(self, data, node):
return data[_ID_COL] return data[_ID_COL]
def column_change(self,data,node): def column_change(self, data, node):
return unicode(time.strftime('%x %X',time.localtime(data[_CHANGE_COL])), return unicode(time.strftime('%x %X', time.localtime(data[_CHANGE_COL])),
_codeset) _codeset)
def column_gender(self,data,node): def column_gender(self, data, node):
return _GENDER[data[_GENDER_COL]] return _GENDER[data[_GENDER_COL]]
def column_birth_day(self,data,node): def column_birth_day(self, data, node):
if data[_BIRTH_COL]: if data[_BIRTH_COL]:
b=EventRef() b=EventRef()
b.unserialize(data[_BIRTH_COL]) b.unserialize(data[_BIRTH_COL])
@ -350,13 +351,13 @@ class PeopleModel(gtk.GenericTreeModel):
event = self.db.get_event_from_handle(er.ref) event = self.db.get_event_from_handle(er.ref)
etype = event.get_type()[0] etype = event.get_type()[0]
date_str = DateHandler.get_date(event) date_str = DateHandler.get_date(event)
if (etype in [Event.BAPTISM, Event.CHRISTEN] if (etype in [Event.BAPTISM,Event.CHRISTEN]
and date_str != ""): and date_str != ""):
return "<i>" + cgi.escape(date_str) + "</i>" return "<i>" + cgi.escape(date_str) + "</i>"
return u"" return u""
def column_death_day(self,data,node): def column_death_day(self, data, node):
if data[_DEATH_COL]: if data[_DEATH_COL]:
dr = EventRef() dr = EventRef()
dr.unserialize(data[_DEATH_COL]) dr.unserialize(data[_DEATH_COL])
@ -371,13 +372,13 @@ class PeopleModel(gtk.GenericTreeModel):
event = self.db.get_event_from_handle(er.ref) event = self.db.get_event_from_handle(er.ref)
etype = event.get_type()[0] etype = event.get_type()[0]
date_str = DateHandler.get_date(event) date_str = DateHandler.get_date(event)
if (etype in [Event.BURIAL, Event.CREMATION] if (etype in [Event.BURIAL,Event.CREMATION]
and date_str != ""): and date_str != ""):
return "<i>" + cgi.escape(date_str) + "</i>" return "<i>" + cgi.escape(date_str) + "</i>"
return u"" return u""
def column_cause_of_death(self,data,node): def column_cause_of_death(self, data, node):
if data[_DEATH_COL]: if data[_DEATH_COL]:
dr = EventRef() dr = EventRef()
dr.unserialize(data[_DEATH_COL]) dr.unserialize(data[_DEATH_COL])
@ -385,15 +386,16 @@ class PeopleModel(gtk.GenericTreeModel):
else: else:
return u"" return u""
def column_birth_place(self,data,node): def column_birth_place(self, data, node):
if data[_BIRTH_COL]: if data[_BIRTH_COL]:
br = EventRef() br = EventRef()
br.unserialize(data[_BIRTH_COL]) br.unserialize(data[_BIRTH_COL])
event = self.db.get_event_from_handle(br.ref) event = self.db.get_event_from_handle(br.ref)
if event: if event:
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place_title = self.db.get_place_from_handle(place_handle).get_title() place = self.db.get_place_from_handle(place_handle)
place_title = place.get_title()
if place_title != "": if place_title != "":
return cgi.escape(place_title) return cgi.escape(place_title)
@ -402,23 +404,24 @@ class PeopleModel(gtk.GenericTreeModel):
er.unserialize(event_ref) er.unserialize(event_ref)
event = self.db.get_event_from_handle(er.ref) event = self.db.get_event_from_handle(er.ref)
etype = event.get_type()[0] etype = event.get_type()[0]
if etype in [Event.BAPTISM, Event.CHRISTEN]: if etype in [Event.BAPTISM,Event.CHRISTEN]:
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place_title = self.db.get_place_from_handle(place_handle).get_title() place = self.db.get_place_from_handle(place_handle)
place_title = place.get_title()
if place_title != "": if place_title != "":
return "<i>" + cgi.escape(place_title) + "</i>" return "<i>" + cgi.escape(place_title) + "</i>"
return u"" return u""
def column_death_place(self,data,node): def column_death_place(self, data, node):
if data[_DEATH_COL]: if data[_DEATH_COL]:
dr = EventRef() dr = EventRef()
dr.unserialize(data[_DEATH_COL]) dr.unserialize(data[_DEATH_COL])
event = self.db.get_event_from_handle(dr.ref) event = self.db.get_event_from_handle(dr.ref)
if event: if event:
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place_title = self.db.get_place_from_handle(place_handle).get_title() place_title = self.db.get_place_from_handle(place_handle).get_title()
if place_title != "": if place_title != "":
return cgi.escape(place_title) return cgi.escape(place_title)
@ -428,7 +431,7 @@ class PeopleModel(gtk.GenericTreeModel):
er.unserialize(event_ref) er.unserialize(event_ref)
event = self.db.get_event_from_handle(er.ref) event = self.db.get_event_from_handle(er.ref)
etype = event.get_type()[0] etype = event.get_type()[0]
if etype in [Event.BURIAL, Event.CREMATION]: if etype in [Event.BURIAL,Event.CREMATION]:
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle: if place_handle:
place_title = self.db.get_place_from_handle(place_handle).get_title() place_title = self.db.get_place_from_handle(place_handle).get_title()
@ -437,7 +440,7 @@ class PeopleModel(gtk.GenericTreeModel):
return u"" return u""
def column_marker_text(self,data,node): def column_marker_text(self, data, node):
try: try:
if data[_MARKER_COL]: if data[_MARKER_COL]:
if data[_MARKER_COL][0] == PrimaryObject.MARKER_CUSTOM: if data[_MARKER_COL][0] == PrimaryObject.MARKER_CUSTOM:
@ -448,7 +451,7 @@ class PeopleModel(gtk.GenericTreeModel):
return "" return ""
return "" return ""
def column_marker_color(self,data,node): def column_marker_color(self, data, node):
try: try:
if data[_MARKER_COL]: if data[_MARKER_COL]:
if data[_MARKER_COL][0] == PrimaryObject.MARKER_COMPLETE: if data[_MARKER_COL][0] == PrimaryObject.MARKER_COMPLETE:
@ -461,49 +464,48 @@ class PeopleModel(gtk.GenericTreeModel):
pass pass
return None return None
def column_tooltip(self,data,node): def column_tooltip(self, data, node):
if const.use_tips: if const.use_tips:
return ToolTips.TipFromFunction(self.db, lambda: self.db.get_person_from_handle(data[0])) return ToolTips.TipFromFunction(self.db,lambda: self.db.get_person_from_handle(data[0]))
else: else:
return u'' return u''
def column_int_id(self,data,node): def column_int_id(self, data, node):
return node return node
def column_header(self,node): def column_header(self, node):
return node return node
def column_header_view(self,node): def column_header_view(self, node):
return True return True
_GENDER = [ _(u'female'), _(u'male'), _(u'unknown') ] _GENDER = [ _(u'female'),_(u'male'),_(u'unknown') ]
# table of column definitions # table of column definitions
# (unless this is declared after the PeopleModel class, an error is thrown) # (unless this is declared after the PeopleModel class,an error is thrown)
COLUMN_DEFS = [ COLUMN_DEFS = [
# data column (method) header column (method) column data type # data column (method) header column (method) column data type
(PeopleModel.column_name, PeopleModel.column_header, str), (PeopleModel.column_name, PeopleModel.column_header, str),
(PeopleModel.column_id, None, str), (PeopleModel.column_id, None, str),
(PeopleModel.column_gender, None, str), (PeopleModel.column_gender, None, str),
(PeopleModel.column_birth_day, None, str), (PeopleModel.column_birth_day, None, str),
(PeopleModel.column_birth_place,None, str), (PeopleModel.column_birth_place, None, str),
(PeopleModel.column_death_day, None, str), (PeopleModel.column_death_day, None, str),
(PeopleModel.column_death_place,None, str), (PeopleModel.column_death_place, None, str),
(PeopleModel.column_spouse, None, str), (PeopleModel.column_spouse, None, str),
(PeopleModel.column_change, None, str), (PeopleModel.column_change, None, str),
(PeopleModel.column_cause_of_death, None, str), (PeopleModel.column_cause_of_death, None, str),
(PeopleModel.column_marker_text, None, str), (PeopleModel.column_marker_text, None, str),
(PeopleModel.column_marker_color, None, str), (PeopleModel.column_marker_color, None, str),
# the order of the above columns must match PeopleView.column_names # the order of the above columns must match PeopleView.column_names
# these columns are hidden, and must always be last in the list # these columns are hidden,and must always be last in the list
(PeopleModel.column_tooltip, None, object), (PeopleModel.column_tooltip, None, object),
# (PeopleModel.column_sort_name, None, str), (PeopleModel.column_int_id, None, str),
(PeopleModel.column_int_id, None, str),
] ]
# dynamic calculation of column indices, for use by various Views # dynamic calculation of column indices,for use by various Views
COLUMN_INT_ID = 13 COLUMN_INT_ID = 13
# indices into main column definition table # indices into main column definition table