2006-05-16 02:20:25 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2003-2006 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
|
|
|
|
#
|
|
|
|
|
2006-05-17 11:15:53 +05:30
|
|
|
# $Id$
|
2006-05-16 02:20:25 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
2006-05-17 10:13:53 +05:30
|
|
|
import pango
|
2006-05-16 02:20:25 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import ManagedWindow
|
2007-09-25 17:39:25 +05:30
|
|
|
from Filters import SearchBar
|
2006-05-16 02:20:25 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# SelectEvent
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class BaseSelector(ManagedWindow.ManagedWindow):
|
2007-09-25 17:39:25 +05:30
|
|
|
"""Base class for the selectors, showing a dialog from which to select
|
|
|
|
one of the primary objects
|
|
|
|
"""
|
|
|
|
|
2006-05-17 10:13:53 +05:30
|
|
|
NONE = -1
|
|
|
|
TEXT = 0
|
|
|
|
MARKUP = 1
|
|
|
|
IMAGE = 2
|
|
|
|
|
2007-09-25 17:39:25 +05:30
|
|
|
def __init__(self, dbstate, uistate, track=[], filter=None, skip=set(),
|
|
|
|
show_search_bar = True):
|
|
|
|
'''Set up the dialog with the dbstate and uistate, track of parent
|
|
|
|
windows for ManagedWindow, initial filter for the model, skip with
|
|
|
|
set of handles to skip in the view, and search_bar to show the
|
|
|
|
SearchBar at the top or not.
|
|
|
|
'''
|
2006-05-17 10:13:53 +05:30
|
|
|
self.title = self.get_window_title()
|
2006-05-16 02:20:25 +05:30
|
|
|
|
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
|
|
|
|
|
2006-05-17 10:13:53 +05:30
|
|
|
self.renderer = gtk.CellRendererText()
|
|
|
|
self.renderer.set_property('ellipsize',pango.ELLIPSIZE_END)
|
|
|
|
|
2006-05-16 02:20:25 +05:30
|
|
|
self.db = dbstate.db
|
2007-09-08 11:24:02 +05:30
|
|
|
self.glade = gtk.glade.XML(const.GLADE_FILE,"select_person","gramps")
|
2006-05-16 02:20:25 +05:30
|
|
|
window = self.glade.get_widget('select_person')
|
|
|
|
title_label = self.glade.get_widget('title')
|
2007-09-25 17:39:25 +05:30
|
|
|
vbox = self.glade.get_widget('select_person_vbox')
|
2006-05-17 10:13:53 +05:30
|
|
|
self.tree = self.glade.get_widget('plist')
|
2007-09-26 05:36:20 +05:30
|
|
|
self.tree.set_headers_visible(True)
|
|
|
|
self.tree.set_headers_clickable(True)
|
2007-01-10 04:35:29 +05:30
|
|
|
self.tree.connect('row-activated', self._on_row_activated)
|
2007-09-25 17:39:25 +05:30
|
|
|
|
|
|
|
self.colinfo = self.column_view_names()
|
|
|
|
#add the search bar
|
|
|
|
self.search_bar = SearchBar(dbstate, uistate,
|
|
|
|
self.build_tree)
|
|
|
|
filter_box = self.search_bar.build()
|
|
|
|
self.setup_filter()
|
|
|
|
vbox.pack_start(filter_box, False, False)
|
|
|
|
vbox.reorder_child(filter_box, 1)
|
2006-05-16 02:20:25 +05:30
|
|
|
|
|
|
|
self.set_window(window,title_label,self.title)
|
2007-09-26 05:36:20 +05:30
|
|
|
|
|
|
|
#set up sorting
|
|
|
|
self.sort_col = 0
|
|
|
|
self.setupcols = True
|
|
|
|
self.columns = []
|
|
|
|
self.sortorder = gtk.SORT_ASCENDING
|
2006-05-16 02:20:25 +05:30
|
|
|
|
2007-09-25 17:39:25 +05:30
|
|
|
self.skip_list=skip
|
|
|
|
self.build_tree()
|
2006-05-17 10:13:53 +05:30
|
|
|
self.selection = self.tree.get_selection()
|
2007-09-26 05:36:20 +05:30
|
|
|
|
2007-09-25 17:39:25 +05:30
|
|
|
|
2006-05-17 11:43:37 +05:30
|
|
|
self._local_init()
|
2007-09-25 17:39:25 +05:30
|
|
|
|
2006-05-16 02:20:25 +05:30
|
|
|
self.show()
|
2007-09-25 17:39:25 +05:30
|
|
|
#show or hide search bar?
|
|
|
|
self.set_show_search_bar(show_search_bar)
|
|
|
|
#Hide showall always (used in person selector only)
|
|
|
|
showbox = self.glade.get_widget('showall')
|
|
|
|
showbox.hide()
|
2006-05-16 02:20:25 +05:30
|
|
|
|
2006-05-17 10:13:53 +05:30
|
|
|
def add_columns(self,tree):
|
|
|
|
tree.set_fixed_height_mode(True)
|
|
|
|
titles = self.get_column_titles()
|
|
|
|
for ix in range(len(titles)):
|
|
|
|
item = titles[ix]
|
|
|
|
if item[2] == BaseSelector.NONE:
|
|
|
|
continue
|
|
|
|
elif item[2] == BaseSelector.TEXT:
|
|
|
|
column = gtk.TreeViewColumn(item[0],self.renderer,text=ix)
|
|
|
|
elif item[2] == BaseSelector.MARKUP:
|
|
|
|
column = gtk.TreeViewColumn(item[0],self.renderer,markup=ix)
|
|
|
|
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
|
|
|
column.set_fixed_width(item[1])
|
2006-06-22 01:28:49 +05:30
|
|
|
column.set_resizable(True)
|
2007-09-26 05:36:20 +05:30
|
|
|
#connect click
|
|
|
|
column.connect('clicked', self.column_clicked, ix)
|
|
|
|
column.set_clickable(True)
|
|
|
|
##column.set_sort_column_id(ix) # model has its own sort implemented
|
|
|
|
self.columns.append(column)
|
2006-05-17 10:13:53 +05:30
|
|
|
tree.append_column(column)
|
|
|
|
|
2006-05-16 02:20:25 +05:30
|
|
|
def build_menu_names(self,obj):
|
|
|
|
return (self.title, None)
|
|
|
|
|
2006-05-17 10:13:53 +05:30
|
|
|
def get_selected_ids(self):
|
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.select_function,mlist)
|
|
|
|
return mlist
|
|
|
|
|
|
|
|
def select_function(self,store,path,iter,id_list):
|
|
|
|
handle_column = self.get_handle_column()
|
|
|
|
id_list.append(self.model.get_value(iter,handle_column))
|
|
|
|
|
2006-05-16 02:20:25 +05:30
|
|
|
def run(self):
|
|
|
|
val = self.window.run()
|
|
|
|
if val == gtk.RESPONSE_OK:
|
2006-05-17 10:13:53 +05:30
|
|
|
id_list = self.get_selected_ids()
|
|
|
|
self.close()
|
|
|
|
if id_list and id_list[0]:
|
|
|
|
return_value = self.get_from_handle_func()(id_list[0])
|
2006-05-16 02:20:25 +05:30
|
|
|
else:
|
|
|
|
return_value = None
|
2007-01-10 04:35:29 +05:30
|
|
|
return return_value
|
2006-06-18 08:35:33 +05:30
|
|
|
elif val != gtk.RESPONSE_DELETE_EVENT:
|
2006-05-16 02:20:25 +05:30
|
|
|
self.close()
|
|
|
|
return None
|
2006-06-18 08:35:33 +05:30
|
|
|
else:
|
|
|
|
return None
|
2006-05-16 02:20:25 +05:30
|
|
|
|
2007-01-10 04:35:29 +05:30
|
|
|
def _on_row_activated(self, treeview, path, view_col):
|
|
|
|
self.window.response(gtk.RESPONSE_OK)
|
|
|
|
|
2006-05-17 11:43:37 +05:30
|
|
|
def _local_init(self):
|
|
|
|
# define selector-specific init routine
|
|
|
|
pass
|
|
|
|
|
2006-05-17 10:13:53 +05:30
|
|
|
def get_window_title(self):
|
2006-05-16 02:20:25 +05:30
|
|
|
assert False, "Must be defined in the subclass"
|
|
|
|
|
2006-05-17 10:13:53 +05:30
|
|
|
def get_model_class(self):
|
2006-05-16 02:20:25 +05:30
|
|
|
assert False, "Must be defined in the subclass"
|
|
|
|
|
2006-05-17 10:13:53 +05:30
|
|
|
def get_column_titles(self):
|
2006-05-16 02:20:25 +05:30
|
|
|
assert False, "Must be defined in the subclass"
|
|
|
|
|
2006-05-17 10:13:53 +05:30
|
|
|
def get_from_handle_func(self):
|
2006-05-16 02:20:25 +05:30
|
|
|
assert False, "Must be defined in the subclass"
|
2006-05-17 10:13:53 +05:30
|
|
|
|
|
|
|
def get_handle_column(self):
|
|
|
|
# return 3
|
2006-05-16 02:20:25 +05:30
|
|
|
assert False, "Must be defined in the subclass"
|
2007-09-25 17:39:25 +05:30
|
|
|
|
|
|
|
def set_show_search_bar(self, value):
|
|
|
|
'''make the search bar at the top shown
|
|
|
|
'''
|
|
|
|
self.show_search_bar = value
|
|
|
|
if not self.search_bar :
|
|
|
|
return
|
|
|
|
if self.show_search_bar :
|
|
|
|
self.search_bar.show()
|
|
|
|
else :
|
|
|
|
self.search_bar.hide()
|
|
|
|
|
2007-09-26 05:36:20 +05:30
|
|
|
def begintree(self, store, path, node, sel_list):
|
|
|
|
handle_column = self.get_handle_column()
|
|
|
|
handle = store.get_value(node, handle_column)
|
|
|
|
sel_list.append(handle)
|
|
|
|
|
|
|
|
def first_selected(self):
|
|
|
|
""" first selected entry in the Selector tree
|
|
|
|
"""
|
|
|
|
mlist = []
|
|
|
|
self.selection.selected_foreach(self.begintree, mlist)
|
|
|
|
if mlist:
|
|
|
|
return mlist[0]
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2007-09-25 17:39:25 +05:30
|
|
|
def column_order(self):
|
|
|
|
"""
|
|
|
|
Column order for db columns
|
|
|
|
|
|
|
|
Derived classes must override this function.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def column_view_names(self):
|
|
|
|
"""
|
|
|
|
Get correct column view names on which model is based
|
|
|
|
|
|
|
|
Derived classes must override this function.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def setup_filter(self):
|
|
|
|
"""
|
|
|
|
Builds the default filters and add them to the filter bar.
|
|
|
|
"""
|
|
|
|
cols = []
|
|
|
|
for pair in [pair for pair in self.column_order() if pair[0]]:
|
|
|
|
cols.append((self.colinfo[pair[1]], pair[1]))
|
|
|
|
self.search_bar.setup_filter(cols)
|
|
|
|
|
|
|
|
def build_tree(self):
|
|
|
|
"""
|
|
|
|
Builds the selection people see in the Selector
|
|
|
|
"""
|
|
|
|
#search info for the
|
|
|
|
filter_info = (False, self.search_bar.get_value())
|
2007-09-26 05:36:20 +05:30
|
|
|
#set up cols the first time
|
|
|
|
if self.setupcols :
|
|
|
|
self.add_columns(self.tree)
|
|
|
|
|
|
|
|
#reset the model with correct sorting
|
|
|
|
self.model = self.get_model_class()(self.db, self.sort_col,
|
|
|
|
self.sortorder,
|
|
|
|
sort_map=self.column_order(),
|
|
|
|
skip=self.skip_list,
|
2007-09-25 17:39:25 +05:30
|
|
|
search=filter_info)
|
|
|
|
|
|
|
|
self.tree.set_model(self.model)
|
2007-09-26 05:36:20 +05:30
|
|
|
|
|
|
|
#sorting arrow in column header (not on start, only on click)
|
|
|
|
if not self.setupcols :
|
|
|
|
for i in xrange(len(self.columns)):
|
|
|
|
enable_sort_flag = (i==self.sort_col)
|
|
|
|
self.columns[i].set_sort_indicator(enable_sort_flag)
|
|
|
|
self.columns[self.sort_col].set_sort_order(self.sortorder)
|
|
|
|
|
|
|
|
# set the search column to be the sorted column
|
|
|
|
search_col = self.column_order()[self.sort_col][1]
|
|
|
|
self.tree.set_search_column(search_col)
|
|
|
|
|
|
|
|
self.setupcols = False
|
2007-09-25 17:39:25 +05:30
|
|
|
|
2007-09-26 05:36:20 +05:30
|
|
|
def column_clicked(self, obj, data):
|
|
|
|
if self.sort_col != data:
|
|
|
|
self.sortorder = gtk.SORT_ASCENDING
|
|
|
|
else:
|
|
|
|
if (self.columns[data].get_sort_order() == gtk.SORT_DESCENDING
|
|
|
|
or not self.columns[data].get_sort_indicator()):
|
|
|
|
self.sortorder = gtk.SORT_ASCENDING
|
|
|
|
else:
|
|
|
|
self.sortorder = gtk.SORT_DESCENDING
|
2007-09-25 17:39:25 +05:30
|
|
|
|
2007-09-26 05:36:20 +05:30
|
|
|
self.sort_col = data
|
|
|
|
handle = self.first_selected()
|
|
|
|
|
|
|
|
self.build_tree()
|
|
|
|
|
|
|
|
if handle:
|
|
|
|
path = self.model.on_get_path(handle)
|
|
|
|
self.selection.select_path(path)
|
|
|
|
self.tree.scroll_to_cell(path, None, 1, 0.5, 0)
|
|
|
|
|
|
|
|
return True
|