public
Description: Google's Webkit, ported to Python, ported to Desktops.
Homepage: http://lkcl.net/pyjamas-desktop
Clone URL: git://github.com/lkcl/pyjamas-desktop.git
pyjamas-desktop / pyjamas-web / library / __pyjamas__.py
100644 93 lines (78 sloc) 2.371 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
from lxml import etree
import sys
import inspect
 
def JS(txt):
    error
    return txt
 
def console(txt):
    print txt
 
global xml_doc
xml_doc = None
 
def init_doc(html_file):
    global xml_doc
    doc = open(html_file).read()
    xml_doc = etree.HTML(doc)
 
def doc():
    global xml_doc
    return xml_doc
 
def module_stack_name(fn, todo):
    if todo and hasattr(fn, todo):
        # it's a class
        return "%s.%s.%s" % (fn.__module__, fn.__class__.__name__, todo)
    # it's a function
    return "%s.%s" % (fn.__module__, fn.func_code.co_name)
 
def frame_stack_name(fn=None, skip=0, break_at=None):
    if fn is None:
        fn = sys._getframe(1)
    name = []
 
    old_txt = None
    while fn.f_back and fn.f_code.co_name != break_at:
        if skip:
            skip -= 1
        else:
            txt = fn.f_code.co_name
            self_obj = fn.f_locals.get('self')
            if self_obj: #inspect.isclass(fn):
                txt = "%s.%s" % (self_obj.__class__.__name__, txt)
            if txt != old_txt:
                name.append(txt)
                old_txt = txt
        fn = fn.f_back
    name.reverse()
    return '+'.join(name)
 
def doc_process(module, REQUEST):
    from ui import RootPanel, get_widget_by_id, reset_widgets
    import DOM
    global xml_doc
 
    # first, carry out the initial document creation.
    reset_widgets()
    m = module()
    m.onModuleLoad()
 
    p = RootPanel()
    
    if REQUEST.has_key('__post__'):
        for k in REQUEST.keys():
            if k == '__post__':
                continue
            widget = get_widget_by_id(k)
            if not widget:
                continue
            event = DOM.BrowserEvent("click")
            DOM.dispatchEvent(event, widget.getElement(), widget)
 
    # last, set up a FORM around the entire document.
    body = xml_doc.find('body')
    form = DOM.createElement('form')
    DOM.setAttribute(form, "action", "./")
    DOM.setAttribute(form, "method", "GET")
    hidden = DOM.createElement('input')
    DOM.setAttribute(hidden, "type", "hidden")
    DOM.setAttribute(hidden, "name", "__post__")
    form.append(hidden)
    while len(body):
        child = body[0]
        body.remove(child)
        form.append(child)
    body.append(form)
 
    #from pickle import dump
    #f = open("/tmp/dump.obj", "w")
    #dump(m, f)
    return etree.tostring(xml_doc)