Mercurial > libervia-backend
comparison frontends/wix/xmlui.py @ 104:5458ac1380cc
XMLUI: added tabs layout
xmltools: tabs layout are added, and a new addCategory method is used to add tabs
wix: tabs layout are managed with notebook
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 23 Jun 2010 14:55:04 +0800 |
parents | 6be927a465ed |
children | d2630fba8dfd |
comparison
equal
deleted
inserted
replaced
103:6be927a465ed | 104:5458ac1380cc |
---|---|
52 | 52 |
53 self.constructUI(xml_data) | 53 self.constructUI(xml_data) |
54 | 54 |
55 self.Show() | 55 self.Show() |
56 | 56 |
57 def __parse_elems(self, childs, parent, sizer): | 57 def __parseElems(self, node, parent): |
58 """Parse elements inside a <layout> tags, and add them to the sizer""" | 58 """Parse elements inside a <layout> tags, and add them to the parent sizer""" |
59 for elem in childs: | 59 for elem in node.childNodes: |
60 if elem.nodeName != "elem": | 60 if elem.nodeName != "elem": |
61 message=_("Unmanaged tag") | 61 message=_("Unmanaged tag") |
62 error(message) | 62 error(message) |
63 raise Exception(message) | 63 raise Exception(message) |
64 _proportion = 0 | 64 _proportion = 0 |
88 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) | 88 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) |
89 _proportion = 1 | 89 _proportion = 1 |
90 else: | 90 else: |
91 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! | 91 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! |
92 raise NotImplementedError | 92 raise NotImplementedError |
93 sizer.Add(ctrl, _proportion, flag=wx.EXPAND) | 93 parent.sizer.Add(ctrl, _proportion, flag=wx.EXPAND) |
94 | 94 |
95 def __parseChilds(self, parent, current_param, elem, wanted = ['layout']): | |
96 """Recursively parse childNodes of an elemen | |
97 @param parent: parent wx.Window | |
98 @param current_param: current wx.Window (often wx.Panel) or None if we must create one | |
99 @param elem: element from which childs will be parsed | |
100 @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant""" | |
101 for node in elem.childNodes: | |
102 if wanted and not node.nodeName in wanted: | |
103 raise Exception("Invalid XMLUI") #TODO: make a custom exception | |
104 if node.nodeName == "layout": | |
105 type = node.getAttribute('type') | |
106 if type == "tabs": | |
107 current = wx.Notebook(parent, -1, style=wx.NB_LEFT if self.type=='param' else 0) | |
108 self.__parseChilds(current, None, node, ['category']) | |
109 else: | |
110 if current_param == None: | |
111 current = wx.Panel(parent, -1) | |
112 else: | |
113 current = current_param | |
114 if type == "vertical": | |
115 current.sizer = wx.BoxSizer(wx.VERTICAL) | |
116 elif type == "pairs": | |
117 current.sizer = wx.FlexGridSizer(cols=2) | |
118 current.sizer.AddGrowableCol(1) #The growable column need most of time to be the right one in pairs | |
119 else: | |
120 warning(_("Unknown layout, using default one")) | |
121 current.sizer = wx.BoxSizer(wx.VERTICAL) | |
122 current.SetSizer(current.sizer) | |
123 self.__parseElems(node, current) | |
124 if parent: | |
125 parent.sizer.Add(current, flag=wx.EXPAND) | |
126 elif node.nodeName == "category": | |
127 name = node.getAttribute('name') | |
128 if not node.nodeName in wanted or not name or not isinstance(parent,wx.Notebook): | |
129 raise Exception("Invalid XMLUI") #TODO: make a custom exception | |
130 notebook = parent | |
131 tab_panel = wx.Panel(notebook, -1) | |
132 tab_panel.sizer = wx.BoxSizer(wx.VERTICAL) | |
133 tab_panel.SetSizer(tab_panel.sizer) | |
134 notebook.AddPage(tab_panel, name) | |
135 self.__parseChilds(tab_panel, None, node, ['layout']) | |
136 | |
137 else: | |
138 message=_("Unknown tag") | |
139 error(message) | |
140 raise Exception(message) #TODO: raise a custom exception here | |
95 | 141 |
96 | 142 |
97 def constructUI(self, xml_data): | 143 def constructUI(self, xml_data): |
98 panel=wx.Panel(self) | 144 panel=wx.Panel(self) |
99 panel.sizer = wx.BoxSizer(wx.VERTICAL) | 145 panel.sizer = wx.BoxSizer(wx.VERTICAL) |
100 | 146 |
101 cat_dom = minidom.parseString(xml_data.encode('utf-8')) | 147 cat_dom = minidom.parseString(xml_data.encode('utf-8')) |
102 top= cat_dom.documentElement | 148 top= cat_dom.documentElement |
103 self.type = top.getAttribute("type") | 149 self.type = top.getAttribute("type") |
104 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: | 150 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: |
105 message = _("XML UI received is invalid") | 151 raise Exception("Invalid XMLUI") #TODO: make a custom exception |
106 error(message) | 152 |
107 raise Exception(message) | 153 self.__parseChilds(panel, None, cat_dom.documentElement) |
108 | |
109 for node in cat_dom.documentElement.childNodes: | |
110 if node.nodeName == "layout": | |
111 layout_panel = wx.Panel(panel, -1) | |
112 if node.getAttribute('type') == "vertical": | |
113 current_sizer = wx.BoxSizer(wx.VERTICAL) | |
114 elif node.getAttribute('type') == "pairs": | |
115 current_sizer = wx.FlexGridSizer(cols=2) | |
116 current_sizer.AddGrowableCol(1) #The growable column need most of time to be the right one in pairs | |
117 else: | |
118 warning(_("Unknown layout, using default one")) | |
119 current_sizer = wx.BoxSizer(wx.VERTICAL) | |
120 layout_panel.SetSizer(current_sizer) | |
121 self.__parse_elems(node.childNodes, layout_panel, current_sizer) | |
122 panel.sizer.Add(layout_panel, flag=wx.EXPAND) | |
123 else: | |
124 message=_("Unknown tag") | |
125 error(message) | |
126 raise Exception(message) #TODO: raise a custom exception here | |
127 | 154 |
128 if self.type == 'form': | 155 if self.type == 'form': |
129 dialogButtons = wx.StdDialogButtonSizer() | 156 dialogButtons = wx.StdDialogButtonSizer() |
130 submitButton = wx.Button(panel,wx.ID_OK, label=_("Submit")) | 157 submitButton = wx.Button(panel,wx.ID_OK, label=_("Submit")) |
131 dialogButtons.AddButton(submitButton) | 158 dialogButtons.AddButton(submitButton) |