5 class DlgLayoutBuilder(object):
6 def __init__ (self
, dlgnode
):
10 def addWidget (self
, elem
):
11 x
, y
= int(elem
.getAttr('x')), int(elem
.getAttr('y'))
12 self
.rows
[y
] = self
.rows
.get (y
, {})
13 while self
.rows
[y
].has_key(x
):
15 self
.rows
[y
] = self
.rows
.get (y
, {})
16 self
.rows
[y
][x
] = elem
19 root
= Element('vbox')
23 xs
= self
.rows
[y
].keys()
27 root
.appendChild(self
.rows
[y
][xs
[0]])
30 hbox
= Element('hbox')
31 root
.appendChild(hbox
)
33 elem
= self
.rows
[y
][x
]
34 hbox
.appendChild(elem
)
40 def __init__ (self
, root
):
46 for dlgnode
in self
.root
.children
:
47 newdlgnode
= self
.__walkDlgNode
(dlgnode
)
48 newroot
.children
.append(newdlgnode
)
52 def __walkDlgNode (self
, dlgnode
):
54 newnode
= Element(dlgnode
.name
)
55 newnode
.clone(dlgnode
)
56 if dlgnode
.name
== 'string':
58 newnode
.setAttr("xmlns", "http://openoffice.org/2007/layout")
59 newnode
.setAttr("xmlns:cnt", "http://openoffice.org/2007/layout/container")
60 mx
= DlgLayoutBuilder(newnode
)
62 # Each dialog node is expected to have a flat list of widgets.
63 for widget
in dlgnode
.children
:
64 if widget
.hasAttr('x') and widget
.hasAttr('y'):
67 newnode
.appendChild(widget
)
70 if len(vbox
.children
) > 0:
71 newnode
.appendChild(vbox
)