Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced version of the Filter gramplet #1721

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kkujansuu
Copy link

This is an enhanced version of the Filter gramplet. The enhancements are

  1. The elapsed time is displayed.
  2. A new 'Define filter' button that opens a filter editor dialog and automatically populates it with the rules that correspond to values given in the gramplet.
  3. The person filter has two new fields: Birth place and Death place
  4. The default confidence value in the Citation filter is 'Very low'.
  5. Place filter: An error message is displayed if the user fills in the 'Within' value but no place is active

@emyoulation
Copy link
Contributor

emyoulation commented May 11, 2024

Very nice!

You have one of the few functional aborts in Gramps for your Filter Params test feature.

I cannot count the number of times that the Filter progress dialog has appeared and I have wished for an abort. (Usually because I had set a parameter incorrectly.)

Could that test abort routine be made compatible with the Filter Progress dialog?

It would probably have to abort to "unfiltered"... would that be intuitive enough?

@kkujansuu
Copy link
Author

kkujansuu commented May 11, 2024 via email

@emyoulation
Copy link
Contributor

emyoulation commented May 11, 2024

Not easily.

Understood and thanks for looking... and another 'thanks' for not being aggravated by the extra ask.

Looks like the PR test fails are formatting compliance. I ran into similar fails for the last PR that I tried. And they would have had the same fails for the module before my changes.

Maybe there's a way to start re-submit the original modules for a compliance check with the new requirements. Although the new proposal (for Type Hints and static type checking) might make that necessary again in the near future.

https://sourceforge.net/p/gramps/mailman/gramps-devel/thread/46818942-927a-463d-ba3c-4d04de3aaf41%40gramps-project.org/#msg58766730

Copy link
Member

@Nick-Hall Nick-Hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I just made a few suggestions.

To get rid of the formatting errors, run black on the files you changed.

rule.list[2] = str(rule.list[2])
new_rules.append(rule)
the_filter.flist = new_rules
comment = "Created by Filter gramplet on " + time.strftime("%Y-%m-%d", time.localtime(time.time()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string looks like it should be translated. Should we use the current locale settings for the date format?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a commit to fix this. I think we can leave the date in ISO format.

if isinstance(rule, gramps.gen.filters.rules.place.WithinArea):
if rule.list[0] is None: # No active place
msg = _("You should select a place when using the 'Within' rule")
self.msg_label.set_markup("<span color='red'>" + msg + "</span>")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to add the css error class to the widget style context rather than hard-coding the colour "red". For example you could use:

self.msg_label.set_text(msg)
self.msg_label.get_style_context().add_class("error")

This will use the error colour defined in the theme. This is useful for visually impaired users and non-European cultures.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand how css and themes work in Gramps. If I add the "error" class then the label still doesn't change color.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I've pushed a commit to your branch which works for me. The errors are red, but the elapsed time is black.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make the css style work if I manually make changes in the file ~/.config/gtk-3.0/gtk.css. But that is probably not the correct the way to do this, is it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, it seems that we are doing changes simultaneously. Did I mess things up?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What operating system and theme are you using? No changes to the css should be necessary.

When you run Gramps in the master branch, what colour is the version number in the status bar? That is set using the "destructive-action" class.

You can either use my changes or update the code yourself.

self.filterdb = gramps.gen.filters.CustomFilters
the_filter = self.get_filter()
if the_filter is None:
self.msg_label.set_markup("<span color='red'>" + _("Supply at least one value") + "</span>")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

@@ -71,4 +72,5 @@
HasTag,
MatchesPlaceFilter,
HasDayOfWeek,
HasEventBase,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is HasEventBase and HasSourceBase related to this PR? I can't see them referenced anywhere.

Copy link
Author

@kkujansuu kkujansuu May 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'Define filter' feature does not work without it.

Event filtering uses the rule class HasEventBase and 'Define filter' will store that class name in custom_filters.xml. For example:

  <object type="Event">
    <filter name="test" function="and" comment="Created by Filter gramplet on 2024-05-12">
      <rule class="HasEventBase" use_regex="False" use_case="False">
        ...
      </rule>
  </object>

However, when custom_filters.xml is read and interpreted then the corresponding rule is silently ignored because the class is not imported in gramps.gen.filters.rules.event.__init__.py. There is only this message on the console:

ERROR: Filter rule 'HasEventBase' in filter 'test' not found!

My solution is to import the class in the __init__.py file. At first i thought it also needed to be added in 'editor_rule_list' but that does not seem to be necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any warnings or errors if I comment these lines out.

The HasEventBase is used as the "Events with parameters" rule. It works if I click the 'Define filter' button in the sidebar, or if I invoke the filter editor from the menu.

@emyoulation
Copy link
Contributor

Kari,

Could you add your 2024 copyright to the list of contributors for these 5 files? It isn't just about taking credit. It also agrees to the terms of the licensing for your contribution. And it also builds confidence by showing that the modules are continuing to evolve. Most of these show 2010 as the last touch.

Cross-link to Discourse forum discussion:
https://gramps.discourse.group/t/can-add-on-gramplets-use-the-lib-plugin-type-to-supersede-built-ins/5422/10

MantisBT request 0013289: Roll Filter+ gramplet plugins into the core (built-in) plugins for 5.3

@kkujansuu
Copy link
Author

kkujansuu commented May 12, 2024 via email

@kkujansuu
Copy link
Author

kkujansuu commented May 12, 2024 via email

@Nick-Hall
Copy link
Member

Nick-Hall commented May 12, 2024

I am using Linux Mint and I don't know what theme I am using! How to check that?

From the command line, start Gramps with:

GTK_DEBUG=interactive python Gramps.py

Then, in the debugger, look in the "Visual" tab.

Note: The Adwaita error colour is (204, 0, 0). The colour "red" is (255, 0, 0).

@kkujansuu
Copy link
Author

kkujansuu commented May 13, 2024 via email

@kkujansuu
Copy link
Author

kkujansuu commented May 13, 2024 via email

@Nick-Hall
Copy link
Member

GTK Theme = Mint-Y

The Mint-Y theme doesn't seem to define the "error" class for labels, although the Mint-X theme does. The "destructive-action" class is only used by buttons.

I suggest that we add the following line to our gramps.css file:

label.error {color: @error_color}

This will let us use classes as recommended. I expect that the @error_color will be used by themes anyway, so overriding it in this way shouldn't cause a problem.

@emyoulation
Copy link
Contributor

Have you tried the GTK+ Inspector tool? It was very enlightening when exploring what CSS was applied to each element of the Gramps GUI.

For Linux only. Wish there were Windows and macOS versions.

@Nick-Hall
Copy link
Member

Have you tried the GTK+ Inspector tool?

What happens if you try to start it in Windows?

@emyoulation
Copy link
Contributor

Have you tried the GTK+ Inspector tool?
What happens if you try to start it in Windows?

I only found GTK+ Inspector in the Gnome project. Haven't found info about installation for Windows or macOS

@jralls
Copy link
Member

jralls commented May 14, 2024

The inspector is part of Gtk. Just start Gramps from the command line with e.g. GTK_DEBUG=interactive gramps and it pops up behind the gramps window. On Windows you probably have to do it in two lines, e.g.

set GTK_DEBUG interactive
gramps

There are also two keyboard shortcuts, <ctrl><shift>I and <ctrl><shift>D, to open it when $GTK_DEBUG isn't set. They don't work on macOS but might on Windows.

@kkujansuu
Copy link
Author

kkujansuu commented May 14, 2024 via email

@Nick-Hall
Copy link
Member

@kkujansuu I'll finish this for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants