Example #1
0
def get_image_size(image):
    """Return the size of an image in pixels as (width, height)."""
    # Get the size of the input image in pixels (Excel sizes are in points,
    # or 1/72th of an inch.
    xl = xl_app()
    dc = win32gui.GetDC(xl.Hwnd)
    pixels_per_inch_x = win32ui.GetDeviceCaps(dc, win32con.LOGPIXELSX)
    pixels_per_inch_y = win32ui.GetDeviceCaps(dc, win32con.LOGPIXELSY)
    size_x = int(image.Width * pixels_per_inch_x / 72)
    size_y = int(image.Height * pixels_per_inch_y / 72)

    return size_x, size_y
Example #2
0
def wndProc(hWnd, message, wParam, lParam):
    if message == win32con.WM_PAINT:
        hdc, paintStruct = win32gui.BeginPaint(hWnd)
        dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
        fontSize = 18
        lf = win32gui.LOGFONT()
        lf.lfFaceName = "Comic Sans"
        lf.lfHeight = int(round(dpiScale * fontSize))
        hf = win32gui.CreateFontIndirect(lf)
        win32gui.SelectObject(hdc, hf)
        rect = win32gui.GetClientRect(hWnd)
        win32gui.DrawText(
            hdc, windowText, -1, rect,
            win32con.DT_LEFT | win32con.DT_BOTTOM | win32con.DT_SINGLELINE)
        win32gui.EndPaint(hWnd, paintStruct)
        return 0

    elif message == win32con.WM_DESTROY:
        print('Being destroyed')
        win32gui.PostQuitMessage(0)
        return 0

    else:
        return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
        calrect = win32gui.DrawText(hdc, text, -1, rect,
                                    textformat | win32con.DT_CALCRECT)

        rect.top = rect.bottom - calcrect.bottom
        win32gui.DrawText(hDC, text, -1, rect, textformat)
Example #3
0
    def wndProc_edge(self, hWnd, message, wParam, lParam):
        if message == win32con.WM_PAINT:
            hdc, paintStruct = win32gui.BeginPaint(hWnd)

            dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
            fontSize = self.fontSize + 12
            win32gui.SetTextColor(hdc, self.color_edge)
            # https://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
            lf = win32gui.LOGFONT()
            lf.lfFaceName = "微軟正黑體"
            lf.lfHeight = int(round(dpiScale * fontSize))
            lf.lfWeight = 700
            # Use nonantialiased to remove the white edges around the text.
            lf.lfQuality = win32con.NONANTIALIASED_QUALITY
            hf = win32gui.CreateFontIndirect(lf)
            win32gui.SelectObject(hdc, hf)

            rect = win32gui.GetClientRect(hWnd)
            # https://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx
            win32gui.DrawTextW(
                hdc, self.text, -1, rect,
                win32con.DT_CENTER | win32con.DT_NOCLIP
                | win32con.DT_SINGLELINE | win32con.DT_VCENTER)
            win32gui.EndPaint(hWnd, paintStruct)
            return 0

        elif message == win32con.WM_DESTROY:
            # print('Closing the window.')
            win32gui.PostQuitMessage(0)
            return 0

        else:
            return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Example #4
0
def cfgPrt(selPrt):

    p = win32print.OpenPrinter(selPrt)
    printprocessor = win32print.GetPrinter(p, 2)['pPrintProcessor']
    dmsize = win32print.DocumentProperties(0, p, selPrt, None, None, 0)
    driverextra = dmsize - pywintypes.DEVMODEType().Size
    dm = pywintypes.DEVMODEType(driverextra)
    dm.Fields = dm.Fields | win32con.DM_ORIENTATION | win32con.DM_COPIES  #|win32con.DM_PAPERSIZE
    dm.Orientation = win32con.DMORIENT_LANDSCAPE
    dm.Copies = 1
    #dm.Papersize=win32con.DM_PAPERLENGTH(790)
    #dm.Paperwidth=530
    win32print.DocumentProperties(
        0, p, selPrt, dm, dm, win32con.DM_IN_BUFFER | win32con.DM_OUT_BUFFER)
    hDC = win32gui.CreateDC(printprocessor, selPrt, dm)
    printerwidth = win32ui.GetDeviceCaps(hDC, 110)
    printerheight = win32ui.GetDeviceCaps(hDC, 111)
