def OnPaint_1(hwnd, msg, wp, lp):
    dc, ps = win32gui.BeginPaint(hwnd)
    win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED)
    br = win32gui.CreateSolidBrush(win32api.RGB(255, 0, 0))
    win32gui.SelectObject(dc, br)
    angle = win32gui.GetWindowLong(hwnd, win32con.GWL_USERDATA)
    win32gui.SetWindowLong(hwnd, win32con.GWL_USERDATA, angle + 2)
    r_angle = angle * (math.pi / 180)
    win32gui.SetWorldTransform(
        dc, {
            'M11': math.cos(r_angle),
            'M12': math.sin(r_angle),
            'M21': math.sin(r_angle) * -1,
            'M22': math.cos(r_angle),
            'Dx': 250,
            'Dy': 250
        })
    win32gui.MoveToEx(dc, 250, 250)
    win32gui.BeginPath(dc)
    win32gui.Pie(dc, 10, 70, 200, 200, 350, 350, 75, 10)
    win32gui.Chord(dc, 200, 200, 850, 0, 350, 350, 75, 10)
    win32gui.LineTo(dc, 300, 300)
    win32gui.LineTo(dc, 100, 20)
    win32gui.LineTo(dc, 20, 100)
    win32gui.LineTo(dc, 400, 0)
    win32gui.LineTo(dc, 0, 400)
    win32gui.EndPath(dc)
    win32gui.StrokeAndFillPath(dc)
    win32gui.EndPaint(hwnd, ps)
    return 0
示例#2
0
def OnPaint(hwnd, msg, wp, lp):
    global dx
    font = win32gui.LOGFONT()
    font.lfFaceName = "Consolas"
    font.lfHeight = 48
    # font.lfWidth=font.lfHeight
    # font.lfWeight=150
    # font.lfItalic=1
    # font.lfUnderline=1
    hfont = win32gui.CreateFontIndirect(font)
    dc, ps = win32gui.BeginPaint(hwnd)
    win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED)
    l, t, r, b = win32gui.GetClientRect(hwnd)
    br = win32gui.CreateSolidBrush(win32api.RGB(0, 0, 255))
    bitmap = win32gui.CreateBitmap(20, 5, 4, 1, None)
    win32gui.SelectObject(dc, bitmap)
    win32gui.SelectObject(dc, br)
    win32gui.SelectObject(dc, hfont)
    win32gui.SetTextColor(
        dc, win32api.RGB(randint(1, 255), randint(1, 255), randint(1, 255)))
    win32gui.DrawText(dc, 'hello', -1, (100, 100, 300, 300), 0)
    win32gui.FillRect(dc, (200 + dx, 200 + dx, 100 + dx, 100 + dx), br)
    dx = (dx + 10) % 100
    win32gui.EndPaint(hwnd, ps)
    return 0
示例#3
0
    def drawRightArc(self,
                     hdc,
                     pos,
                     radius,
                     width,
                     span,
                     percent,
                     color=ColorCode.BLACK):

        if percent > 0.0:
            # Get arc center coordinates
            xc = pos[0]
            yc = pos[1]

            # Calculate a2
            a1 = math.radians(span / 2)
            a2 = math.asin(radius * math.sin(a1) / (radius + width))

            # calculate displacement on x and y axis
            dx = radius * math.cos(a2)
            dy = radius * math.sin(a2)

            # calculate starting point coordinates
            xs = int(xc + dx)
            ys = int(yc + dy)
            a2d = math.degrees(a2)

            # determines arc span
            span = 2 * a2d

            # sets the percentage to be drawn
            n = percent

            # sets arc fill color
            sb = win32gui.CreateSolidBrush(color)
            win32gui.SelectObject(hdc, sb)

            # sets arc stroke
            sp = win32gui.CreatePen(win32con.PS_SOLID, 1, ColorCode.BLACK)
            win32gui.SelectObject(hdc, sp)

            # draws the outline of the arc
            win32gui.BeginPath(hdc)
            win32gui.MoveToEx(hdc, xs, ys)
            win32gui.AngleArc(hdc, xc, yc, radius + width, -a2d, int(n * span))
            win32gui.AngleArc(hdc, xc, yc, radius, int(a2d - (1 - n) * span),
                              -int(n * span))
            win32gui.EndPath(hdc)

            # fills the arc with outer stroke
            win32gui.StrokeAndFillPath(hdc)

            # returns the next arc span and radius
            return span, (radius + width)
        else:
            # if its not drawn, returns original arc span and radius
            return span, radius
