diff --git a/src/ColumnOrder.py b/src/ColumnOrder.py new file mode 100644 index 000000000..0eee0045d --- /dev/null +++ b/src/ColumnOrder.py @@ -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) diff --git a/src/PeopleModel.py b/src/PeopleModel.py index edc5bac0b..09a2f2371 100644 --- a/src/PeopleModel.py +++ b/src/PeopleModel.py @@ -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): @@ -26,12 +22,20 @@ class PeopleModel(gtk.GenericTreeModel): gtk.GenericTreeModel.__init__(self) self.db = db self.rebuild_data() - + 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') ] diff --git a/src/PeopleView.py b/src/PeopleView.py index 1e4b71d96..6c915b4ed 100644 --- a/src/PeopleView.py +++ b/src/PeopleView.py @@ -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() - - 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) + self.renderer = gtk.CellRendererText() - 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): diff --git a/src/RelLib.py b/src/RelLib.py index 10258c1ac..c8f181c0f 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -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)]) + diff --git a/src/gramps.glade b/src/gramps.glade index fb3567db7..52c07c717 100644 --- a/src/gramps.glade +++ b/src/gramps.glade @@ -51,7 +51,7 @@ - + True gtk-new 1 @@ -73,7 +73,7 @@ - + True gtk-open 1 @@ -107,7 +107,7 @@ True - + True gtk-convert 1 @@ -128,7 +128,7 @@ - + True gtk-refresh 1 @@ -156,7 +156,7 @@ - + True gtk-quit 1 @@ -192,7 +192,7 @@ - + True gtk-add 1 @@ -215,7 +215,7 @@ - + True gtk-remove 1 @@ -253,7 +253,7 @@ - + True gtk-find 1 @@ -275,7 +275,7 @@ - + True gtk-convert 1 @@ -302,7 +302,7 @@ - + True gtk-preferences 1 @@ -315,6 +315,15 @@ + + + True + _Column order + True + + + + True @@ -323,7 +332,7 @@ - + True gtk-home 1 @@ -409,7 +418,7 @@ - + True gtk-index 1 @@ -431,7 +440,7 @@ - + True gnome-stock-book-open 1 @@ -504,7 +513,7 @@ - + True gtk-help 1 @@ -525,7 +534,7 @@ - + True gnome-stock-book-open 1 @@ -552,7 +561,7 @@ - + True gtk-jump-to 1 @@ -573,7 +582,7 @@ - + True gnome-stock-mail 1 @@ -627,7 +636,7 @@ - + True gnome-stock-about 1 @@ -8076,4 +8085,132 @@ + + True + + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + gramps.png + False + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + 4 + 2 + False + 6 + 6 + + + + 400 + 300 + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + True + True + + + + + 1 + 2 + 1 + 4 + + + + + + True + <b>Select columns</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 2 + 0 + 1 + fill + + + + + + 6 + True + True + + + + + + diff --git a/src/gramps_main.py b/src/gramps_main.py index c145d1a08..84e159a5a 100755 --- a/src/gramps_main.py +++ b/src/gramps_main.py @@ -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 = []