Пример #1
0
 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
Пример #2
0
    def __call__(self):         #-- v2.0
        try:
            hWnd = FindWindow("Winamp v1.x")
        except:
            raise self.Exceptions.ProgramNotRunning
        strWinAmpTitle = GetWindowText(hWnd)
        sx = strWinAmpTitle.split("*** ")
        try:
            strWinAmpTitle = sx[1] + sx[0]
        except:
            pass

        strWinAmpTitle = strWinAmpTitle.replace("*","").strip()
        strWinAmpTitle = strWinAmpTitle.replace(" - Winamp", "")
        strWinAmpTitle = strWinAmpTitle.replace(" [Stopped]", "")
        strWinAmpTitle = strWinAmpTitle.replace(" [Paused]", "")
        strWinAmpTitle = strWinAmpTitle.replace(" [Stopp]", "")
        strWinAmpTitle = strWinAmpTitle.replace(" [Pause]", "")

        decPos = strWinAmpTitle.find(" ") - 1
        if decPos > 0 and strWinAmpTitle[decPos] == "." and strWinAmpTitle[:decPos].isdigit():
            strWinAmpTitle = strWinAmpTitle[decPos + 2:]

        strWinAmpTitle = strWinAmpTitle.strip()
        return strWinAmpTitle
Пример #3
0
    def __call__(self):         #-- v2.0
        try:
            hWnd = FindWindow("Winamp v1.x")
        except:
            raise self.Exceptions.ProgramNotRunning
        strWinAmpTitle = GetWindowText(hWnd)
        sx = strWinAmpTitle.split("*** ")
        try:
            strWinAmpTitle = sx[1] + sx[0]
        except:
            pass

        strWinAmpTitle = strWinAmpTitle.replace("*","").strip()
        strWinAmpTitle = strWinAmpTitle.replace(" - Winamp", "")
        strWinAmpTitle = strWinAmpTitle.replace(" [Stopped]", "")
        strWinAmpTitle = strWinAmpTitle.replace(" [Paused]", "")
        strWinAmpTitle = strWinAmpTitle.replace(" [Stopp]", "")
        strWinAmpTitle = strWinAmpTitle.replace(" [Pause]", "")

        decPos = strWinAmpTitle.find(" ") - 1
        if decPos > 0 and strWinAmpTitle[decPos] == "." and strWinAmpTitle[:decPos].isdigit():
            strWinAmpTitle = strWinAmpTitle[decPos + 2:]

        strWinAmpTitle = strWinAmpTitle.strip()
        return strWinAmpTitle
    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)
Пример #5
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 __init__(self, hwnd):
     self.hwnd = hwnd
     self.pid = GetWindowPid(hwnd)
     self.name = splitext(GetProcessName(self.pid))[0]
     # The following may change during a window's lifetime
     self.title = GetWindowText(hwnd)
     self.window_class = GetClassName(hwnd)
Пример #7
0
    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)
Пример #8
0
 def __call__(self, item=0):
     hwnd = eg.lastFoundWindows[0]
     clsName = GetClassName(hwnd)
     if clsName == 'TStatusBar' or clsName == 'msctls_statusbar32':
         result = GetStatusBarText(hwnd, 1024)
         if item:
             result = result[item - 1]
         elif len(result) == 1:
             result = result[0]
     else:
         result = GetWindowText(hwnd)
     return result
Пример #9
0
 def __init__(self, hwnd):
     if not hwnd:
         raise ValueError("Invalid hwnd")
     self.hwnd = hwnd
     dwProcessId = DWORD()
     GetWindowThreadProcessId(hwnd, byref(dwProcessId))
     self.pid = dwProcessId.value
     self.name = splitext(GetProcessName(self.pid))[0]
     # The following may change during a window's lifetime
     self.cached_title = ourName if self.pid == GetProcessId(
     ) else GetWindowText(hwnd)
     self.cached_class = GetClassName(hwnd)
    def __getattribute__(self, name):
        if name == 'is_visible':
            return win32gui.IsWindowVisible(self.hwnd)
        elif name == 'is_enabled':
            return win32gui.IsWindowEnabled(self.hwnd)
        elif name == 'title':
            # If the window is closed, GetWindowText and GetClassName
            # return empty strings, so return the cached versions.
            title = GetWindowText(self.hwnd)
            if title != '':
                self.title = title
            # Intentionally fall through to end of method
        elif name == 'window_class':
            win_class = GetClassName(self.hwnd)
            if win_class != '':
                self.window_class = win_class
            # Intentionally fall through to end of method

        return object.__getattribute__(self, name)
 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)
Пример #12
0
    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)
Пример #13
0
 def title(self):
     if self.IsAlive():
         self.cached_title = ourName if self.pid == GetProcessId(
         ) else GetWindowText(self.hwnd)
     return self.cached_title