Mercurial > traipse_dev
comparison orpg/gametree/nodehandlers/forms.py @ 135:dcf4fbe09b70 beta
Traipse Beta 'OpenRPG' {091010-00}
Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on
code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to
offer more advanced features and enhance the productivity of the user.
Update Summary (Beta)
Added Bookmarks
Fix to Remote Admin Commands
Minor fix to text based Server
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
default_manifest.xml renamed to default_upmana.xml
Cleaner clode for saved repositories
New TrueDebug Class in orpg_log (See documentation for usage)
Mercurial's hgweb folder is ported to upmana
**Pretty important update that can help remove thousands of dead children from your gametree.
**Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and
look for dead children!!
**New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author | sirebral |
---|---|
date | Tue, 10 Nov 2009 14:11:28 -0600 |
parents | 68c7bd272f27 |
children | 2345c12d93a7 |
comparison
equal
deleted
inserted
replaced
101:394ebb3b6a0f | 135:dcf4fbe09b70 |
---|---|
37 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0. | 37 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0. |
38 #by running the results of that through this function, we convert it. | 38 #by running the results of that through this function, we convert it. |
39 #if it was an int already, nothing changes. The difference between 1.0 | 39 #if it was an int already, nothing changes. The difference between 1.0 |
40 #and 1, i.e. between ints and floats, is potentially dangerous when we | 40 #and 1, i.e. between ints and floats, is potentially dangerous when we |
41 #use str() on it, but it seems to work fine right now. | 41 #use str() on it, but it seems to work fine right now. |
42 if b: | 42 if b: return 1 |
43 return 1 | 43 else: return 0 |
44 else: | |
45 return 0 | |
46 | 44 |
47 ################################# | 45 ################################# |
48 ## form container | 46 ## form container |
49 ################################# | 47 ################################# |
50 | 48 |
52 """ | 50 """ |
53 <nodehandler name='?' module='forms' class='form_handler' > | 51 <nodehandler name='?' module='forms' class='form_handler' > |
54 <form width='100' height='100' /> | 52 <form width='100' height='100' /> |
55 </nodehandler> | 53 </nodehandler> |
56 """ | 54 """ |
57 | 55 def __init__(self,xml,tree_node): |
58 def __init__(self,xml_dom,tree_node): | 56 container_handler.__init__(self, xml, tree_node) |
59 container_handler.__init__(self,xml_dom,tree_node) | |
60 | 57 |
61 def load_children(self): | 58 def load_children(self): |
62 self.atts = None | 59 self.atts = None |
63 children = self.master_dom._get_childNodes() | 60 for child_xml in self.xml: |
64 for c in children: | 61 if child_xml.tag == "form": self.xml.remove(child_xml) |
65 if c._get_tagName() == "form": | 62 elif child_xml: self.tree.load_xml(child_xml, self.mytree_node) |
66 self.atts = c | 63 if not self.xml.get('width'): self.xml.set('width', '400') |
67 else: | 64 if not self.xml.get('height'): self.xml.set('height', '600') |
68 self.tree.load_xml(c,self.mytree_node) | |
69 if not self.atts: | |
70 elem = minidom.Element('form') | |
71 elem.setAttribute("width","400") | |
72 elem.setAttribute("height","600") | |
73 self.atts = self.master_dom.appendChild(elem) | |
74 | 65 |
75 def get_design_panel(self,parent): | 66 def get_design_panel(self,parent): |
76 return form_edit_panel(parent,self) | 67 return form_edit_panel(parent,self) |
77 | 68 |
78 def get_use_panel(self,parent): | 69 def get_use_panel(self,parent): |
80 | 71 |
81 def on_drop(self,evt): | 72 def on_drop(self,evt): |
82 # make sure its a contorl node | 73 # make sure its a contorl node |
83 container_handler.on_drop(self,evt) | 74 container_handler.on_drop(self,evt) |
84 | 75 |
85 | |
86 class form_panel(ScrolledPanel): | 76 class form_panel(ScrolledPanel): |
87 def __init__(self, parent, handler): | 77 def __init__(self, parent, handler): |
88 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL) | 78 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL) |
89 self.height = int(handler.atts.getAttribute("height")) | 79 self.height = int(handler.xml.get("height")) |
90 self.width = int(handler.atts.getAttribute("width")) | 80 self.width = int(handler.xml.get("width")) |
91 | |
92 | |
93 self.SetSize((0,0)) | 81 self.SetSize((0,0)) |
94 self.handler = handler | 82 self.handler = handler |
95 self.parent = parent | 83 self.parent = parent |
96 self.main_sizer = wx.BoxSizer(wx.VERTICAL) | 84 self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
97 tree = self.handler.tree | 85 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False) |
98 child = tree.GetFirstChild(handler.mytree_node) | |
99 if child[0].IsOk(): | |
100 handler.traverse(child[0], self.create_child_wnd, 0, None, False) | |
101 | |
102 self.SetSizer(self.main_sizer) | 86 self.SetSizer(self.main_sizer) |
103 self.SetAutoLayout(True) | 87 self.SetAutoLayout(True) |
104 | |
105 self.SetupScrolling() | 88 self.SetupScrolling() |
106 | |
107 parent.SetSize(self.GetSize()) | 89 parent.SetSize(self.GetSize()) |
108 self.Fit() | 90 self.Fit() |
109 | |
110 | 91 |
111 def SetSize(self, xy): | 92 def SetSize(self, xy): |
112 (x, y) = self.GetSize() | 93 (x, y) = self.GetSize() |
113 (nx, ny) = xy | 94 (nx, ny) = xy |
114 if x < nx: | 95 if x < nx: |
115 x = nx+10 | 96 x = nx+10 |
116 y += ny+11 | 97 y += ny+11 |
117 ScrolledPanel.SetSize(self, (x, y)) | 98 ScrolledPanel.SetSize(self, (x, y)) |
118 | 99 |
119 | 100 def create_child_wnd(self, treenode, evt): |
120 def create_child_wnd(self, obj, evt): | 101 node = self.handler.tree.GetPyData(treenode) |
121 panel = obj.get_use_panel(self) | 102 panel = node.get_use_panel(self) |
122 size = obj.get_size_constraint() | 103 size = node.get_size_constraint() |
123 if panel: | 104 if panel: |
124 self.main_sizer.Add(panel, size, wx.EXPAND) | 105 self.main_sizer.Add(panel, size, wx.EXPAND) |
125 self.main_sizer.Add(wx.Size(10,10)) | 106 self.main_sizer.Add(wx.Size(10,10)) |
126 | |
127 | |
128 | 107 |
129 F_HEIGHT = wx.NewId() | 108 F_HEIGHT = wx.NewId() |
130 F_WIDTH = wx.NewId() | 109 F_WIDTH = wx.NewId() |
131 class form_edit_panel(wx.Panel): | 110 class form_edit_panel(wx.Panel): |
132 def __init__(self, parent, handler): | 111 def __init__(self, parent, handler): |
133 wx.Panel.__init__(self, parent, -1) | 112 wx.Panel.__init__(self, parent, -1) |
134 self.handler = handler | 113 self.handler = handler |
135 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL) | 114 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL) |
136 wh_sizer = wx.BoxSizer(wx.HORIZONTAL) | 115 wh_sizer = wx.BoxSizer(wx.HORIZONTAL) |
137 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')), | 116 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')), |
138 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.atts.getAttribute('height')), | 117 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.xml.get('height')), |
139 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.atts.getAttribute('width')) | 118 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.xml.get('width')) |
140 } | 119 } |
141 | 120 |
142 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER) | 121 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER) |
143 wh_sizer.Add(wx.Size(10,10)) | 122 wh_sizer.Add(wx.Size(10,10)) |
144 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND) | 123 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND) |
164 def on_text(self,evt): | 143 def on_text(self,evt): |
165 id = evt.GetId() | 144 id = evt.GetId() |
166 txt = self.text[id].GetValue() | 145 txt = self.text[id].GetValue() |
167 if not len(txt): return | 146 if not len(txt): return |
168 if id == P_TITLE: | 147 if id == P_TITLE: |
169 self.handler.master_dom.setAttribute('name',txt) | 148 self.handler.xml.set('name',txt) |
170 self.handler.rename(txt) | 149 self.handler.rename(txt) |
171 elif id == F_HEIGHT or id == F_WIDTH: | 150 elif id == F_HEIGHT or id == F_WIDTH: |
172 try: | 151 try: int(txt) |
173 int(txt) | 152 except: return 0 |
174 except: | 153 if id == F_HEIGHT: self.handler.xml.set("height",txt) |
175 return 0 | 154 elif id == F_WIDTH: self.handler.xml.set("width",txt) |
176 if id == F_HEIGHT: | |
177 self.handler.atts.setAttribute("height",txt) | |
178 elif id == F_WIDTH: | |
179 self.handler.atts.setAttribute("width",txt) | |
180 | |
181 | |
182 | |
183 | |
184 | 155 |
185 ########################## | 156 ########################## |
186 ## control handler | 157 ## control handler |
187 ########################## | 158 ########################## |
188 class control_handler(node_handler): | 159 class control_handler(node_handler): |
189 """ A nodehandler for form controls. | 160 """ A nodehandler for form controls. |
190 <nodehandler name='?' module='forms' class='control_handler' /> | 161 <nodehandler name='?' module='forms' class='control_handler' /> |
191 """ | 162 """ |
192 def __init__(self,xml_dom,tree_node): | 163 def __init__(self, xml, tree_node): |
193 node_handler.__init__(self,xml_dom,tree_node) | 164 node_handler.__init__(self, xml, tree_node) |
194 | 165 |
195 def get_size_constraint(self): | 166 def get_size_constraint(self): |
196 return 0 | 167 return 0 |
197 | |
198 | 168 |
199 ########################## | 169 ########################## |
200 ## textctrl handler | 170 ## textctrl handler |
201 ########################## | 171 ########################## |
202 # | 172 # |
208 class textctrl_handler(node_handler): | 178 class textctrl_handler(node_handler): |
209 """ <nodehandler class="textctrl_handler" module="form" name=""> | 179 """ <nodehandler class="textctrl_handler" module="form" name=""> |
210 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text> | 180 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text> |
211 </nodehandler> | 181 </nodehandler> |
212 """ | 182 """ |
213 def __init__(self,xml_dom,tree_node): | 183 def __init__(self,xml,tree_node): |
214 node_handler.__init__(self,xml_dom,tree_node) | 184 node_handler.__init__(self,xml,tree_node) |
215 self.text_elem = self.master_dom.getElementsByTagName('text')[0] | 185 self.text_elem = self.xml.find('text') |
216 self.text = component.get('xml').safe_get_text_node(self.text_elem) | 186 if self.text_elem.get("send_button") == "": self.text_elem.set("send_button","0") |
217 if self.text_elem.getAttribute("send_button") == "": | 187 if self.text_elem.get("raw_mode") == "": self.text_elem.set("raw_mode","0") |
218 self.text_elem.setAttribute("send_button","0") | 188 if self.text_elem.get("hide_title") == "": self.text_elem.set("hide_title","0") |
219 if self.text_elem.getAttribute("raw_mode") == "": | |
220 self.text_elem.setAttribute("raw_mode","0") | |
221 if self.text_elem.getAttribute("hide_title") == "": | |
222 self.text_elem.setAttribute("hide_title","0") | |
223 | 189 |
224 def get_design_panel(self,parent): | 190 def get_design_panel(self,parent): |
225 return textctrl_edit_panel(parent,self) | 191 return textctrl_edit_panel(parent,self) |
226 | 192 |
227 def get_use_panel(self,parent): | 193 def get_use_panel(self,parent): |
228 return text_panel(parent,self) | 194 return text_panel(parent,self) |
229 | 195 |
230 def get_size_constraint(self): | 196 def get_size_constraint(self): |
231 return int(self.text_elem.getAttribute("multiline")) | 197 return int(self.text_elem.get("multiline",0)) |
232 | 198 |
233 def is_multi_line(self): | 199 def is_multi_line(self): |
234 return int(self.text_elem.getAttribute("multiline")) | 200 return int(self.text_elem.get("multiline",0)) |
235 | 201 |
236 def is_raw_send(self): | 202 def is_raw_send(self): |
237 return int(self.text_elem.getAttribute("raw_mode")) | 203 return int(self.text_elem.get("raw_mode",0)) |
238 | 204 |
239 def is_hide_title(self): | 205 def is_hide_title(self): |
240 return int(self.text_elem.getAttribute("hide_title")) | 206 return int(self.text_elem.get("hide_title",0)) |
241 | 207 |
242 def has_send_button(self): | 208 def has_send_button(self): |
243 return int(self.text_elem.getAttribute("send_button")) | 209 return int(self.text_elem.get("send_button",0)) |
244 | |
245 | 210 |
246 def tohtml(self): | 211 def tohtml(self): |
247 txt = self.text._get_nodeValue() | 212 txt = self.get_value() |
248 txt = string.replace(txt,'\n',"<br />") | 213 txt = string.replace(txt,'\n',"<br />") |
249 if not self.is_hide_title(): | 214 if not self.is_hide_title(): |
250 txt = "<b>"+self.master_dom.getAttribute("name")+":</b> "+txt | 215 txt = "<b>"+self.xml.get("name")+":</b> "+txt |
251 return txt | 216 return txt |
252 | 217 |
218 def get_value(self): | |
219 return self.text_elem.text | |
220 | |
221 def set_value(self, new_value): | |
222 self.text_elem.text = str(new_value) | |
253 | 223 |
254 FORM_TEXT_CTRL = wx.NewId() | 224 FORM_TEXT_CTRL = wx.NewId() |
255 FORM_SEND_BUTTON = wx.NewId() | 225 FORM_SEND_BUTTON = wx.NewId() |
256 | 226 |
257 class text_panel(wx.Panel): | 227 class text_panel(wx.Panel): |
266 else: | 236 else: |
267 sizer_style = wx.ALIGN_CENTER | 237 sizer_style = wx.ALIGN_CENTER |
268 text_style = 0 | 238 text_style = 0 |
269 sizer = wx.BoxSizer(wx.HORIZONTAL) | 239 sizer = wx.BoxSizer(wx.HORIZONTAL) |
270 | 240 |
271 txt = handler.text._get_nodeValue() | 241 txt = handler.get_value() |
242 if txt == None: txt = '' | |
272 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style) | 243 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style) |
273 sizer.Add(wx.StaticText(self, -1, handler.master_dom.getAttribute('name')+": "), 0, sizer_style) | 244 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style) |
274 sizer.Add(wx.Size(5,0)) | 245 sizer.Add(wx.Size(5,0)) |
275 sizer.Add(self.text, 1, sizer_style) | 246 sizer.Add(self.text, 1, sizer_style) |
276 | 247 |
277 if handler.has_send_button(): | 248 if handler.has_send_button(): |
278 sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style) | 249 sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style) |
283 | 254 |
284 parent.SetSize(self.GetBestSize()) | 255 parent.SetSize(self.GetBestSize()) |
285 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL) | 256 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL) |
286 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) | 257 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) |
287 | 258 |
288 def on_text(self,evt): | 259 def on_text(self, evt): |
260 debug() | |
289 txt = self.text.GetValue() | 261 txt = self.text.GetValue() |
290 txt = xml.strip_text(txt) | 262 #txt = strip_text(txt) ##Does not seem to exist. |
291 self.handler.text._set_nodeValue(txt) | 263 self.handler.text_elem.text = txt |
292 | 264 |
293 def on_send(self,evt): | 265 def on_send(self, evt): |
294 txt = self.text.GetValue() | 266 txt = self.text.GetValue() |
267 txt = self.chat.ParseMap(txt, self.handler.xml) | |
295 if not self.handler.is_raw_send(): | 268 if not self.handler.is_raw_send(): |
296 #self.chat.ParsePost(self.tohtml(),True,True) | 269 self.chat.ParsePost(self.handler.tohtml(), True, True) |
297 self.chat.ParsePost(self.handler.tohtml(),True,True) | |
298 return 1 | 270 return 1 |
299 actionlist = txt.split("\n") | 271 actionlist = txt.split("\n") |
300 for line in actionlist: | 272 for line in actionlist: |
301 if(line != ""): | 273 if(line != ""): |
302 if line[0] != "/": ## it's not a slash command | 274 if line[0] != "/": ## it's not a slash command |
303 self.chat.ParsePost(line,True,True) | 275 self.chat.ParsePost(line, True, True) |
304 else: | 276 else: |
305 action = line | 277 action = line |
306 self.chat.chat_cmds.docmd(action) | 278 self.chat.chat_cmds.docmd(action) |
307 return 1 | 279 return 1 |
308 | 280 |
316 def __init__(self, parent, handler): | 288 def __init__(self, parent, handler): |
317 wx.Panel.__init__(self, parent, -1) | 289 wx.Panel.__init__(self, parent, -1) |
318 self.handler = handler | 290 self.handler = handler |
319 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL) | 291 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL) |
320 | 292 |
321 self.title = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) | 293 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) |
322 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line") | 294 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line") |
323 self.multi.SetValue(handler.is_multi_line()) | 295 self.multi.SetValue(handler.is_multi_line()) |
324 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro") | 296 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro") |
325 self.raw_send.SetValue(handler.is_raw_send()) | 297 self.raw_send.SetValue(handler.is_raw_send()) |
326 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title") | 298 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title") |
342 multi = 1 | 314 multi = 1 |
343 else: | 315 else: |
344 sizer_style=wx.EXPAND | 316 sizer_style=wx.EXPAND |
345 text_style = 0 | 317 text_style = 0 |
346 multi = 0 | 318 multi = 0 |
347 self.text = wx.TextCtrl(self, F_TEXT, handler.text._get_nodeValue(),style=text_style) | 319 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style) |
348 sizer.Add(wx.Size(5,0)) | 320 sizer.Add(wx.Size(5,0)) |
349 sizer.Add(self.text, multi, sizer_style) | 321 sizer.Add(self.text, multi, sizer_style) |
350 self.SetSizer(sizer) | 322 self.SetSizer(sizer) |
351 self.SetAutoLayout(True) | 323 self.SetAutoLayout(True) |
352 | 324 |
360 def on_text(self,evt): | 332 def on_text(self,evt): |
361 id = evt.GetId() | 333 id = evt.GetId() |
362 if id == P_TITLE: | 334 if id == P_TITLE: |
363 txt = self.title.GetValue() | 335 txt = self.title.GetValue() |
364 if not len(txt): return | 336 if not len(txt): return |
365 self.handler.master_dom.setAttribute('name',txt) | 337 self.handler.xml.set('name',txt) |
366 self.handler.rename(txt) | 338 self.handler.rename(txt) |
367 if id == F_TEXT: | 339 if id == F_TEXT: |
368 txt = self.text.GetValue() | 340 txt = self.text.GetValue() |
369 txt = xml.strip_text(txt) | 341 #txt = strip_text(txt) ##Does not seem to exist. |
370 self.handler.text._set_nodeValue(txt) | 342 self.handler.text_elem.text = txt |
371 | 343 |
372 def on_button(self,evt): | 344 def on_button(self,evt): |
373 self.handler.text_elem.setAttribute("multiline",str(bool2int(evt.Checked()))) | 345 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked()))) |
374 | 346 |
375 def on_raw_button(self,evt): | 347 def on_raw_button(self,evt): |
376 self.handler.text_elem.setAttribute("raw_mode",str(bool2int(evt.Checked()))) | 348 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked()))) |
377 | 349 |
378 def on_hide_button(self,evt): | 350 def on_hide_button(self,evt): |
379 self.handler.text_elem.setAttribute("hide_title",str(bool2int(evt.Checked()))) | 351 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked()))) |
380 | 352 |
381 def on_send_button(self,evt): | 353 def on_send_button(self,evt): |
382 self.handler.text_elem.setAttribute("send_button",str(bool2int(evt.Checked()))) | 354 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked()))) |
383 | |
384 | |
385 | |
386 | |
387 | 355 |
388 | 356 |
389 ####################### | 357 ####################### |
390 ## listbox handler | 358 ## listbox handler |
391 ####################### | 359 ####################### |
407 <option value="" selected="" >Option Text I</option> | 375 <option value="" selected="" >Option Text I</option> |
408 <option value="" selected="" >Option Text II</option> | 376 <option value="" selected="" >Option Text II</option> |
409 </list> | 377 </list> |
410 </nodehandler> | 378 </nodehandler> |
411 """ | 379 """ |
412 def __init__(self,xml_dom,tree_node): | 380 def __init__(self,xml,tree_node): |
413 node_handler.__init__(self,xml_dom,tree_node) | 381 node_handler.__init__(self,xml,tree_node) |
414 self.list = self.master_dom.getElementsByTagName('list')[0] | 382 self.list = self.xml.find('list') |
415 self.options = self.list.getElementsByTagName('option') | 383 self.options = self.list.findall('option') |
416 if self.list.getAttribute("send_button") == "": | 384 if self.list.get("send_button") == "": |
417 self.list.setAttribute("send_button","0") | 385 self.list.set("send_button","0") |
418 if self.list.getAttribute("hide_title") == "": | 386 if self.list.get("hide_title") == "": |
419 self.list.setAttribute("hide_title","0") | 387 self.list.set("hide_title","0") |
420 | 388 |
421 def get_design_panel(self,parent): | 389 def get_design_panel(self,parent): |
422 return listbox_edit_panel(parent,self) | 390 return listbox_edit_panel(parent,self) |
423 | 391 |
424 def get_use_panel(self,parent): | 392 def get_use_panel(self,parent): |
425 return listbox_panel(parent,self) | 393 return listbox_panel(parent,self) |
426 | 394 |
427 def get_type(self): | 395 def get_type(self): |
428 return int(self.list.getAttribute("type")) | 396 return int(self.list.get("type")) |
429 | 397 |
430 def set_type(self,type): | 398 def set_type(self,type): |
431 self.list.setAttribute("type",str(type)) | 399 self.list.set("type",str(type)) |
432 | 400 |
433 def is_hide_title(self): | 401 def is_hide_title(self): |
434 return int(self.list.getAttribute("hide_title")) | 402 return int(self.list.get("hide_title", 0)) |
435 | 403 |
436 # single selection methods | 404 # single selection methods |
437 def get_selected_node(self): | 405 def get_selected_node(self): |
438 for opt in self.options: | 406 for opt in self.options: |
439 if opt.getAttribute("selected") == "1": return opt | 407 if opt.get("selected") == "1": return opt |
440 return None | 408 return None |
441 | 409 |
442 def get_selected_index(self): | 410 def get_selected_index(self): |
443 i = 0 | 411 i = 0 |
444 for opt in self.options: | 412 for opt in self.options: |
445 if opt.getAttribute("selected") == "1": | 413 if opt.get("selected") == "1": |
446 return i | 414 return i |
447 i += 1 | 415 i += 1 |
448 return 0 | 416 return 0 |
449 | 417 |
450 def get_selected_text(self): | 418 def get_selected_text(self): |
451 node = self.get_selected_node() | 419 node = self.get_selected_node() |
452 if node: | 420 if node: |
453 return component.get('xml').safe_get_text_node(node)._get_nodeValue() | 421 return node.text |
454 else: | 422 else: |
455 return "" | 423 return "" |
456 | 424 |
457 | 425 |
458 # mult selection methods | 426 # mult selection methods |
459 | |
460 def get_selections(self): | 427 def get_selections(self): |
461 opts = [] | 428 opts = [] |
462 for opt in self.options: | 429 for opt in self.options: |
463 if opt.getAttribute("selected") == "1": | 430 if opt.get("selected") == "1": |
464 opts.append(opt) | 431 opts.append(opt) |
465 return opts | 432 return opts |
466 | 433 |
467 def get_selections_text(self): | 434 def get_selections_text(self): |
468 opts = [] | 435 opts = [] |
469 for opt in self.options: | 436 for opt in self.options: |
470 if opt.getAttribute("selected") == "1": | 437 if opt.get("selected") == "1": |
471 opts.append(component.get('xml').safe_get_text_node(opt)._get_nodeValue()) | 438 opts.append(opt.text) |
472 return opts | 439 return opts |
473 | 440 |
474 def get_selections_index(self): | 441 def get_selections_index(self): |
475 opts = [] | 442 opts = [] |
476 i = 0 | 443 i = 0 |
477 for opt in self.options: | 444 for opt in self.options: |
478 if opt.getAttribute("selected") == "1": | 445 if opt.get("selected") == "1": |
479 opts.append(i) | 446 opts.append(i) |
480 i += 1 | 447 i += 1 |
481 return opts | 448 return opts |
482 | 449 |
483 # setting selection method | 450 # setting selection method |
484 | |
485 def set_selected_node(self,index,selected=1): | 451 def set_selected_node(self,index,selected=1): |
486 if self.get_type() != L_CHECK: | 452 if self.get_type() != L_CHECK: |
487 self.clear_selections() | 453 self.clear_selections() |
488 self.options[index].setAttribute("selected", str(bool2int(selected))) | 454 self.options[index].set("selected", str(bool2int(selected))) |
489 | 455 |
490 def clear_selections(self): | 456 def clear_selections(self): |
491 for opt in self.options: | 457 for opt in self.options: |
492 opt.setAttribute("selected","0") | 458 opt.set("selected","0") |
493 | 459 |
494 # misc methods | 460 # misc methods |
495 | |
496 def get_options(self): | 461 def get_options(self): |
497 opts = [] | 462 opts = [] |
498 for opt in self.options: | 463 for opt in self.options: opts.append(opt.text) |
499 opts.append(component.get('xml').safe_get_text_node(opt)._get_nodeValue()) | |
500 return opts | 464 return opts |
501 | 465 |
502 def get_option(self,index): | 466 def get_option(self,index): |
503 return component.get('xml').safe_get_text_node(self.options[index])._get_nodeValue() | 467 return self.options[index].text |
504 | 468 |
505 def add_option(self,opt): | 469 def add_option(self,opt): |
506 elem = minidom.Element('option') | 470 elem = Element('option') |
507 elem.setAttribute("value","0") | 471 elem.set("value","0") |
508 elem.setAttribute("selected","0") | 472 elem.set("selected","0") |
509 t_node = minidom.Text(opt) | 473 elem.text = opt |
510 t_node = elem.appendChild(t_node) | 474 self.list.append(elem) |
511 self.list.appendChild(elem) | 475 self.options = self.list.findall('option') |
512 self.options = self.list.getElementsByTagName('option') | |
513 | 476 |
514 def remove_option(self,index): | 477 def remove_option(self,index): |
515 self.list.removeChild(self.options[index]) | 478 self.list.remove(self.options[index]) |
516 self.options = self.list.getElementsByTagName('option') | 479 self.options = self.list.findall('option') |
517 | 480 |
518 def edit_option(self,index,value): | 481 def edit_option(self,index,value): |
519 component.get('xml').safe_get_text_node(self.options[index])._set_nodeValue(value) | 482 self.options[index].text = value |
520 | 483 |
521 def has_send_button(self): | 484 def has_send_button(self): |
522 if self.list.getAttribute("send_button") == '0': | 485 if self.list.get("send_button") == '0': return False |
523 return False | 486 else: return True |
524 else: | |
525 return True | |
526 | 487 |
527 def get_size_constraint(self): | 488 def get_size_constraint(self): |
528 if self.get_type() == L_DROP: | 489 if self.get_type() == L_DROP: return 0 |
529 return 0 | 490 else: return 1 |
530 else: | |
531 return 1 | |
532 | 491 |
533 def tohtml(self): | 492 def tohtml(self): |
534 opts = self.get_selections_text() | 493 opts = self.get_selections_text() |
535 text = "" | 494 text = "" |
536 if not self.is_hide_title(): | 495 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> " |
537 text = "<b>"+self.master_dom.getAttribute("name")+":</b> " | |
538 comma = ", " | 496 comma = ", " |
539 text += comma.join(opts) | 497 text += comma.join(opts) |
540 return text | 498 return text |
541 | 499 |
500 def get_value(self): | |
501 return "\n".join(self.get_selections_text()) | |
542 | 502 |
543 | 503 |
544 F_LIST = wx.NewId() | 504 F_LIST = wx.NewId() |
545 F_SEND = wx.NewId() | 505 F_SEND = wx.NewId() |
546 | 506 |
551 self.handler = handler | 511 self.handler = handler |
552 self.chat = handler.chat | 512 self.chat = handler.chat |
553 opts = handler.get_options() | 513 opts = handler.get_options() |
554 cur_opt = handler.get_selected_text() | 514 cur_opt = handler.get_selected_text() |
555 type = handler.get_type() | 515 type = handler.get_type() |
556 label = handler.master_dom.getAttribute('name') | 516 label = handler.xml.get('name') |
557 | 517 |
558 if type == L_DROP: | 518 if type == L_DROP: |
559 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY) | 519 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY) |
560 if self.list.GetSize()[0] > 200: | 520 if self.list.GetSize()[0] > 200: |
561 self.list.Destroy() | 521 self.list.Destroy() |
633 def __init__(self, parent, handler): | 593 def __init__(self, parent, handler): |
634 wx.Panel.__init__(self, parent, -1) | 594 wx.Panel.__init__(self, parent, -1) |
635 self.handler = handler | 595 self.handler = handler |
636 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL) | 596 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL) |
637 | 597 |
638 self.text = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) | 598 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) |
639 | 599 |
640 opts = handler.get_options() | 600 opts = handler.get_options() |
641 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB) | 601 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB) |
642 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List'] | 602 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List'] |
643 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts) | 603 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts) |
715 def on_text(self,evt): | 675 def on_text(self,evt): |
716 id = evt.GetId() | 676 id = evt.GetId() |
717 txt = self.text.GetValue() | 677 txt = self.text.GetValue() |
718 if not len(txt): return | 678 if not len(txt): return |
719 if id == P_TITLE: | 679 if id == P_TITLE: |
720 self.handler.master_dom.setAttribute('name',txt) | 680 self.handler.xml.set('name',txt) |
721 self.handler.rename(txt) | 681 self.handler.rename(txt) |
722 | 682 |
723 def on_send_button(self,evt): | 683 def on_send_button(self,evt): |
724 self.handler.list.setAttribute("send_button", str( bool2int(evt.Checked()) )) | 684 self.handler.list.set("send_button", str( bool2int(evt.Checked()) )) |
725 | 685 |
726 def on_hide_button(self,evt): | 686 def on_hide_button(self,evt): |
727 print "hide_title, " + str(bool2int(evt.Checked())) | 687 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) )) |
728 self.handler.list.setAttribute("hide_title", str( bool2int(evt.Checked()) )) | |
729 | 688 |
730 | 689 |
731 ############################### | 690 ############################### |
732 ## link image handlers | 691 ## link image handlers |
733 ############################### | 692 ############################### |
736 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame | 695 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame |
737 <nodehandler name='?' module='forms' class='link_handler' > | 696 <nodehandler name='?' module='forms' class='link_handler' > |
738 <link href='http//??.??' /> | 697 <link href='http//??.??' /> |
739 </nodehandler > | 698 </nodehandler > |
740 """ | 699 """ |
741 def __init__(self,xml_dom,tree_node): | 700 def __init__(self,xml,tree_node): |
742 node_handler.__init__(self,xml_dom,tree_node) | 701 node_handler.__init__(self,xml,tree_node) |
743 self.link = self.master_dom._get_firstChild() | 702 self.link = self.xml[0] |
744 | 703 |
745 def on_use(self,evt): | 704 def on_use(self,evt): |
746 href = self.link.getAttribute("href") | 705 href = self.link.get("href") |
747 wb = webbrowser.get() | 706 wb = webbrowser.get() |
748 wb.open(href) | 707 wb.open(href) |
749 | 708 |
750 def get_design_panel(self,parent): | 709 def get_design_panel(self,parent): |
751 return link_edit_panel(parent,self) | 710 return link_edit_panel(parent,self) |
752 | 711 |
753 def get_use_panel(self,parent): | 712 def get_use_panel(self,parent): |
754 return link_panel(parent,self) | 713 return link_panel(parent,self) |
755 | 714 |
756 def tohtml(self): | 715 def tohtml(self): |
757 href = self.link.getAttribute("href") | 716 href = self.link.get("href") |
758 title = self.master_dom.getAttribute("name") | 717 title = self.xml.get("name") |
759 return "<a href=\""+href+"\" >"+title+"</a>" | 718 return "<a href=\""+href+"\" >"+title+"</a>" |
760 | 719 |
761 class link_panel(wx.StaticText): | 720 class link_panel(wx.StaticText): |
762 def __init__(self,parent,handler): | 721 def __init__(self,parent,handler): |
763 self.handler = handler | 722 self.handler = handler |
764 label = handler.master_dom.getAttribute('name') | 723 label = handler.xml.get('name') |
765 wx.StaticText.__init__(self,parent,-1,label) | 724 wx.StaticText.__init__(self,parent,-1,label) |
766 self.SetForegroundColour(wx.BLUE) | 725 self.SetForegroundColour(wx.BLUE) |
767 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use) | 726 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use) |
768 | 727 |
769 | 728 |
774 wx.Panel.__init__(self, parent, -1) | 733 wx.Panel.__init__(self, parent, -1) |
775 self.handler = handler | 734 self.handler = handler |
776 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL) | 735 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL) |
777 | 736 |
778 self.text = {} | 737 self.text = {} |
779 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) | 738 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) |
780 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.getAttribute('href')) | 739 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href')) |
781 | 740 |
782 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) | 741 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) |
783 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) | 742 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) |
784 sizer.Add(wx.Size(10,10)) | 743 sizer.Add(wx.Size(10,10)) |
785 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND) | 744 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND) |
791 def on_text(self,evt): | 750 def on_text(self,evt): |
792 id = evt.GetId() | 751 id = evt.GetId() |
793 txt = self.text[id].GetValue() | 752 txt = self.text[id].GetValue() |
794 if not len(txt): return | 753 if not len(txt): return |
795 if id == P_TITLE: | 754 if id == P_TITLE: |
796 self.handler.master_dom.setAttribute('name',txt) | 755 self.handler.xml.set('name',txt) |
797 self.handler.rename(txt) | 756 self.handler.rename(txt) |
798 elif id == P_URL: | 757 elif id == P_URL: |
799 self.handler.link.setAttribute('href',txt) | 758 self.handler.link.set('href',txt) |
800 | 759 |
801 ########################## | 760 ########################## |
802 ## webimg node handler | 761 ## webimg node handler |
803 ########################## | 762 ########################## |
804 class webimg_handler(node_handler): | 763 class webimg_handler(node_handler): |
805 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame | 764 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame |
806 <nodehandler name='?' module='forms' class='webimg_handler' > | 765 <nodehandler name='?' module='forms' class='webimg_handler' > |
807 <link href='http//??.??' /> | 766 <link href='http//??.??' /> |
808 </nodehandler > | 767 </nodehandler > |
809 """ | 768 """ |
810 def __init__(self,xml_dom,tree_node): | 769 def __init__(self,xml,tree_node): |
811 node_handler.__init__(self,xml_dom,tree_node) | 770 node_handler.__init__(self,xml,tree_node) |
812 self.link = self.master_dom._get_firstChild() | 771 self.link = self.xml[0] |
813 | 772 |
814 def get_design_panel(self,parent): | 773 def get_design_panel(self,parent): |
815 return link_edit_panel(parent,self) | 774 return link_edit_panel(parent,self) |
816 | 775 |
817 def get_use_panel(self,parent): | 776 def get_use_panel(self,parent): |
818 img = img_helper().load_url(self.link.getAttribute("href")) | 777 img = img_helper().load_url(self.link.get("href")) |
819 #print img | |
820 if not img is None: | 778 if not img is None: |
821 return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight())) | 779 return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight())) |
822 return wx.EmptyBitmap(1, 1) | 780 return wx.EmptyBitmap(1, 1) |
823 | 781 |
824 def tohtml(self): | 782 def tohtml(self): |
825 href = self.link.getAttribute("href") | 783 href = self.link.get("href") |
826 title = self.master_dom.getAttribute("name") | 784 title = self.xml.get("name") |
827 return "<img src=\""+href+"\" alt="+title+" >" | 785 return "<img src=\""+href+"\" alt="+title+" >" |