comparison orpg/gametree/nodehandlers/forms.py @ 131:90d19eb43830 alpha

Traipse Alpha 'OpenRPG' {091003-03} 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 (Cleaning up for 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!! (Apparently I pasted from the OpenRPG folder. Wrong! Pro's or not, they need to eventually see the read text in their own debugger console.) Dead Node Children, now that's a O O -v-v- Happy Halloween!
author sirebral
date Tue, 03 Nov 2009 21:30:36 -0600
parents d54e1328dbb1
children fe4dc5817d5e
comparison
equal deleted inserted replaced
130:d54e1328dbb1 131:90d19eb43830
27 # 27 #
28 28
29 __version__ = "$Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $" 29 __version__ = "$Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $"
30 30
31 from containers import * 31 from containers import *
32 import wx.lib.scrolledpanel 32 import orpg.minidom as minidom
33 from orpg.orpg_xml import xml
34 from wx.lib.scrolledpanel import ScrolledPanel
33 35
34 def bool2int(b): 36 def bool2int(b):
35 #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.
36 #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.
37 #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
38 #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
39 #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.
40 if b: 42 if b: return 1
41 return 1 43 else: return 0
42 else:
43 return 0
44 44
45 ################################# 45 #################################
46 ## form container 46 ## form container
47 ################################# 47 #################################
48 48
50 """ 50 """
51 <nodehandler name='?' module='forms' class='form_handler' > 51 <nodehandler name='?' module='forms' class='form_handler' >
52 <form width='100' height='100' /> 52 <form width='100' height='100' />
53 </nodehandler> 53 </nodehandler>
54 """ 54 """
55
56 def __init__(self,xml,tree_node): 55 def __init__(self,xml,tree_node):
57 container_handler.__init__(self,xml,tree_node) 56 container_handler.__init__(self, xml, tree_node)
58 57
59 def load_children(self): 58 def load_children(self):
60 self.atts = None 59 self.atts = None
61 for child_xml in self.xml: 60 for child_xml in self.xml:
62 if child_xml.tag == "form": 61 if child_xml.tag == "form": self.xml.remove(child_xml)
63 self.atts = child_xml 62 elif child_xml: self.tree.load_xml(child_xml, self.mytree_node)
64 else: 63 if not self.xml.get('width'): self.xml.set('width', '400')
65 self.tree.load_xml(child_xml,self.mytree_node) 64 if not self.xml.get('height'): self.xml.set('height', '600')
66 if not self.atts:
67 self.atts = ET.Element('form')
68 self.atts.set("width","400")
69 self.atts.set("height","600")
70 self.xml.append(self.atts)
71 65
72 def get_design_panel(self,parent): 66 def get_design_panel(self,parent):
73 return form_edit_panel(parent,self) 67 return form_edit_panel(parent,self)
74 68
75 def get_use_panel(self,parent): 69 def get_use_panel(self,parent):
77 71
78 def on_drop(self,evt): 72 def on_drop(self,evt):
79 # make sure its a contorl node 73 # make sure its a contorl node
80 container_handler.on_drop(self,evt) 74 container_handler.on_drop(self,evt)
81 75
82 76 class form_panel(ScrolledPanel):
83 class form_panel(wx.lib.scrolledpanel.ScrolledPanel):
84 def __init__(self, parent, handler): 77 def __init__(self, parent, handler):
85 wx.lib.scrolledpanel.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)
86 self.height = int(handler.atts.get("height")) 79 self.height = int(handler.xml.get("height"))
87 self.width = int(handler.atts.get("width")) 80 self.width = int(handler.xml.get("width"))
88
89
90 self.SetSize((0,0)) 81 self.SetSize((0,0))
91 self.handler = handler 82 self.handler = handler
92 self.parent = parent 83 self.parent = parent
93 self.main_sizer = wx.BoxSizer(wx.VERTICAL) 84 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
94 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False) 85 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False)
95
96 self.SetSizer(self.main_sizer) 86 self.SetSizer(self.main_sizer)
97 self.SetAutoLayout(True) 87 self.SetAutoLayout(True)
98
99 self.SetupScrolling() 88 self.SetupScrolling()
100
101 parent.SetSize(self.GetSize()) 89 parent.SetSize(self.GetSize())
102 self.Fit() 90 self.Fit()
103
104 91
105 def SetSize(self, xy): 92 def SetSize(self, xy):
106 (x, y) = self.GetSize() 93 (x, y) = self.GetSize()
107 (nx, ny) = xy 94 (nx, ny) = xy
108 if x < nx: 95 if x < nx:
109 x = nx+10 96 x = nx+10
110 y += ny+11 97 y += ny+11
111 wx.lib.scrolledpanel.ScrolledPanel.SetSize(self, (x, y)) 98 ScrolledPanel.SetSize(self, (x, y))
112
113 99
114 def create_child_wnd(self, treenode, evt): 100 def create_child_wnd(self, treenode, evt):
115 node = self.handler.tree.GetPyData(treenode) 101 node = self.handler.tree.GetPyData(treenode)
116 panel = node.get_use_panel(self) 102 panel = node.get_use_panel(self)
117 size = node.get_size_constraint() 103 size = node.get_size_constraint()
118 if panel: 104 if panel:
119 self.main_sizer.Add(panel, size, wx.EXPAND) 105 self.main_sizer.Add(panel, size, wx.EXPAND)
120 self.main_sizer.Add(wx.Size(10,10)) 106 self.main_sizer.Add(wx.Size(10,10))
121
122
123 107
124 F_HEIGHT = wx.NewId() 108 F_HEIGHT = wx.NewId()
125 F_WIDTH = wx.NewId() 109 F_WIDTH = wx.NewId()
126 class form_edit_panel(wx.Panel): 110 class form_edit_panel(wx.Panel):
127 def __init__(self, parent, handler): 111 def __init__(self, parent, handler):
128 wx.Panel.__init__(self, parent, -1) 112 wx.Panel.__init__(self, parent, -1)
129 self.handler = handler 113 self.handler = handler
130 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL) 114 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL)
131 wh_sizer = wx.BoxSizer(wx.HORIZONTAL) 115 wh_sizer = wx.BoxSizer(wx.HORIZONTAL)
132 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')), 116 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
133 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.atts.get('height')), 117 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.xml.get('height')),
134 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.atts.get('width')) 118 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.xml.get('width'))
135 } 119 }
136 120
137 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)
138 wh_sizer.Add(wx.Size(10,10)) 122 wh_sizer.Add(wx.Size(10,10))
139 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND) 123 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND)
162 if not len(txt): return 146 if not len(txt): return
163 if id == P_TITLE: 147 if id == P_TITLE:
164 self.handler.xml.set('name',txt) 148 self.handler.xml.set('name',txt)
165 self.handler.rename(txt) 149 self.handler.rename(txt)
166 elif id == F_HEIGHT or id == F_WIDTH: 150 elif id == F_HEIGHT or id == F_WIDTH:
167 try: 151 try: int(txt)
168 int(txt) 152 except: return 0
169 except: 153 if id == F_HEIGHT: self.handler.xml.set("height",txt)
170 return 0 154 elif id == F_WIDTH: self.handler.xml.set("width",txt)
171 if id == F_HEIGHT:
172 self.handler.atts.set("height",txt)
173 elif id == F_WIDTH:
174 self.handler.atts.set("width",txt)
175
176
177
178
179 155
180 ########################## 156 ##########################
181 ## control handler 157 ## control handler
182 ########################## 158 ##########################
183 class control_handler(node_handler): 159 class control_handler(node_handler):
184 """ A nodehandler for form controls. 160 """ A nodehandler for form controls.
185 <nodehandler name='?' module='forms' class='control_handler' /> 161 <nodehandler name='?' module='forms' class='control_handler' />
186 """ 162 """
187 def __init__(self,xml,tree_node): 163 def __init__(self, xml, tree_node):
188 node_handler.__init__(self,xml,tree_node) 164 node_handler.__init__(self, xml, tree_node)
189 165
190 def get_size_constraint(self): 166 def get_size_constraint(self):
191 return 0 167 return 0
192
193 168
194 ########################## 169 ##########################
195 ## textctrl handler 170 ## textctrl handler
196 ########################## 171 ##########################
197 # 172 #
242 if not self.is_hide_title(): 217 if not self.is_hide_title():
243 txt = "<b>"+self.xml.get("name")+":</b> "+txt 218 txt = "<b>"+self.xml.get("name")+":</b> "+txt
244 return txt 219 return txt
245 220
246 def get_value(self): 221 def get_value(self):
247 return getText(self.text_elem) 222 return self.text_elem.text
248 223
249 def set_value(self, new_value): 224 def set_value(self, new_value):
250 self.text_elem.text = str(new_value) 225 self.text_elem.text = str(new_value)
251
252
253 226
254 FORM_TEXT_CTRL = wx.NewId() 227 FORM_TEXT_CTRL = wx.NewId()
255 FORM_SEND_BUTTON = wx.NewId() 228 FORM_SEND_BUTTON = wx.NewId()
256 229
257 class text_panel(wx.Panel): 230 class text_panel(wx.Panel):
267 sizer_style = wx.ALIGN_CENTER 240 sizer_style = wx.ALIGN_CENTER
268 text_style = 0 241 text_style = 0
269 sizer = wx.BoxSizer(wx.HORIZONTAL) 242 sizer = wx.BoxSizer(wx.HORIZONTAL)
270 243
271 txt = handler.get_value() 244 txt = handler.get_value()
272 ## if self.handler.tree.ContainsReference(txt): 245 if txt == None: txt = ''
273 ## txt = self.handler.tree.ReplaceReferences(txt, False)
274 ## text_style |= wx.TE_READONLY
275
276 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style) 246 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style)
277 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style) 247 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style)
278 sizer.Add(wx.Size(5,0)) 248 sizer.Add(wx.Size(5,0))
279 sizer.Add(self.text, 1, sizer_style) 249 sizer.Add(self.text, 1, sizer_style)
280 250
289 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL) 259 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
290 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) 260 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
291 261
292 def on_text(self,evt): 262 def on_text(self,evt):
293 txt = self.text.GetValue() 263 txt = self.text.GetValue()
294 txt = strip_text(txt) 264 #txt = strip_text(txt) ##Does not seem to exist.
295 self.handler.text_elem.text = txt 265 self.handler.text_elem.text = txt
296 266
297 def on_send(self,evt): 267 def on_send(self,evt):
298 txt = self.text.GetValue() 268 txt = self.text.GetValue()
299 if not self.handler.is_raw_send(): 269 if not self.handler.is_raw_send():
368 if not len(txt): return 338 if not len(txt): return
369 self.handler.xml.set('name',txt) 339 self.handler.xml.set('name',txt)
370 self.handler.rename(txt) 340 self.handler.rename(txt)
371 if id == F_TEXT: 341 if id == F_TEXT:
372 txt = self.text.GetValue() 342 txt = self.text.GetValue()
373 txt = strip_text(txt) 343 #txt = strip_text(txt) ##Does not seem to exist.
374 self.handler.text_elem.text = txt 344 self.handler.text_elem.text = txt
375 345
376 def on_button(self,evt): 346 def on_button(self,evt):
377 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked()))) 347 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
378 348
429 399
430 def set_type(self,type): 400 def set_type(self,type):
431 self.list.set("type",str(type)) 401 self.list.set("type",str(type))
432 402
433 def is_hide_title(self): 403 def is_hide_title(self):
434 return int(self.list.get("hide_title",0)) 404 return int(self.list.get("hide_title", 0))
435 405
436 # single selection methods 406 # single selection methods
437 def get_selected_node(self): 407 def get_selected_node(self):
438 for opt in self.options: 408 for opt in self.options:
439 if opt.get("selected") == "1": return opt 409 if opt.get("selected") == "1": return opt
448 return 0 418 return 0
449 419
450 def get_selected_text(self): 420 def get_selected_text(self):
451 node = self.get_selected_node() 421 node = self.get_selected_node()
452 if node: 422 if node:
453 return getText(node) 423 return node.text
454 else: 424 else:
455 return "" 425 return ""
456 426
457 427
458 # mult selection methods 428 # mult selection methods
466 436
467 def get_selections_text(self): 437 def get_selections_text(self):
468 opts = [] 438 opts = []
469 for opt in self.options: 439 for opt in self.options:
470 if opt.get("selected") == "1": 440 if opt.get("selected") == "1":
471 opts.append(getText(opt)) 441 opts.append(opt.text)
472 return opts 442 return opts
473 443
474 def get_selections_index(self): 444 def get_selections_index(self):
475 opts = [] 445 opts = []
476 i = 0 446 i = 0
494 # misc methods 464 # misc methods
495 465
496 def get_options(self): 466 def get_options(self):
497 opts = [] 467 opts = []
498 for opt in self.options: 468 for opt in self.options:
499 opts.append(getText(opt)) 469 opts.append(opt.text)
500 return opts 470 return opts
501 471
502 def get_option(self,index): 472 def get_option(self,index):
503 return getText(self.options[index]) 473 return self.options[index].text
504 474
505 def add_option(self,opt): 475 def add_option(self,opt):
506 elem = ET.Element('option') 476 elem = Element('option')
507 elem.set("value","0") 477 elem.set("value","0")
508 elem.set("selected","0") 478 elem.set("selected","0")
509 elem.text = opt 479 elem.text = opt
510 self.list.append(elem) 480 self.list.append(elem)
511 self.options = self.list.findall('option') 481 self.options = self.list.findall('option')
538 text += comma.join(opts) 508 text += comma.join(opts)
539 return text 509 return text
540 510
541 def get_value(self): 511 def get_value(self):
542 return "\n".join(self.get_selections_text()) 512 return "\n".join(self.get_selections_text())
513
543 514
544 F_LIST = wx.NewId() 515 F_LIST = wx.NewId()
545 F_SEND = wx.NewId() 516 F_SEND = wx.NewId()
546 517
547 518
821 792
822 def tohtml(self): 793 def tohtml(self):
823 href = self.link.get("href") 794 href = self.link.get("href")
824 title = self.xml.get("name") 795 title = self.xml.get("name")
825 return "<img src=\""+href+"\" alt="+title+" >" 796 return "<img src=\""+href+"\" alt="+title+" >"
826
827
828
829 #######################
830 ## resource handler
831 #######################
832
833 class resource_handler(node_handler):
834 """
835 <nodehandler class="resource_handler" module="forms" name="">
836 <resource base="5" current="4" checks="1">Multi-line macro</resource>
837 </nodehandler>
838 """
839 def __init__(self,xml,tree_node):
840 node_handler.__init__(self,xml,tree_node)
841 self.resource = self.xml.find('resource')
842 if self.resource.get("checks") == "":
843 self.resource.set("checks","1")
844 if self.resource.get("base") == "":
845 self.resource.set("base","1")
846 if self.resource.get("current") == "":
847 self.resource.set("current", self.resource.get("base"))
848
849 def get_design_panel(self,parent):
850 return resource_edit_panel(parent,self)
851
852 def get_use_panel(self,parent):
853 return resource_panel(parent,self)
854
855 def tohtml(self):
856 # decrement the current value or post a "nothing left" message
857 # print the multi-line macro
858 return "resource"
859
860 def use_checks(self):
861 if self.resource.get("checks") == "1":
862 return True
863 return False
864
865 def get_base(self):
866 return int(self.resource.get("base",0))
867
868 def get_current(self):
869 return int(self.resource.get("current",0))
870
871 def get_macro(self):
872 return getText(self.resource)
873
874 def get_value(self):
875 return self.resource.get("current")
876
877 def set_value(self, new_value):
878 self.resource.set("current", new_value)
879
880
881 RESOURCE_RESET = wx.NewId()
882 RESOURCE_CHECKS = wx.NewId()
883 RESOURCE_NUMBER = wx.NewId()
884 RESOURCE_DONE = wx.NewId()
885
886
887 class resource_panel(wx.Panel):
888 def __init__(self, parent, handler):
889 wx.Panel.__init__(self, parent, -1)
890 self.handler = handler
891 self.chat = handler.chat
892
893 sizer = wx.BoxSizer(wx.HORIZONTAL)
894 # sizer.Add(wx.Button(self, RESOURCE_RESET, "Reset"))
895 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 1, wx.ALIGN_RIGHT)
896 if self.handler.use_checks():
897 grid = wx.GridSizer(1, 11, 0, 0)
898 sizer.Add(grid, 0, wx.ALIGN_RIGHT)
899 self.checks = []
900 used = self.handler.get_base() - self.handler.get_current()
901 for i in range(self.handler.get_base()):
902 self.checks.append(wx.CheckBox(self, RESOURCE_CHECKS, ""))
903 checked = False
904 if i < used:
905 checked = True
906 self.checks[i].SetValue(checked)
907 grid.Add(self.checks[i])
908 if i-int(i/10)*10==4:
909 grid.Add(wx.Size(1,1))
910 else:
911 self.number = wx.TextCtrl(self, RESOURCE_NUMBER, self.handler.resource.get("current"))
912 sizer.Add(self.number, 0, wx.ALIGN_RIGHT)
913 sizer.Add(wx.Size(10,10), 0, wx.ALIGN_RIGHT)
914 sizer.Add(wx.Button(self, RESOURCE_DONE, "Apply"), 0, wx.ALIGN_RIGHT)
915 # self.chat.InfoPost("res 10")
916 sizer.SetMinSize(wx.Size(380,10))
917 self.sizer = sizer
918 self.SetSizer(sizer)
919 self.SetAutoLayout(True)
920 self.Fit()
921 # self.chat.InfoPost("res 20")
922 self.Bind(wx.EVT_BUTTON, self.on_reset, id=RESOURCE_RESET)
923 self.Bind(wx.EVT_BUTTON, self.on_done, id=RESOURCE_DONE)
924
925
926 def on_reset(self,evt):
927 # uncheck all the check boxes or set the text to max
928 if self.handler.use_checks():
929 for c in self.checks:
930 c.SetValue(False)
931 else:
932 self.number.SetValue(self.handler.resource.get("base"))
933 self.handler.resource.set("current", self.handler.resource.get("base"))
934
935 def on_done(self,evt):
936 # save the changes back to the handler
937 current = 0
938 if self.handler.use_checks():
939 for c in self.checks:
940 if not c.GetValue():
941 current += 1
942 else:
943 # validate text
944 current = int(self.number.GetValue())
945 change = self.handler.get_current()-current
946 if change > 0:
947 macro_text = self.handler.get_macro()
948 macro_text = macro_text.replace("_NAME_",self.handler.xml.get("name"))
949 macro_text = macro_text.replace("_CHANGE_", str(change))
950 macro_text = macro_text.replace("_CURRENT_", str(current))
951 self.handler.chat.ParsePost(macro_text, True, True)
952 self.handler.resource.set("current",str(current))
953
954
955 RES_EDIT_TITLE = wx.NewId()
956 RES_EDIT_BASE = wx.NewId()
957 RES_EDIT_CURRENT = wx.NewId()
958 RES_EDIT_CHECKS = wx.NewId()
959 RES_EDIT_MACRO = wx.NewId()
960
961
962 class resource_edit_panel(wx.Panel):
963 def __init__(self, parent, handler):
964 wx.Panel.__init__(self, parent, -1)
965 self.handler = handler
966
967 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Resource Properties"), wx.VERTICAL)
968 sizer.Add(wx.StaticText(self, -1, "Name of resource:"), 0, wx.EXPAND)
969 self.title = wx.TextCtrl(self, RES_EDIT_TITLE, self.handler.xml.get('name'))
970 sizer.Add(self.title, 0, wx.EXPAND)
971 sizer.Add(wx.Size(10,10))
972
973 sizer.Add(wx.StaticText(self, -1, "Base amount of resource:"), 0, wx.EXPAND)
974 self.base = wx.TextCtrl(self, RES_EDIT_BASE, self.handler.resource.get("base"))
975 sizer.Add(self.base, 0, wx.EXPAND)
976 sizer.Add(wx.Size(10,10))
977
978 sizer.Add(wx.StaticText(self, -1, "Current amount of resource:"), 0, wx.EXPAND)
979 self.current = wx.TextCtrl(self, RES_EDIT_CURRENT, self.handler.resource.get("current"))
980 sizer.Add(self.current, 0, wx.EXPAND)
981 sizer.Add(wx.Size(10,10))
982
983 opts = ['Text Number', 'Check Boxes']
984 self.radio = wx.RadioBox(self, RES_EDIT_CHECKS, "Amount of resource is represented by:", choices=opts)
985 if self.handler.use_checks():
986 self.radio.SetSelection(1)
987 else:
988 self.radio.SetSelection(0)
989 sizer.Add(self.radio, 0, wx.EXPAND)
990 sizer.Add(wx.Size(10,10))
991
992 sizer.Add(wx.StaticText(self, -1, "Send the following macro:"), 0, wx.EXPAND)
993 self.macro = wx.TextCtrl(self, RES_EDIT_MACRO, self.handler.get_macro(), style=wx.TE_MULTILINE)
994 sizer.Add(self.macro, 1, wx.EXPAND)
995
996 self.SetSizer(sizer)
997 self.SetAutoLayout(True)
998 self.Fit()
999 parent.SetSize(self.GetBestSize())
1000
1001 self.Bind(wx.EVT_TEXT, self.on_title, id=RES_EDIT_TITLE)
1002 self.Bind(wx.EVT_TEXT, self.on_base, id=RES_EDIT_BASE)
1003 self.Bind(wx.EVT_TEXT, self.on_current, id=RES_EDIT_CURRENT)
1004 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=RES_EDIT_CHECKS)
1005 self.Bind(wx.EVT_TEXT, self.on_macro, id=RES_EDIT_MACRO)
1006
1007
1008 def on_title(self, evt):
1009 if len(self.title.GetValue()):
1010 self.handler.xml.set('name', self.title.GetValue())
1011 self.handler.rename(self.title.GetValue())
1012
1013 def on_base(self, evt):
1014 try:
1015 b = int(self.base.GetValue())
1016 self.handler.resource.set("base",str(b))
1017 except:
1018 pass
1019
1020 def on_current(self, evt):
1021 try:
1022 c = int(self.current.GetValue())
1023 self.handler.resource.set("current",str(c))
1024 except:
1025 pass
1026
1027 def on_type(self,evt):
1028 self.handler.resource.set("checks",str(self.radio.GetSelection()))
1029
1030 def on_macro(self,evt):
1031 self.handler.resource.text = self.macro.GetValue()
1032
1033
1034 #######################
1035 ## bonus handler
1036 #######################
1037
1038 class bonus_handler(node_handler):
1039 """
1040 <nodehandler class="bonus_handler" module="forms" name="">
1041 <bonus value="2" type="optional">Multi-line list of node references</bonus>
1042 </nodehandler>
1043 """
1044 def __init__(self,xml,tree_node):
1045 node_handler.__init__(self,xml,tree_node)
1046 self.bonus_xml = self.xml.find('bonus')
1047 self.add_to_bonus_map()
1048
1049 def get_design_panel(self,parent):
1050 return bonus_edit_panel(parent,self)
1051
1052 def get_use_panel(self,parent):# there is no 'use' for a bonus
1053 return bonus_edit_panel(parent,self)
1054
1055 def tohtml(self):
1056 return "bonus"# there is no 'send to chat' or 'pretty print'
1057
1058 def get_value(self):
1059 return self.bonus_xml.get('value', '')
1060
1061 def delete(self):
1062 self.remove_from_bonus_map()
1063 return node_handler.delete(self)
1064
1065 def add_to_bonus_map(self):
1066 for target in getText(self.bonus_xml).split('\n'):
1067 self.tree.AddBonus(target, self)
1068
1069 def remove_from_bonus_map(self):
1070 for target in getText(self.bonus_xml).split('\n'):
1071 self.tree.RemoveBonus(target, self)
1072
1073
1074
1075 BONUS_EDIT_TITLE = wx.NewId()
1076 BONUS_EDIT_VALUE = wx.NewId()
1077 BONUS_EDIT_TYPE = wx.NewId()
1078 BONUS_EDIT_REF = wx.NewId()
1079
1080
1081 class bonus_edit_panel(wx.Panel):
1082 def __init__(self, parent, handler):
1083 wx.Panel.__init__(self, parent, -1)
1084 self.handler = handler
1085
1086 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Bonus Properties"), wx.VERTICAL)
1087 sizer.Add(wx.StaticText(self, -1, "Name of bonus:"), 0, wx.EXPAND)
1088 self.title = wx.TextCtrl(self, BONUS_EDIT_TITLE, self.handler.xml.get('name'))
1089 sizer.Add(self.title, 0, wx.EXPAND)
1090 sizer.Add(wx.Size(10,10))
1091
1092 sizer.Add(wx.StaticText(self, -1, "Size of bonus:"), 0, wx.EXPAND)
1093 self.value = wx.TextCtrl(self, BONUS_EDIT_VALUE, self.handler.bonus_xml.get('value', ''))
1094 sizer.Add(self.value, 0, wx.EXPAND)
1095 sizer.Add(wx.Size(10,10))
1096
1097 sizer.Add(wx.StaticText(self, -1, "Type of bonus:"), 0, wx.EXPAND)
1098 self.type = wx.TextCtrl(self, BONUS_EDIT_TYPE, self.handler.bonus_xml.get("type"))
1099 sizer.Add(self.type, 0, wx.EXPAND)
1100 sizer.Add(wx.Size(10,10))
1101
1102 sizer.Add(wx.StaticText(self, -1, "Add to the following nodes:"), 0, wx.EXPAND)
1103 self.ref = wx.TextCtrl(self, BONUS_EDIT_REF, getText(self.handler.bonus_xml), style=wx.TE_MULTILINE)
1104 sizer.Add(self.ref, 1, wx.EXPAND)
1105
1106 self.SetSizer(sizer)
1107 self.SetAutoLayout(True)
1108 self.Fit()
1109 parent.SetSize(self.GetBestSize())
1110
1111 self.Bind(wx.EVT_TEXT, self.on_title, id=BONUS_EDIT_TITLE)# too many calls - should call only upon close
1112 self.Bind(wx.EVT_TEXT, self.on_value, id=BONUS_EDIT_VALUE)
1113 self.Bind(wx.EVT_TEXT, self.on_type, id=BONUS_EDIT_TYPE)
1114 self.Bind(wx.EVT_TEXT, self.on_ref, id=BONUS_EDIT_REF)
1115
1116
1117 def on_title(self, evt):
1118 if len(self.title.GetValue()):
1119 self.handler.xml.set('name', self.title.GetValue())
1120 self.handler.rename(self.title.GetValue())
1121
1122 def on_value(self, evt):
1123 self.handler.bonus_xml.set('value', self.value.GetValue())
1124
1125 def on_type(self, evt):
1126 self.handler.bonus_xml.set('type', self.type.GetValue())
1127
1128 def on_ref(self, evt):
1129 self.handler.remove_from_bonus_map()
1130 self.handler.bonus_xml.text = self.ref.GetValue()
1131 self.handler.add_to_bonus_map()