PageRenderTime 26ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/env/Lib/site-packages/pywin32-218-py2.7-win32.egg/pywin/Demos/ocx/ocxtest.py

https://bitbucket.org/beqa/nvdadependencyvirtualenvironment
Python | 186 lines | 154 code | 15 blank | 17 comment | 7 complexity | 863c843c409ec3e047db4ed84047d44a MD5 | raw file
  1. # OCX Tester for Pythonwin
  2. #
  3. # This file _is_ ready to run. All that is required is that the OCXs being tested
  4. # are installed on your machine.
  5. #
  6. # The .py files behind the OCXs will be automatically generated and imported.
  7. from pywin.mfc import dialog, window, activex
  8. import win32ui, win32uiole
  9. import win32con
  10. import os, sys, win32api, glob
  11. from win32com.client import gencache
  12. def MakeDlgTemplate():
  13. style = win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT
  14. cs = win32con.WS_CHILD | win32con.WS_VISIBLE
  15. dlg = [ ["OCX Demos", (0, 0, 350, 350), style, None, (8, "MS Sans Serif")], ]
  16. s = win32con.WS_TABSTOP | cs
  17. # dlg.append([131, None, 130, (5, 40, 110, 48),
  18. # s | win32con.LBS_NOTIFY | win32con.LBS_SORT | win32con.LBS_NOINTEGRALHEIGHT | win32con.WS_VSCROLL | win32con.WS_BORDER])
  19. # dlg.append(["{8E27C92B-1264-101C-8A2F-040224009C02}", None, 131, (5, 40, 110, 48),win32con.WS_TABSTOP])
  20. dlg.append([128, "About", win32con.IDOK, (124, 5, 50, 14), s | win32con.BS_DEFPUSHBUTTON])
  21. s = win32con.BS_PUSHBUTTON | s
  22. dlg.append([128, "Close", win32con.IDCANCEL, (124, 22, 50, 14), s])
  23. return dlg
  24. ####################################
  25. #
  26. # Calendar test code
  27. #
  28. def GetTestCalendarClass():
  29. global calendarParentModule
  30. win32ui.DoWaitCursor(1)
  31. calendarParentModule = gencache.EnsureModule("{8E27C92E-1264-101C-8A2F-040224009C02}", 0, 7, 0)
  32. win32ui.DoWaitCursor(0)
  33. if calendarParentModule is None:
  34. return None
  35. class TestCalDialog(dialog.Dialog):
  36. def OnInitDialog(self):
  37. class MyCal(activex.Control, calendarParentModule.Calendar):
  38. def OnAfterUpdate(self):
  39. print "OnAfterUpdate"
  40. def OnClick(self):
  41. print "OnClick"
  42. def OnDblClick(self):
  43. print "OnDblClick"
  44. def OnKeyDown(self, KeyCode, Shift):
  45. print "OnKeyDown", KeyCode, Shift
  46. def OnKeyPress(self, KeyAscii):
  47. print "OnKeyPress", KeyAscii
  48. def OnKeyUp(self, KeyCode, Shift):
  49. print "OnKeyUp", KeyCode, Shift
  50. def OnBeforeUpdate(self, Cancel):
  51. print "OnBeforeUpdate", Cancel
  52. def OnNewMonth(self):
  53. print "OnNewMonth"
  54. def OnNewYear(self):
  55. print "OnNewYear"
  56. rc = dialog.Dialog.OnInitDialog(self)
  57. self.olectl = MyCal()
  58. try:
  59. self.olectl.CreateControl("OCX", win32con.WS_TABSTOP | win32con.WS_VISIBLE, (7,43,500,300), self._obj_, 131)
  60. except win32ui.error:
  61. self.MessageBox("The Calendar Control could not be created")
  62. self.olectl = None
  63. self.EndDialog(win32con.IDCANCEL)
  64. return rc
  65. def OnOK(self):
  66. self.olectl.AboutBox()
  67. return TestCalDialog
  68. ####################################
  69. #
  70. # Video Control
  71. #
  72. def GetTestVideoModule():
  73. global videoControlModule, videoControlFileName
  74. win32ui.DoWaitCursor(1)
  75. videoControlModule = gencache.EnsureModule("{05589FA0-C356-11CE-BF01-00AA0055595A}", 0, 2, 0)
  76. win32ui.DoWaitCursor(0)
  77. if videoControlModule is None:
  78. return None
  79. fnames = glob.glob(os.path.join(win32api.GetWindowsDirectory(), "*.avi"))
  80. if not fnames:
  81. print "No AVI files available in system directory"
  82. return None
  83. videoControlFileName = fnames[0]
  84. return videoControlModule
  85. def GetTestVideoDialogClass():
  86. if GetTestVideoModule() is None:
  87. return None
  88. class TestVideoDialog(dialog.Dialog):
  89. def OnInitDialog(self):
  90. rc = dialog.Dialog.OnInitDialog(self)
  91. try:
  92. self.olectl = activex.MakeControlInstance(videoControlModule.ActiveMovie)
  93. self.olectl.CreateControl("", win32con.WS_TABSTOP | win32con.WS_VISIBLE, (7,43,500,300), self._obj_, 131)
  94. except win32ui.error:
  95. self.MessageBox("The Video Control could not be created")
  96. self.olectl = None
  97. self.EndDialog(win32con.IDCANCEL)
  98. return
  99. self.olectl.FileName = videoControlFileName
  100. # self.olectl.Run()
  101. return rc
  102. def OnOK(self):
  103. self.olectl.AboutBox()
  104. return TestVideoDialog
  105. ###############
  106. #
  107. # An OCX in an MDI Frame
  108. #
  109. class OCXFrame(window.MDIChildWnd):
  110. def __init__(self):
  111. pass # Dont call base class doc/view version...
  112. def Create(self, controlClass, title, rect = None, parent = None):
  113. style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW
  114. self._obj_ = win32ui.CreateMDIChild()
  115. self._obj_.AttachObject(self)
  116. self._obj_.CreateWindow(None, title, style, rect, parent)
  117. rect = self.GetClientRect()
  118. rect = (0,0,rect[2]-rect[0], rect[3]-rect[1])
  119. self.ocx = controlClass()
  120. self.ocx.CreateControl("", win32con.WS_VISIBLE | win32con.WS_CHILD, rect, self, 1000)
  121. def MDITest():
  122. calendarParentModule = gencache.EnsureModule("{8E27C92E-1264-101C-8A2F-040224009C02}", 0, 7, 0)
  123. class MyCal(activex.Control, calendarParentModule.Calendar):
  124. def OnAfterUpdate(self):
  125. print "OnAfterUpdate"
  126. def OnClick(self):
  127. print "OnClick"
  128. f = OCXFrame()
  129. f.Create(MyCal, "Calendar Test")
  130. def test1():
  131. klass = GetTestCalendarClass()
  132. if klass is None:
  133. print "Can not test the MSAccess Calendar control - it does not appear to be installed"
  134. return
  135. d = klass(MakeDlgTemplate() )
  136. d.DoModal()
  137. def test2():
  138. klass = GetTestVideoDialogClass()
  139. if klass is None:
  140. print "Can not test the Video OCX - it does not appear to be installed,"
  141. print "or no AVI files can be found."
  142. return
  143. d = klass(MakeDlgTemplate() )
  144. d.DoModal()
  145. d = None
  146. def test3():
  147. d = TestCOMMDialog(MakeDlgTemplate() )
  148. d.DoModal()
  149. d = None
  150. def testall():
  151. test1()
  152. test2()
  153. def demo():
  154. testall()
  155. if __name__=='__main__':
  156. import demoutils
  157. if demoutils.NeedGoodGUI():
  158. testall()