Skip to content

Commit

Permalink
Enable wildcard in window title match
Browse files Browse the repository at this point in the history
Reuse code rather than code duplication for hwnd from title
  • Loading branch information
jsa34 committed Feb 22, 2022
1 parent 2d2e7ba commit 0666466
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pyjab/common/win32utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fnmatch
import time
from ctypes.wintypes import HWND
from typing import Dict, Generator, List, Optional
Expand Down Expand Up @@ -228,15 +229,13 @@ def get_all_hwnds(hwnd, _):
return dict_hwnd

def get_hwnd_by_title(self, title: str) -> Optional[HWND]:
dict_hwnd = self.enum_windows()
try:
return list(dict_hwnd.keys())[list(dict_hwnd.values()).index(title)]
except ValueError:
return None
if possible_matches := self.get_hwnds_by_title(title):
return possible_matches[0]
return None

def get_hwnds_by_title(self, title: str) -> List[HWND]:
dict_hwnd = self.enum_windows()
return [hwnd for hwnd, win_title in dict_hwnd.items() if title == win_title]
return [hwnd for hwnd, win_title in dict_hwnd.items() if fnmatch.fnmatch(win_title, title)]

def get_title_by_hwnd(self, hwnd: HWND) -> str:
return win32api.GetWindowText(hwnd)
Expand Down

0 comments on commit 0666466

Please sign in to comment.