File size: 2,507 Bytes
d12bc25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#
# Window creation example
#
# 	This example creates a minimal "control" that just fills in its
# 	window with red.  To make your own control, subclass Control and
# 	write your own OnPaint() method.  See PyCWnd.HookMessage for what
# 	the parameters to OnPaint are.
#

import win32api
import win32con
import win32ui
from pywin.mfc import dialog, window


class Control(window.Wnd):
    """Generic control class"""

    def __init__(self):
        window.Wnd.__init__(self, win32ui.CreateWnd())

    def OnPaint(self):
        dc, paintStruct = self.BeginPaint()
        self.DoPaint(dc)
        self.EndPaint(paintStruct)

    def DoPaint(self, dc):  # Override this!
        pass


class RedBox(Control):
    def DoPaint(self, dc):
        dc.FillSolidRect(self.GetClientRect(), win32api.RGB(255, 0, 0))


class RedBoxWithPie(RedBox):
    def DoPaint(self, dc):
        RedBox.DoPaint(self, dc)
        r = self.GetClientRect()
        dc.Pie(r[0], r[1], r[2], r[3], 0, 0, r[2], r[3] // 2)


def MakeDlgTemplate():
    style = (
        win32con.DS_MODALFRAME
        | win32con.WS_POPUP
        | win32con.WS_VISIBLE
        | win32con.WS_CAPTION
        | win32con.WS_SYSMENU
        | win32con.DS_SETFONT
    )
    cs = win32con.WS_CHILD | win32con.WS_VISIBLE

    w = 64
    h = 64

    dlg = [
        ["Red box", (0, 0, w, h), style, None, (8, "MS Sans Serif")],
    ]

    s = win32con.WS_TABSTOP | cs

    dlg.append(
        [
            128,
            "Cancel",
            win32con.IDCANCEL,
            (7, h - 18, 50, 14),
            s | win32con.BS_PUSHBUTTON,
        ]
    )

    return dlg


class TestDialog(dialog.Dialog):
    def OnInitDialog(self):
        rc = dialog.Dialog.OnInitDialog(self)
        self.redbox = RedBox()
        self.redbox.CreateWindow(
            None,
            "RedBox",
            win32con.WS_CHILD | win32con.WS_VISIBLE,
            (5, 5, 90, 68),
            self,
            1003,
        )
        return rc


class TestPieDialog(dialog.Dialog):
    def OnInitDialog(self):
        rc = dialog.Dialog.OnInitDialog(self)
        self.control = RedBoxWithPie()
        self.control.CreateWindow(
            None,
            "RedBox with Pie",
            win32con.WS_CHILD | win32con.WS_VISIBLE,
            (5, 5, 90, 68),
            self,
            1003,
        )


def demo(modal=0):
    d = TestPieDialog(MakeDlgTemplate())
    if modal:
        d.DoModal()
    else:
        d.CreateWindow()


if __name__ == "__main__":
    demo(1)