[Feature] Add exclude_titles feature for enhanced window title exclusion#99
Conversation
This commit introduces the `--exclude-titles` argument to the aw-watcher-window module, allowing users to specify a list of window titles or regular expression patterns to exclude from tracking. This new feature is designed to complement the existing `--exclude-title` flag, providing enhanced flexibility for users who need to exclude multiple window titles without breaking compatibility with existing configurations. Key Changes: - Added the `--exclude-titles` argument to the argparse configuration in `config.py`, enabling the specification of multiple exclusion patterns. - Updated the `heartbeat_loop` function in `main.py` to support both `exclude_title` and `exclude_titles`, with `exclude_titles` allowing for an array of titles to be excluded. - Utilized the `re` module for regex pattern matching against window titles, ensuring case-insensitive comparisons. This enhancement ensures that users can now more precisely control which window titles are excluded from tracking, making the aw-watcher-window module more versatile and user-friendly.
|
I have been using this feature since I opened this PR and have not had any problems so far |
aw_watcher_window/main.py
Outdated
| if exclude_titles: | ||
| for title in exclude_titles: | ||
| pattern = re.compile(re.escape(title), re.IGNORECASE) | ||
| if pattern.search(current_window["title"]): |
There was a problem hiding this comment.
Seems you are treating all strings as regexes? This might confuse some users given the help string "List of window titles or regular expression patterns".
Co-authored-by: Erik Bjäreholt <erik.bjareholt@gmail.com>
aw_watcher_window/main.py
Outdated
| poll_time=args.poll_time, | ||
| strategy=args.strategy, | ||
| exclude_title=args.exclude_title, | ||
| exclude_titles=[re.compile(re.escape(title), re.IGNORECASE) for title in args.exclude_titles] |
There was a problem hiding this comment.
Why are you escaping this? If you are escaping, then it's not really matching a regex, as all regex-special characters (.[]()+*? etc) would be escaped and wouldn't work (iirc).
There was a problem hiding this comment.
I did it this way because it is the way that worked for me in all cases, but it is perfectly possible to remove it
There was a problem hiding this comment.
What do you mean "all cases"? This breaks regex functionality completely. Perhaps you used a bad regex?
There was a problem hiding this comment.
It is not so much that they are bad regex, but that by putting part of a title it excludes it, but without escaping the characters it works the same.
|
@ellipsis-dev Can you review this, and the |
…tles` feature for enhanced window title exclusion);
|
@ErikBjare, I have addressed your comments in pull request #102 |
|
It seems Ellipsis wanted to put the compile in a try/except, which is probably a good idea (although it messed up the syntax). |
This commit introduces the
--exclude-titlesargument to the aw-watcher-window module, allowing users to specify a list of window titles or regular expression patterns to exclude from tracking. This new feature is designed to complement the existing--exclude-titleflag, providing enhanced flexibility for users who need to exclude multiple window titles without breaking compatibility with existing configurations.Key Changes:
--exclude-titlesargument to the argparse configuration inconfig.py, enabling the specification of multiple exclusion patterns.heartbeat_loopfunction inmain.pyto support bothexclude_titleandexclude_titles, withexclude_titlesallowing for an array of titles to be excluded.remodule for regex pattern matching against window titles, ensuring case-insensitive comparisons.This enhancement ensures that users can now more precisely control which window titles are excluded from tracking, making the aw-watcher-window module more versatile and user-friendly.