def __call__(self, hwnd=None): # Gather info about the target window hwnd = GetBestHwnd(hwnd) icon = GetHwndIcon(hwnd) title = unicode(GetWindowText(hwnd)) # If valid, minimize target to the systray if hwnd in eg.WinApi.GetTopLevelWindowList(False) and isinstance( icon, wx._gdi.Icon): trayIcon = wx.TaskBarIcon() trayIcon.SetIcon(icon, title) self.plugin.iconDict[hwnd] = trayIcon def OnClick2(): # Remove our tray icon and restore the window try: BringHwndToFront(hwnd) del self.plugin.iconDict[hwnd] except: pass finally: trayIcon.RemoveIcon() trayIcon.Destroy() def OnClick(*dummyArgs): wx.CallAfter(OnClick2) trayIcon.Bind(wx.EVT_TASKBAR_LEFT_UP, OnClick) wx.CallAfter(ShowWindow, hwnd, 0)
def __init__(self, parent, hwnds): wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT | wx.LC_SINGLE_SEL) listmix.ListCtrlAutoWidthMixin.__init__(self) imageList = wx.ImageList(16, 16) imageList.Add(GetInternalBitmap("cwindow")) self.AssignImageList(imageList, wx.IMAGE_LIST_SMALL) self.InsertColumn(0, "Program") self.InsertColumn(1, "Name") self.InsertColumn(2, "Class") self.InsertColumn(3, "Handle", wx.LIST_FORMAT_RIGHT) for hwnd in hwnds: imageIdx = 0 icon = GetHwndIcon(hwnd) if icon: imageIdx = imageList.AddIcon(icon) idx = self.InsertImageStringItem(sys.maxint, GetWindowProcessName(hwnd), imageIdx) self.SetStringItem(idx, 1, GetWindowText(hwnd)) self.SetStringItem(idx, 2, GetClassName(hwnd)) self.SetStringItem(idx, 3, str(hwnd)) for i in range(4): self.SetColumnWidth(i, -2) headerSize = self.GetColumnWidth(i) self.SetColumnWidth(i, -1) labelSize = self.GetColumnWidth(i) if headerSize > labelSize: self.SetColumnWidth(i, headerSize)
def AppendPrograms(self): self.pids.clear() processes = EnumProcesses() # get PID list for pid in processes: self.pids[pid] = [] hwnds = GetTopLevelWindowList(self.includeInvisible) for hwnd in hwnds: pid = GetWindowThreadProcessId(hwnd)[1] if pid == eg.processId: continue self.pids[pid].append(hwnd) for pid in processes: if len(self.pids[pid]) == 0: continue iconIndex = 0 for hwnd in self.pids[pid]: icon = GetHwndIcon(hwnd) if icon: iconIndex = self.imageList.AddIcon(icon) break exe = GetProcessName(pid) item = self.AppendItem(self.root, exe) self.SetItemHasChildren(item, True) self.SetPyData(item, pid) self.SetItemImage(item, iconIndex, which=wx.TreeItemIcon_Normal)
def AppendChildWindows(self, parentHwnd, item): for hwnd in GetHwndChildren(parentHwnd, self.includeInvisible): name = GetWindowText(hwnd) className = GetClassName(hwnd) if name != "": name = "\"" + name + "\" " index = self.AppendItem(item, name + className, 0) self.SetPyData(index, hwnd) if className == "Edit" or className == "TEdit": self.SetItemImage(index, 1, which=wx.TreeItemIcon_Normal) elif className == "Static" or className == "TStaticText": self.SetItemImage(index, 2, which=wx.TreeItemIcon_Normal) elif className == "Button" or className == "TButton": self.SetItemImage(index, 3, which=wx.TreeItemIcon_Normal) elif GetClassName(parentHwnd) == "MDIClient": icon = GetHwndIcon(hwnd) if icon: iconIndex = self.imageList.AddIcon(icon) self.SetItemImage( index, iconIndex, which=wx.TreeItemIcon_Normal ) if HwndHasChildren(hwnd, self.includeInvisible): self.SetItemHasChildren(index, True)
def AppendToplevelWindows(self, pid, item): hwnds = self.pids[pid] for hwnd in hwnds: try: name = GetWindowText(hwnd) className = GetClassName(hwnd) icon = GetHwndIcon(hwnd) except: continue if name != '': name = '"%s"' % name iconIndex = 0 if icon: iconIndex = self.imageList.AddIcon(icon) newItem = self.AppendItem(item, name) self.SetPyData(newItem, hwnd) self.SetItemText(newItem, name + className) self.SetItemImage(newItem, iconIndex, which=wx.TreeItemIcon_Normal) if HwndHasChildren(hwnd, self.includeInvisible): self.SetItemHasChildren(newItem, True)