示例#4
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)
示例#5
0
def OnPaint(hwnd, msg, wp, lp):
	global dx
	dc, ps=win32gui.BeginPaint(hwnd)
	win32gui.SetGraphicsMode(dc, win32con.GM_ADVANCED)
	l,t,r,b=win32gui.GetClientRect(hwnd)
	br=win32gui.CreateSolidBrush(win32api.RGB(0,0,255))
	win32gui.SelectObject(dc, br)
	win32gui.FillRect(dc,(200+dx,200+dx,100+dx,100+dx),br)
	dx=(dx+10)%100
	win32gui.EndPaint(hwnd, ps)
	return 0
示例#6
0
def OnPaint(hwnd, msg, wp, lp):
    """Windows needs repainting"""

    dc, ps = win32gui.BeginPaint(hwnd)

    #Draw red circle
    br = win32gui.CreateSolidBrush(win32api.RGB(255, 0, 0))
    win32gui.SelectObject(dc, br)
    win32gui.Ellipse(dc, 20, 20, 120, 120)

    #Draw green rectangle
    br = win32gui.CreateSolidBrush(win32api.RGB(0, 255, 0))
    win32gui.SelectObject(dc, br)
    win32gui.Rectangle(dc, 150, 20, 300, 120)

    #Draw blue triangle
    br = win32gui.CreateSolidBrush(win32api.RGB(0, 0, 255))
    win32gui.SelectObject(dc, br)
    win32gui.Polygon(dc, [(400, 20), (350, 120), (450, 120)])

    win32gui.EndPaint(hwnd, ps)
    return 0
