Replace "Title" with "Enclosed By" in place sidebar filter

This commit is contained in:
Nick Hall 2015-06-28 19:31:41 +01:00
parent 741d192f1f
commit 563f8e263d
4 changed files with 91 additions and 9 deletions

View File

@ -3,7 +3,7 @@
# #
# Copyright (C) 2002-2006 Donald N. Allingham # Copyright (C) 2002-2006 Donald N. Allingham
# Copyright (C) 2008 Gary Burton # Copyright (C) 2008 Gary Burton
# Copyright (C) 2010 Nick Hall # Copyright (C) 2010,2015 Nick Hall
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -45,7 +45,7 @@ from gramps.gen.lib import Place, PlaceType
from .. import build_filter_model from .. import build_filter_model
from . import SidebarFilter from . import SidebarFilter
from gramps.gen.filters import GenericFilterFactory, rules from gramps.gen.filters import GenericFilterFactory, rules
from gramps.gen.filters.rules.place import (RegExpIdOf, HasData, HasTitle, from gramps.gen.filters.rules.place import (RegExpIdOf, HasData, IsEnclosedBy,
HasTag, HasNoteRegexp, HasTag, HasNoteRegexp,
MatchesFilter) MatchesFilter)
@ -61,7 +61,6 @@ class PlaceSidebarFilter(SidebarFilter):
self.clicked_func = clicked self.clicked_func = clicked
self.filter_id = widgets.BasicEntry() self.filter_id = widgets.BasicEntry()
self.filter_title = widgets.BasicEntry()
self.filter_name = widgets.BasicEntry() self.filter_name = widgets.BasicEntry()
self.filter_place = Place() self.filter_place = Place()
self.filter_place.set_type((PlaceType.CUSTOM, '')) self.filter_place.set_type((PlaceType.CUSTOM, ''))
@ -72,6 +71,7 @@ class PlaceSidebarFilter(SidebarFilter):
self.filter_place.set_type, self.filter_place.set_type,
self.filter_place.get_type) self.filter_place.get_type)
self.filter_code = widgets.BasicEntry() self.filter_code = widgets.BasicEntry()
self.filter_enclosed = widgets.PlaceEntry(dbstate, uistate, [])
self.filter_note = widgets.BasicEntry() self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
@ -95,10 +95,10 @@ class PlaceSidebarFilter(SidebarFilter):
self.tag.add_attribute(cell, 'text', 0) self.tag.add_attribute(cell, 'text', 0)
self.add_text_entry(_('ID'), self.filter_id) self.add_text_entry(_('ID'), self.filter_id)
self.add_text_entry(_('Title'), self.filter_title)
self.add_text_entry(_('Name'), self.filter_name) self.add_text_entry(_('Name'), self.filter_name)
self.add_entry(_('Type'), self.ptype) self.add_entry(_('Type'), self.ptype)
self.add_text_entry(_('Code'), self.filter_code) self.add_text_entry(_('Code'), self.filter_code)
self.add_text_entry(_('Enclosed By'), self.filter_enclosed)
self.add_text_entry(_('Note'), self.filter_note) self.add_text_entry(_('Note'), self.filter_note)
self.add_entry(_('Tag'), self.tag) self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic) self.add_filter_entry(_('Custom filter'), self.generic)
@ -106,9 +106,9 @@ class PlaceSidebarFilter(SidebarFilter):
def clear(self, obj): def clear(self, obj):
self.filter_id.set_text('') self.filter_id.set_text('')
self.filter_title.set_text('')
self.filter_name.set_text('') self.filter_name.set_text('')
self.filter_code.set_text('') self.filter_code.set_text('')
self.filter_enclosed.set_text('')
self.filter_note.set_text('') self.filter_note.set_text('')
self.ptype.get_child().set_text('') self.ptype.get_child().set_text('')
self.tag.set_active(0) self.tag.set_active(0)
@ -116,16 +116,16 @@ class PlaceSidebarFilter(SidebarFilter):
def get_filter(self): def get_filter(self):
gid = str(self.filter_id.get_text()).strip() gid = str(self.filter_id.get_text()).strip()
title = str(self.filter_title.get_text()).strip()
name = str(self.filter_name.get_text()).strip() name = str(self.filter_name.get_text()).strip()
ptype = self.filter_place.get_type().xml_str() ptype = self.filter_place.get_type().xml_str()
code = str(self.filter_code.get_text()).strip() code = str(self.filter_code.get_text()).strip()
enclosed = str(self.filter_enclosed.get_text()).strip()
note = str(self.filter_note.get_text()).strip() note = str(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active() regex = self.filter_regex.get_active()
tag = self.tag.get_active() > 0 tag = self.tag.get_active() > 0
gen = self.generic.get_active() > 0 gen = self.generic.get_active() > 0
empty = not (gid or title or name or ptype or code or note or regex empty = not (gid or name or ptype or code or enclosed or note or regex
or tag or gen) or tag or gen)
if empty: if empty:
generic_filter = None generic_filter = None
@ -135,8 +135,8 @@ class PlaceSidebarFilter(SidebarFilter):
rule = RegExpIdOf([gid], use_regex=regex) rule = RegExpIdOf([gid], use_regex=regex)
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
if title: if enclosed:
rule = HasTitle([title], use_regex=regex) rule = IsEnclosedBy([enclosed])
generic_filter.add_rule(rule) generic_filter.add_rule(rule)
rule = HasData([name, ptype, code], use_regex=regex) rule = HasData([name, ptype, code], use_regex=regex)

View File

@ -28,6 +28,7 @@ from .expandcollapsearrow import *
from .labels import * from .labels import *
from .linkbox import * from .linkbox import *
from .photo import * from .photo import *
from .placeentry import *
from .monitoredwidgets import * from .monitoredwidgets import *
from .selectionwidget import SelectionWidget, Region from .selectionwidget import SelectionWidget, Region
from .shortlistcomboentry import * from .shortlistcomboentry import *

View File

@ -0,0 +1,80 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2015 Nick Hall
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
__all__ = ["PlaceEntry"]
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
import logging
_LOG = logging.getLogger(".widgets.placeentry")
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from ..selectors import SelectorFactory
#-------------------------------------------------------------------------
#
# PlaceEntry class
#
#-------------------------------------------------------------------------
class PlaceEntry(Gtk.Box):
def __init__(self, dbstate, uistate, track):
Gtk.Box.__init__(self)
self.dbstate = dbstate
self.uistate = uistate
self.track = track
self.entry = Gtk.Entry()
self.entry.set_width_chars(5)
self.pack_start(self.entry, True, True, 0)
image = Gtk.Image()
image.set_from_icon_name('gtk-index', Gtk.IconSize.BUTTON)
button = Gtk.Button()
button.set_image(image)
button.set_relief(Gtk.ReliefStyle.NORMAL)
self.pack_start(button, False, True, 0)
button.connect('clicked', self.on_clicked)
self.show_all()
def on_clicked(self, button):
SelectPlace = SelectorFactory('Place')
sel = SelectPlace(self.dbstate, self.uistate, self.track)
place = sel.run()
if place:
self.set_text(place.gramps_id)
def get_text(self):
return self.entry.get_text()
def set_text(self, text):
self.entry.set_text(text)

View File

@ -365,6 +365,7 @@ gramps/gui/widgets/fanchartdesc.py
gramps/gui/widgets/linkbox.py gramps/gui/widgets/linkbox.py
gramps/gui/widgets/menuitem.py gramps/gui/widgets/menuitem.py
gramps/gui/widgets/multitreeview.py gramps/gui/widgets/multitreeview.py
gramps/gui/widgets/placeentry.py
gramps/gui/widgets/shortlistcomboentry.py gramps/gui/widgets/shortlistcomboentry.py
gramps/gui/widgets/springseparator.py gramps/gui/widgets/springseparator.py
gramps/gui/widgets/statusbar.py gramps/gui/widgets/statusbar.py