2007-12-20 Douglas S. Blank <dblank@cs.brynmawr.edu>
* src/plugins/siblings.py: Quick Reports under construction... * src/Simple/_SimpleDoc.py: added table style defaults * src/Simple/__init__.py: added SimpleTable * src/BaseDoc.py: added doc.type = "standard" * src/docgen/TextBufDoc.py: added doc.type = "gtk" * src/Simple/_SimpleTable.py: new file defining table svn: r9550
This commit is contained in:
parent
7d5b16d3e0
commit
f84b9c816c
@ -1,3 +1,11 @@
|
||||
2007-12-20 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||
* src/plugins/siblings.py: Quick Reports under construction...
|
||||
* src/Simple/_SimpleDoc.py: added table style defaults
|
||||
* src/Simple/__init__.py: added SimpleTable
|
||||
* src/BaseDoc.py: added doc.type = "standard"
|
||||
* src/docgen/TextBufDoc.py: added doc.type = "gtk"
|
||||
* src/Simple/_SimpleTable.py: new file defining table
|
||||
|
||||
2007-12-20 Benny Malengier <benny.malengier@gramps-project.org>
|
||||
* src/glade/gramps.glade: date keybindings, issue #1453
|
||||
|
||||
|
@ -1340,6 +1340,7 @@ class BaseDoc:
|
||||
self._creator = ""
|
||||
self.print_req = 0
|
||||
self.init_called = False
|
||||
self.type = "standard"
|
||||
|
||||
def init(self):
|
||||
self.init_called = True
|
||||
|
@ -84,7 +84,7 @@ def make_basic_stylesheet():
|
||||
fstyle.set_size(14)
|
||||
fstyle.set_bold(True)
|
||||
pstyle.set_font(fstyle)
|
||||
pstyle.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
|
||||
pstyle.set_alignment(BaseDoc.PARA_ALIGN_LEFT)
|
||||
sheet.add_paragraph_style('Title', pstyle)
|
||||
|
||||
pstyle = BaseDoc.ParagraphStyle()
|
||||
@ -121,4 +121,25 @@ def make_basic_stylesheet():
|
||||
pstyle = BaseDoc.ParagraphStyle()
|
||||
pstyle.set_tabs([4, 8, 12, 16])
|
||||
sheet.add_paragraph_style('Normal', pstyle)
|
||||
|
||||
# Styles for tables:
|
||||
tbl = BaseDoc.TableStyle()
|
||||
tbl.set_width(100)
|
||||
tbl.set_columns(2)
|
||||
tbl.set_column_width(0,20)
|
||||
tbl.set_column_width(1,80)
|
||||
sheet.add_table_style("Table",tbl)
|
||||
|
||||
cell = BaseDoc.TableCellStyle()
|
||||
cell.set_top_border(1)
|
||||
cell.set_bottom_border(1)
|
||||
sheet.add_cell_style("TableHead",cell)
|
||||
|
||||
cell = BaseDoc.TableCellStyle()
|
||||
sheet.add_cell_style("TableNormalCell",cell)
|
||||
|
||||
cell = BaseDoc.TableCellStyle()
|
||||
cell.set_longlist(1)
|
||||
sheet.add_cell_style("TableListCell",cell)
|
||||
|
||||
return sheet
|
||||
|
122
src/Simple/_SimpleTable.py
Normal file
122
src/Simple/_SimpleTable.py
Normal file
@ -0,0 +1,122 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2007 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 simplified table creation interface
|
||||
"""
|
||||
|
||||
import copy
|
||||
|
||||
class SimpleTable:
|
||||
"""
|
||||
Provides a simplified table creation interface.
|
||||
"""
|
||||
|
||||
def __init__(self, access, doc, title=None):
|
||||
"""
|
||||
Initializes the class with the real document
|
||||
"""
|
||||
self.access = access
|
||||
self.doc = doc # simpledoc; doc.doc = actual document
|
||||
self.title = title
|
||||
self.__columns = []
|
||||
self.__rows = []
|
||||
self.__sort_col = None
|
||||
self.__sort_reverse = False
|
||||
|
||||
def columns(self, *columns):
|
||||
self.__columns = list(copy.copy(columns))
|
||||
|
||||
def row(self, *data):
|
||||
self.__rows.append(copy.copy(data))
|
||||
|
||||
def sort(self, column_name, reverse=False):
|
||||
self.__sort_col = column_name
|
||||
self.__sort_reverse = reverse
|
||||
|
||||
def __sort(self):
|
||||
idx = self.__columns.index(self.__sort_col)
|
||||
if self.__sort_reverse:
|
||||
self.__rows.sort(lambda a, b: -cmp(a[idx],b[idx]))
|
||||
else:
|
||||
self.__rows.sort(lambda a, b: cmp(a[idx],b[idx]))
|
||||
|
||||
def write(self):
|
||||
if self.doc.doc.type == "standard":
|
||||
self.doc.start_table('simple','Table')
|
||||
columns = len(self.__columns)
|
||||
if self.title:
|
||||
self.doc.start_row()
|
||||
self.doc.start_cell('TableHead',columns)
|
||||
self.doc.start_paragraph('TableTitle')
|
||||
self.doc.write_text(_(self.title))
|
||||
self.doc.end_paragraph()
|
||||
self.doc.end_cell()
|
||||
self.doc.end_row()
|
||||
if self.__sort_col:
|
||||
self.__sort()
|
||||
self.doc.start_row()
|
||||
for col in self.__columns:
|
||||
self.doc.start_cell('TableNormalCell',1)
|
||||
self.doc.write_text(col,'TableTitle')
|
||||
self.doc.end_cell()
|
||||
self.doc.end_row()
|
||||
for row in self.__rows:
|
||||
self.doc.start_row()
|
||||
for col in row:
|
||||
self.doc.start_cell('TableNormalCell',1)
|
||||
self.doc.write_text(col,'Normal')
|
||||
self.doc.end_cell()
|
||||
self.doc.end_row()
|
||||
self.doc.end_table()
|
||||
self.doc.start_paragraph("Normal")
|
||||
self.doc.end_paragraph()
|
||||
elif self.doc.doc.type == "gtk":
|
||||
import gtk
|
||||
buffer = self.doc.doc.buffer
|
||||
text_view = self.doc.doc.text_view
|
||||
model_index = 0
|
||||
if self.__sort_col:
|
||||
sort_index = self.__columns.index(self.__sort_col)
|
||||
else:
|
||||
sort_index = 0
|
||||
treeview = gtk.TreeView()
|
||||
treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
|
||||
renderer = gtk.CellRendererText()
|
||||
types = []
|
||||
for col in self.__columns:
|
||||
types.append(type(col))
|
||||
column = gtk.TreeViewColumn(col,renderer,text=model_index)
|
||||
column.set_sort_column_id(model_index)
|
||||
treeview.append_column(column)
|
||||
#if model_index == sort_index:
|
||||
# FIXME: what to set here?
|
||||
model_index += 1
|
||||
frame = gtk.Frame()
|
||||
frame.add(treeview)
|
||||
model = gtk.ListStore(*types)
|
||||
treeview.set_model(model)
|
||||
iter = buffer.get_end_iter()
|
||||
anchor = buffer.create_child_anchor(iter)
|
||||
text_view.add_child_at_anchor(frame, anchor)
|
||||
for data in self.__rows:
|
||||
model.append(row=list(data))
|
||||
frame.show_all()
|
||||
self.doc.paragraph("")
|
@ -28,4 +28,5 @@ __version__ = "$Revision: 7972 $"
|
||||
|
||||
from _SimpleAccess import *
|
||||
from _SimpleDoc import *
|
||||
from _SimpleTable import *
|
||||
|
||||
|
@ -61,12 +61,11 @@ _WIDTH_IN_CHARS = 72
|
||||
|
||||
|
||||
class DisplayBuf:
|
||||
|
||||
def __init__(self, title, buffer):
|
||||
def __init__(self, title, document):
|
||||
g = gtk.glade.XML(const.GLADE_FILE,'scrollmsg')
|
||||
self.top = g.get_widget('scrollmsg')
|
||||
msg = g.get_widget('msg')
|
||||
msg.set_buffer(buffer)
|
||||
document.text_view = g.get_widget('msg')
|
||||
document.text_view.set_buffer(document.buffer)
|
||||
g.get_widget('close').connect('clicked', self.close)
|
||||
|
||||
def close(self, obj):
|
||||
@ -85,6 +84,7 @@ class TextBufDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc):
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def open(self, filename):
|
||||
self.type = "gtk"
|
||||
self.tag_table = gtk.TextTagTable()
|
||||
|
||||
sheet = self.get_style_sheet()
|
||||
@ -137,6 +137,7 @@ class TextBufDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc):
|
||||
|
||||
self.tag_table.add(tag)
|
||||
self.buffer = gtk.TextBuffer(self.tag_table)
|
||||
DisplayBuf('',self)
|
||||
return
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
@ -145,7 +146,7 @@ class TextBufDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc):
|
||||
#
|
||||
#--------------------------------------------------------------------
|
||||
def close(self):
|
||||
DisplayBuf('',self.buffer)
|
||||
pass
|
||||
|
||||
def get_usable_width(self):
|
||||
return _WIDTH_IN_CHARS
|
||||
|
@ -23,16 +23,12 @@
|
||||
Display a person's siblings in a report window
|
||||
"""
|
||||
|
||||
from Simple import SimpleAccess, SimpleDoc
|
||||
from Simple import SimpleAccess, SimpleDoc, SimpleTable
|
||||
from gen.lib import Person
|
||||
from gettext import gettext as _
|
||||
from PluginUtils import register_quick_report, relationship_class
|
||||
from ReportBase import CATEGORY_QR_PERSON
|
||||
|
||||
# define the formatting string once as a constant. Since this is reused
|
||||
|
||||
__FMT = "%-30s\t%-10s\t%-18s\t%s"
|
||||
|
||||
def run(database, document, person):
|
||||
"""
|
||||
Loops through the families that the person is a child in, and display
|
||||
@ -56,10 +52,8 @@ def run(database, document, person):
|
||||
# display the title
|
||||
sdoc.title(_("Siblings of %s") % sdb.name(person))
|
||||
sdoc.paragraph("")
|
||||
|
||||
# display the header of a table
|
||||
sdoc.header1(__FMT % (_("Sibling"), _("Gender"), _("Birth Date"),
|
||||
_("Type")))
|
||||
st = SimpleTable(sdb, sdoc)
|
||||
st.columns(_("Sibling"), _("Gender"), _("Birth Date"), _("Type"))
|
||||
|
||||
# grab our current id, so we can filter the active person out
|
||||
# of the data
|
||||
@ -68,10 +62,8 @@ def run(database, document, person):
|
||||
|
||||
# loop through each family in which the person is a child
|
||||
for family in sdb.child_in(person):
|
||||
|
||||
# loop through each child in the family
|
||||
for child in sdb.children(family):
|
||||
|
||||
# only display if this child is not the active person
|
||||
if sdb.gid(child) != gid:
|
||||
rel_str = rel_class.get_sibling_relationship_string(
|
||||
@ -80,11 +72,10 @@ def run(database, document, person):
|
||||
if rel_str == rel_str_m or rel_str == rel_str_f or \
|
||||
rel_str == rel_str_u :
|
||||
rel_str = ''
|
||||
sdoc.paragraph(__FMT % (
|
||||
sdb.name(child),
|
||||
sdb.gender(child),
|
||||
sdb.birth_date(child),
|
||||
rel_str))
|
||||
st.row(sdb.name(child), sdb.gender(child), sdb.birth_date(child),
|
||||
rel_str)
|
||||
#st.sort(_("Sibling"))
|
||||
st.write()
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user