Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
createwin.py115 linesDownload Raw Back to Demos
1#2# Window creation example3#4# 	This example creates a minimal "control" that just fills in its5# 	window with red.  To make your own control, subclass Control and6# 	write your own OnPaint() method.  See PyCWnd.HookMessage for what7# 	the parameters to OnPaint are.8#9 10import win32api11import win32con12import win32ui13from pywin.mfc import dialog, window14 15 16class Control(window.Wnd):17    """Generic control class"""18 19    def __init__(self):20        window.Wnd.__init__(self, win32ui.CreateWnd())21 22    def OnPaint(self):23        dc, paintStruct = self.BeginPaint()24        self.DoPaint(dc)25        self.EndPaint(paintStruct)26 27    def DoPaint(self, dc):  # Override this!28        pass29 30 31class RedBox(Control):32    def DoPaint(self, dc):33        dc.FillSolidRect(self.GetClientRect(), win32api.RGB(255, 0, 0))34 35 36class RedBoxWithPie(RedBox):37    def DoPaint(self, dc):38        RedBox.DoPaint(self, dc)39        r = self.GetClientRect()40        dc.Pie(r[0], r[1], r[2], r[3], 0, 0, r[2], r[3] // 2)41 42 43def MakeDlgTemplate():44    style = (45        win32con.DS_MODALFRAME46        | win32con.WS_POPUP47        | win32con.WS_VISIBLE48        | win32con.WS_CAPTION49        | win32con.WS_SYSMENU50        | win32con.DS_SETFONT51    )52    cs = win32con.WS_CHILD | win32con.WS_VISIBLE53 54    w = 6455    h = 6456 57    dlg = [58        ["Red box", (0, 0, w, h), style, None, (8, "MS Sans Serif")],59    ]60 61    s = win32con.WS_TABSTOP | cs62 63    dlg.append(64        [65            128,66            "Cancel",67            win32con.IDCANCEL,68            (7, h - 18, 50, 14),69            s | win32con.BS_PUSHBUTTON,70        ]71    )72 73    return dlg74 75 76class TestDialog(dialog.Dialog):77    def OnInitDialog(self):78        rc = dialog.Dialog.OnInitDialog(self)79        self.redbox = RedBox()80        self.redbox.CreateWindow(81            None,82            "RedBox",83            win32con.WS_CHILD | win32con.WS_VISIBLE,84            (5, 5, 90, 68),85            self,86            1003,87        )88        return rc89 90 91class TestPieDialog(dialog.Dialog):92    def OnInitDialog(self):93        rc = dialog.Dialog.OnInitDialog(self)94        self.control = RedBoxWithPie()95        self.control.CreateWindow(96            None,97            "RedBox with Pie",98            win32con.WS_CHILD | win32con.WS_VISIBLE,99            (5, 5, 90, 68),100            self,101            1003,102        )103 104 105def demo(modal=0):106    d = TestPieDialog(MakeDlgTemplate())107    if modal:108        d.DoModal()109    else:110        d.CreateWindow()111 112 113if __name__ == "__main__":114    demo(1)115 
codekingpro/portable-devtools · Team Ai