codekingpro/portable-devtools
114k
1# sliderdemo.py2# Demo of the slider control courtesy of Mike Fletcher.3 4import win32con5import win32ui6from pywin.mfc import dialog7 8 9class MyDialog(dialog.Dialog):10 """11 Example using simple controls12 """13 14 _dialogstyle = (15 win32con.WS_MINIMIZEBOX16 | win32con.WS_DLGFRAME17 | win32con.DS_MODALFRAME18 | win32con.WS_POPUP19 | win32con.WS_VISIBLE20 | win32con.WS_CAPTION21 | win32con.WS_SYSMENU22 | win32con.DS_SETFONT23 )24 _buttonstyle = (25 win32con.BS_PUSHBUTTON26 | win32con.WS_TABSTOP27 | win32con.WS_CHILD28 | win32con.WS_VISIBLE29 )30 ### The static template, contains all "normal" dialog items31 DIALOGTEMPLATE = [32 # the dialog itself is the first element in the template33 ["Example slider", (0, 0, 50, 43), _dialogstyle, None, (8, "MS SansSerif")],34 # rest of elements are the controls within the dialog35 # standard "Close" button36 [128, "Close", win32con.IDCANCEL, (0, 30, 50, 13), _buttonstyle],37 ]38 ### ID of the control to be created during dialog initialisation39 IDC_SLIDER = 950040 41 def __init__(self):42 dialog.Dialog.__init__(self, self.DIALOGTEMPLATE)43 44 def OnInitDialog(self):45 rc = dialog.Dialog.OnInitDialog(self)46 # now initialise your controls that you want to create47 # programmatically, including those which are OLE controls48 # those created directly by win32ui.Create*49 # and your "custom controls" which are subclasses/whatever50 win32ui.EnableControlContainer()51 self.slider = win32ui.CreateSliderCtrl()52 self.slider.CreateWindow(53 win32con.WS_TABSTOP | win32con.WS_VISIBLE,54 (0, 0, 100, 30),55 self._obj_,56 self.IDC_SLIDER,57 )58 self.HookMessage(self.OnSliderMove, win32con.WM_HSCROLL)59 return rc60 61 def OnSliderMove(self, params):62 print("Slider moved")63 64 def OnCancel(self):65 print("The slider control is at position", self.slider.GetPos())66 self._obj_.OnCancel()67 68 69###70def demo():71 dia = MyDialog()72 dia.DoModal()73 74 75if __name__ == "__main__":76 demo()77 