SuperFilter in SuperTool (from Geneanet by PatriceLegoux)

Google Translation of Geneanet Jul 2021 thread Re: I love the SuperTool!) by @PLegoux

Hello,

I am going to share here the few creations of fairly generic SuperTool (ST) filters which could be useful to others, and which have no equivalent in classic Gramps filter.

I provide you with the ST script because it is much more practical than transmitting the Gramps filter XML but once loaded in ST it must be saved as a filter (‘Save as filter’) in the citation filters.

This therefore filters the quotes based on their attributes. In this case, it is looking for an attribute “Consulted on” with the value ‘To be defined’, type and value which can be changed to whatever you want (‘*’ to search for everything)

It also works if it is saved without modification in source filters which also do not have a way to filter sources based on their attributes.

[title]
90. Attribute[{'Consulted on': 'To be defined'}] - 105p

[category]
Sources

[initial_statements]
# Editable values - beginning
# Possible values:  'text' or '*'

attribute_type    = 'Consulted on'
attribute_value = 'To be defined'

# Editable values - end

gid = []

[statements]
for attribute in attributes:
 if attribute_type == '*' and attribute_value == '*':
  gid.append(gramps_id)
  break
 
 if attribut_type == '*':
  if attribute[1] == attribute_value:
   gid.append(gramps_id)
   break
 elif attribute_value == '*':
  if attribute[0] == attribute_type:
   gid.append(gramps_id)
   break
 else:
  if attribute == (attribute_type, attribute_value):
   gid.append(gramps_id)
   break

[filter]
gramps_id in gid

[scope]
all
Note that at home I saved it as below, with two includes, one for initialization and another for the statements, which will allow me to modify the code of the Gramps filters already created on this basis without having to go through it again. in each of them. It does exactly the same thing (for now - includes will probably evolve to allow searching for regexes).

G:\5. Design\Gramps\Isotammi\C90.105p.script:

[title]
90. Attribute[{'Consulted on': 'To be defined'}] - 105p

[category]
Sources

[initial_statements]
# Editable values - begin
# Possible values :  'text' or '*'

attribute_type    = 'Consulted on'
attribute_value = 'To be defined'

# Editable values - end

@include SC_attr_init.py

[statements]
@include SC_attr_statement.py

[filter]
gramps_id in gid

[expressions]

[scope]
all

C:\Users\Patrice\supertool\SC_attr_init.py:

# Include SC_attr_init
gid = []

C:\Users\Patrice\supertool\SC_attr_statement.py:

# Include SC_attr_statement

for attribute in attributes:
 if attribute_type == '*' and attribute_value == '*':
  gid.append(gramps_id)
  break
 
 if attribute_type == '*':
  if attribute[1] == attribute_value:
   gid.append(gramps_id)
   break
 elif attribute_value == '*':
  if attribute[0] == attribute_type:
   gid.append(gramps_id)
   break
 else:
  if attribute == (attribute_type, attribute_value):
   gid.append(gramps_id)
   break

You can use the version you want, the first in a single script or the second with a script and 2 includes. They do the same thing. However, I recommend the second one even if it is a little more complicated to install.

You can use either version without fear of changes to your data, it just filters like any classic Gramps filter.

1 Like

from Re: I love the SuperTool! in Message by patricelegoux »July 11, 2021, 12:08 p.m.

A second that can be combined with the previous one. It searches for sources with source support (electronic, photo, book, etc.) in the particular repository.

[title]
90. RepositorySupport['Electronic'] - 149p

[category]
Sources

[initial_statements]
# Editable values - begin

type_support = 'Electronic'

# Editable values - end

@include S_SupportType_init.py

[statements]
@include S_SupportType_statement.py

[filter]
repository_media_type == [type_support]

[expressions]
title

[scope]
all

S_SupportType_init.py:

# Include S_SupportType_init

S_SupportType_statement.py:

# Include S_SupportType_statement

repository_media_type = [(repo.media_type.string) for repo in source.reporef_list]

from Re: I love the SuperTool! a Message by patricelegoux »July 16, 2021, 1:12 p.m.

Hello,

A new supertool filter. It searches for events with a To Do note .

The supertool script:

[title]
90. Note['To do'] - 363p

[category]
Events

[initial_statements]
# Editable values - begin
note_type = 'To do'
# Editable values - end

@include note_type_search_init.py

[statements]
@include note_type_search_statement.py

[filter]
gramps_id in records_with_note

[expressions]
[note.text for note in notes]

[scope]
all
include note_type_search_init.py:
# note_type_search_init

records_with_note = []
include note_type_search_statement.py:
# note_type_search_statement

for note in notes:
	read_note = db.get_note_from_gramps_id(note.gramps_id)
	if read_note.type == note_type:
		records_with_note.append(gramps_id)
		break

As before:

  • create the 3 files E363p.script, note_type_search_statement.py and note_type_search_init.py in the supertool directory that you previously created (ex in my case: C:\Users\Patrice\supertool . NB: there are only 3 well-defined directories where this supertool directory can be created),
  • in the Events view launch supertool and load the E363p.script file,
  • from there you can:
    – either use it in supertool itself (click on “Execute”)
    – or click on “Save as filter” and you have a filter named “90. Note[‘To do’] - 363p” (which you can rename it if you want)

We should be able to put it in any other module - quotes, individuals… - to make it look for the same or other types of notes without too much difficulty (basically without changing a line of code, just the type note in the first line that I indicated “editable”): note_type = ‘To do’ , for example note_type = ‘Transcription’ to create a filter on this type of notes in citations. Then remember to change the name of the supertool script in order to create the filter with the right name (Title field, for example 90. Note[‘Transcription’] - nnnp )

PS: I added a Supertool section on my page on Gramps including these filters.