예제 #1
0
    def __call__(self, x=None, y=None, displayNumber=None, center=False):
        point = POINT()
        GetCursorPos(point)
        X = point.x
        Y = point.y
        mons = EnumDisplayMonitors(None, None)
        mons = [item[2] for item in mons]
        for mon in range(
                len(mons)):  # on what monitor (= mon) is the pointer ?
            m = mons[mon]
            if m[0] <= X and X <= m[2] and m[1] <= Y and Y <= m[3]:
                break
        if displayNumber is None:
            displayNumber = mon

        monitorDimensions = GetMonitorDimensions()
        try:
            displayRect = monitorDimensions[displayNumber]
        except IndexError:
            displayNumber = 0
            displayRect = monitorDimensions[displayNumber]
        if center:
            x = displayRect[2] / 2
            y = displayRect[3] / 2

        if x is None:
            x = X - mons[displayNumber][0]
        if y is None:
            y = Y - mons[displayNumber][1]

        x += displayRect[0]
        y += displayRect[1]
        SetCursorPos(x, y)
 def __call__(self, x, y, displayNumber=0):
     monitorDimensions = GetMonitorDimensions()
     try:
         displayRect = monitorDimensions[displayNumber]
     except IndexError:
         displayRect = monitorDimensions[0]
     rect = RECT()
     mons = EnumDisplayMonitors(None, None)
     mons = [item[2] for item in mons]
     for hwnd in GetTopLevelOfTargetWindows():
         GetWindowRect(hwnd, byref(rect))
         X = rect.left
         Y = rect.top
         for mon in range(len(mons)):
             if mons[mon][0] <= X and X <= mons[mon][2] and mons[mon][
                     1] <= Y and Y <= mons[mon][3]:
                 break
         if mon == len(mons):
             mon = 0
         if x is None:
             x = rect.left - mons[mon][0]
         if y is None:
             y = rect.top - mons[mon][1]
         x += displayRect[0]
         y += displayRect[1]
         MoveWindow(hwnd, x, y, rect.right - rect.left,
                    rect.bottom - rect.top, 1)
예제 #3
0
 def SetDrawing(self, drawFunc, args):
     self.drawing = drawFunc
     d = GetMonitorDimensions()[self.displayNum]
     self.SetDimensions(d.x, d.y, d.width, d.height)
     self._buffer = wx.EmptyBitmap(d.width, d.height)
     dc = wx.BufferedDC(wx.ClientDC(self), self._buffer)
     self.drawing(dc, *args)
     #self.Refresh(eraseBackground=False)
     wx.Frame.Show(self, True)
     BringHwndToFront(self.GetHandle(), False)
     self.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
    def __init__(self, panel, parent, style):

        text = self.text.IgnDbgFrame
        header = dc(text.DbgIgnCol)
        nC = len(header)

        wx.ListCtrl.__init__(self, parent, -1, style=style)
        CheckListCtrlMixin.__init__(self)

        while header:
            self.InsertColumn(nC - len(header),
                              header.pop(0),
                              format=wx.LIST_FORMAT_LEFT)

        def build(testTable, lines):
            cW = []
            self.insertItems(dc(testTable))
            for i in range(nC):
                self.SetColumnWidth(i, wx.LIST_AUTOSIZE)
                cW += [self.GetColumnWidth(i)]
            tW = wx.SYS_VSCROLL_X + self.GetWindowBorderSize()[0] + sum(cW)
            rect = self.GetItemRect(0, wx.LIST_RECT_BOUNDS)
            rect = 2 + rect[1] + lines * rect[3]
            self.DeleteAllItems()
            return cW, tW, rect

        monW = 0
        monH = 0
        for mon in GetMonitorDimensions():
            monW = min(monW, mon[2])
            monH = min(monH, mon[3])

        cW, tW, rect = build(text.NoDataLrg, 10)
        rect = min(monH, rect * 2 + 400)
        tW = min(monW, tW * 2 + 150)

        if monH == rect or monW == tW:
            line = 5 if monH == rect else 10
            tmpText = text.NoDataSml if monW == tW else text.NoDataLrg
            cW, tW, rect = build(tmpText, line)

        parent.panelMin = (tW + 75, rect + 175)
        self.SetMinSize((tW, rect))
        self.cW = cW
        self.tW = tW
        self.nC = nC
        self.panel = panel

        self.OnCheckItem = panel.onCheck
        self.Bind(wx.EVT_SIZE, self.onSize)
