-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
[Feature] Add exclude_titles
feature for enhanced window title exclusion
#99
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -92,10 +93,11 @@ def main(): | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean "all cases"? This breaks regex functionality completely. Perhaps you used a bad regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks :)
@@ -30,6 +31,13 @@ | |||
except ProcessLookupError: | |||
logger.info("Process {} already dead".format(pid)) | |||
|
|||
def try_compile_title_regex(title): |
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note
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:
--exclude-titles
argument to the argparse configuration inconfig.py
, enabling the specification of multiple exclusion patterns.heartbeat_loop
function inmain.py
to support bothexclude_title
andexclude_titles
, withexclude_titles
allowing for an array of titles to be excluded.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.