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

Add param for getWindowsWithTitle(title, equal_or_in='in') #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/pygetwindow/_pygetwindow_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,24 @@ def getWindowsAt(x, y):
return windowsAtXY


def getWindowsWithTitle(title):
"""Returns a list of Window objects that substring match ``title`` in their title text."""
def getWindowsWithTitle(title, equal_or_in='in'):
"""Returns a list of Window objects that substring match ``title`` in their title text.

* ``title`` (str, required): The title of the window(s).
* ``equal_or_in`` (str, optional): Exactly match or in the window(s) title text.
"""
hWndsAndTitles = _getAllTitles()
windowObjs = []
for hWnd, winTitle in hWndsAndTitles:
if title.upper() in winTitle.upper(): # do a case-insensitive match
windowObjs.append(Win32Window(hWnd))
if equal_or_in == 'in':
if title.upper() in winTitle.upper(): # do a case-insensitive match
windowObjs.append(Win32Window(hWnd))
elif equal_or_in == '=':
if title.upper() == winTitle.upper(): # do a case-insensitive match
windowObjs.append(Win32Window(hWnd))
else:
raise PyGetWindowException(("Error code: getWindowsWithTitle(title, equal_or_in='in')"
" equal_or_in shuould in ['in', '=']"))
return windowObjs


Expand Down