2002-10-25 10:22:51 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2003-06-03 08:24:56 +05:30
|
|
|
# Copyright (C) 2000 Donald N. Allingham
|
2002-10-25 10:22:51 +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.
|
|
|
|
#
|
2007-07-12 09:54:44 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2002-10-25 10:22:51 +05:30
|
|
|
# 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-07-12 09:54:44 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Provide the basic functionality for a list view
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
|
|
|
|
2006-07-05 05:08:51 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-25 10:22:51 +05:30
|
|
|
import gtk
|
2006-03-19 12:19:03 +05:30
|
|
|
import pango
|
2006-03-29 23:26:11 +05:30
|
|
|
import const
|
2002-10-25 10:22:51 +05:30
|
|
|
|
2006-07-05 05:08:51 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-04-28 10:18:30 +05:30
|
|
|
TEXT = 0
|
|
|
|
TOGGLE = 1
|
|
|
|
COMBO = 2
|
2006-03-29 23:26:11 +05:30
|
|
|
IMAGE = 3
|
2006-06-22 05:39:20 +05:30
|
|
|
INTEGER = 4
|
2010-08-17 23:13:44 +05:30
|
|
|
COLOR = 5
|
2005-04-28 10:18:30 +05:30
|
|
|
|
|
|
|
NOSORT = -1
|
2006-07-05 05:08:51 +05:30
|
|
|
|
2003-02-24 10:21:57 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ListModel
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class ListModel(object):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2009-11-13 03:23:47 +05:30
|
|
|
Simple model for lists in smaller dialogs (not views).
|
2010-08-25 05:13:42 +05:30
|
|
|
|
|
|
|
tree: A Gtk TreeView object.
|
|
|
|
dlist: A list of column definitions. Each column definition is a tuple
|
|
|
|
consisting of the following elements:
|
|
|
|
(name, sort_id, width, type, editable, callback)
|
|
|
|
name: The column name. If the name is an empty string then the
|
|
|
|
column is hidden. Use a single space for the column to be
|
|
|
|
displayed but have no heading.
|
|
|
|
sort_id: The column id to used to sort the column. Use the NOSORT
|
|
|
|
constant to disable sorting on the column.
|
|
|
|
width: The column width.
|
|
|
|
type: An optional column type. One of the constants TEXT, TOGGLE,
|
|
|
|
COMBO, IMAGE, INTEGER or COLOR. Default = TEXT.
|
|
|
|
editable: An optional boolean. True if the column is editable.
|
|
|
|
Used with TEXT, INTEGER, COMBO and TOGGLE columns.
|
|
|
|
Default = False.
|
|
|
|
callback: An optional callback to be executed when the column is
|
|
|
|
edited. Used with TEXT, INTEGER, COMBO and TOGGLE columns.
|
|
|
|
Default = None.
|
|
|
|
select_func: Function called when the TreeView selection changes.
|
|
|
|
event_func: Function called when the user double-clicks on a row.
|
|
|
|
mode: Selection mode for TreeView. See Gtk documentation.
|
2010-11-30 08:39:19 +05:30
|
|
|
list_mode: "list" or "tree"
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2005-04-28 10:18:30 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def __init__(self, tree, dlist, select_func=None, event_func=None,
|
2010-11-30 08:39:19 +05:30
|
|
|
mode=gtk.SELECTION_SINGLE, list_mode="list"):
|
2007-07-12 09:54:44 +05:30
|
|
|
|
2002-10-25 10:22:51 +05:30
|
|
|
self.tree = tree
|
2006-03-19 12:19:03 +05:30
|
|
|
self.tree.set_fixed_height_mode(True)
|
2005-04-23 21:23:30 +05:30
|
|
|
self.mylist = []
|
2005-04-24 09:09:07 +05:30
|
|
|
self.data_index = 0
|
2007-07-12 09:54:44 +05:30
|
|
|
self.sel_iter = None
|
2010-11-30 08:39:19 +05:30
|
|
|
self.list_mode = list_mode # "list", or "tree"
|
2007-07-12 09:54:44 +05:30
|
|
|
|
|
|
|
for info in dlist:
|
2010-11-30 08:39:19 +05:30
|
|
|
col_type = TEXT
|
|
|
|
if isinstance(info, (list, tuple)):
|
|
|
|
if len(info) > 3:
|
|
|
|
col_type = info[3]
|
|
|
|
elif isinstance(info, dict):
|
|
|
|
col_type = info.get("type", TEXT)
|
|
|
|
# Now, add columns:
|
|
|
|
if col_type == TOGGLE:
|
|
|
|
self.mylist.append(bool)
|
|
|
|
elif col_type == IMAGE:
|
|
|
|
self.mylist.append(gtk.gdk.Pixbuf)
|
|
|
|
elif col_type == INTEGER:
|
|
|
|
self.mylist.append(int)
|
|
|
|
elif col_type == COLOR:
|
|
|
|
self.mylist.append(str)
|
2005-04-23 21:23:30 +05:30
|
|
|
else:
|
2006-03-19 12:19:03 +05:30
|
|
|
self.mylist.append(str)
|
2005-04-24 09:09:07 +05:30
|
|
|
self.data_index += 1
|
2006-03-19 12:19:03 +05:30
|
|
|
self.mylist.append(object)
|
2005-05-01 05:15:17 +05:30
|
|
|
|
|
|
|
self.function = {}
|
2005-02-24 05:55:34 +05:30
|
|
|
self.tree.set_rules_hint(True)
|
2003-05-30 05:57:59 +05:30
|
|
|
self.model = None
|
2003-06-11 08:24:57 +05:30
|
|
|
self.selection = None
|
2002-12-29 11:14:35 +05:30
|
|
|
self.mode = mode
|
2003-06-03 08:24:56 +05:30
|
|
|
self.new_model()
|
2003-01-06 10:44:49 +05:30
|
|
|
self.count = 0
|
2003-05-30 05:57:59 +05:30
|
|
|
self.cid = None
|
2002-12-06 09:07:31 +05:30
|
|
|
self.cids = []
|
2003-10-14 09:52:24 +05:30
|
|
|
self.idmap = {}
|
2005-04-19 09:50:17 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
self.__build_columns(dlist)
|
2007-07-28 07:53:43 +05:30
|
|
|
self.connect_model()
|
2007-07-12 09:54:44 +05:30
|
|
|
|
|
|
|
if select_func:
|
|
|
|
self.selection.connect('changed', select_func)
|
|
|
|
if event_func:
|
|
|
|
self.double_click = event_func
|
|
|
|
self.tree.connect('event', self.__button_press)
|
|
|
|
|
2008-02-21 10:28:56 +05:30
|
|
|
def __build_image_column(self, cnum, name, renderer, column):
|
|
|
|
renderer = gtk.CellRendererPixbuf()
|
|
|
|
column = gtk.TreeViewColumn(name[0], renderer)
|
|
|
|
column.add_attribute(renderer, 'pixbuf', cnum)
|
|
|
|
renderer.set_property('height', const.THUMBSCALE / 2)
|
|
|
|
return renderer, column
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def __build_columns(self, dlist):
|
|
|
|
"""
|
|
|
|
Builds the columns based of the data in dlist
|
|
|
|
"""
|
2002-10-25 10:22:51 +05:30
|
|
|
cnum = 0
|
2007-07-12 09:54:44 +05:30
|
|
|
|
2010-11-30 08:39:19 +05:30
|
|
|
for item in dlist:
|
|
|
|
visible_col = None
|
|
|
|
if isinstance(item, (list, tuple)):
|
|
|
|
if not item[2]:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
# [name, sort_id, width, [type, [editable, [callback]]]
|
|
|
|
name = item
|
|
|
|
elif isinstance(item, dict):
|
|
|
|
# valid fields: name, sort_id, width, type, editable, callback, visible_col
|
|
|
|
name = [item.get("name", " "), item.get("sort_id", NOSORT), item.get("width", 10),
|
|
|
|
item.get("type", TEXT), item.get("editable", False), item.get("callback", None)]
|
|
|
|
visible_col = item.get("visible_col", None)
|
2005-04-28 10:18:30 +05:30
|
|
|
if len(name) == 3:
|
2007-07-12 09:54:44 +05:30
|
|
|
name = (name[0], name[1], name[2], TEXT, False, None)
|
2005-05-01 05:15:17 +05:30
|
|
|
elif len(name) == 4:
|
2007-07-12 09:54:44 +05:30
|
|
|
name = (name[0], name[1], name[2], name[3], False, None)
|
2010-08-25 05:13:42 +05:30
|
|
|
elif len(name) == 5:
|
|
|
|
name = (name[0], name[1], name[2], name[3], name[4], None)
|
2005-05-01 05:15:17 +05:30
|
|
|
|
2005-04-28 10:18:30 +05:30
|
|
|
if name[0] and name[3] == TOGGLE:
|
2005-04-23 21:23:30 +05:30
|
|
|
renderer = gtk.CellRendererToggle()
|
2010-11-30 08:39:19 +05:30
|
|
|
if visible_col is not None:
|
|
|
|
column = gtk.TreeViewColumn(name[0], renderer, visible=visible_col)
|
|
|
|
else:
|
|
|
|
column = gtk.TreeViewColumn(name[0], renderer)
|
2007-07-12 09:54:44 +05:30
|
|
|
column.add_attribute(renderer, 'active', cnum)
|
2010-08-25 05:13:42 +05:30
|
|
|
if name[4]:
|
|
|
|
renderer.set_property('activatable', True)
|
|
|
|
renderer.connect('toggled', self.__toggled_cb, cnum)
|
|
|
|
if name[5]:
|
|
|
|
self.function[cnum] = name[5]
|
|
|
|
else:
|
|
|
|
renderer.set_property('activatable', False)
|
2006-03-29 23:26:11 +05:30
|
|
|
elif name[0] and name[3] == IMAGE:
|
2008-02-21 10:28:56 +05:30
|
|
|
renderer, column = self.__build_image_column(cnum, name, renderer, column)
|
2010-08-17 23:13:44 +05:30
|
|
|
elif name[0] and name[3] == COLOR:
|
|
|
|
renderer = gtk.CellRendererText()
|
2010-11-30 08:39:19 +05:30
|
|
|
if visible_col is not None:
|
|
|
|
column = gtk.TreeViewColumn(name[0], renderer, background=cnum,
|
|
|
|
visible=visible_col)
|
|
|
|
else:
|
|
|
|
column = gtk.TreeViewColumn(name[0], renderer, background=cnum)
|
2005-04-19 09:50:17 +05:30
|
|
|
else:
|
|
|
|
renderer = gtk.CellRendererText()
|
2005-04-23 21:23:30 +05:30
|
|
|
renderer.set_fixed_height_from_font(True)
|
2006-03-19 12:19:03 +05:30
|
|
|
renderer.set_property('ellipsize', pango.ELLIPSIZE_END)
|
2010-08-25 05:13:42 +05:30
|
|
|
if name[4]:
|
2007-07-12 09:54:44 +05:30
|
|
|
renderer.set_property('editable', True)
|
|
|
|
renderer.connect('edited', self.__edited_cb, cnum)
|
2010-08-25 05:13:42 +05:30
|
|
|
if name[5]:
|
|
|
|
self.function[cnum] = name[5]
|
2005-05-01 05:15:17 +05:30
|
|
|
else:
|
2007-07-12 09:54:44 +05:30
|
|
|
renderer.set_property('editable', False)
|
2010-11-30 08:39:19 +05:30
|
|
|
if visible_col is not None:
|
|
|
|
column = gtk.TreeViewColumn(name[0], renderer, text=cnum, visible=visible_col)
|
|
|
|
else:
|
|
|
|
column = gtk.TreeViewColumn(name[0], renderer, text=cnum)
|
2005-04-23 21:23:30 +05:30
|
|
|
column.set_reorderable(True)
|
2002-11-10 06:08:58 +05:30
|
|
|
column.set_min_width(name[2])
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
if name[0] == '':
|
2005-02-24 05:55:34 +05:30
|
|
|
column.set_visible(False)
|
2002-11-03 02:49:58 +05:30
|
|
|
else:
|
2005-02-24 05:55:34 +05:30
|
|
|
column.set_resizable(True)
|
2002-11-25 10:00:36 +05:30
|
|
|
if name[1] == -1:
|
2005-02-24 05:55:34 +05:30
|
|
|
column.set_clickable(False)
|
2002-11-25 10:00:36 +05:30
|
|
|
else:
|
2005-02-24 05:55:34 +05:30
|
|
|
column.set_clickable(True)
|
2011-02-15 16:42:57 +05:30
|
|
|
column.set_sort_column_id(name[1])
|
2002-12-06 09:07:31 +05:30
|
|
|
|
2006-03-19 12:19:03 +05:30
|
|
|
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
|
|
|
column.set_fixed_width(name[2])
|
|
|
|
|
2005-04-19 09:50:17 +05:30
|
|
|
cnum += 1
|
2002-12-06 09:07:31 +05:30
|
|
|
self.cids.append(name[1])
|
2003-01-06 10:44:49 +05:30
|
|
|
if name[0] != '':
|
2002-12-06 09:07:31 +05:30
|
|
|
self.tree.append_column(column)
|
2002-12-11 10:48:47 +05:30
|
|
|
|
2010-08-25 05:13:42 +05:30
|
|
|
def __toggled_cb(self, obj, path, col):
|
|
|
|
"""
|
|
|
|
Callback executed when the checkbox of the cell renderer is clicked
|
|
|
|
"""
|
|
|
|
new_value = not self.model[path][col]
|
|
|
|
self.model[path][col] = new_value
|
|
|
|
if col in self.function:
|
|
|
|
self.function[col](int(path), new_value)
|
2010-08-14 05:05:53 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def __edited_cb(self, cell, path, new_text, col):
|
|
|
|
"""
|
|
|
|
Callback executed when the text of the cell renderer has changed
|
|
|
|
"""
|
2005-04-19 09:50:17 +05:30
|
|
|
self.model[path][col] = new_text
|
2008-07-17 23:40:32 +05:30
|
|
|
if col in self.function:
|
2007-07-12 09:54:44 +05:30
|
|
|
self.function[col](int(path), new_text)
|
2005-04-19 09:50:17 +05:30
|
|
|
|
2003-01-08 10:28:00 +05:30
|
|
|
def unselect(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Remove the selection from the view
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
2003-01-08 10:28:00 +05:30
|
|
|
self.selection.unselect_all()
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def set_reorderable(self, order):
|
|
|
|
"""
|
|
|
|
Enables or disables reordering of data
|
|
|
|
"""
|
2003-01-02 10:01:52 +05:30
|
|
|
self.tree.set_reorderable(order)
|
|
|
|
|
2002-11-17 10:36:43 +05:30
|
|
|
def new_model(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a new model instance
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
2003-05-30 05:57:59 +05:30
|
|
|
if self.model:
|
|
|
|
self.cid = self.model.get_sort_column_id()
|
2003-06-11 08:24:57 +05:30
|
|
|
del self.model
|
|
|
|
del self.selection
|
2003-01-06 10:44:49 +05:30
|
|
|
self.count = 0
|
2010-11-30 08:39:19 +05:30
|
|
|
if self.list_mode == "list":
|
|
|
|
self.model = gtk.ListStore(*self.mylist)
|
|
|
|
elif self.list_mode == "tree":
|
|
|
|
self.model = gtk.TreeStore(*self.mylist)
|
2003-06-03 08:24:56 +05:30
|
|
|
self.selection = self.tree.get_selection()
|
|
|
|
self.selection.set_mode(self.mode)
|
|
|
|
self.sel_iter = None
|
|
|
|
|
2007-07-28 07:53:43 +05:30
|
|
|
def connect_model(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
|
|
|
Connects the model to the associated tree
|
|
|
|
"""
|
2002-11-17 10:36:43 +05:30
|
|
|
self.tree.set_model(self.model)
|
2003-06-03 08:24:56 +05:30
|
|
|
if self.sel_iter:
|
|
|
|
self.selection.select_iter(self.sel_iter)
|
2003-10-21 08:37:19 +05:30
|
|
|
|
|
|
|
# if the sort column has not been defined (val[0] == -2), set
|
|
|
|
# the sort column to the first column
|
|
|
|
|
|
|
|
val = self.model.get_sort_column_id()
|
|
|
|
if val[0] == -2 and self.cid:
|
2007-07-12 09:54:44 +05:30
|
|
|
self.model.set_sort_column_id(self.cid[0], self.cid[1])
|
2002-12-06 09:07:31 +05:30
|
|
|
self.sort()
|
2002-12-04 10:28:07 +05:30
|
|
|
|
|
|
|
def sort(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
|
|
|
Sorts the current view
|
|
|
|
"""
|
2002-12-04 10:28:07 +05:30
|
|
|
val = self.model.get_sort_column_id()
|
2002-12-06 09:07:31 +05:30
|
|
|
col = val[0]
|
2003-01-06 10:44:49 +05:30
|
|
|
if col < 0:
|
|
|
|
return
|
2002-12-06 09:07:31 +05:30
|
|
|
if col > 0:
|
2007-07-12 09:54:44 +05:30
|
|
|
self.model.set_sort_column_id(col, val[1])
|
2002-12-06 09:07:31 +05:30
|
|
|
else:
|
2007-07-12 09:54:44 +05:30
|
|
|
self.model.set_sort_column_id(self.cids[0], val[1])
|
2002-12-04 10:28:07 +05:30
|
|
|
self.model.sort_column_changed()
|
2002-11-17 10:36:43 +05:30
|
|
|
|
2002-11-14 11:01:42 +05:30
|
|
|
def get_selected(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the selected items
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
2002-11-14 11:01:42 +05:30
|
|
|
return self.selection.get_selected()
|
2002-11-10 06:08:58 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def get_row_at(self, xpos, ypos):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the row at the specified (x,y) coordinates
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
|
|
|
path = self.tree.get_path_at_pos(xpos, ypos)
|
2008-06-16 20:31:46 +05:30
|
|
|
if path is None:
|
2003-01-06 10:44:49 +05:30
|
|
|
return self.count -1
|
|
|
|
else:
|
|
|
|
return path[0][0]-1
|
|
|
|
|
|
|
|
def get_selected_row(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Get the selected row number
|
2007-07-12 09:54:44 +05:30
|
|
|
"""
|
2004-08-20 17:41:56 +05:30
|
|
|
store, node = self.selection.get_selected()
|
|
|
|
if node:
|
|
|
|
rows = store.get_path(node)
|
2003-01-06 10:44:49 +05:30
|
|
|
return rows[0]
|
|
|
|
else:
|
|
|
|
return -1
|
|
|
|
|
2002-12-29 11:14:35 +05:30
|
|
|
def get_selected_objects(self):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the list of selected objects in the list
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2003-01-06 10:44:49 +05:30
|
|
|
if self.count == 0:
|
|
|
|
return []
|
|
|
|
elif self.mode == gtk.SELECTION_SINGLE:
|
2007-07-12 09:54:44 +05:30
|
|
|
store, node = self.selection.get_selected()
|
2004-08-20 17:41:56 +05:30
|
|
|
if node:
|
2007-07-12 09:54:44 +05:30
|
|
|
return [self.model.get_value(node, self.data_index)]
|
2002-12-29 11:14:35 +05:30
|
|
|
else:
|
|
|
|
return []
|
|
|
|
else:
|
|
|
|
mlist = []
|
2007-09-17 00:15:57 +05:30
|
|
|
self.selection.selected_foreach(self.__build_select_list, mlist)
|
2002-12-29 11:14:35 +05:30
|
|
|
return mlist
|
|
|
|
|
2003-01-06 10:44:49 +05:30
|
|
|
def get_icon(self):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2009-08-12 15:29:41 +05:30
|
|
|
Return an icon to be used for Drag and drop.
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2003-01-06 10:44:49 +05:30
|
|
|
if self.mode == gtk.SELECTION_SINGLE:
|
2007-07-12 09:54:44 +05:30
|
|
|
store, node = self.selection.get_selected()
|
2004-08-20 17:41:56 +05:30
|
|
|
path = self.model.get_path(node)
|
2003-01-06 10:44:49 +05:30
|
|
|
else:
|
|
|
|
mlist = []
|
2007-09-17 00:15:57 +05:30
|
|
|
self.selection.selected_foreach(self.__build_select_list, mlist)
|
2003-01-06 10:44:49 +05:30
|
|
|
path = self.model.get_path(mlist[0])
|
|
|
|
return self.tree.create_row_drag_icon(path)
|
|
|
|
|
2007-09-17 00:15:57 +05:30
|
|
|
def __build_select_list(self, store, path, node, dlist):
|
|
|
|
"""
|
2009-08-12 15:29:41 +05:30
|
|
|
GTK callback function for walking a select list
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2007-07-12 09:54:44 +05:30
|
|
|
dlist.append(self.model.get_value(node, self.data_index))
|
2002-12-29 11:14:35 +05:30
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
def clear(self):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
|
|
|
Clears all data in the list
|
|
|
|
"""
|
2003-01-06 10:44:49 +05:30
|
|
|
self.count = 0
|
2002-11-03 02:49:58 +05:30
|
|
|
self.model.clear()
|
2002-11-14 11:01:42 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def remove(self, node):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Remove the item from the model
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2004-08-20 17:41:56 +05:30
|
|
|
self.model.remove(node)
|
2005-04-19 09:50:17 +05:30
|
|
|
self.count -= 1
|
2002-11-15 09:19:39 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def get_row(self, node):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the row associated with the selected node
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2004-08-20 17:41:56 +05:30
|
|
|
row = self.model.get_path(node)
|
2002-11-21 10:11:40 +05:30
|
|
|
return row[0]
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def select_row(self, row):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
|
|
|
Selects the item based on path
|
|
|
|
"""
|
2008-03-05 03:58:59 +05:30
|
|
|
self.selection.select_path(row)
|
2003-06-11 08:24:57 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def select_iter(self, node):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
|
|
|
Selects the item based on iter
|
|
|
|
"""
|
2004-08-20 17:41:56 +05:30
|
|
|
self.selection.select_iter(node)
|
2002-11-21 10:11:40 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def get_object(self, node):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return the object associated with the node. This is controlled
|
2007-09-17 00:15:57 +05:30
|
|
|
by extracting the data from the associated data index
|
|
|
|
"""
|
2007-07-12 09:54:44 +05:30
|
|
|
return self.model.get_value(node, self.data_index)
|
2002-11-03 02:49:58 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def insert(self, position, data, info=None, select=0):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
|
|
|
Inserts the item at the specified position in the model.
|
|
|
|
"""
|
2005-04-19 09:50:17 +05:30
|
|
|
self.count += 1
|
2004-08-20 17:41:56 +05:30
|
|
|
node = self.model.insert(position)
|
2002-10-25 10:22:51 +05:30
|
|
|
col = 0
|
2004-08-20 17:41:56 +05:30
|
|
|
for obj in data:
|
2007-07-12 09:54:44 +05:30
|
|
|
self.model.set_value(node, col, obj)
|
2005-04-19 09:50:17 +05:30
|
|
|
col += 1
|
2007-07-12 09:54:44 +05:30
|
|
|
self.model.set_value(node, col, info)
|
2003-10-14 09:52:24 +05:30
|
|
|
if info:
|
2004-08-20 17:41:56 +05:30
|
|
|
self.idmap[str(info)] = node
|
2002-11-25 10:00:36 +05:30
|
|
|
if select:
|
2004-08-20 17:41:56 +05:30
|
|
|
self.selection.select_iter(node)
|
|
|
|
return node
|
2003-06-03 08:24:56 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def get_data(self, node, cols):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return a list of data from the model associated with the node
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2007-07-12 09:54:44 +05:30
|
|
|
return [ self.model.get_value(node, c) for c in cols ]
|
2003-06-03 08:24:56 +05:30
|
|
|
|
2010-11-30 08:39:19 +05:30
|
|
|
def add(self, data, info=None, select=0, node=None):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Add the data to the model at the end of the model
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2005-04-19 09:50:17 +05:30
|
|
|
self.count += 1
|
2010-11-30 08:39:19 +05:30
|
|
|
need_to_set = True
|
|
|
|
# Create the node:
|
|
|
|
if self.list_mode == "list":
|
|
|
|
node = self.model.append()
|
|
|
|
elif self.list_mode == "tree":
|
|
|
|
if node is None: # new node
|
|
|
|
node = self.model.append(None, data + [None])
|
|
|
|
need_to_set = False
|
|
|
|
else: # use a previous node, passed in
|
|
|
|
node = self.model.append(node)
|
|
|
|
# Add data:
|
|
|
|
if need_to_set:
|
|
|
|
col = 0
|
|
|
|
for obj in data:
|
|
|
|
self.model.set_value(node, col, obj)
|
|
|
|
col += 1
|
|
|
|
self.model.set_value(node, col, info)
|
|
|
|
# Set info and select:
|
2009-07-28 23:45:49 +05:30
|
|
|
if info is not None:
|
2004-08-20 17:41:56 +05:30
|
|
|
self.idmap[str(info)] = node
|
2003-06-02 19:04:18 +05:30
|
|
|
if select:
|
2004-08-20 17:41:56 +05:30
|
|
|
self.sel_iter = node
|
2003-07-31 17:28:08 +05:30
|
|
|
self.selection.select_iter(self.sel_iter)
|
2010-11-30 08:39:19 +05:30
|
|
|
# Return created node
|
2004-08-20 17:41:56 +05:30
|
|
|
return node
|
2003-06-03 08:24:56 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def set(self, node, data, info=None, select=0):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Change the data associated with the specific node. It does not
|
2007-09-17 00:15:57 +05:30
|
|
|
add any data, just alters an existing row.
|
|
|
|
"""
|
2003-06-16 10:27:25 +05:30
|
|
|
col = 0
|
2004-08-20 17:41:56 +05:30
|
|
|
for obj in data:
|
2007-07-12 09:54:44 +05:30
|
|
|
self.model.set_value(node, col, obj)
|
2005-04-19 09:50:17 +05:30
|
|
|
col += 1
|
2007-07-12 09:54:44 +05:30
|
|
|
self.model.set_value(node, col, info)
|
2003-10-14 09:52:24 +05:30
|
|
|
if info:
|
2004-08-20 17:41:56 +05:30
|
|
|
self.idmap[str(info)] = node
|
2003-06-16 10:27:25 +05:30
|
|
|
if select:
|
2004-08-20 17:41:56 +05:30
|
|
|
self.sel_iter = node
|
|
|
|
return node
|
2003-06-16 10:27:25 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def __button_press(self, obj, event):
|
|
|
|
"""
|
|
|
|
Called when a button press is executed
|
|
|
|
"""
|
2002-11-14 11:01:42 +05:30
|
|
|
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
|
|
|
self.double_click(obj)
|
2005-04-19 09:50:17 +05:30
|
|
|
return True
|
|
|
|
return False
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def find(self, info):
|
2007-09-17 00:15:57 +05:30
|
|
|
"""
|
|
|
|
Selects the item associated with the pass information.
|
|
|
|
"""
|
2009-05-23 00:13:40 +05:30
|
|
|
if info in self.idmap:
|
2004-08-20 17:41:56 +05:30
|
|
|
node = self.idmap[str(info)]
|
|
|
|
self.selection.select_iter(node)
|
2003-10-14 09:52:24 +05:30
|
|
|
|
2010-09-21 05:28:16 +05:30
|
|
|
def move_up(self, row):
|
|
|
|
"""
|
|
|
|
Move the given row up one position.
|
|
|
|
"""
|
|
|
|
if row < 1 or row == -1:
|
|
|
|
return False
|
|
|
|
this_row = self.model.get_iter((row, ))
|
|
|
|
prev_row = self.model.get_iter((row - 1, ))
|
|
|
|
self.model.move_before(this_row, prev_row)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def move_down(self, row):
|
|
|
|
"""
|
|
|
|
Move the given row down one position.
|
|
|
|
"""
|
|
|
|
if row >= self.count - 1 or row == -1:
|
|
|
|
return False
|
|
|
|
this_row = self.model.get_iter((row, ))
|
|
|
|
next_row = self.model.get_iter((row + 1, ))
|
|
|
|
self.model.move_after(this_row, next_row)
|
|
|
|
return True
|