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
|
|
|
|
2006-05-27 02:18:40 +05:30
|
|
|
try:
|
|
|
|
set()
|
|
|
|
except:
|
|
|
|
from sets import Set as set
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# SelectEvent
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class BaseSelector(ManagedWindow.ManagedWindow):
|
2006-05-17 10:13:53 +05:30
|
|
|
NONE = -1
|
|
|
|
TEXT = 0
|
|
|
|
MARKUP = 1
|
|
|
|
IMAGE = 2
|
|
|
|
|
2006-05-27 02:18:40 +05:30
|
|
|
def __init__(self, dbstate, uistate, track=[], filter=None, skip=set()):
|
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
|
|
|
|
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps")
|
|
|
|
window = self.glade.get_widget('select_person')
|
|
|
|
title_label = self.glade.get_widget('title')
|
2006-05-17 10:13:53 +05:30
|
|
|
self.tree = self.glade.get_widget('plist')
|
2006-05-16 02:20:25 +05:30
|
|
|
|
|
|
|
self.set_window(window,title_label,self.title)
|
|
|
|
|
2006-05-27 02:18:40 +05:30
|
|
|
self.model = self.get_model_class()(self.db,skip=skip)
|
2006-05-17 10:13:53 +05:30
|
|
|
self.selection = self.tree.get_selection()
|
2006-05-16 02:20:25 +05:30
|
|
|
|
2006-05-17 10:13:53 +05:30
|
|
|
self.tree.set_model(self.model)
|
|
|
|
self.add_columns(self.tree)
|
2006-05-17 11:43:37 +05:30
|
|
|
self._local_init()
|
2006-05-16 02:20:25 +05:30
|
|
|
self.show()
|
|
|
|
|
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)
|
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
|
|
|
|
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
|
|
|
|
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):
|
|
|
|
# return _("Select something")
|
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):
|
|
|
|
# return SourceModel
|
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):
|
|
|
|
# return [(_('Title'),350,), (_('ID'),1,50)]
|
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):
|
|
|
|
# return self.db.get_source_from_handle
|
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"
|