From 5d2f999431594a3f768b3b89e373ce5b812b848b Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Tue, 3 Jun 2003 02:54:56 +0000 Subject: [PATCH] Fixed spouse selection when family changes svn: r1643 --- src/AddSpouse.py | 4 +- src/AddrEdit.py | 6 +- src/AttrEdit.py | 5 +- src/DrawDoc.py | 3 + src/EventEdit.py | 8 +- src/FamilyView.py | 40 +++--- src/ListModel.py | 42 +++--- src/NameEdit.py | 5 +- src/UrlEdit.py | 9 +- src/docgen/AbiWord2Doc.py | 278 ++++++++++++++++++++++++++++++++++++++ src/docgen/Makefile.am | 3 +- src/docgen/PdfDrawDoc.py | 60 ++++++-- 12 files changed, 401 insertions(+), 62 deletions(-) create mode 100644 src/docgen/AbiWord2Doc.py diff --git a/src/AddSpouse.py b/src/AddSpouse.py index a4c086166..7e588ea1c 100644 --- a/src/AddSpouse.py +++ b/src/AddSpouse.py @@ -218,7 +218,7 @@ class AddSpouse: sgender = const.male else: sgender = const.female - + self.entries = [] self.slist.clear() self.slist.new_model() @@ -260,9 +260,7 @@ class AddSpouse: # 100 years from spouse deathdate if abs(pdday.getYear() - dday.getYear()) > 100: continue - self.slist.add([data[0],data[1],data[3],data[5],data[6]],key,person==key) - self.slist.connect_model() def on_show_toggled(self,obj): diff --git a/src/AddrEdit.py b/src/AddrEdit.py index 5f9e328d5..cddb690ba 100644 --- a/src/AddrEdit.py +++ b/src/AddrEdit.py @@ -76,7 +76,11 @@ class AddressEditor: self.addr = addr name = parent.person.getPrimaryName().getName() - text = _("Address Editor for %s") % name + print "'%s'" % name + if name == ", ": + text = _("Address Editor") + else: + text = _("Address Editor for %s") % name title_label = self.top.get_widget("title") diff --git a/src/AttrEdit.py b/src/AttrEdit.py index 8928f4650..fae1eedf5 100644 --- a/src/AttrEdit.py +++ b/src/AttrEdit.py @@ -88,7 +88,10 @@ class AttributeEditor: self.top.get_widget('edit_src'), self.top.get_widget('del_src')) - title = _("Attribute Editor for %s") % title + if title == ", ": + title = _("Attribute Editor") + else: + title = _("Attribute Editor for %s") % title l = self.top.get_widget("title") Utils.set_titles(self.window,l,title,_('Attribute Editor')) diff --git a/src/DrawDoc.py b/src/DrawDoc.py index 83cb6ecfa..7282f73c3 100644 --- a/src/DrawDoc.py +++ b/src/DrawDoc.py @@ -182,6 +182,9 @@ class DrawDoc: def draw_line(self,style,x1,y1,x2,y2): pass + def draw_wedge(self, style, centerx, centery, radius, start_angle, end_angle): + pass + def start_path(self,style,x,y): pass diff --git a/src/EventEdit.py b/src/EventEdit.py index 27d1de288..966039720 100644 --- a/src/EventEdit.py +++ b/src/EventEdit.py @@ -83,8 +83,12 @@ class EventEditor: self.window = self.top.get_widget("event_edit") title_label = self.top.get_widget('title') - Utils.set_titles(self.window,title_label, - _('Event Editor for %s') % name, + if name == ", ": + etitle = _('Event Editor') + else: + etitle = _('Event Editor for %s') % name + + Utils.set_titles(self.window,title_label, etitle, _('Event Editor')) self.name_field = self.top.get_widget("eventName") diff --git a/src/FamilyView.py b/src/FamilyView.py index 4ea40b971..e827f933d 100644 --- a/src/FamilyView.py +++ b/src/FamilyView.py @@ -266,7 +266,7 @@ class FamilyView: def spouse_swap(self,obj): if self.selected_spouse: self.parent.active_person = self.selected_spouse - self.load_family() + self.load_family(self.family) def ap_parents_clicked(self,obj): self.change_families(self.person) @@ -331,9 +331,14 @@ class FamilyView: self.child_model.clear() self.sp_parents_model.clear() splist = self.person.getFamilyList() - f = None - first_family = None - first_spouse = None + + if len(splist) > 1: + self.spouse_selection.set_mode(gtk.SELECTION_SINGLE) + else: + self.spouse_selection.set_mode(gtk.SELECTION_NONE) + + flist = {} + for f in splist: if not f: continue @@ -343,19 +348,8 @@ class FamilyView: sp = f.getFather() iter = self.spouse_model.append() - if f == family: - first_spouse = sp - first_family = f - elif first_spouse == None: - first_spouse = sp - first_family = f + flist[f.getId()] = iter - if len(splist) > 1: - self.spouse_selection.set_mode(gtk.SELECTION_SINGLE) - self.spouse_selection.select_path(0) - else: - self.spouse_selection.set_mode(gtk.SELECTION_NONE) - if sp: if f.getMarriage(): mdate = " - %s" % f.getMarriage().getDate() @@ -367,11 +361,19 @@ class FamilyView: else: self.spouse_model.set(iter,0,"unknown\n") - if first_family: - self.display_marriage(first_family) + if family in splist: + self.display_marriage(family) + iter = flist[family.getId()] + self.spouse_selection.select_iter(iter) + elif len(flist) > 0: + f = splist[0] + iter = flist[f.getId()] + self.spouse_selection.select_iter(iter) + self.display_marriage(f) + else: + self.display_marriage(None) self.update_list(self.ap_parents_model,self.ap_parents,self.person) - self.family = first_family def update_list(self,model,tree,person): model.clear() diff --git a/src/ListModel.py b/src/ListModel.py index b59f93b0d..3fb50ed06 100644 --- a/src/ListModel.py +++ b/src/ListModel.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2003 Donald N. Allingham +# Copyright (C) 2000 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 @@ -34,10 +34,8 @@ class ListModel: self.tree.set_rules_hint(gtk.TRUE) self.model = None - self.new_model() - self.selection = self.tree.get_selection() - self.selection.set_mode(mode) self.mode = mode + self.new_model() self.data_index = l self.count = 0 self.cid = None @@ -84,9 +82,14 @@ class ListModel: self.cid = self.model.get_sort_column_id() self.count = 0 self.model = gtk.ListStore(*self.mylist) - + self.selection = self.tree.get_selection() + self.selection.set_mode(self.mode) + self.sel_iter = None + def connect_model(self): self.tree.set_model(self.model) + if self.sel_iter: + self.selection.select_iter(self.sel_iter) if self.cid: self.model.set_sort_column_id(self.cid[0],self.cid[1]) self.sort() @@ -165,18 +168,6 @@ class ListModel: def get_object(self,iter): return self.model.get_value(iter,self.data_index) - def add(self,data,info=None,select=0): - self.count = self.count + 1 - iter = self.model.append() - col = 0 - for object in data: - self.model.set_value(iter,col,object) - col = col + 1 - self.model.set_value(iter,col,info) - if select: - self.selection.select_iter(iter) - return iter - def insert(self,position,data,info=None,select=0): self.count = self.count + 1 iter = self.model.insert(position) @@ -192,6 +183,18 @@ class ListModel: def get_data(self,iter,cols): return [ self.model.get_value(iter,c) for c in cols ] + def add(self,data,info=None,select=0): + self.count = self.count + 1 + iter = self.model.append() + col = 0 + for object in data: + self.model.set_value(iter,col,object) + col = col + 1 + self.model.set_value(iter,col,info) + if select: + self.sel_iter = iter + return iter + def add_and_select(self,data,info=None): self.count = self.count + 1 iter = self.model.append() @@ -204,8 +207,9 @@ class ListModel: def center_selected(self): model,iter = self.selection.get_selected() - path = model.get_path(iter) - self.tree.scroll_to_cell(path,None,gtk.TRUE,0.5,0.5) + if iter: + path = model.get_path(iter) + self.tree.scroll_to_cell(path,None,gtk.TRUE,0.5,0.5) def button_press(self,obj,event): if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: diff --git a/src/NameEdit.py b/src/NameEdit.py index 19da5f72c..708da2825 100644 --- a/src/NameEdit.py +++ b/src/NameEdit.py @@ -75,7 +75,10 @@ class NameEditor: alt_title = self.top.get_widget("title") - tmsg = _("Alternate Name Editor for %s") % full_name + if full_name == ", ": + tmsg = _("Alternate Name Editor") + else: + tmsg = _("Alternate Name Editor for %s") % full_name Utils.set_titles(self.window, alt_title, tmsg, _('Alternate Name Editor')) diff --git a/src/UrlEdit.py b/src/UrlEdit.py index 22792404a..55c770553 100644 --- a/src/UrlEdit.py +++ b/src/UrlEdit.py @@ -52,8 +52,13 @@ class UrlEditor: self.priv = self.top.get_widget("priv") title_label = self.top.get_widget("title") - Utils.set_titles(self.window,title_label, - _('Internet Address Editor for %s') % name, + if name == ", ": + etitle =_('Internet Address Editor') + else: + etitle =_('Internet Address Editor for %s') % name, + + + Utils.set_titles(self.window,title_label, etitle, _('Internet Address Editor')) if url != None: self.des.set_text(url.get_description()) diff --git a/src/docgen/AbiWord2Doc.py b/src/docgen/AbiWord2Doc.py new file mode 100644 index 000000000..0ef7e48e9 --- /dev/null +++ b/src/docgen/AbiWord2Doc.py @@ -0,0 +1,278 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +""" +Provides a TextDoc based interface to the AbiWord document format. +""" + +#------------------------------------------------------------------------- +# +# Imported Modules +# +#------------------------------------------------------------------------- +import os +import base64 + +import TextDoc +from latin_utf8 import latin_to_utf8 +import string +import Plugins +import ImgManip +from intl import gettext as _ + +#------------------------------------------------------------------------- +# +# Class Definitions +# +#------------------------------------------------------------------------- +class AbiWordDoc(TextDoc.TextDoc): + """AbiWord document generator. Inherits from the TextDoc generic + document interface class.""" + + def __init__(self,styles,type,template,orientation): + """Initializes the AbiWordDoc class, calling the __init__ routine + of the parent TextDoc class""" + TextDoc.TextDoc.__init__(self,styles,type,template,orientation) + self.f = None + self.level = 0 + self.new_page = 0 + self.in_table = 0 + self.icount = 0; + self.imap = {} + + def open(self,filename): + """Opens the document, writing the necessary header information. + AbiWord uses an XML format, so the document format is pretty easy + to understand""" + if filename[-4:] != ".abw": + self.filename = "%s.abw" % filename + else: + self.filename = filename + + try: + self.f = open(self.filename,"w") + except IOError,msg: + errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg) + raise Errors.ReportError(errmsg) + except: + raise Errors.ReportError(_("Could not create %s") % self.filename) + + # doctype + self.f.write('\n') + self.f.write('\n') + self.f.write('\n') + + # metadata section + self.f.write('\n') + self.f.write('application/x-abiword\n') + self.f.write('AbiWord\n') + self.f.write('Mon May 19 14:16:24 2003\n') + self.f.write('\n') + + self.write_styles() + + # page size section + self.f.write('\n') + self.f.write('
\n') + + def write_styles(self): + self.f.write('\n') + for style_name in self.style_list.keys(): + style = self.style_list[style_name] + self.current_style = style + self.f.write('\n') + self.f.write('\n') + + def close(self): + """Write the trailing information and closes the file""" + self.f.write('
\n') + if len(self.photo_list) > 0: + self.f.write('\n') + for file_tuple in self.photo_list: + tag = self.imap[file_tuple[0]] + + img = ImgManip.ImgManip(file_tuple[0]) + buf = img.png_data() + + self.f.write('\n' % tag) + self.f.write(base64.encodestring(buf)) + self.f.write('\n') + self.f.write('\n') + + self.f.write('
\n') + self.f.close() + + def add_photo(self,name,pos,x_cm,y_cm): + + image = ImgManip.ImgManip(name) + (x,y) = image.size() + aspect_ratio = float(x)/float(y) + + if aspect_ratio > x_cm/y_cm: + act_width = x_cm + act_height = y_cm/aspect_ratio + else: + act_height = y_cm + act_width = x_cm*aspect_ratio + + self.photo_list.append((name,act_width,act_height)) + + tag = "image%d" % self.icount + + self.f.write('' % y_cm) + self.imap[name] = tag + self.icount += 1 + + def start_superscript(self): + fsize = self.my_para.get_font().get_size() + self.text = self.text + '' + + def end_superscript(self): + self.text = self.text + '' + + def start_paragraph(self,style_name,leader=None): + style = self.style_list[style_name] + self.current_style = style + self.f.write('

