2007-08-16 Don Allingham <don@gramps-project.org>
* src/Filters/SideBar/_PersonSidebarFilter.py: document a little bit more svn: r8823
This commit is contained in:
parent
2efbe7da69
commit
8b80b70602
@ -1,3 +1,6 @@
|
||||
2007-08-16 Don Allingham <don@gramps-project.org>
|
||||
* src/Filters/SideBar/_PersonSidebarFilter.py: document a little bit more
|
||||
|
||||
2007-08-16 Benny Malengier <bm@cage.ugent.be>
|
||||
* src/plugins/GraphViz.py: Port FamilyLines.py people images to descendant chart
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
# 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,
|
||||
# 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.
|
||||
@ -47,6 +47,15 @@ from _SidebarFilter import SidebarFilter
|
||||
from Filters.Rules.Person import *
|
||||
from Filters import GenericFilter, build_filter_model, Rules
|
||||
|
||||
|
||||
def extract_text(entry_widget):
|
||||
"""
|
||||
Extracts the text from the entry widget, strips off any extra spaces,
|
||||
and converts the string to unicode. For some strange reason a gtk bug
|
||||
prevents the extracted string from being of type unicode.
|
||||
"""
|
||||
return unicode(entry_widget.get_text().strip())
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# PersonSidebarFilter class
|
||||
@ -64,19 +73,19 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
self.filter_birth = gtk.Entry()
|
||||
self.filter_death = gtk.Entry()
|
||||
self.filter_event = RelLib.Event()
|
||||
self.filter_event.set_type((RelLib.EventType.CUSTOM,u''))
|
||||
self.filter_event.set_type((RelLib.EventType.CUSTOM, u''))
|
||||
self.etype = gtk.ComboBoxEntry()
|
||||
self.event_menu = GrampsWidgets.MonitoredDataType(
|
||||
self.etype,
|
||||
self.filter_event.set_type,
|
||||
self.etype,
|
||||
self.filter_event.set_type,
|
||||
self.filter_event.get_type)
|
||||
|
||||
self.filter_marker = RelLib.Person()
|
||||
self.filter_marker.set_marker((RelLib.MarkerType.CUSTOM,u''))
|
||||
self.filter_marker.set_marker((RelLib.MarkerType.CUSTOM, u''))
|
||||
self.mtype = gtk.ComboBoxEntry()
|
||||
self.marker_menu = GrampsWidgets.MonitoredDataType(
|
||||
self.mtype,
|
||||
self.filter_marker.set_marker,
|
||||
self.mtype,
|
||||
self.filter_marker.set_marker,
|
||||
self.filter_marker.get_marker)
|
||||
|
||||
self.filter_note = gtk.Entry()
|
||||
@ -107,9 +116,9 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
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(_('Birth date'), self.filter_birth,
|
||||
_('example: "%s" or "%s"') % (msg1, msg2))
|
||||
self.add_text_entry(_('Death date'), self.filter_death,
|
||||
self.add_text_entry(_('Death date'), self.filter_death,
|
||||
_('example: "%s" or "%s"') % (msg1, msg2))
|
||||
self.add_entry(_('Event'), self.etype)
|
||||
self.add_entry(_('Marker'), self.mtype)
|
||||
@ -127,31 +136,49 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
self.etype.child.set_text(u'')
|
||||
self.mtype.child.set_text(u'')
|
||||
self.generic.set_active(0)
|
||||
|
||||
|
||||
def get_filter(self):
|
||||
name = unicode(self.filter_name.get_text()).strip()
|
||||
gid = unicode(self.filter_id.get_text()).strip()
|
||||
birth = unicode(self.filter_birth.get_text()).strip()
|
||||
death = unicode(self.filter_death.get_text()).strip()
|
||||
"""
|
||||
Extracts the text strings from the sidebar, and uses them to build up
|
||||
a new filter.
|
||||
"""
|
||||
|
||||
# extract text values from the entry widgets
|
||||
name = extract_text(self.filter_name)
|
||||
gid = extract_text(self.filter_id)
|
||||
birth = extract_text(self.filter_birth)
|
||||
death = extract_text(self.filter_death)
|
||||
note = extract_text(self.filter_note)
|
||||
|
||||
# extract remaining data from the menus
|
||||
etype = self.filter_event.get_type().xml_str()
|
||||
mtype = self.filter_marker.get_marker().xml_str()
|
||||
note = unicode(self.filter_note.get_text()).strip()
|
||||
gender = self.filter_gender.get_active()
|
||||
regex = self.filter_regex.get_active()
|
||||
gen = self.generic.get_active() > 0
|
||||
|
||||
# check to see if the filter is empty. If it is empty, then
|
||||
# we don't build a filter
|
||||
|
||||
empty = not (name or gid or birth or death or etype or mtype
|
||||
or note or gender or regex or gen)
|
||||
if empty:
|
||||
generic_filter = None
|
||||
else:
|
||||
# build a GenericFilter
|
||||
generic_filter = GenericFilter()
|
||||
|
||||
# if the name is not empty, choose either the regular expression
|
||||
# version or the normal text match
|
||||
if name:
|
||||
if regex:
|
||||
rule = RegExpName([name])
|
||||
else:
|
||||
rule = SearchName([name])
|
||||
generic_filter.add_rule(rule)
|
||||
|
||||
# if the id is not empty, choose either the regular expression
|
||||
# version or the normal text match
|
||||
if gid:
|
||||
if regex:
|
||||
rule = RegExpIdOf([gid])
|
||||
@ -159,6 +186,7 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
rule = MatchIdOf([gid])
|
||||
generic_filter.add_rule(rule)
|
||||
|
||||
# check the gender, and select the right rule based on gender
|
||||
if gender > 0:
|
||||
if gender == 1:
|
||||
generic_filter.add_rule(IsMale([]))
|
||||
@ -167,20 +195,30 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
else:
|
||||
generic_filter.add_rule(HasUnknownGender([]))
|
||||
|
||||
# check the Marker type
|
||||
if mtype:
|
||||
rule = HasMarkerOf([mtype])
|
||||
generic_filter.add_rule(rule)
|
||||
|
||||
|
||||
# Build an event filter if needed
|
||||
if etype:
|
||||
rule = HasEvent([etype, u'', u'', u''])
|
||||
generic_filter.add_rule(rule)
|
||||
|
||||
# Build birth event filter if needed
|
||||
# Arguments for the HasBirth filter are Date, Place, and Description
|
||||
# Since the value we extracted to the "birth" variable is the
|
||||
# request date, we pass it as the first argument
|
||||
if birth:
|
||||
rule = HasBirth([birth,u'',u''])
|
||||
rule = HasBirth([birth, u'', u''])
|
||||
generic_filter.add_rule(rule)
|
||||
|
||||
# Build death event filter if needed
|
||||
if death:
|
||||
rule = HasDeath([death,u'',u''])
|
||||
rule = HasDeath([death, u'', u''])
|
||||
generic_filter.add_rule(rule)
|
||||
|
||||
# Build note filter if needed
|
||||
if note:
|
||||
if regex:
|
||||
rule = HasNoteRegexp([note])
|
||||
@ -197,7 +235,7 @@ class PersonSidebarFilter(SidebarFilter):
|
||||
|
||||
return generic_filter
|
||||
|
||||
def on_filters_changed(self,name_space):
|
||||
def on_filters_changed(self, name_space):
|
||||
if name_space == 'Person':
|
||||
all = GenericFilter()
|
||||
all.set_name(_("None"))
|
||||
|
Loading…
Reference in New Issue
Block a user