예제 #5
0
    def __call__(self,
                 x=None,
                 y=None,
                 displayNumber=None,
                 center=False,
                 useAlternateMethod=False):
        point = POINT()
        GetCursorPos(point)
        X = point.x
        Y = point.y
        mons = EnumDisplayMonitors(None, None)
        mons = [item[2] for item in mons]
        for mon in range(len(mons)):  # on what monitor (= mon) is the cursor?
            m = mons[mon]
            if m[0] <= X and X <= m[2] and m[1] <= Y and Y <= m[3]:
                break
        if displayNumber is None:
            displayNumber = mon

        monitorDimensions = GetMonitorDimensions()
        try:
            displayRect = monitorDimensions[displayNumber]
        except IndexError:
            displayNumber = 0
            displayRect = monitorDimensions[displayNumber]
        if center:
            x = displayRect[2] / 2
            y = displayRect[3] / 2

        if x is None:
            x = X - mons[displayNumber][0]
        if y is None:
            y = Y - mons[displayNumber][1]

        x += displayRect[0]
        y += displayRect[1]
        if useAlternateMethod:
            x = x * 65535 / GetSystemMetrics(0)
            y = y * 65535 / GetSystemMetrics(1)
            mouse_event2(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y)
        else:
            SetCursorPos(x, y)
예제 #6
0
    def ShowOSD(
            self,
            osdText="",
            fontInfo=None,
            textColour=(255, 255, 255),
            outlineColour=(0, 0, 0),
            alignment=0,
            offset=(0, 0),
            displayNumber=0,
            timeout=3.0,
            event=None,
            skin=None,
    ):
        self.timer.cancel()
        if osdText.strip() == "":
            self.bitmap = wx.EmptyBitmap(0, 0)
            SetWindowPos(self.hwnd, 0, 0, 0, 0, 0, HWND_FLAGS | SWP_HIDEWINDOW)
            SetEvent(event)
            return

        #self.Freeze()
        memoryDC = wx.MemoryDC()

        # make sure the mask colour is not used by foreground or
        # background colour
        forbiddenColours = (textColour, outlineColour)
        maskColour = (255, 0, 255)
        if maskColour in forbiddenColours:
            maskColour = (0, 0, 2)
            if maskColour in forbiddenColours:
                maskColour = (0, 0, 3)
        maskBrush = wx.Brush(maskColour, wx.SOLID)
        memoryDC.SetBackground(maskBrush)

        if fontInfo is None:
            fontInfo = DEFAULT_FONT_INFO
        font = wx.FontFromNativeInfoString(fontInfo)
        memoryDC.SetFont(font)

        textLines = osdText.splitlines()
        sizes = [memoryDC.GetTextExtent(line or " ") for line in textLines]
        textWidths, textHeights = zip(*sizes)
        textWidth = max(textWidths)
        textHeight = sum(textHeights)

        if skin:
            bitmap = self.GetSkinnedBitmap(textLines, textWidths, textHeights,
                                           textWidth, textHeight, memoryDC,
                                           textColour, "Default")
            width, height = bitmap.GetSize()
        elif outlineColour is None:
            width, height = textWidth, textHeight
            bitmap = wx.EmptyBitmap(width, height)
            memoryDC.SelectObject(bitmap)

            # fill the DC background with the maskColour
            memoryDC.Clear()

            # draw the text with the foreground colour
            memoryDC.SetTextForeground(textColour)
            DrawTextLines(memoryDC, textLines, textHeights)

            # mask the bitmap, so we can use it to get the needed
            # region of the window
            memoryDC.SelectObject(wx.NullBitmap)
            bitmap.SetMask(wx.Mask(bitmap, maskColour))

            # fill the anti-aliased pixels of the text with the foreground
            # colour, because the region of the window will add these
            # half filled pixels also. Otherwise we would get an ugly
            # border with mask-coloured pixels.
            memoryDC.SetBackground(wx.Brush(textColour, wx.SOLID))
            memoryDC.SelectObject(bitmap)
            memoryDC.Clear()
            memoryDC.SelectObject(wx.NullBitmap)
        else:
            width, height = textWidth + 5, textHeight + 5
            outlineBitmap = wx.EmptyBitmap(width, height, 1)
            outlineDC = wx.MemoryDC()
            outlineDC.SetFont(font)
            outlineDC.SelectObject(outlineBitmap)
            outlineDC.Clear()
            outlineDC.SetBackgroundMode(wx.SOLID)
            DrawTextLines(outlineDC, textLines, textHeights)
            outlineDC.SelectObject(wx.NullBitmap)
            outlineBitmap.SetMask(wx.Mask(outlineBitmap))
            outlineDC.SelectObject(outlineBitmap)

            bitmap = wx.EmptyBitmap(width, height)
            memoryDC.SetTextForeground(outlineColour)
            memoryDC.SelectObject(bitmap)
            memoryDC.Clear()

            Blit = memoryDC.Blit
            logicalFunc = wx.COPY
            for x in xrange(5):
                for y in xrange(5):
                    Blit(x, y, width, height, outlineDC, 0, 0, logicalFunc,
                         True)
            outlineDC.SelectObject(wx.NullBitmap)
            memoryDC.SetTextForeground(textColour)
            DrawTextLines(memoryDC, textLines, textHeights, 2, 2)
            memoryDC.SelectObject(wx.NullBitmap)
            bitmap.SetMask(wx.Mask(bitmap, maskColour))

        region = wx.RegionFromBitmap(bitmap)
        self.SetShape(region)
        self.bitmap = bitmap
        monitorDimensions = GetMonitorDimensions()
        try:
            displayRect = monitorDimensions[displayNumber]
        except IndexError:
            displayRect = monitorDimensions[0]
        xOffset, yOffset = offset
        xFunc, yFunc = ALIGNMENT_FUNCS[alignment]
        x = displayRect.x + xFunc((displayRect.width - width), xOffset)
        y = displayRect.y + yFunc((displayRect.height - height), yOffset)
        deviceContext = wx.ClientDC(self)
        deviceContext.DrawBitmap(self.bitmap, 0, 0, False)
        SetWindowPos(self.hwnd, 0, x, y, width, height,
                     HWND_FLAGS | SWP_SHOWWINDOW)

        if timeout > 0.0:
            self.timer = threading.Timer(timeout, self.OnTimeout)
            self.timer.start()
        eg.app.Yield(True)
        SetEvent(event)
