def Find(self): winClassMatch = self.winClassMatch winNameMatch = self.winNameMatch programMatch = self.programMatch includeInvisible = self.includeInvisible topWindowsHwnds = [ hwnd for hwnd in GetTopLevelWindowList(includeInvisible) if ( winClassMatch(GetClassName(hwnd)) and winNameMatch(GetWindowText(hwnd)) ) ] if self.program: topWindowsHwnds = [ hwnd for hwnd in topWindowsHwnds if programMatch(GetWindowProcessName(hwnd).upper()) ] if not self.scanChilds: return topWindowsHwnds childClassMatch = self.childClassMatch childNameMatch = self.childNameMatch childHwnds = [ childHwnd for parentHwnd in topWindowsHwnds for childHwnd in GetWindowChildsList( parentHwnd, includeInvisible ) if ( childClassMatch(GetClassName(childHwnd)) and childNameMatch(GetWindowText(childHwnd)) ) ] return childHwnds
def OnSelectionChanged(self, event): event.Skip() tree = self.tree item = tree.GetSelection() if not item.IsOk(): return hwnd = tree.GetPyData(item) eg.PrintDebugNotice("HWND:", hwnd) if tree.GetItemParent(item) == tree.root: # only selected a program pid = hwnd hwnd = None else: pid = GetWindowThreadProcessId(hwnd)[1] if pid == self.lastPid and hwnd == self.lastHwnd: return self.lastPid = pid self.lastHwnd = hwnd exe = GetProcessName(pid) def SetOption(flag, option, value): checkBox, textCtrl = option checkBox.SetValue(flag) textCtrl.SetValue(value) textCtrl.Enable(flag) rootHwnd = None options = self.options SetOption(bool(exe), options[0], exe) if hwnd is not None: rootHwnd = GetAncestor(hwnd, GA_ROOT) targetWinName = GetWindowText(rootHwnd) targetWinClass = GetClassName(rootHwnd) SetOption(True, options[1], targetWinName) SetOption(True, options[2], targetWinClass) else: SetOption(False, options[1], "") SetOption(False, options[2], "") if rootHwnd is not None and rootHwnd != hwnd: targetWinName = GetWindowText(hwnd) targetWinClass = GetClassName(hwnd) SetOption(True, options[3], targetWinName) SetOption(True, options[4], targetWinClass) searchHwnd = hwnd data = [ child for child in GetWindowChildsList( rootHwnd, tree.includeInvisible ) if ( GetClassName(child) == targetWinClass and GetWindowText(child) == targetWinName ) ] try: count = data.index(searchHwnd) + 1 except: count = 0 else: SetOption(False, options[3], "") SetOption(False, options[4], "") if rootHwnd is not None: data = [ hwnd for hwnd in GetTopLevelWindowList(tree.includeInvisible) # NOQA if ( GetClassName(hwnd) == targetWinClass and GetWindowText(hwnd) != targetWinName and GetWindowThreadProcessId(hwnd)[1] == pid ) ] count = len(data) else: count = 0 SetOption(count > 0, options[5], count or 1)