/
__pyjamas__.py
85 lines (68 loc) · 1.86 KB
/
__pyjamas__.py
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
# This is the gtk-dependent __pyjamas__ module.
# In javascript this module is not needed, any imports of this module
# are removed by the translator.
""" This module interfaces between PyWebkitGTK and the Pyjamas API,
to get applications kick-started.
"""
import sys
from traceback import print_stack
main_frame = None
gtk_module = None
def noSourceTracking(*args):
pass
def unescape(str):
s = s.replace("&", "&")
s = s.replace("<", "<")
s = s.replace(">", ">")
s = s.replace(""", '"')
return s
def set_gtk_module(m):
global gtk_module
gtk_module = m
def get_gtk_module():
global gtk_module
return gtk_module
def set_main_frame(frame):
print "set_main_frame", frame
global main_frame
main_frame = frame
from pyjamas import DOM
# ok - now the main frame has been set we can initialise the
# signal handlers etc.
DOM.init()
def get_main_frame():
return main_frame
def doc():
return main_frame.getDomDocument()
def wnd():
return main_frame.getDomWindow()
def JS(code):
""" try to avoid using this function, it will only give you grief
right now...
"""
ctx = main_frame.gjs_get_global_context()
try:
return ctx.eval(code)
except:
print "code", code
print_stack()
pygwt_moduleNames = []
def pygwt_processMetas():
from pyjamas import DOM
metas = doc().getElementsByTagName("meta")
for i in range(metas.length):
meta = metas.item(i)
name = DOM.getAttribute(meta, "name")
if name == "pygwt:module":
content = DOM.getAttribute(meta, "content")
if content:
pygwt_moduleNames.append(content)
return pygwt_moduleNames
class console:
@staticmethod
def error(msg):
print "TODO CONSOLE:", msg
def debugger():
pass
def INT(i):
return int(i)