' % style_name) + if self.new_page == 1: + self.new_page = 0 + self.f.write('') + if leader != None: + self.f.write(leader) + self.f.write('\t') + + def page_break(self): + self.new_page = 1 + + def end_paragraph(self): + self.f.write('

\n') + + def write_text(self,text): + text = text.replace('&','&'); # Must be first + text = text.replace('<','<'); + text = text.replace('>','>'); + text = text.replace('<super>','') + text = text.replace('</super>','') + self.f.write(text) + + def start_bold(self): + self.f.write('') + + def end_bold(self): + self.f.write('') + + def start_table(self,name,style_name): + self.in_table = 1 + self.tblstyle = self.table_styles[style_name] + self.f.write('\n') + self.current_row = -1 + + def end_table(self): + self.in_table = 0 + self.f.write('
\n') + + def start_row(self): + self.ledge = 0.0 + self.col = 0 + self.current_row += 1 + + def end_row(self): + pass + + def start_cell(self,style_name,span=1): + self.cstyle = self.cell_styles[style_name] + self.f.write('\n') + self.col += span + + def end_cell(self): + self.f.write('\n') + +Plugins.register_text_doc(_("AbiWord (version 1.9 or greater)"),AbiWordDoc,1,1,1,".abw") diff --git a/src/docgen/Makefile.am b/src/docgen/Makefile.am index f3d6b4804..cc0fdae2e 100644 --- a/src/docgen/Makefile.am +++ b/src/docgen/Makefile.am @@ -3,7 +3,8 @@ # If not using GNU make, then list all .py files individually pkgpython_PYTHON = \ - AbiWordDoc.py\ + AbiWordDoc.py\ + AbiWord2Doc.py\ HtmlDoc.py\ KwordDoc.py\ LaTeXDoc.py\ diff --git a/src/docgen/PdfDrawDoc.py b/src/docgen/PdfDrawDoc.py index a0fcfdbf2..61ae7f325 100644 --- a/src/docgen/PdfDrawDoc.py +++ b/src/docgen/PdfDrawDoc.py @@ -152,31 +152,65 @@ class PdfDrawDoc(DrawDoc.DrawDoc): else: self.f.drawPath(p,stroke=1,fill=0) - def draw_half_circle(self,style,x,y,radius): + def draw_wedge(self, style, centerx, centery, radius, start_angle, end_angle, short_radius=0): + centerx += self.lmargin + centery += self.bmargin + from math import sin, cos, pi + + def rnd(val): + return val*cm + + while end_angle < start_angle: + end_angle += 360 + stype = self.draw_styles[style] if stype.get_line_style() == DrawDoc.SOLID: self.f.setDash([],0) else: self.f.setDash([2,4],0) - self.f.setLineWidth(stype.get_line_width()) + degreestoradians = pi/180.0 + radiansdelta = degreestoradians + sangle = start_angle*degreestoradians + eangle = end_angle*degreestoradians + while eangle=sangle: + x = centerx + cos(angle)*short_radius + y = centery + sin(angle)*short_radius + p.lineTo(rnd(x),rnd(y)) + angle = angle-radiansdelta + p.close() + self.f.drawPath(p,stroke=1,fill=1) def draw_box(self,style,text,x,y): x = x + self.lmargin