* src/PeopleModel.py: Column reordering/selection

* src/PeopleView.py: Column reordering/selection
* src/RelLib.py: Column reordering/selection
* src/gramps_main.py: Column reordering/selection
* src/gramps.glade: Column editor
* src/ColumnOrder.py: Column editor


svn: r2998
This commit is contained in:
Don Allingham 2004-03-10 05:15:06 +00:00
parent 2a95e95206
commit 5534cc0035
6 changed files with 342 additions and 74 deletions

91
src/ColumnOrder.py Normal file
View File

@ -0,0 +1,91 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2003 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
#
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gobject
import gtk.glade
import const
from gettext import gettext as _
column_names = [
_('Name'),
_('ID') ,
_('Gender'),
_('Birth Date'),
_('Birth Place'),
_('Death Date'),
_('Death Place'),
]
class ColumnOrder:
def __init__(self,arglist,callback):
self.glade = gtk.glade.XML(const.gladeFile,"columns","gramps")
self.top = self.glade.get_widget('columns')
self.tree = self.glade.get_widget('list')
self.arglist = arglist
self.callback = callback
self.model = gtk.ListStore(gobject.TYPE_BOOLEAN,
gobject.TYPE_STRING,
gobject.TYPE_INT)
self.tree.set_model(self.model)
checkbox = gtk.CellRendererToggle()
checkbox.connect('toggled', self.toggled, self.model)
renderer = gtk.CellRendererText()
column_n = gtk.TreeViewColumn(_('Display'), checkbox, active=0)
column_n.set_min_width(50)
self.tree.append_column(column_n)
column_n = gtk.TreeViewColumn(_('Column Name'), renderer, text=1)
column_n.set_min_width(225)
self.tree.append_column(column_n)
self.glade.get_widget('okbutton').connect('clicked',self.ok_clicked)
self.glade.get_widget('cancelbutton').connect('clicked',self.cancel_clicked)
for item in self.arglist:
iter = self.model.append()
self.model.set(iter,0,item[0],1,column_names[item[1]],2,item[1])
def ok_clicked(self,obj):
newlist = []
for i in range(0,len(self.arglist)):
iter = self.model.get_iter((int(i),))
newlist.append((self.model.get_value(iter,0),
self.model.get_value(iter,2)))
self.callback(newlist)
self.top.destroy()
def cancel_clicked(self,obj):
self.top.destroy()
def toggled(self, cell, path, model):
iter = model.get_iter((int(path),))
value = model.get_value(iter,0)
value = not value
model.set(iter,0,value)

View File

@ -15,10 +15,6 @@ def unique(mylist):
def callback(foo):
pass
class JunkIter(gtk.TreeIter):
def __init__(self):
pass
class PeopleModel(gtk.GenericTreeModel):
def __init__(self,db):
@ -29,9 +25,17 @@ class PeopleModel(gtk.GenericTreeModel):
self.connect('row-inserted',self.on_row_inserted)
self.connect('row-deleted',self.on_row_deleted)
self.fmap = [
self.column_name,
self.column_id,
self.column_gender,
self.column_birth_day,
self.column_birth_place,
self.column_death_day,
self.column_death_place,
]
def rebuild_data(self):
print "rebuild"
self.top_iter2path = {}
self.top_path2iter = {}
self.iter2path = {}
@ -116,26 +120,7 @@ class PeopleModel(gtk.GenericTreeModel):
else:
return ''
else:
data = self.db.person_map[str(iter)]
if col==0:
return str(data[2].get_name())
elif col == 1:
return str(data[0])
elif col == 2:
if data[1]:
return "male"
else:
return "female"
elif col == 3:
if data[5]:
return self.db.find_event_from_id(data[5]).get_date()
else:
return u""
elif col == 4:
if data[6]:
return self.db.find_event_from_id(data[6]).get_date()
else:
return u""
return self.fmap[col](self.db.person_map[str(iter)])
def on_iter_next(self, node):
'''returns the next node at this level of the tree'''
@ -181,3 +166,40 @@ class PeopleModel(gtk.GenericTreeModel):
if path:
return path[0]
return None
def column_name(self,data):
return unicode(data[2].get_name())
def column_id(self,data):
return unicode(data[0])
def column_gender(self,data):
return _GENDER[data[1]]
def column_birth_day(self,data):
if data[6]:
return self.db.find_event_from_id(data[6]).get_date()
else:
return u""
def column_death_day(self,data):
if data[5]:
return self.db.find_event_from_id(data[5]).get_date()
else:
return u""
def column_birth_place(self,data):
if data[6]:
place_id = self.db.find_event_from_id(data[5]).get_place_id()
if place_id:
return self.db.find_place_from_id(place_id).get_title()
return u""
def column_death_place(self,data):
if data[5]:
place_id = self.db.find_event_from_id(data[5]).get_place_id()
if place_id:
return self.db.find_place_from_id(place_id).get_title()
return u""
_GENDER = [ _('female'), _('male'), _('unknown') ]

