codekingpro/portable-devtools
114k
1#2# Progress bar control example3#4# PyCProgressCtrl encapsulates the MFC CProgressCtrl class. To use it,5# you:6#7# - Create the control with win32ui.CreateProgressCtrl()8# - Create the control window with PyCProgressCtrl.CreateWindow()9# - Initialize the range if you want it to be other than (0, 100) using10# PyCProgressCtrl.SetRange()11# - Either:12# - Set the step size with PyCProgressCtrl.SetStep(), and13# - Increment using PyCProgressCtrl.StepIt()14# or:15# - Set the amount completed using PyCProgressCtrl.SetPos()16#17# Example and progress bar code courtesy of KDL Technologies, Ltd., Hong Kong SAR, China.18#19 20import win32con21import win32ui22from pywin.mfc import dialog23 24 25def MakeDlgTemplate():26 style = (27 win32con.DS_MODALFRAME28 | win32con.WS_POPUP29 | win32con.WS_VISIBLE30 | win32con.WS_CAPTION31 | win32con.WS_SYSMENU32 | win32con.DS_SETFONT33 )34 cs = win32con.WS_CHILD | win32con.WS_VISIBLE35 36 w = 21537 h = 3638 39 dlg = [40 [41 "Progress bar control example",42 (0, 0, w, h),43 style,44 None,45 (8, "MS Sans Serif"),46 ],47 ]48 49 s = win32con.WS_TABSTOP | cs50 51 dlg.append(52 [53 128,54 "Tick",55 win32con.IDOK,56 (10, h - 18, 50, 14),57 s | win32con.BS_DEFPUSHBUTTON,58 ]59 )60 61 dlg.append(62 [63 128,64 "Cancel",65 win32con.IDCANCEL,66 (w - 60, h - 18, 50, 14),67 s | win32con.BS_PUSHBUTTON,68 ]69 )70 71 return dlg72 73 74class TestDialog(dialog.Dialog):75 def OnInitDialog(self):76 rc = dialog.Dialog.OnInitDialog(self)77 self.pbar = win32ui.CreateProgressCtrl()78 self.pbar.CreateWindow(79 win32con.WS_CHILD | win32con.WS_VISIBLE, (10, 10, 310, 24), self, 100180 )81 # self.pbar.SetStep (5)82 self.progress = 083 self.pincr = 584 return rc85 86 def OnOK(self):87 # NB: StepIt wraps at the end if you increment past the upper limit!88 # self.pbar.StepIt()89 self.progress = self.progress + self.pincr90 if self.progress > 100:91 self.progress = 10092 if self.progress <= 100:93 self.pbar.SetPos(self.progress)94 95 96def demo(modal=0):97 d = TestDialog(MakeDlgTemplate())98 if modal:99 d.DoModal()100 else:101 d.CreateWindow()102 103 104if __name__ == "__main__":105 demo(1)106 