Repository navigation
Expand file tree
/
Copy pathwxpython.html
More file actions
404 lines (345 loc) · 12.7 KB
/
Copy pathwxpython.html
File metadata and controls
404 lines (345 loc) · 12.7 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>wxPython CEF 3 example (utf-8: ąś)</title>
<style>
body { font: 13px Segoe UI, Arial; line-height: 1.4em; }
pre { background: #ddd; font: 12px Consolas, Courier New; }
</style>
</head>
<body>
Use mouse context menu to go Back/Forward in history navigation.
<h3>Google Search</h3>
<a href="http://www.google.com/">http://www.google.com/</a>
<h3>User agent</h3>
<script>document.write(navigator.userAgent)</script>
<h3>Popup</h3>
<a href="javascript:window.open('wxpython.html')">
window.open('wxpython.html')</a>
<h3>HTML5 video and accelerated content</h3>
<a href="http://www.youtube.com/watch?v=siOHh0uzcuY&html5=True">
HTML 5 video</a><br>
<a href="http://mudcu.be/labs/JS1k/BreathingGalaxies.html">
Accelerated canvas</a><br>
<a href="http://www.webkit.org/blog-files/3d-transforms/poster-circle.html">
Accelerated layers</a><br>
<h3>Javascript bindings</h3>
<a href="javascript:PyPrint('printing in python console from js')">
PyPrint('printing in python console from js')</a><br>
<a href="javascript:window.alert(window.pyProperty)">
window.alert(window.pyProperty)</a><br>
<a href="javascript:window.alert(JSON.stringify(window.pyConfig))">
window.alert(JSON.stringify(window.pyConfig))</a><br>
<a href="javascript:external.Print('printing again from js')">
external.Print('printing again from js')</a><br>
<a href="javascript:external.TestAllTypes(undefined, null, true, 1,
((1<<31)>>>0), 2.14, 'Date not yet supported', 'string',
{key1: 1, key2: 2}, {key1: {'key1.1': 'nested object'}, 'key1.2': [1]},
[1, 2], [1, [2.1, 'nested array']], [{key1: [{}]}])">
external.TestAllTypes</a>
<small>(undefined, null, true, 1,
((1<<31)>>>0), 2.14, 'Date not yet supported', 'string',
{key1: 1, key2: 2}, {key1: {'key1.1': 'nested object'}, 'key1.2': [1]},
[1, 2], [1, [2.1, 'nested array']], [{key1: [{}]}])</small>
<br>
<script>
function JavascriptAlert(message) { window.alert(message); }
</script>
<pre>
<script>
function JavascriptAlert(message) { window.alert(message); }
</script>
</pre>
<a href="javascript:external.ExecuteFunction('JavascriptAlert',
'python called from js and then js called from python')">
external.ExecuteFunction('JavascriptAlert',
'python called from js and then js called from python')</a>
<h3>Javascript callbacks</h3>
<script>
function JSCallback(arg1) {
window.alert(arg1)
}
</script>
<pre>
<script>
function JSCallback(arg1) {
window.alert(arg1)
}
</script>
</pre>
<pre>
def TestJSCallback(self, jsCallback):
print("jsCallback.GetFunctionName() = %s" % jsCallback.GetFunctionName())
print("jsCallback.GetFrame().GetIdentifier() = %s" % \
jsCallback.GetFrame().GetIdentifier())
jsCallback.Call("This message was sent from python using js callback")
</pre>
<a href="javascript:external.TestJSCallback(JSCallback)">
external.TestJSCallback(JSCallback)</a>
<script>
function JSCallback2() {
window.alert(JSON.stringify(arguments))
}
</script>
<pre>
<script>
function JSCallback2() {
window.alert(JSON.stringify(arguments))
}
</script>
</pre>
<pre>
def TestJSCallbackComplexArguments(self, jsObject):
jsCallback = jsObject["myCallback"];
jsCallback.Call(1, None, 2.14, "string", ["list", ["nested list", \
{"nested object":None}]], \
{"nested list next":[{"deeply nested object":1}]})
</pre>
<a href="javascript:external.TestJSCallbackComplexArguments(
{'myCallback':JSCallback2})">
external.TestJSCallbackComplexArguments({"myCallback": JSCallback2})
</a>
<h3>Python callbacks</h3>
<script>
function JSCallback3(pyCallback) {
pyCallback(1, 2.14, "string", [1, [2, {"key": "value"}]], {"list": [1,2]});
}
</script>
<pre>
<script>
function JSCallback3(pyCallback) {
pyCallback(1, 2.14, "string", [1, [2, {"key": "value"}]], {"list": [1,2]});
}
</script>
</pre>
<pre>
def TestPythonCallback(self, jsCallback):
jsCallback.Call(PyCallback)
def PyCallback(self, *args):
message = "PyCallback() was executed successfully! Arguments: %s" \
% str(args)
print(message)
self.mainBrowser.GetMainFrame().ExecuteJavascript(
"window.alert(\"%s\")" % message)
</pre>
<a href="javascript:external.TestPythonCallback(JSCallback3)">
external.TestPythonCallback(JSCallback3)</a>
<h3>Display handler</h3>
See messages in the console.
<pre>
def OnLoadingStateChange(self, browser, isLoading, canGoBack,
canGoForward):
print("ClientHandler::OnLoadingStateChange()")
print("isLoading = %s, canGoBack = %s, canGoForward = %s" \
% (isLoading, canGoBack, canGoForward))
def OnAddressChange(self, browser, frame, url):
print("ClientHandler::OnAddressChange()")
print("url = %s" % url)
def OnTitleChange(self, browser, title):
print("ClientHandler::OnTitleChange()")
print("title = %s" % title)
def OnTooltip(self, browser, text):
print("ClientHandler::OnTooltip()")
print("text = %s")
def OnStatusMessage(self, browser, value):
if not value:
# Do not notify in the console about empty statuses.
return
self.statusMessageCount += 1
if self.statusMessageCount > 3:
# Do not spam too much.
return
print("DisplayHandler::OnStatusMessage()")
print("value = %s" % value)
def OnConsoleMessage(self, browser, message, source, line):
print("ClientHandler::OnConsoleMessage()")
print("message = %s" % message)
print("source = %s" % source)
print("line = %s" % line)
</pre>
<h3>Keyboard handler</h3>
<p>
Click anywhere in the window first to set keyboard focus.
Next press F5 to reload the page.
</p>
<pre>
def OnPreKeyEvent(self, browser, event, eventHandle,
isKeyboardShortcutOut):
print("ClientHandler::OnPreKeyEvent()")
def OnKeyEvent(self, browser, event, eventHandle):
print("ClientHandler::OnKeyEvent()")
print("native_key_code = %s" % event["native_key_code"])
if platform.system() == "Linux":
# F5 = 71
if event["native_key_code"] == 71:
print("F5 pressed! Reloading page..")
browser.ReloadIgnoreCache()
</pre>
<h3>Request handler</h3>
<pre>
def OnBeforeResourceLoad(self, browser, frame, request):
print("RequestHandler::OnBeforeResourceLoad()")
print("url = %s" % request.GetUrl()[:70])
return False
</pre>
See messages in the console.
<pre>
def OnResourceRedirect(self, browser, frame, oldUrl, newUrlOut):
print("RequestHandler::OnResourceRedirect()")
print("old url = %s" % oldUrl[:70])
print("new url = %s" % newUrlOut[0][:70])
</pre>
Try this:
<a href="http://tinyurl.com/google404redirect">
http://tinyurl.com/google404redirect</a>
<pre>
def GetAuthCredentials(self, browser, frame, isProxy, host, port, realm,
scheme, callback):
print("RequestHandler::GetAuthCredentials()")
print("host = %s" % host)
print("realm = %s" % realm)
callback.Continue(username="test", password="test")
return True
</pre>
Try this:
<a href="http://browserspy.dk/password-ok.php">
http://browserspy.dk/password-ok.php</a>
<pre>
def OnQuotaRequest(self, browser, originUrl, newSize, callback):
print("RequestHandler::OnQuotaRequest()")
print("origin url = %s" % originUrl)
print("new size = %s" % newSize)
callback.Continue(True)
return True
</pre>
<pre>
<script>
function DoRequestQuota() {
// Request Quota (only for File System API)
try {
navigator.webkitPersistentStorage.requestQuota(PERSISTENT, 1024*1024,
function(bytes){ window.alert("Granted bytes: "+bytes);},
function(error){ window.alert(error); });
} catch(e) {
navigator.webkitPersistentStorage.requestQuota(1024*1024,
function(bytes){ window.alert("Granted bytes: "+bytes);},
function(error){ window.alert(error); });
}
}
</script>
</pre>
<script>
function DoRequestQuota() {
// Request Quota (only for File System API)
try {
navigator.webkitPersistentStorage.requestQuota(PERSISTENT, 1024*1024,
function(bytes){ window.alert("Granted bytes: "+bytes);},
function(error){ window.alert(error); });
} catch(e) {
navigator.webkitPersistentStorage.requestQuota(1024*1024,
function(bytes){ window.alert("Granted bytes: "+bytes);},
function(error){ window.alert(error); });
}
}
</script>
Try this:
<a href="https://googledrive.com/host/0B1di2XiBBfacMnhRRkI1YlotUEk/requestquota.html">
https://googledrive.com/host/0B1di2XiBBfacMnhRRkI1YlotUEk/requestquota.html</a>
<pre>
def OnProtocolExecution(self, browser, url, allowExecutionOut):
# There's no default implementation for OnProtocolExecution on Linux,
# you have to make OS system call on your own. You probably also need
# to use LoadHandler::OnLoadError() when implementing this on Linux.
print("RequestHandler::OnProtocolExecution()")
print("url = %s" % url)
if url.startswith("magnet:"):
print("Magnet link allowed!")
allowExecutionOut[0] = True
</pre>
Try this:
<a href="magnet:?xt=urn:btih:a4224b45b27f436374391379cc5c7e629e2e5189">
magnet:?xt=urn:btih:a4224b45b27f436374391379cc5c7e629e2e5189</a>
<pre>
def _OnBeforePluginLoad(self, browser, url, policyUrl, info):
# Plugins are loaded on demand, only when website requires it,
# the same plugin may be called multiple times.
print("RequestHandler::OnBeforePluginLoad()")
print("url = %s" % url)
print("policy url = %s" % policyUrl)
print("info.GetName() = %s" % info.GetName())
print("info.GetPath() = %s" % info.GetPath())
print("info.GetVersion() = %s" % info.GetVersion())
print("info.GetDescription() = %s" % info.GetDescription())
# False to allow, True to block plugin.
return False
</pre>
Try OnBeforePluginLoad() with Flash:
<a href="http://www.adobe.com/software/flash/about/">
http://www.adobe.com/software/flash/about/</a>
<pre>
def _OnCertificateError(self, certError, requestUrl, callback):
print("RequestHandler::OnCertificateError()")
print("certError = %s" % certError)
print("requestUrl = %s" % requestUrl)
if requestUrl.startswith(
"https://sage.math.washington.edu:8091/do-not-allow"):
print("Not allowed!")
return False
if requestUrl.startswith(
"https://sage.math.washington.edu:8091/hudson/job/"):
print("Allowed!")
callback.Continue(True)
return True
return False
</pre>
This won't be allowed:
<a href="https://sage.math.washington.edu:8091/do-not-allow">
https://sage.math.washington.edu:8091/do-not-allow</a>
<br>
This will be allowed:
<a href="https://sage.math.washington.edu:8091/hudson/job/cython-docs/">
https://sage.math.washington.edu:8091/hudson/job/cython-docs/</a>
<h3>Cookie tests</h3>
See messages in the console.
<pre>
def GetCookieManager(self, browser, mainUrl):
# Create unique cookie manager for each browser.
# --
# Buggy implementation in CEF, reported here:
# http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=10901
cookieManager = browser.GetUserData("cookieManager")
if cookieManager:
return cookieManager
else:
cookieManager = cefpython.CookieManager.CreateManager("")
browser.SetUserData("cookieManager", cookieManager)
return cookieManager
</pre>
RequestHandler.GetCookieManager() - an example of having an unique
cookie manager for each browser. Visit
<a href="http://www.html-kit.com/tools/cookietester/">
http://www.html-kit.com/tools/cookietester/</a> and set some cookie,
then go back to this page using the context menu and open a
<a href="javascript:window.open('http://www.html-kit.com/tools/cookietester/')">
new popup window</a>, the cookie should not appear in the popup browser window.
<br><br>
CookieManager.VisitAllCookies() - visit all cookies:
<a href="javascript:external.VisitAllCookies()">external.VisitAllCookies()</a>
(note: visit some http:// webpage first, otherwise cookie manager is not
yet created)
<br><br>
CookieManager.VisitUrlCookies("http://www.html-kit.com/tools/cookietester/")
- visit a subset of cookies given the url, test:
<a href="javascript:external.VisitUrlCookies()">external.VisitUrlCookies()</a>
<br><br>
CookieManager.SetCookie("http://www.html-kit.com/tools/cookietester/",
{name:"Created_Via_Python", value:"yeah really"}) - create the cookie:
<a href="javascript:external.SetCookie()">external.SetCookie()</a>
<br><br>
CookieManager.DeleteCookies() - delete the single cookie previously created
via SetCookie(): <a href="javascript:external.DeleteCookies()">
external.DeleteCookies()</a>
<br><br>
</body>
</html>