View File

@ -47,6 +47,7 @@ _sel_mode = gtk.SELECTION_MULTIPLE
#-------------------------------------------------------------------------
import PeopleModel
import Filter
import ColumnOrder
#-------------------------------------------------------------------------
#
@ -63,39 +64,34 @@ class PeopleView:
self.person_tree = self.parent.gtop.get_widget("person_tree")
self.person_tree.set_rules_hint(gtk.TRUE)
renderer = gtk.CellRendererText()
self.renderer = gtk.CellRendererText()
column_n = gtk.TreeViewColumn(_('Name'), renderer,text=0)
column_n.set_resizable(gtk.TRUE)
column_n.set_clickable(gtk.TRUE)
column_n.set_min_width(225)
self.person_tree.append_column(column_n)
column_i = gtk.TreeViewColumn(_('ID'), renderer,text=1)
column_i.set_resizable(gtk.TRUE)
column_i.set_clickable(gtk.TRUE)
column_i.set_min_width(75)
self.person_tree.append_column(column_i)
column_g = gtk.TreeViewColumn(_('Gender'), renderer,text=2)
column_g.set_resizable(gtk.TRUE)
column_g.set_clickable(gtk.TRUE)
column_g.set_min_width(75)
self.person_tree.append_column(column_g)
column_b = gtk.TreeViewColumn(_('Birth Date'), renderer,text=3)
column_b.set_resizable(gtk.TRUE)
column_b.set_clickable(gtk.TRUE)
column_b.set_min_width(150)
self.person_tree.append_column(column_b)
column_d = gtk.TreeViewColumn(_('Death Date'), renderer,text=4)
column_d.set_resizable(gtk.TRUE)
column_d.set_clickable(gtk.TRUE)
column_d.set_min_width(150)
self.person_tree.append_column(column_d)
self.columns = []
self.build_columns()
self.build_tree()
def build_columns(self):
for column in self.columns:
self.person_tree.remove_column(column)
column = gtk.TreeViewColumn(_('Name'), self.renderer,text=0)
column.set_resizable(gtk.TRUE)
column.set_clickable(gtk.TRUE)
column.set_min_width(225)
self.person_tree.append_column(column)
self.columns = [column]
for pair in self.parent.db.get_column_order():
if not pair[0]:
continue
name = ColumnOrder.column_names[pair[1]]
column = gtk.TreeViewColumn(name, self.renderer, text=pair[1])
column.set_resizable(gtk.TRUE)
column.set_clickable(gtk.TRUE)
column.set_min_width(75)
self.columns.append(column)
self.person_tree.append_column(column)
def build_tree(self):
self.person_tree.set_model(None)
self.person_model = PeopleModel.PeopleModel(self.parent.db)
@ -128,6 +124,7 @@ class PeopleView:
self.person_tree.unselect()
def change_db(self,db):
self.build_columns()
self.build_tree()
def clear(self):

View File

@ -2294,6 +2294,7 @@ class GrampsDB:
self.media_map = None
self.event_map = None
self.surnames = None
self.metadata = None
def load(self,name,callback):
if self.person_map:
@ -3157,3 +3158,14 @@ class GrampsDB:
else:
map[idVal] = self.add_source(source)
return source
def set_column_order(self,list):
if self.metadata != None:
self.metadata['columns'] = list
def get_column_order(self):
if self.metadata == None:
return [(1,1),(1,2),(1,3),(0,4),(1,5),(0,6)]
else:
return self.metadata.get('columns',[(1,1),(1,2),(1,3),(0,4),(1,5),(0,6)])

View File