Example #5
0
def wndProc(hWnd, message, wParam, lParam):
    global data

    if message == win32con.WM_PAINT:
        hdc, paintStruct = win32gui.BeginPaint(hWnd)

        dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
        fontSize = 80

        # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
        lf = win32gui.LOGFONT()
        lf.lfFaceName = "Times New Roman"
        lf.lfHeight = int(round(dpiScale * fontSize))
        #lf.lfWeight = 150
        # Use nonantialiased to remove the white edges around the text.
        # lf.lfQuality = win32con.NONANTIALIASED_QUALITY
        hf = win32gui.CreateFontIndirect(lf)
        win32gui.SelectObject(hdc, hf)

        rect = win32gui.GetClientRect(hWnd)
        # http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx
        if not loaded:
            win32gui.DrawText(
                hdc, 'Loading Neural Net...', -1, rect,
                win32con.DT_CENTER | win32con.DT_NOCLIP
                | win32con.DT_SINGLELINE | win32con.DT_VCENTER)

        color = win32api.RGB(0, 0, 255)
        color2 = win32api.RGB(255, 255, 0)
        brush = win32gui.CreateSolidBrush(color)
        fontSize = 12
        lf = win32gui.LOGFONT()
        lf.lfFaceName = 'Times New Roman'
        lf.lfHeight = int(round(dpiScale * fontSize))
        lf.lfQuality = win32con.NONANTIALIASED_QUALITY
        hf = win32gui.CreateFontIndirect(lf)
        win32gui.SelectObject(hdc, hf)
        win32gui.SetTextColor(hdc, color2)

        for minion in data:
            win32gui.DrawText(
                hdc, minion['class'] + ' ' + str(int(minion['score'] * 100)),
                -1, minion['location'], win32con.DT_BOTTOM
                | win32con.DT_SINGLELINE | win32con.DT_NOCLIP)
            win32gui.FrameRect(hdc, minion['location'], brush)

        win32gui.EndPaint(hWnd, paintStruct)
        return 0

    elif message == win32con.WM_DESTROY:
        print('Closing the window.')
        win32gui.PostQuitMessage(0)
        return 0

    else:
        return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Example #6
0
 def init_font(self, hdc, paintStruct):
     # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
     lf = win32gui.LOGFONT()
     lf.lfFaceName = "InputMono"
     fontSize = 36
     dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
     lf.lfHeight = int(round(dpiScale * fontSize))
     # lf.lfWeight = 150
     # Use nonantialiased to remove the white edges around the text.
     # lf.lfQuality = win32con.NONANTIALIASED_QUALITY
     lf.lfQuality = win32con.NONANTIALIASED_QUALITY
     self.font = win32gui.CreateFontIndirect(lf)
Example #7
0
def get_systemfont_style():
    # Get DC
    hdc = win32gui.GetDC(0)
    # Get system DPI
    dpi = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSY)
    # Get system font, it's name and size
    z = win32gui.SystemParametersInfo(win32con.SPI_GETNONCLIENTMETRICS)
    font = z['lfMessageFont']
    font_name = font.lfFaceName
    font_size = int(round(abs(font.lfHeight) * 72 / dpi))
    # Release DC
    win32gui.ReleaseDC(0, hdc)
    # Construct sytle for all widget
    font_style = '''
        style "openerp-user-font" {
            font_name = "%s %s"
        }
        widget_class "*" style "openerp-user-font"
    ''' % (font_name, font_size)
    return font_style
Example #8
0
def debugRender(hWnd, hdc, paintStruct):
    dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
    fontSize = 12

    # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
    lf = win32gui.LOGFONT()
    lf.lfFaceName = "Arial"
    lf.lfHeight = int(round(dpiScale * fontSize))
    #lf.lfWeight = 150
    # Use nonantialiased to remove the white edges around the text.
    lf.lfQuality = win32con.NONANTIALIASED_QUALITY
    hf = win32gui.CreateFontIndirect(lf)
    win32gui.SelectObject(hdc, hf)

    rect = win32gui.GetClientRect(hWnd)
    logging.debug(rect)
    # http://msdn.microsoft.com/en-us/library/windows/desktop/dd162498(v=vs.85).aspx
    win32gui.DrawText(
        hdc, 'Text on the screen', -1, rect, win32con.DT_CENTER
        | win32con.DT_NOCLIP | win32con.DT_SINGLELINE | win32con.DT_VCENTER)
def wndProc(hWnd, message, wParam, lParam):
    if message == win32con.WM_PAINT:
        hdc, paintStruct = win32gui.BeginPaint(hWnd)
        print 'windProc'
        dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
        fontSize = 80
        lf = win32gui.LOGFONT()
        lf.lfFaceName = "Times New Roman"
        lf.lfHeight = int(round(dpiScale * fontSize))
        hf = win32gui.CreateFontIndirect(lf)
        win32gui.SelectObject(hdc, hf)
        rect = win32gui.GetClientRect(hWnd)
        win32gui.DrawText(
            hdc, 'O', -1, rect, win32con.DT_CENTER | win32con.DT_NOCLIP
            | win32con.DT_SINGLELINE | win32con.DT_VCENTER)
        win32gui.EndPaint(hWnd, paintStruct)
        return 0
    elif message == win32con.WM_DESTROY:
        print 'Closing the window.'
        win32gui.PostQuitMessage(0)
        return 0
    else:
        return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Example #10
