2004-03-10 10:45:06 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-04-24 09:36:17 +05:30
|
|
|
# Copyright (C) 2000-2003 Donald N. Allingham
|
2010-02-04 02:04:35 +05:30
|
|
|
# Copyright (C) 2010 Benny Malengier
|
2010-03-28 06:25:09 +05:30
|
|
|
# Copyright (C) 2010 Nick Hall
|
2004-03-10 10:45:06 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2007-05-20 10:05:46 +05:30
|
|
|
"""
|
|
|
|
Handle the column ordering
|
|
|
|
"""
|
|
|
|
|
2004-03-10 10:45:06 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2007-05-20 10:05:46 +05:30
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2007-05-20 10:05:46 +05:30
|
|
|
import logging
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK modules
|
2004-03-10 10:45:06 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-19 01:37:09 +05:30
|
|
|
import gtk
|
2008-01-22 03:33:43 +05:30
|
|
|
import gobject
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2007-05-20 10:05:46 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-03-10 10:45:06 +05:30
|
|
|
import const
|
2006-04-24 03:44:28 +05:30
|
|
|
import ManagedWindow
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
|
|
|
|
2006-04-24 03:44:28 +05:30
|
|
|
|
2006-03-05 10:15:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# set up logging
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-05-20 10:05:46 +05:30
|
|
|
__LOG = logging.getLogger(".ColumnOrder")
|
2006-03-05 10:15:44 +05:30
|
|
|
|
2010-02-01 18:34:19 +05:30
|
|
|
class ColumnOrder(gtk.VBox):
|
2007-05-20 10:05:46 +05:30
|
|
|
"""
|
2010-02-01 18:34:19 +05:30
|
|
|
Column ordering selection widget
|
2007-05-20 10:05:46 +05:30
|
|
|
"""
|
2006-04-24 03:44:28 +05:30
|
|
|
|
2010-03-28 06:25:09 +05:30
|
|
|
def __init__(self, config, column_names, widths, on_apply, tree=False):
|
2007-05-20 10:05:46 +05:30
|
|
|
"""
|
2010-02-01 18:34:19 +05:30
|
|
|
Create the Column Ordering widget based on config
|
2006-04-24 03:44:28 +05:30
|
|
|
|
2010-02-01 18:34:19 +05:30
|
|
|
config: a configuration file with column data
|
|
|
|
column_names: translated names for the possible columns
|
2010-03-28 06:25:09 +05:30
|
|
|
widths: the widths of the visible columns
|
2010-02-01 18:34:19 +05:30
|
|
|
on_apply: function to run when apply is clicked
|
|
|
|
tree: are the columns for a treeview, if so, the first columns is not
|
|
|
|
changable
|
|
|
|
"""
|
|
|
|
gtk.VBox.__init__(self)
|
2006-04-24 03:44:28 +05:30
|
|
|
|
2010-02-01 18:34:19 +05:30
|
|
|
self.treeview = tree
|
|
|
|
self.colnames = column_names
|
|
|
|
self.config = config
|
|
|
|
self.on_apply = on_apply
|
|
|
|
|
2010-02-04 02:04:35 +05:30
|
|
|
self.pack_start(gtk.Label(' '), expand=False, fill=False)
|
|
|
|
|
2010-02-01 18:34:19 +05:30
|
|
|
self.startrow = 0
|
|
|
|
if self.treeview:
|
|
|
|
label = gtk.Label(
|
|
|
|
_('Tree View: first column "%s" cannot be changed') %
|
|
|
|
column_names[0])
|
|
|
|
self.startrow = 1
|
|
|
|
self.pack_start(label, expand=False, fill=False)
|
2010-02-04 02:04:35 +05:30
|
|
|
self.pack_start(gtk.Label(' '), expand=False, fill=False)
|
2010-02-01 18:34:19 +05:30
|
|
|
|
2010-02-04 02:04:35 +05:30
|
|
|
self.pack_start(gtk.Label(_('Drag and drop the columns to change'
|
|
|
|
' the order')), expand=False, fill=False)
|
|
|
|
self.pack_start(gtk.Label(' '), expand=False, fill=False)
|
2010-02-01 18:34:19 +05:30
|
|
|
hbox = gtk.HBox()
|
|
|
|
hbox.set_spacing(10)
|
2010-02-04 02:04:35 +05:30
|
|
|
hbox.pack_start(gtk.Label(' '))
|
2010-02-01 18:34:19 +05:30
|
|
|
scroll = gtk.ScrolledWindow()
|
2010-02-05 14:18:58 +05:30
|
|
|
scroll.set_size_request(300,300)
|
2010-02-01 18:34:19 +05:30
|
|
|
hbox.pack_start(scroll)
|
|
|
|
self.tree = gtk.TreeView()
|
|
|
|
self.tree.set_reorderable(True)
|
|
|
|
scroll.add(self.tree)
|
|
|
|
self.apply_button = gtk.Button(stock='gtk-apply')
|
|
|
|
btns = gtk.HButtonBox()
|
|
|
|
btns.set_layout(gtk.BUTTONBOX_END)
|
|
|
|
btns.pack_start(self.apply_button)
|
|
|
|
hbox.pack_start(btns, expand=False)
|
|
|
|
self.pack_start(hbox)
|
2004-03-10 10:45:06 +05:30
|
|
|
|
2008-01-22 03:33:43 +05:30
|
|
|
self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_INT, object)
|
2004-03-10 10:45:06 +05:30
|
|
|
|
|
|
|
self.tree.set_model(self.model)
|
|
|
|
|
|
|
|
checkbox = gtk.CellRendererToggle()
|
2007-07-08 08:57:06 +05:30
|
|
|
checkbox.connect('toggled', toggled, self.model)
|
2004-03-10 10:45:06 +05:30
|
|
|
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)
|
|
|
|
|
2010-02-01 18:34:19 +05:30
|
|
|
self.apply_button.connect('clicked', self.__on_apply)
|
|
|
|
|
|
|
|
#obtain the columns from config file
|
2010-03-28 04:30:41 +05:30
|
|
|
self.oldorder = self.config.get('columns.rank')
|
|
|
|
self.oldsize = self.config.get('columns.size')
|
2010-02-01 18:34:19 +05:30
|
|
|
self.oldvis = self.config.get('columns.visible')
|
|
|
|
colord = []
|
2010-03-28 06:25:09 +05:30
|
|
|
index = 0
|
2010-02-01 18:34:19 +05:30
|
|
|
for val, size in zip(self.oldorder, self.oldsize):
|
|
|
|
if val in self.oldvis:
|
2010-03-28 06:25:09 +05:30
|
|
|
size = widths[index]
|
|
|
|
index += 1
|
2010-02-01 18:34:19 +05:30
|
|
|
colord.append((1, val, size))
|
|
|
|
else:
|
|
|
|
colord.append((0, val, size))
|
|
|
|
for item in colord[self.startrow:]:
|
2004-08-11 09:12:38 +05:30
|
|
|
node = self.model.append()
|
2006-04-24 03:28:17 +05:30
|
|
|
self.model.set(node,
|
|
|
|
0, item[0],
|
|
|
|
1, column_names[item[1]],
|
|
|
|
2, item[1],
|
2010-02-01 18:34:19 +05:30
|
|
|
3, item[2])
|
2004-03-10 10:45:06 +05:30
|
|
|
|
2010-02-01 18:34:19 +05:30
|
|
|
def __on_apply(self, obj):
|
2007-05-20 10:05:46 +05:30
|
|
|
"""
|
|
|
|
called with the OK button is pressed
|
|
|
|
"""
|
2010-02-01 18:34:19 +05:30
|
|
|
neworder = []
|
|
|
|
newsize = []
|
|
|
|
newvis = []
|
|
|
|
if self.treeview:
|
|
|
|
#first row is fixed
|
|
|
|
neworder.append(self.oldorder[0])
|
|
|
|
newvis.append(self.oldvis[0])
|
|
|
|
newsize.append(self.oldsize[0])
|
|
|
|
for i in range(0, len(self.colnames[self.startrow:])):
|
2007-05-20 10:05:46 +05:30
|
|
|
node = self.model.get_iter((int(i), ))
|
2006-04-24 03:28:17 +05:30
|
|
|
enable = self.model.get_value(node, 0)
|
|
|
|
index = self.model.get_value(node, 2)
|
2010-02-01 18:34:19 +05:30
|
|
|
size = self.model.get_value(node, 3)
|
|
|
|
if enable:
|
|
|
|
newvis.append(index)
|
|
|
|
neworder.append(index)
|
|
|
|
newsize.append(size)
|
2010-03-28 04:30:41 +05:30
|
|
|
self.config.set('columns.rank', neworder)
|
|
|
|
self.config.set('columns.size', newsize)
|
2010-02-01 18:34:19 +05:30
|
|
|
self.config.set('columns.visible', newvis)
|
|
|
|
self.config.save()
|
|
|
|
if self.on_apply:
|
|
|
|
self.on_apply()
|
2004-03-10 10:45:06 +05:30
|
|
|
|
2007-07-08 08:57:06 +05:30
|
|
|
def toggled(cell, path, model):
|
2007-05-20 10:05:46 +05:30
|
|
|
"""
|
|
|
|
Called when the cell information is changed, updating the
|
|
|
|
data model so the that change occurs.
|
|
|
|
"""
|
|
|
|
node = model.get_iter((int(path), ))
|
|
|
|
value = not model.get_value(node, 0)
|
|
|
|
model.set(node, 0, value)
|