1# 2# Gramps - a GTK+/GNOME based genealogy program 3# 4# Copyright (C) 2003-2006 Donald N. Allingham 5# 2009 Gary Burton 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20# 21 22#------------------------------------------------------------------------- 23# 24# internationalization 25# 26#------------------------------------------------------------------------- 27from gi.repository import Gdk 28from gi.repository import Gtk 29 30#------------------------------------------------------------------------- 31# 32# gramps modules 33# 34#------------------------------------------------------------------------- 35from gramps.gen.const import GRAMPS_LOCALE as glocale 36_ = glocale.translation.sgettext 37from ..views.treemodels import PeopleBaseModel, PersonTreeModel 38from .baseselector import BaseSelector 39from gramps.gen.const import URL_MANUAL_SECT1 40 41#------------------------------------------------------------------------- 42# 43# Constants 44# 45#------------------------------------------------------------------------- 46 47 48#------------------------------------------------------------------------- 49# 50# SelectEvent 51# 52#------------------------------------------------------------------------- 53class SelectPerson(BaseSelector): 54 55 def __init__(self, dbstate, uistate, track=[], title=None, filter=None, 56 skip=set(), show_search_bar=False, default=None): 57 58 # SelectPerson may have a title passed to it which should be used 59 # instead of the default defined for get_window_title() 60 if title is not None: 61 self.title = title 62 self.WIKI_HELP_PAGE = URL_MANUAL_SECT1 63 if title == _("Select Father"): 64 self.WIKI_HELP_SEC = _('manual|Select_Father_selector') 65 elif title == _("Select Mother"): 66 self.WIKI_HELP_SEC = _('manual|Select_Mother_selector') 67 elif title == _("Select Child"): 68 self.WIKI_HELP_SEC = _('manual|Select_Child_selector') 69 else: 70 self.WIKI_HELP_SEC = _('manual|Select_Person_selector') 71 72 BaseSelector.__init__(self, dbstate, uistate, track, filter, 73 skip, show_search_bar, default) 74 75 def _local_init(self): 76 """ 77 Perform local initialisation for this class 78 """ 79 self.setup_configs('interface.person-sel', 600, 450) 80 self.tree.connect('key-press-event', self._key_press) 81 82 def get_window_title(self): 83 return _("Select Person") 84 85 def get_model_class(self): 86 return PersonTreeModel 87 88 def get_column_titles(self): 89 return [ 90 (_('Name'), 250, BaseSelector.TEXT, 0), 91 (_('ID'), 75, BaseSelector.TEXT, 1), 92 (_('Gender'), 75, BaseSelector.TEXT, 2), 93 (_('Birth Date'), 150, BaseSelector.MARKUP, 3), 94 (_('Birth Place'), 150, BaseSelector.MARKUP, 4), 95 (_('Death Date'), 150, BaseSelector.MARKUP, 5), 96 (_('Death Place'), 150, BaseSelector.MARKUP, 6), 97 (_('Spouse'), 150, BaseSelector.TEXT, 7), 98 (_('Last Change'), 150, BaseSelector.TEXT, 14) 99 ] 100 101 def get_from_handle_func(self): 102 return self.db.get_person_from_handle 103 104 def exact_search(self): 105 """ 106 Returns a tuple indicating columns requiring an exact search 107 """ 108 return (2,) # Gender ('female' contains the string 'male') 109 110 def _on_row_activated(self, treeview, path, view_col): 111 store, paths = self.selection.get_selected_rows() 112 if paths and len(paths[0].get_indices()) == 2 : 113 self.window.response(Gtk.ResponseType.OK) 114 115 def _key_press(self, obj, event): 116 if event.keyval in (Gdk.KEY_Return, Gdk.KEY_KP_Enter): 117 store, paths = self.selection.get_selected_rows() 118 if paths and len(paths[0].get_indices()) == 1 : 119 if self.tree.row_expanded(paths[0]): 120 self.tree.collapse_row(paths[0]) 121 else: 122 self.tree.expand_row(paths[0], 0) 123 return True 124 return False 125