0
    def wndProc(self, hWnd, message, wParam, lParam):

        if message == win32con.WM_PAINT:
            hdc, paintStruct = win32gui.BeginPaint(hWnd)

            # Font configuration
            dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
            fontSize = 10

            # http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx
            lf = win32gui.LOGFONT()
            lf.lfFaceName = "Tahoma"
            lf.lfHeight = int(round(dpiScale * fontSize))
            lf.lfWeight = 700  # bold
            lf.lfQuality = win32con.NONANTIALIASED_QUALITY  # Use nonantialiased to remove the white edges around the text.

            hf = win32gui.CreateFontIndirect(lf)

            win32gui.SelectObject(hdc, hf)

            br = win32gui.CreateSolidBrush(win32api.RGB(255, 0, 0))
            win32gui.SelectObject(hdc, br)

            # Update positions
            self.updatePositions()

            # Bars
            # Positions the bars
            if self.mounted:
                xc = self.axcm
                yc = self.aycm
            else:
                xc = self.axc
                yc = self.ayc

            r = self.aradius
            dr = self.awidth
            alpha = self.aangle

            #print(xc,yc)

            ## Text
            # Positions the text
            pleft = self.tleft
            ptop = self.ttop
            pright = self.tright
            pbottom = self.tbottom
            spc = self.tspc

            #print(pleft,ptop,pright,pbottom)
            if self.setup:
                sr = alpha
                rr = r
                for _ in range(2):
                    sr, rr = self.drawRightArc(hdc, (xc, yc), rr, dr, sr, 1.0,
                                               ColorCode.ORANGE)

                sl = alpha
                rl = r
                for _ in range(2):
                    sl, rl = self.drawLeftArc(hdc, (xc, yc), rl, dr, sl, 1.0,
                                              ColorCode.ORANGE)

                for i in range(50):
                    pos = (pleft, ptop + i * spc, pright, pbottom)
                    self.drawTextLabel(hdc, pos, ColorCode.ORANGE,
                                       'ExampleText')
                    self.drawTimerLabel(hdc, pos, ColorCode.ORANGE, float(i))

            else:
                idx = 0
                sr = alpha
                rr = r
                for idx, action in enumerate(self.rightArcToDraw):
                    sr, rr = self.drawRightArc(hdc, (xc, yc), rr, dr, sr,
                                               action.getPercentage(),
                                               action.color)

                sl = alpha
                rl = r
                for idx, action in enumerate(self.leftArcToDraw):
                    sl, rl = self.drawLeftArc(hdc, (xc, yc), rl, dr, sl,
                                              action.getPercentage(),
                                              action.color)

                for idx, group in enumerate(self.groupsToDraw):
                    pos = (pleft, ptop + idx * spc, pright, pbottom)
                    self.drawTextLabel(hdc, pos, group.color, group.labelText)
                    self.drawTimerLabel(hdc, pos, group.color, group.countdown)

                k = idx + 2
                for idx, action in enumerate(self.actionsToDraw):
                    if (idx + 1) in self.emptyLines: k = k + 1

                    pos = (pleft, ptop + (idx + k) * spc, pright, pbottom)
                    self.drawTextLabel(hdc, pos, action.color,
                                       action.labelText)
                    self.drawTimerLabel(hdc, pos, action.color,
                                        action.countdown)

                k = k + idx + 2
                for idx, equip in enumerate(self.equipmentToDraw):
                    #if (idx+1) in emptyLines : k=k+1

                    pos = (pleft, ptop + (idx + k) * spc, pright, pbottom)
                    self.drawTextLabel(hdc, pos, equip.color, equip.labelText)
                    self.drawTimerLabel(hdc, pos, equip.color, equip.countdown)

                win32gui.EndPaint(hWnd, paintStruct)
                return 0

        elif message == win32con.WM_DESTROY:
            win32gui.PostQuitMessage(0)
            return 0

        else:
            return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
Example #11
0
	def getDisplaySettings(self):
		'''return x_resolution, y_resolution, colour_depth'''
		xScreen = WA.GetSystemMetrics(WC.SM_CXSCREEN)	# SM_CXSCREEN = 0
		yScreen = WA.GetSystemMetrics(WC.SM_CYSCREEN)	# SM_CYSCREEN = 1
		bPixels = WU.GetDeviceCaps(WG.GetDC(0), WC.BITSPIXEL)
		return [xScreen, yScreen, bPixels]
Example #12
0
 def _get_dpi_scale(handle: int) -> float:
     """Return the DPI scaling factor"""
     return ui.GetDeviceCaps(handle, con.LOGPIXELSX) / 60.0