예제 #7
0
 def setOsDialog():
     frg = ctrlEvtString.GetForegroundColour()
     bck = ctrlEvtString.GetBackgroundColour()
     mon = self.configs[self.config][6]
     monDim = GetMonitorDimensions()
     try:
         x, y, ws, hs = monDim[mon]
     except IndexError:
         x, y, ws, hs = monDim[0]
     maxlen = (ws - 50) / 64
     ft = ctrlEvtString.GetFont()
     if len(self.evtString) <= maxlen:
         ft.SetPointSize(64)
     elif len(self.evtString) <= maxlen * 2:
         ft.SetPointSize(32)
     elif len(self.evtString) <= maxlen * 4:
         ft.SetPointSize(16)
     else:
         ft.SetPointSize(10)
     ctrlEvtString.SetFont(ft)
     statTextEvent.SetLabel(self.evtName)
     strEvt = self.evtString + ' '
     ctrlEvtString.ChangeValue(strEvt)
     if self.mode != 2 and len(ctrlEvtString.GetValue()) > 0:
         ctrlEvtString.SetStyle(0, self.pos, wx.TextAttr(frg, bck, ft))
         ctrlEvtString.SetStyle(self.pos, self.pos + 1,
                                wx.TextAttr(bck, frg, ft))
         ctrlEvtString.SetStyle(self.pos + 1,
                                len(ctrlEvtString.GetValue()) + 1,
                                wx.TextAttr(frg, bck, ft))
     else:
         ctrlEvtString.SetStyle(0,
                                len(ctrlEvtString.GetValue()) + 1,
                                wx.TextAttr(frg, bck, ft))
     w0, h0 = self.osDialog.GetSize()
     w1, h1 = statTextEvent.GetTextExtent(self.evtName)
     w2, h2 = ctrlEvtString.GetTextExtent(strEvt)
     wE, hE = ctrlEvtString.GetTextExtent(' ')
     if self.mode == 0 or self.mode >= 3:
         w3, h3 = statTextCapsLock.GetTextExtent('Caps Lock')
         w4a = keysLabel.GetTextExtent('88888888')[0]
         w4b = keysLabel.GetTextExtent(self.oldKeys)[0]
         w4 = max(w4a, w4b)
     else:
         w3 = w4 = h3 = 0
     w0 = min(wE, w0 - 16)
     w = max(w0, w1, w2, w3 + w4 + 20)
     h = h1 + h2 + h3 + 8 + 16
     x_pos = x + (ws - w - 16) / 2
     y_pos = y + (hs - h) / 2
     self.osDialog.SetDimensions(x_pos, y_pos, w + 16, h)
     ctrlEvtString.SetPosition((7, 7 + 8 + h3 + h1))
     ctrlEvtString.SetSize((w, h2))
     statTextEvent.SetPosition((7, 7 + h3))
     statTextEvent.SetSize((w, h1))
     if self.mode == 0 or self.mode >= 3:
         statTextCapsLock.SetPosition((7, 7))
         statTextCapsLock.SetSize((w3, h3))
         keysLabel.SetPosition((w + 7 - w4, 7))
         keysLabel.SetSize((w4, h3))
         if self.shift:
             statTextCapsLock.SetForegroundColour(wx.Colour(255, 0, 0))
         else:
             statTextCapsLock.SetForegroundColour(
                 wx.Colour(100, 149, 237))
         fnt = keysLabel.GetFont()
         keysLabel.SetValue(self.oldKeys)
         keysLabel.SetStyle(0, self.indx, wx.TextAttr(frg, bck, fnt))
         keysLabel.SetStyle(self.indx, self.indx + 1,
                            wx.TextAttr(bck, frg, fnt))
         keysLabel.SetStyle(self.indx + 1,
                            len(self.oldKeys) + 1,
                            wx.TextAttr(frg, bck, fnt))