From a97e7e2abd61ce64e086762c05a3557691da5d50 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 15 May 2006 20:37:19 +0000 Subject: [PATCH] * src/Filters/__init__.py: add SidebarFilter, PersonSidebarFilter * src/Filters/_SidebarFilter.py: added * src/Filters/_PersonSidebarFilter.py: added svn: r6672 --- gramps2/ChangeLog | 3 + gramps2/src/DataViews/_PersonView.py | 164 +------------------- gramps2/src/Filters/_PersonSidebarFilter.py | 133 ++++++++++++++++ gramps2/src/Filters/_SidebarFilter.py | 90 +++++++++++ gramps2/src/Filters/__init__.py | 2 + 5 files changed, 234 insertions(+), 158 deletions(-) create mode 100644 gramps2/src/Filters/_PersonSidebarFilter.py create mode 100644 gramps2/src/Filters/_SidebarFilter.py diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index c35061930..947c535b9 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,7 @@ 2006-05-15 Don Allingham + * src/Filters/__init__.py: add SidebarFilter, PersonSidebarFilter + * src/Filters/_SidebarFilter.py: added + * src/Filters/_PersonSidebarFilter.py: added * src/DataViews/_PersonView.py: cleaner interface to filters * src/plugins/RelCalc.py: cleaner interface to filters * src/PeopleModel.py: cleaner interface to filters diff --git a/gramps2/src/DataViews/_PersonView.py b/gramps2/src/DataViews/_PersonView.py index 7602adcac..c06a07ebb 100644 --- a/gramps2/src/DataViews/_PersonView.py +++ b/gramps2/src/DataViews/_PersonView.py @@ -62,9 +62,7 @@ import Config import const from Editors import EditPerson -from Filters import SearchBar, GenericFilter -from Filters.Rules.Person import * - +from Filters import SearchBar, GenericFilter, PersonSidebarFilter from DdTargets import DdTargets column_names = [ @@ -81,6 +79,7 @@ column_names = [ ] + class PersonView(PageView.PersonNavView): def __init__(self,dbstate,uistate): @@ -207,167 +206,16 @@ class PersonView(PageView.PersonNavView): self.selection.set_mode(gtk.SELECTION_MULTIPLE) self.selection.connect('changed',self.row_changed) - - self.filter_pane = self.build_filter_sidebar() + self.filter_sidebar = PersonSidebarFilter(self.filter_clicked) + self.filter_pane = self.filter_sidebar.get_widget() hpaned.pack_start(self.vbox, True, True) hpaned.pack_end(self.filter_pane, False, False) return hpaned - def build_filter_sidebar(self): - table = gtk.Table(3,11) - table.set_border_width(6) - table.set_row_spacings(6) - - self.filter_name = gtk.Entry() - self.filter_id = gtk.Entry() - self.filter_birth = gtk.Entry() - self.filter_death = gtk.Entry() - self.filter_event = RelLib.Event() - self.filter_event.set_type((RelLib.EventType.CUSTOM,'')) - etype = gtk.ComboBoxEntry() - - self.event_menu = GrampsWidgets.MonitoredDataType( - etype, - self.filter_event.set_type, - self.filter_event.get_type) - - self.filter_note = gtk.Entry() - self.filter_gender = gtk.combo_box_new_text() - for i in [ _('any'), _('male'), _('female'), _('unknown') ]: - self.filter_gender.append_text(i) - self.filter_gender.set_active(0) - - self.filter_regex = gtk.CheckButton(_('Use regular expressions')) - - self.apply_btn = gtk.Button(stock=gtk.STOCK_FIND) - self.apply_btn.connect('clicked', self.filter_clicked) - - self.clear_btn = gtk.Button(stock=gtk.STOCK_CLEAR) - self.clear_btn.connect('clicked', self.clear_clicked) - - table.set_col_spacing(0,6) - table.set_col_spacing(1,6) - - table.attach(GrampsWidgets.MarkupLabel(_('Filter')), - 0, 3, 0, 1, xoptions=gtk.FILL, yoptions=0) - - table.attach(GrampsWidgets.BasicLabel(_('Name')), - 1, 2, 1, 2, xoptions=gtk.FILL, yoptions=0) - - table.attach(self.filter_name, 2, 3, 1, 2, - xoptions=gtk.FILL, yoptions=0) - - table.attach(GrampsWidgets.BasicLabel(_('ID')), - 1, 2, 2, 3, xoptions=gtk.FILL, yoptions=0) - - table.attach(self.filter_id, 2, 3, 2, 3, - xoptions=gtk.FILL, yoptions=0) - - table.attach(GrampsWidgets.BasicLabel(_('Gender')), - 1, 2, 3, 4, xoptions=gtk.FILL, yoptions=0) - - table.attach(self.filter_gender, 2, 3, 3, 4, - xoptions=gtk.FILL, yoptions=0) - - table.attach(GrampsWidgets.BasicLabel(_('Birth date')), - 1, 2, 4, 5, xoptions=gtk.FILL, yoptions=0) - - table.attach(self.filter_birth, 2, 3, 4, 5, - xoptions=gtk.FILL, yoptions=0) - - table.attach(GrampsWidgets.BasicLabel(_('Death date')), - 1, 2, 5, 6, xoptions=gtk.FILL, yoptions=0) - - table.attach(self.filter_death, 2, 3, 5, 6, - xoptions=gtk.FILL, yoptions=0) - - table.attach(GrampsWidgets.BasicLabel(_('Has Event')), - 1, 2, 6, 7, xoptions=gtk.FILL, yoptions=0) - - table.attach(etype, 2, 3, 6, 7, xoptions=gtk.FILL, yoptions=0) - - table.attach(GrampsWidgets.BasicLabel(_('Note')), - 1, 2, 7, 8, xoptions=gtk.FILL, yoptions=0) - - table.attach(self.filter_note, 2, 3, 7, 8, - xoptions=gtk.FILL, yoptions=0) - - table.attach(self.filter_regex, 2, 3, 8, 9, xoptions=gtk.FILL, - yoptions=0) - - hbox = gtk.HBox() - hbox.add(self.apply_btn) - hbox.add(self.clear_btn) - hbox.show() - table.attach(hbox, 2, 3, 9, 10, xoptions=gtk.FILL, - yoptions=0) - - return table - - def clear_clicked(self,obj): - self.filter_name.set_text('') - self.filter_id.set_text('') - self.filter_birth.set_text('') - self.filter_death.get_text('') - self.filter_note.get_text('') - self.filter_gender.set_active(0) - self.event_menu.child.set_text('') - - def filter_clicked(self, obj): - name = self.filter_name.get_text().strip() - gid = self.filter_id.get_text().strip() - birth = self.filter_birth.get_text().strip() - death = self.filter_death.get_text().strip() - note = self.filter_note.get_text().strip() - gender = self.filter_gender.get_active() - regex = self.filter_regex.get_active() - - if not name and not gid and not birth and not death \ - and not str(self.filter_event.get_type()) and \ - not note and not gender > 0: - self.generic_filter = None - else: - self.generic_filter = GenericFilter() - if name: - if regex: - rule = RegExpName([name]) - else: - rule = SearchName([name]) - self.generic_filter.add_rule(rule) - if gid: - if regex: - rule = RegExpIdOf([gid]) - else: - rule = MatchIdOf([gid]) - self.generic_filter.add_rule(rule) - if gender > 0: - if gender == 1: - self.generic_filter.add_rule(IsMale([])) - elif gender == 2: - self.generic_filter.add_rule(IsFemale([])) - else: - self.generic_filter.add_rule(HasUnknownGender([])) - - etype = self.filter_event.get_type() - if str(etype): - rule = HasEvent([etype, '', '', '']) - self.generic_filter.add_rule(rule) - - if birth: - rule = HasBirth([birth,'','']) - self.generic_filter.add_rule(rule) - if death: - rule = HasDeath([death,'','']) - self.generic_filter.add_rule(rule) - if note: - if regex: - rule = HasNoteRegexp([note]) - else: - rule = HasNoteMatchingSubstringOf([note]) - self.generic_filter.add_rule(rule) - + def filter_clicked(self): + self.generic_filter = self.filter_sidebar.get_filter() self.build_tree() def drag_begin(self, widget, *data): diff --git a/gramps2/src/Filters/_PersonSidebarFilter.py b/gramps2/src/Filters/_PersonSidebarFilter.py new file mode 100644 index 000000000..c903d890f --- /dev/null +++ b/gramps2/src/Filters/_PersonSidebarFilter.py @@ -0,0 +1,133 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-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 +# + +# $Id: _FilterList.py 6529 2006-05-03 06:29:07Z rshura $ + +import gtk +import GrampsWidgets +import RelLib + +from _SidebarFilter import SidebarFilter +from Filters.Rules.Person import * +from Filters import GenericFilter + +class PersonSidebarFilter(SidebarFilter): + + def __init__(self, clicked): + SidebarFilter.__init__(self) + self.clicked = clicked + + def create_widget(self): + self.filter_name = gtk.Entry() + self.filter_id = gtk.Entry() + self.filter_birth = gtk.Entry() + self.filter_death = gtk.Entry() + self.filter_event = RelLib.Event() + self.filter_event.set_type((RelLib.EventType.CUSTOM,'')) + self.etype = gtk.ComboBoxEntry() + + self.event_menu = GrampsWidgets.MonitoredDataType( + self.etype, + self.filter_event.set_type, + self.filter_event.get_type) + + self.filter_note = gtk.Entry() + self.filter_gender = gtk.combo_box_new_text() + for i in [ _('any'), _('male'), _('female'), _('unknown') ]: + self.filter_gender.append_text(i) + self.filter_gender.set_active(0) + + self.filter_regex = gtk.CheckButton(_('Use regular expressions')) + + self.add_text_entry(_('Name'), self.filter_name) + self.add_text_entry(_('ID'), self.filter_id) + self.add_entry(_('Gender'), self.filter_gender) + self.add_text_entry(_('Birth date'), self.filter_birth) + self.add_text_entry(_('Death date'), self.filter_death) + self.add_entry(_('Has Event'), self.etype) + self.add_text_entry(_('Note'), self.filter_note) + self.add_entry(None, self.filter_regex) + + def clear(self, obj): + self.filter_name.set_text('') + self.filter_id.set_text('') + self.filter_birth.set_text('') + self.filter_death.get_text('') + self.filter_note.get_text('') + self.filter_gender.set_active(0) + self.etype.set_text('') + + def clicked(self, obj): + self.clicked() + + def get_filter(self): + name = self.filter_name.get_text().strip() + gid = self.filter_id.get_text().strip() + birth = self.filter_birth.get_text().strip() + death = self.filter_death.get_text().strip() + note = self.filter_note.get_text().strip() + gender = self.filter_gender.get_active() + regex = self.filter_regex.get_active() + + if not name and not gid and not birth and not death \ + and not str(self.filter_event.get_type()) and \ + not note and not gender > 0: + generic_filter = None + else: + generic_filter = GenericFilter() + if name: + if regex: + rule = RegExpName([name]) + else: + rule = SearchName([name]) + generic_filter.add_rule(rule) + if gid: + if regex: + rule = RegExpIdOf([gid]) + else: + rule = MatchIdOf([gid]) + generic_filter.add_rule(rule) + if gender > 0: + if gender == 1: + generic_filter.add_rule(IsMale([])) + elif gender == 2: + generic_filter.add_rule(IsFemale([])) + else: + generic_filter.add_rule(HasUnknownGender([])) + + etype = self.filter_event.get_type() + if str(etype): + rule = HasEvent([etype, '', '', '']) + generic_filter.add_rule(rule) + + if birth: + rule = HasBirth([birth,'','']) + generic_filter.add_rule(rule) + if death: + rule = HasDeath([death,'','']) + generic_filter.add_rule(rule) + if note: + if regex: + rule = HasNoteRegexp([note]) + else: + rule = HasNoteMatchingSubstringOf([note]) + generic_filter.add_rule(rule) + return generic_filter + diff --git a/gramps2/src/Filters/_SidebarFilter.py b/gramps2/src/Filters/_SidebarFilter.py new file mode 100644 index 000000000..8c4d704da --- /dev/null +++ b/gramps2/src/Filters/_SidebarFilter.py @@ -0,0 +1,90 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-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 +# + +# $Id: _FilterList.py 6529 2006-05-03 06:29:07Z rshura $ + +import gtk +import GrampsWidgets + +_RETURN = gtk.gdk.keyval_from_name("Return") + +class SidebarFilter: + + def __init__(self): + self.position = 1 + self.table = gtk.Table(3,11) + self.table.set_border_width(6) + self.table.set_row_spacings(6) + self.table.set_col_spacing(0,6) + self.table.set_col_spacing(1,6) + self._init_interface() + + def _init_interface(self): + self.table.attach(GrampsWidgets.MarkupLabel(_('Filter')), + 0, 3, 0, 1, xoptions=gtk.FILL, yoptions=0) + + self.create_widget() + + self.apply_btn = gtk.Button(stock=gtk.STOCK_FIND) + self.apply_btn.connect('clicked', self.clicked) + + self.clear_btn = gtk.Button(stock=gtk.STOCK_CLEAR) + self.clear_btn.connect('clicked', self.clear) + + hbox = gtk.HBox() + hbox.set_spacing(6) + hbox.add(self.apply_btn) + hbox.add(self.clear_btn) + hbox.show() + self.table.attach(hbox, 2, 3, self.position, self.position+1, + xoptions=gtk.FILL, yoptions=0) + + def get_widget(self): + return self.table + + def create_widget(self): + pass + + def clear(self, obj): + pass + + def clicked(self): + pass + + def get_filter(self): + pass + + def add_text_entry(self, name, widget): + self.add_entry(name, widget) + widget.connect('key-press-event',self.key_press) + + def key_press(self, obj, event): + if event.keyval == _RETURN and not event.state: + self.clicked() + return False + + def add_entry(self, name, widget): + if name: + self.table.attach(GrampsWidgets.BasicLabel(name), + 1, 2, self.position, self.position+1, + xoptions=gtk.FILL, yoptions=0) + self.table.attach(widget, 2, 3, self.position, self.position+1, + xoptions=gtk.FILL, yoptions=0) + self.position += 1 diff --git a/gramps2/src/Filters/__init__.py b/gramps2/src/Filters/__init__.py index 890f08ad0..bec139e03 100644 --- a/gramps2/src/Filters/__init__.py +++ b/gramps2/src/Filters/__init__.py @@ -57,3 +57,5 @@ from _FilterMenu import build_filter_menu from _FilterStore import FilterStore from _SearchBar import SearchBar from _SearchFilter import SearchFilter +from _SidebarFilter import SidebarFilter +from _PersonSidebarFilter import PersonSidebarFilter