[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Layout module for Pygame surfaces
I have felt the same, thinking back to handling xml in the past. I was thinking that you draw a SVG in inkscape, which xml is read for python UI.
It looks like its a pythonic way if you need xml, but I've only used it in small protos. I'm curious if anyone has used "amara" in bigger projects?
(Not
saying specifically this project, for anything.)
http://www.xml3k.org/Amara/QuickRef [ link to amara1.0 quickref, since 2.0
if curious: random snippit, using ETree vs amara.
http://stackoverflow.com/questions/1926512/editing-the-xml-attributes-from-a-xml-file-using-python/1934375#1934375
Here's something I whipped up. Loads window containing list of buttons.
# testing amara for xml
# see also: eclipse://jakeref/xml-amara.py
def test():
# quick example for UI interface
xml_ui = """
<window type="dialog.ok cancel" text="ok?">
<button type="ok" text="save" selected="true">
<loc x="100" y="240" w="40" h="10" />
</button>
<button type="cancel" text="cancel">
<loc x="300" y="240" w="40" h="10" />
</button>
</window>"""
import amara
from amara import bindery
import pygame
from pygame.locals import Rect
class Window():
def __str__(self): return "Window<type='%s', text='%s'>" % (self.type, self.text)
class Button():
def __str__(self): return "\tButton<type='%s', text='%s', rect='%s'>" % (self.type, self.text, self.rect)
doc = bindery.parse(xml_ui)
win = Window()
win.widgets = []
win.text, win.type = doc.window.text, doc.window.type
for cur in doc.window.button:
b = Button()
b.rect = pygame.Rect( int(cur.loc.x), int(cur.loc.y), int(cur.loc.w), int(cur.loc.h))
b.type = cur.type
b.text = cur.text
win.widgets.append(b)
"""output:
Window<type='dialog.ok cancel', text='ok?'>
Button<type='ok' text='save', rect='<rect(100, 240, 40, 10)>'>
Button<type='cancel' text='cancel', rect='<rect(300, 240, 40, 10)>'>
"""
print win
for cur in win.widgets: print cur
--
Jake