Mercurial > traipse_dev
comparison orpg/gametree/nodehandlers/forms.py @ 130:d54e1328dbb1 alpha
Traipse Alpha 'OpenRPG' {091003-02}
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!!
Dead Node Children, not that's a
O O
-v-v- Happy Halloween!
author | sirebral |
---|---|
date | Tue, 03 Nov 2009 21:06:03 -0600 |
parents | 43ad912b7c17 |
children | 90d19eb43830 |
comparison
equal
deleted
inserted
replaced
129:43ad912b7c17 | 130:d54e1328dbb1 |
---|---|
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 orpg.minidom as minidom | 32 import wx.lib.scrolledpanel |
33 from orpg.orpg_xml import xml | |
34 from wx.lib.scrolledpanel import ScrolledPanel | |
35 | 33 |
36 def bool2int(b): | 34 def bool2int(b): |
37 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0. | 35 #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. | 36 #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 | 37 #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 | 38 #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. | 39 #use str() on it, but it seems to work fine right now. |
42 if b: return 1 | 40 if b: |
43 else: return 0 | 41 return 1 |
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 | |
55 def __init__(self,xml,tree_node): | 56 def __init__(self,xml,tree_node): |
56 container_handler.__init__(self,xml,tree_node) | 57 container_handler.__init__(self,xml,tree_node) |
57 | 58 |
58 def load_children(self): | 59 def load_children(self): |
59 self.atts = None | 60 self.atts = None |
60 for child_xml in self.xml: | 61 for child_xml in self.xml: |
61 if child_xml.tag == "form": self.atts = child_xml | 62 if child_xml.tag == "form": |
62 else: self.tree.load_xml(child_xml,self.mytree_node) | 63 self.atts = child_xml |
64 else: | |
65 self.tree.load_xml(child_xml,self.mytree_node) | |
63 if not self.atts: | 66 if not self.atts: |
64 self.atts = Element('form') | 67 self.atts = ET.Element('form') |
65 self.atts.set("width","400") | 68 self.atts.set("width","400") |
66 self.atts.set("height","600") | 69 self.atts.set("height","600") |
67 self.xml.append(self.atts) | 70 self.xml.append(self.atts) |
68 | 71 |
69 def get_design_panel(self,parent): | 72 def get_design_panel(self,parent): |
74 | 77 |
75 def on_drop(self,evt): | 78 def on_drop(self,evt): |
76 # make sure its a contorl node | 79 # make sure its a contorl node |
77 container_handler.on_drop(self,evt) | 80 container_handler.on_drop(self,evt) |
78 | 81 |
79 class form_panel(ScrolledPanel): | 82 |
83 class form_panel(wx.lib.scrolledpanel.ScrolledPanel): | |
80 def __init__(self, parent, handler): | 84 def __init__(self, parent, handler): |
81 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL) | 85 wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL) |
82 self.height = int(handler.atts.get("height")) | 86 self.height = int(handler.atts.get("height")) |
83 self.width = int(handler.atts.get("width")) | 87 self.width = int(handler.atts.get("width")) |
88 | |
89 | |
84 self.SetSize((0,0)) | 90 self.SetSize((0,0)) |
85 self.handler = handler | 91 self.handler = handler |
86 self.parent = parent | 92 self.parent = parent |
87 self.main_sizer = wx.BoxSizer(wx.VERTICAL) | 93 self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
88 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False) | 94 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False) |
95 | |
89 self.SetSizer(self.main_sizer) | 96 self.SetSizer(self.main_sizer) |
90 self.SetAutoLayout(True) | 97 self.SetAutoLayout(True) |
98 | |
91 self.SetupScrolling() | 99 self.SetupScrolling() |
100 | |
92 parent.SetSize(self.GetSize()) | 101 parent.SetSize(self.GetSize()) |
93 self.Fit() | 102 self.Fit() |
103 | |
94 | 104 |
95 def SetSize(self, xy): | 105 def SetSize(self, xy): |
96 (x, y) = self.GetSize() | 106 (x, y) = self.GetSize() |
97 (nx, ny) = xy | 107 (nx, ny) = xy |
98 if x < nx: | 108 if x < nx: |
99 x = nx+10 | 109 x = nx+10 |
100 y += ny+11 | 110 y += ny+11 |
101 ScrolledPanel.SetSize(self, (x, y)) | 111 wx.lib.scrolledpanel.ScrolledPanel.SetSize(self, (x, y)) |
112 | |
102 | 113 |
103 def create_child_wnd(self, treenode, evt): | 114 def create_child_wnd(self, treenode, evt): |
104 node = self.handler.tree.GetPyData(treenode) | 115 node = self.handler.tree.GetPyData(treenode) |
105 panel = node.get_use_panel(self) | 116 panel = node.get_use_panel(self) |
106 size = node.get_size_constraint() | 117 size = node.get_size_constraint() |
107 if panel: | 118 if panel: |
108 self.main_sizer.Add(panel, size, wx.EXPAND) | 119 self.main_sizer.Add(panel, size, wx.EXPAND) |
109 self.main_sizer.Add(wx.Size(10,10)) | 120 self.main_sizer.Add(wx.Size(10,10)) |
121 | |
122 | |
110 | 123 |
111 F_HEIGHT = wx.NewId() | 124 F_HEIGHT = wx.NewId() |
112 F_WIDTH = wx.NewId() | 125 F_WIDTH = wx.NewId() |
113 class form_edit_panel(wx.Panel): | 126 class form_edit_panel(wx.Panel): |
114 def __init__(self, parent, handler): | 127 def __init__(self, parent, handler): |
149 if not len(txt): return | 162 if not len(txt): return |
150 if id == P_TITLE: | 163 if id == P_TITLE: |
151 self.handler.xml.set('name',txt) | 164 self.handler.xml.set('name',txt) |
152 self.handler.rename(txt) | 165 self.handler.rename(txt) |
153 elif id == F_HEIGHT or id == F_WIDTH: | 166 elif id == F_HEIGHT or id == F_WIDTH: |
154 try: int(txt) | 167 try: |
155 except: return 0 | 168 int(txt) |
156 if id == F_HEIGHT: self.handler.atts.set("height",txt) | 169 except: |
157 elif id == F_WIDTH: self.handler.atts.set("width",txt) | 170 return 0 |
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 | |
158 | 179 |
159 ########################## | 180 ########################## |
160 ## control handler | 181 ## control handler |
161 ########################## | 182 ########################## |
162 class control_handler(node_handler): | 183 class control_handler(node_handler): |
163 """ A nodehandler for form controls. | 184 """ A nodehandler for form controls. |
164 <nodehandler name='?' module='forms' class='control_handler' /> | 185 <nodehandler name='?' module='forms' class='control_handler' /> |
165 """ | 186 """ |
166 def __init__(self, xml, tree_node): | 187 def __init__(self,xml,tree_node): |
167 node_handler.__init__(self, xml, tree_node) | 188 node_handler.__init__(self,xml,tree_node) |
168 | 189 |
169 def get_size_constraint(self): | 190 def get_size_constraint(self): |
170 return 0 | 191 return 0 |
192 | |
171 | 193 |
172 ########################## | 194 ########################## |
173 ## textctrl handler | 195 ## textctrl handler |
174 ########################## | 196 ########################## |
175 # | 197 # |
220 if not self.is_hide_title(): | 242 if not self.is_hide_title(): |
221 txt = "<b>"+self.xml.get("name")+":</b> "+txt | 243 txt = "<b>"+self.xml.get("name")+":</b> "+txt |
222 return txt | 244 return txt |
223 | 245 |
224 def get_value(self): | 246 def get_value(self): |
225 return self.text_elem.text | 247 return getText(self.text_elem) |
226 | 248 |
227 def set_value(self, new_value): | 249 def set_value(self, new_value): |
228 self.text_elem.text = str(new_value) | 250 self.text_elem.text = str(new_value) |
251 | |
252 | |
229 | 253 |
230 FORM_TEXT_CTRL = wx.NewId() | 254 FORM_TEXT_CTRL = wx.NewId() |
231 FORM_SEND_BUTTON = wx.NewId() | 255 FORM_SEND_BUTTON = wx.NewId() |
232 | 256 |
233 class text_panel(wx.Panel): | 257 class text_panel(wx.Panel): |
243 sizer_style = wx.ALIGN_CENTER | 267 sizer_style = wx.ALIGN_CENTER |
244 text_style = 0 | 268 text_style = 0 |
245 sizer = wx.BoxSizer(wx.HORIZONTAL) | 269 sizer = wx.BoxSizer(wx.HORIZONTAL) |
246 | 270 |
247 txt = handler.get_value() | 271 txt = handler.get_value() |
248 if txt == None: txt = '' | 272 ## if self.handler.tree.ContainsReference(txt): |
273 ## txt = self.handler.tree.ReplaceReferences(txt, False) | |
274 ## text_style |= wx.TE_READONLY | |
275 | |
249 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style) | 276 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style) |
250 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style) | 277 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style) |
251 sizer.Add(wx.Size(5,0)) | 278 sizer.Add(wx.Size(5,0)) |
252 sizer.Add(self.text, 1, sizer_style) | 279 sizer.Add(self.text, 1, sizer_style) |
253 | 280 |
262 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL) | 289 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL) |
263 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) | 290 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) |
264 | 291 |
265 def on_text(self,evt): | 292 def on_text(self,evt): |
266 txt = self.text.GetValue() | 293 txt = self.text.GetValue() |
267 #txt = strip_text(txt) ##Does not seem to exist. | 294 txt = strip_text(txt) |
268 self.handler.text_elem.text = txt | 295 self.handler.text_elem.text = txt |
269 | 296 |
270 def on_send(self,evt): | 297 def on_send(self,evt): |
271 txt = self.text.GetValue() | 298 txt = self.text.GetValue() |
272 if not self.handler.is_raw_send(): | 299 if not self.handler.is_raw_send(): |
341 if not len(txt): return | 368 if not len(txt): return |
342 self.handler.xml.set('name',txt) | 369 self.handler.xml.set('name',txt) |
343 self.handler.rename(txt) | 370 self.handler.rename(txt) |
344 if id == F_TEXT: | 371 if id == F_TEXT: |
345 txt = self.text.GetValue() | 372 txt = self.text.GetValue() |
346 #txt = strip_text(txt) ##Does not seem to exist. | 373 txt = strip_text(txt) |
347 self.handler.text_elem.text = txt | 374 self.handler.text_elem.text = txt |
348 | 375 |
349 def on_button(self,evt): | 376 def on_button(self,evt): |
350 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked()))) | 377 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked()))) |
351 | 378 |
402 | 429 |
403 def set_type(self,type): | 430 def set_type(self,type): |
404 self.list.set("type",str(type)) | 431 self.list.set("type",str(type)) |
405 | 432 |
406 def is_hide_title(self): | 433 def is_hide_title(self): |
407 return int(self.list.get("hide_title", 0)) | 434 return int(self.list.get("hide_title",0)) |
408 | 435 |
409 # single selection methods | 436 # single selection methods |
410 def get_selected_node(self): | 437 def get_selected_node(self): |
411 for opt in self.options: | 438 for opt in self.options: |
412 if opt.get("selected") == "1": return opt | 439 if opt.get("selected") == "1": return opt |
421 return 0 | 448 return 0 |
422 | 449 |
423 def get_selected_text(self): | 450 def get_selected_text(self): |
424 node = self.get_selected_node() | 451 node = self.get_selected_node() |
425 if node: | 452 if node: |
426 return node.text | 453 return getText(node) |
427 else: | 454 else: |
428 return "" | 455 return "" |
429 | 456 |
430 | 457 |
431 # mult selection methods | 458 # mult selection methods |
439 | 466 |
440 def get_selections_text(self): | 467 def get_selections_text(self): |
441 opts = [] | 468 opts = [] |
442 for opt in self.options: | 469 for opt in self.options: |
443 if opt.get("selected") == "1": | 470 if opt.get("selected") == "1": |
444 opts.append(opt.text) | 471 opts.append(getText(opt)) |
445 return opts | 472 return opts |
446 | 473 |
447 def get_selections_index(self): | 474 def get_selections_index(self): |
448 opts = [] | 475 opts = [] |
449 i = 0 | 476 i = 0 |
467 # misc methods | 494 # misc methods |
468 | 495 |
469 def get_options(self): | 496 def get_options(self): |
470 opts = [] | 497 opts = [] |
471 for opt in self.options: | 498 for opt in self.options: |
472 opts.append(opt.text) | 499 opts.append(getText(opt)) |
473 return opts | 500 return opts |
474 | 501 |
475 def get_option(self,index): | 502 def get_option(self,index): |
476 return self.options[index].text | 503 return getText(self.options[index]) |
477 | 504 |
478 def add_option(self,opt): | 505 def add_option(self,opt): |
479 elem = Element('option') | 506 elem = ET.Element('option') |
480 elem.set("value","0") | 507 elem.set("value","0") |
481 elem.set("selected","0") | 508 elem.set("selected","0") |
482 elem.text = opt | 509 elem.text = opt |
483 self.list.append(elem) | 510 self.list.append(elem) |
484 self.options = self.list.findall('option') | 511 self.options = self.list.findall('option') |
511 text += comma.join(opts) | 538 text += comma.join(opts) |
512 return text | 539 return text |
513 | 540 |
514 def get_value(self): | 541 def get_value(self): |
515 return "\n".join(self.get_selections_text()) | 542 return "\n".join(self.get_selections_text()) |
516 | |
517 | 543 |
518 F_LIST = wx.NewId() | 544 F_LIST = wx.NewId() |
519 F_SEND = wx.NewId() | 545 F_SEND = wx.NewId() |
520 | 546 |
521 | 547 |
795 | 821 |
796 def tohtml(self): | 822 def tohtml(self): |
797 href = self.link.get("href") | 823 href = self.link.get("href") |
798 title = self.xml.get("name") | 824 title = self.xml.get("name") |
799 return "<img src=\""+href+"\" alt="+title+" >" | 825 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() |