forked from mhammond/pywin32
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocxtest.py
More file actions
244 lines (192 loc) · 6.56 KB
/
ocxtest.py
File metadata and controls
244 lines (192 loc) · 6.56 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# OCX Tester for Pythonwin
#
# This file _is_ ready to run. All that is required is that the OCXs being tested
# are installed on your machine.
#
# The .py files behind the OCXs will be automatically generated and imported.
import glob
import os
import win32api
import win32con
import win32ui
import win32uiole
from pywin.mfc import activex, dialog, window
from win32com.client import gencache
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
dlg = [
["OCX Demos", (0, 0, 350, 350), style, None, (8, "MS Sans Serif")],
]
s = win32con.WS_TABSTOP | cs
# dlg.append([131, None, 130, (5, 40, 110, 48),
# s | win32con.LBS_NOTIFY | win32con.LBS_SORT | win32con.LBS_NOINTEGRALHEIGHT | win32con.WS_VSCROLL | win32con.WS_BORDER])
# dlg.append(["{8E27C92B-1264-101C-8A2F-040224009C02}", None, 131, (5, 40, 110, 48),win32con.WS_TABSTOP])
dlg.append(
[128, "About", win32con.IDOK, (124, 5, 50, 14), s | win32con.BS_DEFPUSHBUTTON]
)
s = win32con.BS_PUSHBUTTON | s
dlg.append([128, "Close", win32con.IDCANCEL, (124, 22, 50, 14), s])
return dlg
####################################
#
# Calendar test code
#
def GetTestCalendarClass():
global calendarParentModule
win32ui.DoWaitCursor(1)
calendarParentModule = gencache.EnsureModule(
"{8E27C92E-1264-101C-8A2F-040224009C02}", 0, 7, 0
)
win32ui.DoWaitCursor(0)
if calendarParentModule is None:
return None
class TestCalDialog(dialog.Dialog):
def OnInitDialog(self):
class MyCal(activex.Control, calendarParentModule.Calendar):
def OnAfterUpdate(self):
print("OnAfterUpdate")
def OnClick(self):
print("OnClick")
def OnDblClick(self):
print("OnDblClick")
def OnKeyDown(self, KeyCode, Shift):
print("OnKeyDown", KeyCode, Shift)
def OnKeyPress(self, KeyAscii):
print("OnKeyPress", KeyAscii)
def OnKeyUp(self, KeyCode, Shift):
print("OnKeyUp", KeyCode, Shift)
def OnBeforeUpdate(self, Cancel):
print("OnBeforeUpdate", Cancel)
def OnNewMonth(self):
print("OnNewMonth")
def OnNewYear(self):
print("OnNewYear")
rc = dialog.Dialog.OnInitDialog(self)
self.olectl = MyCal()
try:
self.olectl.CreateControl(
"OCX",
win32con.WS_TABSTOP | win32con.WS_VISIBLE,
(7, 43, 500, 300),
self._obj_,
131,
)
except win32ui.error:
self.MessageBox("The Calendar Control could not be created")
self.olectl = None
self.EndDialog(win32con.IDCANCEL)
return rc
def OnOK(self):
self.olectl.AboutBox()
return TestCalDialog
####################################
#
# Video Control
#
def GetTestVideoModule():
global videoControlModule, videoControlFileName
win32ui.DoWaitCursor(1)
videoControlModule = gencache.EnsureModule(
"{05589FA0-C356-11CE-BF01-00AA0055595A}", 0, 2, 0
)
win32ui.DoWaitCursor(0)
if videoControlModule is None:
return None
fnames = glob.glob(os.path.join(win32api.GetWindowsDirectory(), "*.avi"))
if not fnames:
print("No AVI files available in system directory")
return None
videoControlFileName = fnames[0]
return videoControlModule
def GetTestVideoDialogClass():
if GetTestVideoModule() is None:
return None
class TestVideoDialog(dialog.Dialog):
def OnInitDialog(self):
rc = dialog.Dialog.OnInitDialog(self)
try:
self.olectl = activex.MakeControlInstance(
videoControlModule.ActiveMovie
)
self.olectl.CreateControl(
"",
win32con.WS_TABSTOP | win32con.WS_VISIBLE,
(7, 43, 500, 300),
self._obj_,
131,
)
except win32ui.error:
self.MessageBox("The Video Control could not be created")
self.olectl = None
self.EndDialog(win32con.IDCANCEL)
return
self.olectl.FileName = videoControlFileName
# self.olectl.Run()
return rc
def OnOK(self):
self.olectl.AboutBox()
return TestVideoDialog
###############
#
# An OCX in an MDI Frame
#
class OCXFrame(window.MDIChildWnd):
def __init__(self):
pass # Don't call base class doc/view version...
def Create(self, controlClass, title, rect=None, parent=None):
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW
self._obj_ = win32ui.CreateMDIChild()
self._obj_.AttachObject(self)
self._obj_.CreateWindow(None, title, style, rect, parent)
rect = self.GetClientRect()
rect = (0, 0, rect[2] - rect[0], rect[3] - rect[1])
self.ocx = controlClass()
self.ocx.CreateControl(
"", win32con.WS_VISIBLE | win32con.WS_CHILD, rect, self, 1000
)
def MDITest():
calendarParentModule = gencache.EnsureModule(
"{8E27C92E-1264-101C-8A2F-040224009C02}", 0, 7, 0
)
class MyCal(activex.Control, calendarParentModule.Calendar):
def OnAfterUpdate(self):
print("OnAfterUpdate")
def OnClick(self):
print("OnClick")
f = OCXFrame()
f.Create(MyCal, "Calendar Test")
def test1():
klass = GetTestCalendarClass()
if klass is None:
print(
"Can not test the MSAccess Calendar control - it does not appear to be installed"
)
return
d = klass(MakeDlgTemplate())
d.DoModal()
def test2():
klass = GetTestVideoDialogClass()
if klass is None:
print("Can not test the Video OCX - it does not appear to be installed,")
print("or no AVI files can be found.")
return
d = klass(MakeDlgTemplate())
d.DoModal()
d = None
def testall():
test1()
test2()
def demo():
testall()
if __name__ == "__main__":
from . import demoutils
if demoutils.NeedGoodGUI():
testall()