# Adding a Match media filter in Persons filters

**URL:** <https://gramps.discourse.group/t/adding-a-match-media-filter-in-persons-filters/968>\
**Category:** Help\
**Created:** [November 29, 2020, 12:11pm UTC](https://gramps.discourse.group/t/adding-a-match-media-filter-in-persons-filters/968 "2020-11-29T12:11:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PLegoux](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/plegoux/32/413_2.png) [@PLegoux](https://gramps.discourse.group/u/PLegoux)\
**Post date:** [November 29, 2020, 12:11pm UTC](https://gramps.discourse.group/t/adding-a-match-media-filter-in-persons-filters/968/1 "2020-11-29T12:11:41Z")

</div>

Hi,

I’m trying to add a _Match media filter_ in Persons filters.

I’ve created two files and modified two others:

- files created:

- files modified: \_init\_.py in the same directories

\_matchesmediafilterbase.py is based on \_matcheseventfilterbase.py from the same directory.

My filter works fine, it returns me people with the selected filter medias but I’ve an issue when creating the filter: media filter selection is not the filters list but just a text box:

 ![image](https://global.discourse-cdn.com/free1/uploads/gramps/original/1X/bb451afdc35f973f2718a18730394ef64107b90d.png)

If I fill it with any media filter name I have, filter works well:

 ![image](https://global.discourse-cdn.com/free1/uploads/gramps/original/1X/a6a02e607546faa11021a1dc067b9993ed9c31e2.png)  
 ![image](https://global.discourse-cdn.com/free1/uploads/gramps/original/1X/720b1652fa71255e8da59a205d866f3ceced3d62.jpeg)

But, what do I have to change to have media filters list in the rule editor instead of that box?

Thanks!

---

<div class="post-metadata">

**Author:** ![Mattkmmr](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/mattkmmr/32/410_2.png) [@Mattkmmr](https://gramps.discourse.group/u/Mattkmmr)\
**Post date:** [November 29, 2020, 1:13pm UTC](https://gramps.discourse.group/t/adding-a-match-media-filter-in-persons-filters/968/2 "2020-11-29T13:13:32Z")

</div>

@PLegoux: I think you have to create your own filter selector, because it’s not supported yet.

@prculley created this filter selector and it’s working fine:

> <https://github.com/gramps-project/addons-source/blob/maintenance/gramps51/FilterRules/infamilyrule.py#L98>

---

<div class="post-metadata">

**Author:** ![PLegoux](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/plegoux/32/413_2.png) [@PLegoux](https://gramps.discourse.group/u/PLegoux)\
**Post date:** [November 29, 2020, 5:16pm UTC](https://gramps.discourse.group/t/adding-a-match-media-filter-in-persons-filters/968/3 "2020-11-29T17:16:21Z")

</div>

I’d tried it.

I’d replaced this

```
caller_locals = stack[1][0].f_locals # locals from caller
# the caller has an attribute 'filterdb' which has what we need
MyFilters. __init__ (self,
                   caller_locals["filterdb"].get_filters('Family'))

```

by this

```
caller_locals = stack[1][0].f_locals # locals from caller
# the caller has an attribute 'filterdb' which has what we need
MyFilters. __init__ (self,
                   caller_locals["filterdb"].get_filters('Media'))

```

but Gramps had crashed at startup with this error stack:

```
5168: ERROR: grampsapp.py: line 157: Unhandled exception
Traceback (most recent call last):
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\grampsgui.py", line 794, in do_activate
    Gramps(self.argparser, self)
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\grampsgui.py", line 603, in __init__
    from .viewmanager import ViewManager
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\viewmanager.py", line 67, in <module>
    from gramps.cli.grampscli import CLIManager
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\cli\grampscli.py", line 67, in <module>
    from gramps.gen.filters import reload_custom_filters
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gen\filters\ __init__.py", line 28, in <module>
    from ._filterlist import FilterList
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gen\filters\_filterlist.py", line 37, in <module>
    from ._filterparser import FilterParser
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gen\filters\_filterparser.py", line 36, in <module>
    from . import rules
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gen\filters\rules\ __init__.py", line 81, in <module>
    from ._matchesmediafilterbase import MatchesMediaFilterBase
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gen\filters\rules\_matchesmediafilterbase.py", line 38, in <module>
    from ....gui.editors.filtereditor import MyFilters
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\editors\ __init__.py", line 30, in <module>
    from .editfamily import EditFamily
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\editors\editfamily.py", line 94, in <module>
    SelectPerson = SelectorFactory('Person')
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\selectors\selectorfactory.py", line 26, in SelectorFactory
    from .selectperson import SelectPerson
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\selectors\selectperson.py", line 37, in <module>
    from ..views.treemodels import PeopleBaseModel, PersonTreeModel
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\views\treemodels\ __init__.py", line 25, in <module>
    from .peoplemodel import PeopleBaseModel, PersonListModel, PersonTreeModel
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\views\treemodels\peoplemodel.py", line 63, in <module>
    from .flatbasemodel import FlatBaseModel
  File "C:\Program Files\GrampsAIO64-5.1.1\gramps\gui\views\treemodels\flatbasemodel.py", line 73, in <module>
    from gramps.gen.filters import SearchFilter, ExactSearchFilter
ImportError: cannot import name 'SearchFilter'

```

It seems to look at the familly and/or person structures (?) which previous code was design for.

I’ve tried that too but it don’t change anything (f\_locals -\> m\_locals):

```
caller_locals = stack[1][0].m_locals # locals from caller
```

---

<div class="post-metadata">

**Author:** ![GeorgeWilmes](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@GeorgeWilmes](https://gramps.discourse.group/u/GeorgeWilmes)\
**Post date:** [January 16, 2023, 8:30pm UTC](https://gramps.discourse.group/t/adding-a-match-media-filter-in-persons-filters/968/6 "2023-01-16T20:30:05Z")

</div>

I’m not sure if I understand all of the details, but would it help to change this code in filtereditor.py:

```
            elif v == _('Filter name:'):
                t = MyFilters(self.filterdb.get_filters(self.namespace),
                              self.filter_name)
            # filters of another namespace, name may be same as caller!
            elif v == _('Person filter name:'):
                t = MyFilters(self.filterdb.get_filters('Person'))
            elif v == _('Event filter name:'):
                t = MyFilters(self.filterdb.get_filters('Event'))
            elif v == _('Source filter name:'):
                t = MyFilters(self.filterdb.get_filters('Source'))
            elif v == _('Repository filter name:'):
                t = MyFilters(self.filterdb.get_filters('Repository'))
            elif v == _('Place filter name:'):
                t = MyFilters(self.filterdb.get_filters('Place'))
            elif v in _name2typeclass:

```

to include lines for ‘Media’ as well? (And ‘Citations’ too?)