@ -51,7 +51,7 @@
<accelerator key="N" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1783">
<widget class="GtkImage" id="image1800">
<property name="visible">True</property>
<property name="stock">gtk-new</property>
<property name="icon_size">1</property>
@ -73,7 +73,7 @@
<accelerator key="O" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1784">
<widget class="GtkImage" id="image1801">
<property name="visible">True</property>
<property name="stock">gtk-open</property>
<property name="icon_size">1</property>
@ -107,7 +107,7 @@
<property name="use_underline">True</property>
<child internal-child="image">
<widget class="GtkImage" id="image1785">
<widget class="GtkImage" id="image1802">
<property name="visible">True</property>
<property name="stock">gtk-convert</property>
<property name="icon_size">1</property>
@ -128,7 +128,7 @@
<signal name="activate" handler="on_reload_plugins_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1786">
<widget class="GtkImage" id="image1803">
<property name="visible">True</property>
<property name="stock">gtk-refresh</property>
<property name="icon_size">1</property>
@ -156,7 +156,7 @@
<accelerator key="Q" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1787">
<widget class="GtkImage" id="image1804">
<property name="visible">True</property>
<property name="stock">gtk-quit</property>
<property name="icon_size">1</property>
@ -192,7 +192,7 @@
<accelerator key="Insert" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1788">
<widget class="GtkImage" id="image1805">
<property name="visible">True</property>
<property name="stock">gtk-add</property>
<property name="icon_size">1</property>
@ -215,7 +215,7 @@
<accelerator key="Delete" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1789">
<widget class="GtkImage" id="image1806">
<property name="visible">True</property>
<property name="stock">gtk-remove</property>
<property name="icon_size">1</property>
@ -253,7 +253,7 @@
<accelerator key="F" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1790">
<widget class="GtkImage" id="image1807">
<property name="visible">True</property>
<property name="stock">gtk-find</property>
<property name="icon_size">1</property>
@ -275,7 +275,7 @@
<accelerator key="M" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1791">
<widget class="GtkImage" id="image1808">
<property name="visible">True</property>
<property name="stock">gtk-convert</property>
<property name="icon_size">1</property>
@ -302,7 +302,7 @@
<signal name="activate" handler="on_preferences1_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1792">
<widget class="GtkImage" id="image1809">
<property name="visible">True</property>
<property name="stock">gtk-preferences</property>
<property name="icon_size">1</property>
@ -315,6 +315,15 @@
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="column_order">
<property name="visible">True</property>
<property name="label" translatable="yes">_Column order</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_column_order_activate" last_modification_time="Wed, 10 Mar 2004 04:36:07 GMT"/>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="default_person1">
<property name="visible">True</property>
@ -323,7 +332,7 @@
<signal name="activate" handler="on_default_person_activate" last_modification_time="Sat, 16 Aug 2003 01:58:26 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image1793">
<widget class="GtkImage" id="image1810">
<property name="visible">True</property>
<property name="stock">gtk-home</property>
<property name="icon_size">1</property>
@ -409,7 +418,7 @@
<accelerator key="D" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1794">
<widget class="GtkImage" id="image1811">
<property name="visible">True</property>
<property name="stock">gtk-index</property>
<property name="icon_size">1</property>
@ -431,7 +440,7 @@
<accelerator key="B" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1795">
<widget class="GtkImage" id="image1812">
<property name="visible">True</property>
<property name="stock">gnome-stock-book-open</property>
<property name="icon_size">1</property>
@ -504,7 +513,7 @@
<accelerator key="F1" modifiers="0" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1796">
<widget class="GtkImage" id="image1813">
<property name="visible">True</property>
<property name="stock">gtk-help</property>
<property name="icon_size">1</property>
@ -525,7 +534,7 @@
<signal name="activate" handler="on_faq_activate" last_modification_time="Wed, 26 Nov 2003 17:59:23 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image1797">
<widget class="GtkImage" id="image1814">
<property name="visible">True</property>
<property name="stock">gnome-stock-book-open</property>
<property name="icon_size">1</property>
@ -552,7 +561,7 @@
<signal name="activate" handler="on_gramps_home_page_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1798">
<widget class="GtkImage" id="image1815">
<property name="visible">True</property>
<property name="stock">gtk-jump-to</property>
<property name="icon_size">1</property>
@ -573,7 +582,7 @@
<signal name="activate" handler="on_gramps_mailing_lists_activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image1799">
<widget class="GtkImage" id="image1816">
<property name="visible">True</property>
<property name="stock">gnome-stock-mail</property>
<property name="icon_size">1</property>
@ -627,7 +636,7 @@
<signal name="activate" handler="on_about_activate" last_modification_time="Tue, 01 Apr 2003 03:44:24 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image1800">
<widget class="GtkImage" id="image1817">
<property name="visible">True</property>
<property name="stock">gnome-stock-about</property>
<property name="icon_size">1</property>
@ -8076,4 +8085,132 @@
</child>
</widget>
<widget class="GtkDialog" id="columns">
<property name="visible">True</property>
<property name="title" translatable="yes"></property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="icon">gramps.png</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox15">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area15">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="cancelbutton">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="okbutton">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table46">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">6</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow77">
<property name="width_request">400</property>
<property name="height_request">300</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="list">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">False</property>
<property name="reorderable">True</property>
<property name="enable_search">True</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label395">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Select columns&lt;/b&gt;</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">6</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -260,6 +260,7 @@ class Gramps:
self.child_windows = {}
self.gtop.signal_autoconnect({
"on_column_order_activate": self.column_order,
"on_back_clicked" : self.back_clicked,
"on_back_pressed" : self.back_pressed,
"on_fwd_clicked" : self.fwd_clicked,
@ -347,6 +348,14 @@ class Gramps:
self.topWindow.show()
self.enable_toolbar(self.use_toolbar)
def set_column_order(self,list):
self.db.set_column_order(list)
self.people_view.build_columns()
def column_order(self,obj):
import ColumnOrder
ColumnOrder.ColumnOrder(self.db.get_column_order(),self.set_column_order)
def clear_history(self):
self.history = []
self.mhistory = []