find window methods
spyoungtech opened this issue · 5 comments
Something analogous to selenium's find_element_by
methods or BeautifulSoup
's find
/find_all
methods.
I think the API will also be similar with window Controls.
These are now available, but the implementation may be subject to change... currently, one pretty much must use byte strings to match titles. Wonder if there's a better way; wonder how AHK does it.
Previously, titles were attempted to be decoded first, but some window titles (esp browsers) can contain characters that will break decoding. So, for now seems bytes are safest bet.
Comment on window title matching:
Supposing the existence of two windows, named
- 'Untitled - Google Search - Google Chrome'
- 'Untitled - Notepad'
ahk.win_get('Untitled') method will return the Notepad window-object. Closing the Notepad window, it returns the Google window-object.
Is this behavior inherited from AHK, or is it intended to work like this in the wrapper? If so, it'd be great if a kwarg could be added to specify absolute matching.
There is a kwarg for exact
in the current implementation. It's just not yet documented :)
If I'm understanding you correctly, that is what you mean by 'absolute matching'
find_windows_by_title(b'Untitled - Notepad', exact=True)
Is this behavior inherited from AHK, or is it intended to work like this in the wrapper?
The current implementation of all the find_
methods for windows, the matching is implemented in Python. At present, we just rely on AHK to give us all of the window handles and then they are filtered with Python.
In fact, you can pass a Python callable (function) to find_windows
to filter results.
def always_on_top(win):
return win.always_on_top
find_windows(always_on_top) # should return a generator of windows where func (`always_on_top`) evaluates True
I'll slot this for a documentation update task on the feature.
The underlying implementation may change, but find_window(s) has been more or less complete for a while.
Closing this as done.