Пример #1
0
from dsl import parse_layout

doc = parse_layout("""
Chatbox <- ((text:?x?)[text = "History", autoscroll=1]
            ---
            (text:?x20)[text = "Chat line"] | (button:40x20)[text = "send", clicked=sendbtn]):(0.7*w)x?

Lists <- (((label:?x20)[text="Rooms"]
          ---
          (listbox)[items="", selected=roomselect]
          ---
          (label:?x20)[text="Users"]
          ---
          (listbox)[items="", selected=userselect]
         ):(0.3*w)x?)[min_width = 200]

main <- (((Chatbox) | (Lists)):(w)x(h))[init_width = 800, init_height=600, 
                                        roomselect=?(0), userselect=?(0), sendbtn=?(0)]

""")

def traverse(node, i = 0):
    print "%s%r, %s" % ("  " * i, node.root, type(node))
    for child in node.subtrees:
        traverse(child, i + 1)

traverse(doc["main"])



Пример #2
0
    else:
        raise TypeError(type(node), node)

def ast_to_dom(doc):
    dom = {}
    for name, node in doc.items():
        if name not in dom:
            dom[name] = _ast_to_dom(dom, doc, node)
    return dom

def run(dom):
    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    window.set_title("Hello Buttons!")
    window.connect("delete_event", lambda *args: False)
    window.connect("destroy", lambda *args: gtk.main_quit())
        



if __name__ == "__main__":
    doc = parse_layout("""
    foo <- (label:20x20)[text="hello"] | (label)[text="world"]
    
    """)
    
    dom = ast_to_dom(doc)
    foo = dom["foo"]
    print foo


Пример #3
0
        else:
            return Atom(node.kind, simplify_attrs(node))
    else:
        raise TypeError(type(node), node)


def ast_to_dom(doc):
    dom = {}
    for name, node in doc.items():
        if name not in dom:
            dom[name] = _ast_to_dom(dom, doc, node)
    return dom


def run(dom):
    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    window.set_title("Hello Buttons!")
    window.connect("delete_event", lambda *args: False)
    window.connect("destroy", lambda *args: gtk.main_quit())


if __name__ == "__main__":
    doc = parse_layout("""
    foo <- (label:20x20)[text="hello"] | (label)[text="world"]
    
    """)

    dom = ast_to_dom(doc)
    foo = dom["foo"]
    print foo
Пример #4
0
from dsl import parse_layout

doc = parse_layout("""
Chatbox <- ((text:?x?)[text = "History", autoscroll=1]
            ---
            (text:?x20)[text = "Chat line"] | (button:40x20)[text = "send", clicked=sendbtn]):(0.7*w)x?

Lists <- (((label:?x20)[text="Rooms"]
          ---
          (listbox)[items="", selected=roomselect]
          ---
          (label:?x20)[text="Users"]
          ---
          (listbox)[items="", selected=userselect]
         ):(0.3*w)x?)[min_width = 200]

main <- (((Chatbox) | (Lists)):(w)x(h))[init_width = 800, init_height=600, 
                                        roomselect=?(0), userselect=?(0), sendbtn=?(0)]

""")


def traverse(node, i=0):
    print "%s%r, %s" % ("  " * i, node.root, type(node))
    for child in node.subtrees:
        traverse(child, i + 1)


traverse(doc["main"])
Пример #5
0
from dsl import parse_layout, parse_arithmetic



subprograms_1 = """
L <- (label)[text=question]
     ----------------------------
     (radio)[checked=v] | (label)[text="Yes"] | (radio)[checked=!v] | (label)[text="No"]
I <- (image:32x32)[filename={(v)=>("dislike.png"), otherwise ("dislike.png")}]
main_window <- ((L) | (I))[question="Do you like?"]
"""
print parse_layout(subprograms_1)


subprograms_2 = """
        L <-  (((label:?x?)[text="Do you like"]
                ---((radio:?x?)[checked=v]|(label:20x10)[text="Yes"]|(radio:?x?)[checked=v]|(label:20x?)[text="No"] )))
        I <-   (button:30x?)[text="Tell a friend"]
        main_window <- (L)[v=?(1)]
        """      

print '-----'
a = parse_layout(subprograms_2)
print a
for key in a:
    if hasattr(a[key], 'attributes'):
        print key, ":", a[key].attributes
print '-----'

vsplit_w_scroll_1 = """ main_window <- (
    (button:?x(height*0.5))