Mercurial > traipse_dev
comparison orpg/gametree/nodehandlers/forms.py @ 118:217fb049bd00 alpha
Traipse Alpha 'OpenRPG' {091028-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:
Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images!
Changes made to the map for increased portability. SnowDog has changes planned in
Core, though.
Added an initial push to the BCG. Not much to see, just shows off how it is
re-writing Main code.
Fix to remote admin commands
Minor fix to texted based server, works in /System/ folder
Some Core changes to gametree to correctly disply Pretty Print, thanks David!
Fix to Splitter Nodes not being created.
Added images to Plugin Control panel for Autostart feature
Fix to massive amounts of images loading; from Core
fix to gsclient so with_statement imports
Added 'boot' command to remote admin
Prep work in Pass tool for remote admin rankings and different passwords, ei,
Server, Admin, Moderator, etc.
Remote Admin Commands more organized, more prep work.
Added Confirmation window for sent nodes.
Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without
breaking)
{091028}
00:
Made changes to gametree to start working with Element Tree, mostly from Core
Minor changes to Map to start working with Element Tree, from Core
Preliminary changes to map efficiency, from FlexiRPG
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Changes to main.py to start working with Element Tree
author | sirebral |
---|---|
date | Wed, 28 Oct 2009 14:24:54 -0500 |
parents | 0c936d98f9eb |
children | 43ad912b7c17 |
comparison
equal
deleted
inserted
replaced
117:0f18d16f3fe7 | 118:217fb049bd00 |
---|---|
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.atts = child_xml |
65 if c._get_tagName() == "form": | 62 else: self.tree.load_xml(child_xml,self.mytree_node) |
66 self.atts = c | |
67 else: | |
68 self.tree.load_xml(c,self.mytree_node) | |
69 if not self.atts: | 63 if not self.atts: |
70 elem = minidom.Element('form') | 64 self.atts = Element('form') |
71 elem.setAttribute("width","400") | 65 self.atts.set("width","400") |
72 elem.setAttribute("height","600") | 66 self.atts.set("height","600") |
73 self.atts = self.master_dom.appendChild(elem) | 67 self.xml.append(self.atts) |
74 | 68 |
75 def get_design_panel(self,parent): | 69 def get_design_panel(self,parent): |
76 return form_edit_panel(parent,self) | 70 return form_edit_panel(parent,self) |
77 | 71 |
78 def get_use_panel(self,parent): | 72 def get_use_panel(self,parent): |
80 | 74 |
81 def on_drop(self,evt): | 75 def on_drop(self,evt): |
82 # make sure its a contorl node | 76 # make sure its a contorl node |
83 container_handler.on_drop(self,evt) | 77 container_handler.on_drop(self,evt) |
84 | 78 |
85 | |
86 class form_panel(ScrolledPanel): | 79 class form_panel(ScrolledPanel): |
87 def __init__(self, parent, handler): | 80 def __init__(self, parent, handler): |
88 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL) | 81 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL) |
89 self.height = int(handler.atts.getAttribute("height")) | 82 self.height = int(handler.atts.get("height")) |
90 self.width = int(handler.atts.getAttribute("width")) | 83 self.width = int(handler.atts.get("width")) |
91 | |
92 self.SetSize((0,0)) | 84 self.SetSize((0,0)) |
93 self.handler = handler | 85 self.handler = handler |
94 self.parent = parent | 86 self.parent = parent |
95 self.main_sizer = wx.BoxSizer(wx.VERTICAL) | 87 self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
96 tree = self.handler.tree | 88 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False) |
97 handler.traverse(handler.mytree_node, self.create_child_wnd, None, False) | |
98 | |
99 self.SetSizer(self.main_sizer) | 89 self.SetSizer(self.main_sizer) |
100 self.SetAutoLayout(True) | 90 self.SetAutoLayout(True) |
101 | |
102 self.SetupScrolling() | 91 self.SetupScrolling() |
103 | |
104 parent.SetSize(self.GetSize()) | 92 parent.SetSize(self.GetSize()) |
105 self.Fit() | 93 self.Fit() |
106 | |
107 | 94 |
108 def SetSize(self, xy): | 95 def SetSize(self, xy): |
109 (x, y) = self.GetSize() | 96 (x, y) = self.GetSize() |
110 (nx, ny) = xy | 97 (nx, ny) = xy |
111 if x < nx: | 98 if x < nx: |
112 x = nx+10 | 99 x = nx+10 |
113 y += ny+11 | 100 y += ny+11 |
114 ScrolledPanel.SetSize(self, (x, y)) | 101 ScrolledPanel.SetSize(self, (x, y)) |
115 | 102 |
116 | 103 def create_child_wnd(self, treenode, evt): |
117 def create_child_wnd(self, obj, evt): | 104 node = self.handler.tree.GetPyData(treenode) |
118 panel = obj.get_use_panel(self) | 105 panel = node.get_use_panel(self) |
119 size = obj.get_size_constraint() | 106 size = node.get_size_constraint() |
120 if panel: | 107 if panel: |
121 self.main_sizer.Add(panel, size, wx.EXPAND) | 108 self.main_sizer.Add(panel, size, wx.EXPAND) |
122 self.main_sizer.Add(wx.Size(10,10)) | 109 self.main_sizer.Add(wx.Size(10,10)) |
123 | |
124 | |
125 | 110 |
126 F_HEIGHT = wx.NewId() | 111 F_HEIGHT = wx.NewId() |
127 F_WIDTH = wx.NewId() | 112 F_WIDTH = wx.NewId() |
128 class form_edit_panel(wx.Panel): | 113 class form_edit_panel(wx.Panel): |
129 def __init__(self, parent, handler): | 114 def __init__(self, parent, handler): |
130 wx.Panel.__init__(self, parent, -1) | 115 wx.Panel.__init__(self, parent, -1) |
131 self.handler = handler | 116 self.handler = handler |
132 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL) | 117 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL) |
133 wh_sizer = wx.BoxSizer(wx.HORIZONTAL) | 118 wh_sizer = wx.BoxSizer(wx.HORIZONTAL) |
134 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')), | 119 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')), |
135 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.atts.getAttribute('height')), | 120 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.atts.get('height')), |
136 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.atts.getAttribute('width')) | 121 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.atts.get('width')) |
137 } | 122 } |
138 | 123 |
139 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER) | 124 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER) |
140 wh_sizer.Add(wx.Size(10,10)) | 125 wh_sizer.Add(wx.Size(10,10)) |
141 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND) | 126 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND) |
161 def on_text(self,evt): | 146 def on_text(self,evt): |
162 id = evt.GetId() | 147 id = evt.GetId() |
163 txt = self.text[id].GetValue() | 148 txt = self.text[id].GetValue() |
164 if not len(txt): return | 149 if not len(txt): return |
165 if id == P_TITLE: | 150 if id == P_TITLE: |
166 self.handler.master_dom.setAttribute('name',txt) | 151 self.handler.xml.set('name',txt) |
167 self.handler.rename(txt) | 152 self.handler.rename(txt) |
168 elif id == F_HEIGHT or id == F_WIDTH: | 153 elif id == F_HEIGHT or id == F_WIDTH: |
169 try: | 154 try: int(txt) |
170 int(txt) | 155 except: return 0 |
171 except: | 156 if id == F_HEIGHT: self.handler.atts.set("height",txt) |
172 return 0 | 157 elif id == F_WIDTH: self.handler.atts.set("width",txt) |
173 if id == F_HEIGHT: | |
174 self.handler.atts.setAttribute("height",txt) | |
175 elif id == F_WIDTH: | |
176 self.handler.atts.setAttribute("width",txt) | |
177 | |
178 | |
179 | |
180 | |
181 | 158 |
182 ########################## | 159 ########################## |
183 ## control handler | 160 ## control handler |
184 ########################## | 161 ########################## |
185 class control_handler(node_handler): | 162 class control_handler(node_handler): |
186 """ A nodehandler for form controls. | 163 """ A nodehandler for form controls. |
187 <nodehandler name='?' module='forms' class='control_handler' /> | 164 <nodehandler name='?' module='forms' class='control_handler' /> |
188 """ | 165 """ |
189 def __init__(self,xml_dom,tree_node): | 166 def __init__(self, xml, tree_node): |
190 node_handler.__init__(self,xml_dom,tree_node) | 167 node_handler.__init__(self, xml, tree_node) |
191 | 168 |
192 def get_size_constraint(self): | 169 def get_size_constraint(self): |
193 return 0 | 170 return 0 |
194 | |
195 | 171 |
196 ########################## | 172 ########################## |
197 ## textctrl handler | 173 ## textctrl handler |
198 ########################## | 174 ########################## |
199 # | 175 # |
205 class textctrl_handler(node_handler): | 181 class textctrl_handler(node_handler): |
206 """ <nodehandler class="textctrl_handler" module="form" name=""> | 182 """ <nodehandler class="textctrl_handler" module="form" name=""> |
207 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text> | 183 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text> |
208 </nodehandler> | 184 </nodehandler> |
209 """ | 185 """ |
210 def __init__(self,xml_dom,tree_node): | 186 def __init__(self,xml,tree_node): |
211 node_handler.__init__(self,xml_dom,tree_node) | 187 node_handler.__init__(self,xml,tree_node) |
212 self.text_elem = self.master_dom.getElementsByTagName('text')[0] | 188 self.text_elem = self.xml.find('text') |
213 self.text = component.get('xml').safe_get_text_node(self.text_elem) | 189 if self.text_elem.get("send_button") == "": |
214 if self.text_elem.getAttribute("send_button") == "": | 190 self.text_elem.set("send_button","0") |
215 self.text_elem.setAttribute("send_button","0") | 191 if self.text_elem.get("raw_mode") == "": |
216 if self.text_elem.getAttribute("raw_mode") == "": | 192 self.text_elem.set("raw_mode","0") |
217 self.text_elem.setAttribute("raw_mode","0") | 193 if self.text_elem.get("hide_title") == "": |
218 if self.text_elem.getAttribute("hide_title") == "": | 194 self.text_elem.set("hide_title","0") |
219 self.text_elem.setAttribute("hide_title","0") | |
220 | 195 |
221 def get_design_panel(self,parent): | 196 def get_design_panel(self,parent): |
222 return textctrl_edit_panel(parent,self) | 197 return textctrl_edit_panel(parent,self) |
223 | 198 |
224 def get_use_panel(self,parent): | 199 def get_use_panel(self,parent): |
225 return text_panel(parent,self) | 200 return text_panel(parent,self) |
226 | 201 |
227 def get_size_constraint(self): | 202 def get_size_constraint(self): |
228 return int(self.text_elem.getAttribute("multiline")) | 203 return int(self.text_elem.get("multiline",0)) |
229 | 204 |
230 def is_multi_line(self): | 205 def is_multi_line(self): |
231 return int(self.text_elem.getAttribute("multiline")) | 206 return int(self.text_elem.get("multiline",0)) |
232 | 207 |
233 def is_raw_send(self): | 208 def is_raw_send(self): |
234 return int(self.text_elem.getAttribute("raw_mode")) | 209 return int(self.text_elem.get("raw_mode",0)) |
235 | 210 |
236 def is_hide_title(self): | 211 def is_hide_title(self): |
237 return int(self.text_elem.getAttribute("hide_title")) | 212 return int(self.text_elem.get("hide_title",0)) |
238 | 213 |
239 def has_send_button(self): | 214 def has_send_button(self): |
240 return int(self.text_elem.getAttribute("send_button")) | 215 return int(self.text_elem.get("send_button",0)) |
241 | |
242 | 216 |
243 def tohtml(self): | 217 def tohtml(self): |
244 txt = self.text._get_nodeValue() | 218 txt = self.get_value() |
245 txt = string.replace(txt,'\n',"<br />") | 219 txt = string.replace(txt,'\n',"<br />") |
246 if not self.is_hide_title(): | 220 if not self.is_hide_title(): |
247 txt = "<b>"+self.master_dom.getAttribute("name")+":</b> "+txt | 221 txt = "<b>"+self.xml.get("name")+":</b> "+txt |
248 return txt | 222 return txt |
249 | 223 |
224 def get_value(self): | |
225 return self.text_elem.text | |
226 | |
227 def set_value(self, new_value): | |
228 self.text_elem.text = str(new_value) | |
250 | 229 |
251 FORM_TEXT_CTRL = wx.NewId() | 230 FORM_TEXT_CTRL = wx.NewId() |
252 FORM_SEND_BUTTON = wx.NewId() | 231 FORM_SEND_BUTTON = wx.NewId() |
253 | 232 |
254 class text_panel(wx.Panel): | 233 class text_panel(wx.Panel): |
263 else: | 242 else: |
264 sizer_style = wx.ALIGN_CENTER | 243 sizer_style = wx.ALIGN_CENTER |
265 text_style = 0 | 244 text_style = 0 |
266 sizer = wx.BoxSizer(wx.HORIZONTAL) | 245 sizer = wx.BoxSizer(wx.HORIZONTAL) |
267 | 246 |
268 txt = handler.text._get_nodeValue() | 247 txt = handler.get_value() |
248 if txt == None: txt = '' | |
269 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style) | 249 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style) |
270 sizer.Add(wx.StaticText(self, -1, handler.master_dom.getAttribute('name')+": "), 0, sizer_style) | 250 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style) |
271 sizer.Add(wx.Size(5,0)) | 251 sizer.Add(wx.Size(5,0)) |
272 sizer.Add(self.text, 1, sizer_style) | 252 sizer.Add(self.text, 1, sizer_style) |
273 | 253 |
274 if handler.has_send_button(): | 254 if handler.has_send_button(): |
275 sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style) | 255 sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style) |
282 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL) | 262 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL) |
283 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) | 263 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) |
284 | 264 |
285 def on_text(self,evt): | 265 def on_text(self,evt): |
286 txt = self.text.GetValue() | 266 txt = self.text.GetValue() |
287 txt = xml.strip_text(txt) | 267 txt = strip_text(txt) |
288 self.handler.text._set_nodeValue(txt) | 268 self.handler.text_elem.text = txt |
289 | 269 |
290 def on_send(self,evt): | 270 def on_send(self,evt): |
291 txt = self.text.GetValue() | 271 txt = self.text.GetValue() |
292 if not self.handler.is_raw_send(): | 272 if not self.handler.is_raw_send(): |
293 #self.chat.ParsePost(self.tohtml(),True,True) | 273 #self.chat.ParsePost(self.tohtml(),True,True) |
313 def __init__(self, parent, handler): | 293 def __init__(self, parent, handler): |
314 wx.Panel.__init__(self, parent, -1) | 294 wx.Panel.__init__(self, parent, -1) |
315 self.handler = handler | 295 self.handler = handler |
316 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL) | 296 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL) |
317 | 297 |
318 self.title = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) | 298 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) |
319 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line") | 299 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line") |
320 self.multi.SetValue(handler.is_multi_line()) | 300 self.multi.SetValue(handler.is_multi_line()) |
321 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro") | 301 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro") |
322 self.raw_send.SetValue(handler.is_raw_send()) | 302 self.raw_send.SetValue(handler.is_raw_send()) |
323 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title") | 303 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title") |
339 multi = 1 | 319 multi = 1 |
340 else: | 320 else: |
341 sizer_style=wx.EXPAND | 321 sizer_style=wx.EXPAND |
342 text_style = 0 | 322 text_style = 0 |
343 multi = 0 | 323 multi = 0 |
344 self.text = wx.TextCtrl(self, F_TEXT, handler.text._get_nodeValue(),style=text_style) | 324 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style) |
345 sizer.Add(wx.Size(5,0)) | 325 sizer.Add(wx.Size(5,0)) |
346 sizer.Add(self.text, multi, sizer_style) | 326 sizer.Add(self.text, multi, sizer_style) |
347 self.SetSizer(sizer) | 327 self.SetSizer(sizer) |
348 self.SetAutoLayout(True) | 328 self.SetAutoLayout(True) |
349 | 329 |
357 def on_text(self,evt): | 337 def on_text(self,evt): |
358 id = evt.GetId() | 338 id = evt.GetId() |
359 if id == P_TITLE: | 339 if id == P_TITLE: |
360 txt = self.title.GetValue() | 340 txt = self.title.GetValue() |
361 if not len(txt): return | 341 if not len(txt): return |
362 self.handler.master_dom.setAttribute('name',txt) | 342 self.handler.xml.set('name',txt) |
363 self.handler.rename(txt) | 343 self.handler.rename(txt) |
364 if id == F_TEXT: | 344 if id == F_TEXT: |
365 txt = self.text.GetValue() | 345 txt = self.text.GetValue() |
366 txt = xml.strip_text(txt) | 346 txt = strip_text(txt) |
367 self.handler.text._set_nodeValue(txt) | 347 self.handler.text_elem.text = txt |
368 | 348 |
369 def on_button(self,evt): | 349 def on_button(self,evt): |
370 self.handler.text_elem.setAttribute("multiline",str(bool2int(evt.Checked()))) | 350 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked()))) |
371 | 351 |
372 def on_raw_button(self,evt): | 352 def on_raw_button(self,evt): |
373 self.handler.text_elem.setAttribute("raw_mode",str(bool2int(evt.Checked()))) | 353 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked()))) |
374 | 354 |
375 def on_hide_button(self,evt): | 355 def on_hide_button(self,evt): |
376 self.handler.text_elem.setAttribute("hide_title",str(bool2int(evt.Checked()))) | 356 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked()))) |
377 | 357 |
378 def on_send_button(self,evt): | 358 def on_send_button(self,evt): |
379 self.handler.text_elem.setAttribute("send_button",str(bool2int(evt.Checked()))) | 359 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked()))) |
380 | |
381 | |
382 | |
383 | |
384 | 360 |
385 | 361 |
386 ####################### | 362 ####################### |
387 ## listbox handler | 363 ## listbox handler |
388 ####################### | 364 ####################### |
404 <option value="" selected="" >Option Text I</option> | 380 <option value="" selected="" >Option Text I</option> |
405 <option value="" selected="" >Option Text II</option> | 381 <option value="" selected="" >Option Text II</option> |
406 </list> | 382 </list> |
407 </nodehandler> | 383 </nodehandler> |
408 """ | 384 """ |
409 def __init__(self,xml_dom,tree_node): | 385 def __init__(self,xml,tree_node): |
410 node_handler.__init__(self,xml_dom,tree_node) | 386 node_handler.__init__(self,xml,tree_node) |
411 self.list = self.master_dom.getElementsByTagName('list')[0] | 387 self.list = self.xml.find('list') |
412 self.options = self.list.getElementsByTagName('option') | 388 self.options = self.list.findall('option') |
413 if self.list.getAttribute("send_button") == "": | 389 if self.list.get("send_button") == "": |
414 self.list.setAttribute("send_button","0") | 390 self.list.set("send_button","0") |
415 if self.list.getAttribute("hide_title") == "": | 391 if self.list.get("hide_title") == "": |
416 self.list.setAttribute("hide_title","0") | 392 self.list.set("hide_title","0") |
417 | 393 |
418 def get_design_panel(self,parent): | 394 def get_design_panel(self,parent): |
419 return listbox_edit_panel(parent,self) | 395 return listbox_edit_panel(parent,self) |
420 | 396 |
421 def get_use_panel(self,parent): | 397 def get_use_panel(self,parent): |
422 return listbox_panel(parent,self) | 398 return listbox_panel(parent,self) |
423 | 399 |
424 def get_type(self): | 400 def get_type(self): |
425 return int(self.list.getAttribute("type")) | 401 return int(self.list.get("type")) |
426 | 402 |
427 def set_type(self,type): | 403 def set_type(self,type): |
428 self.list.setAttribute("type",str(type)) | 404 self.list.set("type",str(type)) |
429 | 405 |
430 def is_hide_title(self): | 406 def is_hide_title(self): |
431 return int(self.list.getAttribute("hide_title")) | 407 return int(self.list.get("hide_title", 0)) |
432 | 408 |
433 # single selection methods | 409 # single selection methods |
434 def get_selected_node(self): | 410 def get_selected_node(self): |
435 for opt in self.options: | 411 for opt in self.options: |
436 if opt.getAttribute("selected") == "1": return opt | 412 if opt.get("selected") == "1": return opt |
437 return None | 413 return None |
438 | 414 |
439 def get_selected_index(self): | 415 def get_selected_index(self): |
440 i = 0 | 416 i = 0 |
441 for opt in self.options: | 417 for opt in self.options: |
442 if opt.getAttribute("selected") == "1": | 418 if opt.get("selected") == "1": |
443 return i | 419 return i |
444 i += 1 | 420 i += 1 |
445 return 0 | 421 return 0 |
446 | 422 |
447 def get_selected_text(self): | 423 def get_selected_text(self): |
448 node = self.get_selected_node() | 424 node = self.get_selected_node() |
449 if node: | 425 if node: |
450 return component.get('xml').safe_get_text_node(node)._get_nodeValue() | 426 return node.text |
451 else: | 427 else: |
452 return "" | 428 return "" |
453 | 429 |
454 | 430 |
455 # mult selection methods | 431 # mult selection methods |
456 | 432 |
457 def get_selections(self): | 433 def get_selections(self): |
458 opts = [] | 434 opts = [] |
459 for opt in self.options: | 435 for opt in self.options: |
460 if opt.getAttribute("selected") == "1": | 436 if opt.get("selected") == "1": |
461 opts.append(opt) | 437 opts.append(opt) |
462 return opts | 438 return opts |
463 | 439 |
464 def get_selections_text(self): | 440 def get_selections_text(self): |
465 opts = [] | 441 opts = [] |
466 for opt in self.options: | 442 for opt in self.options: |
467 if opt.getAttribute("selected") == "1": | 443 if opt.get("selected") == "1": |
468 opts.append(component.get('xml').safe_get_text_node(opt)._get_nodeValue()) | 444 opts.append(opt.text) |
469 return opts | 445 return opts |
470 | 446 |
471 def get_selections_index(self): | 447 def get_selections_index(self): |
472 opts = [] | 448 opts = [] |
473 i = 0 | 449 i = 0 |
474 for opt in self.options: | 450 for opt in self.options: |
475 if opt.getAttribute("selected") == "1": | 451 if opt.get("selected") == "1": |
476 opts.append(i) | 452 opts.append(i) |
477 i += 1 | 453 i += 1 |
478 return opts | 454 return opts |
479 | 455 |
480 # setting selection method | 456 # setting selection method |
481 | 457 |
482 def set_selected_node(self,index,selected=1): | 458 def set_selected_node(self,index,selected=1): |
483 if self.get_type() != L_CHECK: | 459 if self.get_type() != L_CHECK: |
484 self.clear_selections() | 460 self.clear_selections() |
485 self.options[index].setAttribute("selected", str(bool2int(selected))) | 461 self.options[index].set("selected", str(bool2int(selected))) |
486 | 462 |
487 def clear_selections(self): | 463 def clear_selections(self): |
488 for opt in self.options: | 464 for opt in self.options: |
489 opt.setAttribute("selected","0") | 465 opt.set("selected","0") |
490 | 466 |
491 # misc methods | 467 # misc methods |
492 | 468 |
493 def get_options(self): | 469 def get_options(self): |
494 opts = [] | 470 opts = [] |
495 for opt in self.options: | 471 for opt in self.options: |
496 opts.append(component.get('xml').safe_get_text_node(opt)._get_nodeValue()) | 472 opts.append(opt.text) |
497 return opts | 473 return opts |
498 | 474 |
499 def get_option(self,index): | 475 def get_option(self,index): |
500 return component.get('xml').safe_get_text_node(self.options[index])._get_nodeValue() | 476 return self.options[index].text |
501 | 477 |
502 def add_option(self,opt): | 478 def add_option(self,opt): |
503 elem = minidom.Element('option') | 479 elem = Element('option') |
504 elem.setAttribute("value","0") | 480 elem.set("value","0") |
505 elem.setAttribute("selected","0") | 481 elem.set("selected","0") |
506 t_node = minidom.Text(opt) | 482 elem.text = opt |
507 t_node = elem.appendChild(t_node) | 483 self.list.append(elem) |
508 self.list.appendChild(elem) | 484 self.options = self.list.findall('option') |
509 self.options = self.list.getElementsByTagName('option') | |
510 | 485 |
511 def remove_option(self,index): | 486 def remove_option(self,index): |
512 self.list.removeChild(self.options[index]) | 487 self.list.remove(self.options[index]) |
513 self.options = self.list.getElementsByTagName('option') | 488 self.options = self.list.findall('option') |
514 | 489 |
515 def edit_option(self,index,value): | 490 def edit_option(self,index,value): |
516 component.get('xml').safe_get_text_node(self.options[index])._set_nodeValue(value) | 491 self.options[index].text = value |
517 | 492 |
518 def has_send_button(self): | 493 def has_send_button(self): |
519 if self.list.getAttribute("send_button") == '0': | 494 if self.list.get("send_button") == '0': |
520 return False | 495 return False |
521 else: | 496 else: |
522 return True | 497 return True |
523 | 498 |
524 def get_size_constraint(self): | 499 def get_size_constraint(self): |
529 | 504 |
530 def tohtml(self): | 505 def tohtml(self): |
531 opts = self.get_selections_text() | 506 opts = self.get_selections_text() |
532 text = "" | 507 text = "" |
533 if not self.is_hide_title(): | 508 if not self.is_hide_title(): |
534 text = "<b>"+self.master_dom.getAttribute("name")+":</b> " | 509 text = "<b>"+self.xml.get("name")+":</b> " |
535 comma = ", " | 510 comma = ", " |
536 text += comma.join(opts) | 511 text += comma.join(opts) |
537 return text | 512 return text |
538 | 513 |
514 def get_value(self): | |
515 return "\n".join(self.get_selections_text()) | |
539 | 516 |
540 | 517 |
541 F_LIST = wx.NewId() | 518 F_LIST = wx.NewId() |
542 F_SEND = wx.NewId() | 519 F_SEND = wx.NewId() |
543 | 520 |
548 self.handler = handler | 525 self.handler = handler |
549 self.chat = handler.chat | 526 self.chat = handler.chat |
550 opts = handler.get_options() | 527 opts = handler.get_options() |
551 cur_opt = handler.get_selected_text() | 528 cur_opt = handler.get_selected_text() |
552 type = handler.get_type() | 529 type = handler.get_type() |
553 label = handler.master_dom.getAttribute('name') | 530 label = handler.xml.get('name') |
554 | 531 |
555 if type == L_DROP: | 532 if type == L_DROP: |
556 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY) | 533 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY) |
557 if self.list.GetSize()[0] > 200: | 534 if self.list.GetSize()[0] > 200: |
558 self.list.Destroy() | 535 self.list.Destroy() |
630 def __init__(self, parent, handler): | 607 def __init__(self, parent, handler): |
631 wx.Panel.__init__(self, parent, -1) | 608 wx.Panel.__init__(self, parent, -1) |
632 self.handler = handler | 609 self.handler = handler |
633 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL) | 610 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL) |
634 | 611 |
635 self.text = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) | 612 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) |
636 | 613 |
637 opts = handler.get_options() | 614 opts = handler.get_options() |
638 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB) | 615 self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB) |
639 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List'] | 616 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List'] |
640 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts) | 617 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts) |
712 def on_text(self,evt): | 689 def on_text(self,evt): |
713 id = evt.GetId() | 690 id = evt.GetId() |
714 txt = self.text.GetValue() | 691 txt = self.text.GetValue() |
715 if not len(txt): return | 692 if not len(txt): return |
716 if id == P_TITLE: | 693 if id == P_TITLE: |
717 self.handler.master_dom.setAttribute('name',txt) | 694 self.handler.xml.set('name',txt) |
718 self.handler.rename(txt) | 695 self.handler.rename(txt) |
719 | 696 |
720 def on_send_button(self,evt): | 697 def on_send_button(self,evt): |
721 self.handler.list.setAttribute("send_button", str( bool2int(evt.Checked()) )) | 698 self.handler.list.set("send_button", str( bool2int(evt.Checked()) )) |
722 | 699 |
723 def on_hide_button(self,evt): | 700 def on_hide_button(self,evt): |
724 print "hide_title, " + str(bool2int(evt.Checked())) | 701 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) )) |
725 self.handler.list.setAttribute("hide_title", str( bool2int(evt.Checked()) )) | |
726 | 702 |
727 | 703 |
728 ############################### | 704 ############################### |
729 ## link image handlers | 705 ## link image handlers |
730 ############################### | 706 ############################### |
733 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame | 709 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame |
734 <nodehandler name='?' module='forms' class='link_handler' > | 710 <nodehandler name='?' module='forms' class='link_handler' > |
735 <link href='http//??.??' /> | 711 <link href='http//??.??' /> |
736 </nodehandler > | 712 </nodehandler > |
737 """ | 713 """ |
738 def __init__(self,xml_dom,tree_node): | 714 def __init__(self,xml,tree_node): |
739 node_handler.__init__(self,xml_dom,tree_node) | 715 node_handler.__init__(self,xml,tree_node) |
740 self.link = self.master_dom._get_firstChild() | 716 self.link = self.xml[0] |
741 | 717 |
742 def on_use(self,evt): | 718 def on_use(self,evt): |
743 href = self.link.getAttribute("href") | 719 href = self.link.get("href") |
744 wb = webbrowser.get() | 720 wb = webbrowser.get() |
745 wb.open(href) | 721 wb.open(href) |
746 | 722 |
747 def get_design_panel(self,parent): | 723 def get_design_panel(self,parent): |
748 return link_edit_panel(parent,self) | 724 return link_edit_panel(parent,self) |
749 | 725 |
750 def get_use_panel(self,parent): | 726 def get_use_panel(self,parent): |
751 return link_panel(parent,self) | 727 return link_panel(parent,self) |
752 | 728 |
753 def tohtml(self): | 729 def tohtml(self): |
754 href = self.link.getAttribute("href") | 730 href = self.link.get("href") |
755 title = self.master_dom.getAttribute("name") | 731 title = self.xml.get("name") |
756 return "<a href=\""+href+"\" >"+title+"</a>" | 732 return "<a href=\""+href+"\" >"+title+"</a>" |
757 | 733 |
758 class link_panel(wx.StaticText): | 734 class link_panel(wx.StaticText): |
759 def __init__(self,parent,handler): | 735 def __init__(self,parent,handler): |
760 self.handler = handler | 736 self.handler = handler |
761 label = handler.master_dom.getAttribute('name') | 737 label = handler.xml.get('name') |
762 wx.StaticText.__init__(self,parent,-1,label) | 738 wx.StaticText.__init__(self,parent,-1,label) |
763 self.SetForegroundColour(wx.BLUE) | 739 self.SetForegroundColour(wx.BLUE) |
764 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use) | 740 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use) |
765 | 741 |
766 | 742 |
771 wx.Panel.__init__(self, parent, -1) | 747 wx.Panel.__init__(self, parent, -1) |
772 self.handler = handler | 748 self.handler = handler |
773 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL) | 749 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL) |
774 | 750 |
775 self.text = {} | 751 self.text = {} |
776 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) | 752 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) |
777 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.getAttribute('href')) | 753 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href')) |
778 | 754 |
779 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) | 755 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) |
780 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) | 756 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) |
781 sizer.Add(wx.Size(10,10)) | 757 sizer.Add(wx.Size(10,10)) |
782 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND) | 758 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND) |
788 def on_text(self,evt): | 764 def on_text(self,evt): |
789 id = evt.GetId() | 765 id = evt.GetId() |
790 txt = self.text[id].GetValue() | 766 txt = self.text[id].GetValue() |
791 if not len(txt): return | 767 if not len(txt): return |
792 if id == P_TITLE: | 768 if id == P_TITLE: |
793 self.handler.master_dom.setAttribute('name',txt) | 769 self.handler.xml.set('name',txt) |
794 self.handler.rename(txt) | 770 self.handler.rename(txt) |
795 elif id == P_URL: | 771 elif id == P_URL: |
796 self.handler.link.setAttribute('href',txt) | 772 self.handler.link.set('href',txt) |
797 | 773 |
798 ########################## | 774 ########################## |
799 ## webimg node handler | 775 ## webimg node handler |
800 ########################## | 776 ########################## |
801 class webimg_handler(node_handler): | 777 class webimg_handler(node_handler): |
802 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame | 778 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame |
803 <nodehandler name='?' module='forms' class='webimg_handler' > | 779 <nodehandler name='?' module='forms' class='webimg_handler' > |
804 <link href='http//??.??' /> | 780 <link href='http//??.??' /> |
805 </nodehandler > | 781 </nodehandler > |
806 """ | 782 """ |
807 def __init__(self,xml_dom,tree_node): | 783 def __init__(self,xml,tree_node): |
808 node_handler.__init__(self,xml_dom,tree_node) | 784 node_handler.__init__(self,xml,tree_node) |
809 self.link = self.master_dom._get_firstChild() | 785 self.link = self.xml[0] |
810 | 786 |
811 def get_design_panel(self,parent): | 787 def get_design_panel(self,parent): |
812 return link_edit_panel(parent,self) | 788 return link_edit_panel(parent,self) |
813 | 789 |
814 def get_use_panel(self,parent): | 790 def get_use_panel(self,parent): |
815 img = img_helper().load_url(self.link.getAttribute("href")) | 791 img = img_helper().load_url(self.link.get("href")) |
816 #print img | |
817 if not img is None: | 792 if not img is None: |
818 return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight())) | 793 return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight())) |
819 return wx.EmptyBitmap(1, 1) | 794 return wx.EmptyBitmap(1, 1) |
820 | 795 |
821 def tohtml(self): | 796 def tohtml(self): |
822 href = self.link.getAttribute("href") | 797 href = self.link.get("href") |
823 title = self.master_dom.getAttribute("name") | 798 title = self.xml.get("name") |
824 return "<img src=\""+href+"\" alt="+title+" >" | 799 return "<img src=\""+href+"\" alt="+title+" >" |