varietywalls / variety

Wallpaper downloader and manager for Linux systems
http://peterlevi.com/variety
GNU General Public License v3.0
1.12k stars 137 forks source link

Add regex name filter #619

Open MarelliF opened 1 year ago

MarelliF commented 1 year ago

Hello,

I implemented a simple name regex check to allow filtering what images are shown. It is integrated in the preferences dialog under the Filtering category. This is useful mostly when using a local folder source.

I ran the tests prior to this pull request, all pass except TestNationalGeographicDownloader.TestNationalGeographicDownloader, which is not related to my modifications. I tested a local build on my own machine (Manjaro Gnome), all works as expected.

Please let me know if I should modify anything for this to be merged in the master branch, I would be happy to help.

Best regards, Francois

peterlevi commented 5 months ago

Regexes are mostly a programming concept and most users would not be familiar with them. IMHO, when we are talking about filtering by filename, globs are probably a more suitable, popular and easy-to-use concept - https://en.wikipedia.org/wiki/Glob_(programming). Is there any strong reason to implement this filtering around regexes rather than globs? @jlu5 WDYT?

In both cases, but especially for regexes, it will be good if the preferences UI has a link to an external documentation on globs/regexes (for globs, a description with 1-2 examples for the use of ? and *, plus a link to read more may be better).

Additionally (but it would make the implementation more complex), since this mostly makes sense for local files, it may be better if this is not an option in Filtering, but rather an option that can be specified separately on all "local folder" sources. E.g. I may be interested in all **/*elephant* from my Pictures/Animals folder, and all **/*savannah* in the Pictures/Landscapes folder.

jlu5 commented 5 months ago

Regexes are mostly a programming concept and most users would not be familiar with them. IMHO, when we are talking about filtering by filename, globs are probably a more suitable, popular and easy-to-use concept - https://en.wikipedia.org/wiki/Glob_(programming). Is there any strong reason to implement this filtering around regexes rather than globs? @jlu5 WDYT?

I don't have a strong opinion here. If we only focus on matching filenames, regexps are more expressive with little extra cost (Python's glob matching uses regex under the hood anyways), and the simplest usecase with wildcards aren't that much harder to create compared to globs IMO.

In both cases, but especially for regexes, it will be good if the preferences UI has a link to an external documentation on globs/regexes (for globs, a description with 1-2 examples for the use of ? and *, plus a link to read more may be better).

I agree on this.

Additionally (but it would make the implementation more complex), since this mostly makes sense for local files, it may be better if this is not an option in Filtering, but rather an option that can be specified separately on all "local folder" sources. E.g. I may be interested in all **/*elephant* from my Pictures/Animals folder, and all **/*savannah* in the Pictures/Landscapes folder.

If we go with full path search it'd make more sense to use globs, yeah. Matching directories of arbitrary depth isn't nearly as straightforward with regex.

But maybe glob and regex filters don't need to be mutually exclusive more generally :smile: