lkcl / pyjamas-desktop

Google's Webkit, ported to Python, ported to Desktops.

pyjamas-desktop / pyjamas-webkit / pyjamas / __pyjamas__.py
100644 66 lines (55 sloc) 1.599 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
""" This module interfaces between PyWebkitGTK and the Pyjamas API,
to get applications kick-started.
"""
from traceback import print_stack
 
global main_frame
main_frame = None
 
def unescape(str):
    s = s.replace("&", "&")
    s = s.replace("&lt;", "<")
    s = s.replace("&gt;", ">")
    s = s.replace("&quot;", '"')
    return s
 
def set_main_frame(frame):
    global main_frame
    main_frame = frame
    import DOM
    # ok - now the main frame has been set we can initialise the
    # signal handlers etc.
    DOM.init()
 
def get_main_frame():
    global main_frame
    return main_frame
 
def doc():
    global main_frame
    return main_frame.get_gdom_document()
 
def wnd():
    """ try to avoid using this function until a bug in pywebkitgtk
has been tracked down
"""
    return main_frame.get_dom_window()
 
def JS(code):
    """ try to avoid using this function, it will only give you grief
right now...
"""
    global main_frame
    ctx = main_frame.gjs_get_global_context()
    try:
        return ctx.eval(code)
    except:
        print "code", code
        print_stack()
 
global pygwt_moduleNames
pygwt_moduleNames = []
 
def pygwt_processMetas():
    import DOM
    global pygwt_moduleNames
    metas = doc().get_elements_by_tag_name("meta")
    for i in range(metas.props.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