示例#7
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)
示例#8
0
        def wnd_proc(h_wnd, message, w_param, l_param):
            """Displays a transparent window with some graphic elements
			Displays a transparent window with some graphic elements
			:param h_wnd: an input argument
			:returns: nothing
			"""
            if message == win32con.WM_QUIT:
                # print("Closing the window overlay")
                win32gui.PostQuitMessage(0)
                return 0

            if message == win32con.WM_PAINT:
                hdc, paint_struct = win32gui.BeginPaint(h_wnd)
                win32gui.SetGraphicsMode(hdc, win32con.GM_ADVANCED)
                win32gui.BringWindowToTop(h_wnd)

                for r in self.graphical_elements:

                    if 'geometry' in r:
                        geometry = r['geometry']
                    else:
                        geometry = None
                    if 'x' in r:
                        x = r['x'] - self.x_min
                    else:
                        x = 0
                    if 'y' in r:
                        y = r['y'] - self.y_min
                    else:
                        y = 0
                    if 'width' in r:
                        width = r['width']
                    else:
                        width = 100
                    if 'height' in r:
                        height = r['height']
                    else:
                        height = 100
                    if 'xyrgb_array' in r:
                        xyrgb_array = r['xyrgb_array']
                    else:
                        xyrgb_array = ((15, 15, 255, 0, 0), (15, 45, 0, 255,
                                                             0), (45, 30, 0, 0,
                                                                  255))
                    if 'color' in r:
                        color_r = r['color'][0]
                        color_g = r['color'][1]
                        color_b = r['color'][2]
                    else:
                        color_r = 255
                        color_g = 0
                        color_b = 0

                    if 'thickness' in r:
                        thickness = r['thickness']
                    else:
                        thickness = 0

                    if 'angle' in r:
                        angle = r['angle']
                    else:
                        angle = 0

                    if 'geometry' in r and r['geometry'] is Shape.triangle:
                        vertices = ()
                        for xyrgb in xyrgb_array:
                            vertices = vertices + (
                                {
                                    'x': int(round(xyrgb[0])) - self.x_min,
                                    'y': int(round(xyrgb[1])) - self.y_min,
                                    'Red': xyrgb[2] * 256,
                                    'Green': xyrgb[3] * 256,
                                    'Blue': xyrgb[4] * 256,
                                    'Alpha': 0
                                }, )
                        mesh = ((0, 1, 2), )
                        win32gui.GradientFill(hdc, vertices, mesh,
                                              win32con.GRADIENT_FILL_TRIANGLE)

                    if 'brush_color' in r:
                        brush_color_r = r['brush_color'][0]
                        brush_color_g = r['brush_color'][1]
                        brush_color_b = r['brush_color'][2]
                    else:
                        brush_color_r = 255
                        brush_color_g = 255
                        brush_color_b = 255

                    if thickness == 0:
                        color_r = brush_color_r
                        color_g = brush_color_g
                        color_b = brush_color_b

                    if 'font_size' in r:
                        font_size = r['font_size']
                    else:
                        font_size = 18

                    if 'font_name' in r:
                        font_name = r['font_name']
                    else:
                        font_name = "Arial"

                    my_brush = None
                    if 'brush' in r and width > 1 and height > 1:
                        brush = r['brush']
                        brush_color = win32api.RGB(brush_color_r,
                                                   brush_color_g,
                                                   brush_color_b)
                        if brush is Brush.solid:
                            my_brush = win32gui.CreateSolidBrush(brush_color)
                        elif brush is Brush.b_diagonal:
                            my_brush = win32gui.CreateHatchBrush(
                                win32con.HS_BDIAGONAL, brush_color)
                        elif brush is Brush.cross:
                            my_brush = win32gui.CreateHatchBrush(
                                win32con.HS_CROSS, brush_color)
                        elif brush is Brush.diag_cross:
                            my_brush = win32gui.CreateHatchBrush(
                                win32con.HS_DIAGCROSS, brush_color)
                        elif brush is Brush.f_diagonal:
                            my_brush = win32gui.CreateHatchBrush(
                                win32con.HS_FDIAGONAL, brush_color)
                        elif brush is Brush.horizontal:
                            my_brush = win32gui.CreateHatchBrush(
                                win32con.HS_HORIZONTAL, brush_color)
                        elif brush is Brush.vertical:
                            my_brush = win32gui.CreateHatchBrush(
                                win32con.HS_VERTICAL, brush_color)

                        old_brush = win32gui.SelectObject(hdc, my_brush)
                    pen = win32gui.CreatePen(
                        win32con.PS_GEOMETRIC, thickness,
                        win32api.RGB(color_r, color_g, color_b))
                    old_pen = win32gui.SelectObject(hdc, pen)

                    if 'center_of_rotation' in r:
                        center_of_rotation_x = r['center_of_rotation'][0]
                        center_of_rotation_y = r['center_of_rotation'][1]
                    else:
                        center_of_rotation_x = 0
                        center_of_rotation_y = 0

                    if angle != 0:
                        r_angle = angle * (math.pi / 180)
                        Py_XFORM = win32gui.GetWorldTransform(hdc)
                        win32gui.SetWorldTransform(
                            hdc, {
                                'M11': math.cos(r_angle),
                                'M12': math.sin(r_angle),
                                'M21': math.sin(r_angle) * -1,
                                'M22': math.cos(r_angle),
                                'Dx': x,
                                'Dy': y
                            })
                        x, y = -center_of_rotation_x, -center_of_rotation_y

                    if 'text_format' in r:
                        text_format = eval(r['text_format'])
                    else:
                        text_format = win32con.DT_CENTER | win32con.DT_SINGLELINE | win32con.DT_VCENTER

                    if 'geometry' in r:
                        if r['geometry'] is Shape.rectangle:
                            win32gui.Rectangle(hdc, int(round(x)),
                                               int(round(y)),
                                               int(round(x + width)),
                                               int(round(y + height)))
                        elif r['geometry'] is Shape.ellipse:
                            win32gui.Ellipse(hdc, int(round(x)), int(round(y)),
                                             int(round(x + width)),
                                             int(round(y + height)))
                        elif r['geometry'] is Shape.arrow:
                            a = thickness
                            t = ((x - int(a * 1.4), y), (x - a * 4, y + a * 3),
                                 (x, y), (x - a * 4, y - a * 3),
                                 (x - int(a * 1.4), y), (x - a * 9, y))
                            win32gui.Polyline(hdc, t)
                        elif r['geometry'] is Shape.image:
                            hicon = r['hicon']
                            win32gui.DrawIconEx(hdc, x, y, hicon, 0, 0, 0,
                                                None, 0x0003)
                        elif r['geometry'] is Shape.triangle and thickness > 0:
                            t = ()
                            for xyrgb in xyrgb_array:
                                t = t + ((int(round(
                                    xyrgb[0])), +int(round(xyrgb[1]))), )
                            t = t + ((int(round(xyrgb_array[0][0])),
                                      int(round(xyrgb_array[0][1]))), )
                            win32gui.Polyline(hdc, t)
                        if angle != 0:
                            win32gui.SetWorldTransform(hdc, Py_XFORM)
                        win32gui.SelectObject(hdc, old_pen)

                    if 'brush' in r and width > 1 and height > 1:
                        win32gui.SelectObject(hdc, old_brush)

                    if 'text' in r:
                        text = r['text']
                        lf = win32gui.LOGFONT()
                        lf.lfFaceName = font_name
                        lf.lfHeight = font_size
                        lf.lfWeight = win32con.FW_NORMAL
                        lf.lfQuality = win32con.ANTIALIASED_QUALITY
                        hf = win32gui.CreateFontIndirect(lf)
                        old_font = win32gui.SelectObject(hdc, hf)

                        if 'text_color' in r:
                            text_color_r = r['text_color'][0]
                            text_color_g = r['text_color'][1]
                            text_color_b = r['text_color'][2]
                        else:
                            text_color_r = 0
                            text_color_g = 0
                            text_color_b = 0
                        win32gui.SetTextColor(
                            hdc,
                            win32api.RGB(text_color_r, text_color_g,
                                         text_color_b))

                        if 'text_bg_color' in r:
                            text_bg_color_r = r['text_bg_color'][0]
                            text_bg_color_g = r['text_bg_color'][1]
                            text_bg_color_b = r['text_bg_color'][2]
                        else:
                            text_bg_color_r = brush_color_r
                            text_bg_color_g = brush_color_g
                            text_bg_color_b = brush_color_b
                        win32gui.SetBkMode(hdc, win32con.TRANSPARENT)
                        win32gui.SetBkColor(
                            hdc,
                            win32api.RGB(text_bg_color_r, text_bg_color_g,
                                         text_bg_color_b))
                        tuple_r = tuple([
                            int(round(x)),
                            int(round(y)),
                            int(round(x + width)),
                            int(round(y + height))
                        ])
                        win32gui.DrawTextW(hdc, text, -1, tuple_r, text_format)
                        win32gui.SelectObject(hdc, old_font)
                win32gui.EndPaint(h_wnd, paint_struct)
                return 0
            else:
                return win32gui.DefWindowProc(h_wnd, message, w_param, l_param)
示例#9
0
 def brush(self, color):
     return win32gui.CreateSolidBrush(win32api.RGB(*color))