Mercurial > traipse_dev
comparison orpg/gametree/nodehandlers/containers.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | 449a8900f9ac |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: containers.py | |
21 # Author: Chris Davis | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: containers.py,v 1.43 2007/08/08 19:17:17 digitalxero Exp $ | |
25 # | |
26 # Description: The file contains code for the container nodehandlers | |
27 # | |
28 | |
29 | |
30 from core import * | |
31 import wx.lib.splitter | |
32 | |
33 | |
34 ########################## | |
35 ## base contiainer | |
36 ########################## | |
37 | |
38 class container_handler(node_handler): | |
39 """ should not be used! only a base class! | |
40 <nodehandler name='?' module='core' class='container_handler' /> | |
41 """ | |
42 def __init__(self,xml_dom,tree_node): | |
43 node_handler.__init__(self,xml_dom,tree_node) | |
44 self.load_children() | |
45 | |
46 def load_children(self): | |
47 children = self.master_dom._get_childNodes() | |
48 for c in children: | |
49 self.tree.load_xml(c,self.mytree_node) | |
50 | |
51 def check_map_aware(self, obj, evt): | |
52 if hasattr(obj,"map_aware") and obj.map_aware(): | |
53 obj.on_send_to_map(evt) | |
54 | |
55 | |
56 def on_send_to_map(self, evt): | |
57 child = self.tree.GetFirstChild(self.mytree_node) | |
58 if child[0].IsOk(): | |
59 self.traverse(child[0], self.check_map_aware, 0, evt) | |
60 | |
61 | |
62 def checkChildToMap(self, obj, evt): | |
63 if hasattr(obj,"map_aware") and obj.map_aware(): | |
64 self.mapcheck = True | |
65 | |
66 def checkToMapMenu(self): | |
67 self.mapcheck = False | |
68 child = self.tree.GetFirstChild(self.mytree_node) | |
69 if child[0].IsOk(): | |
70 self.traverse(child[0], self.checkChildToMap, 0, self.mapcheck) | |
71 | |
72 return self.mapcheck | |
73 | |
74 def on_drop(self,evt): | |
75 drag_obj = self.tree.drag_obj | |
76 if drag_obj == self or self.tree.is_parent_node(self.mytree_node,drag_obj.mytree_node): | |
77 return | |
78 opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL) | |
79 if opt == wx.YES: | |
80 xml_dom = self.tree.drag_obj.delete() | |
81 xml_dom = self.master_dom.insertBefore(xml_dom,None) | |
82 self.tree.load_xml(xml_dom, self.mytree_node) | |
83 self.tree.Expand(self.mytree_node) | |
84 elif opt == wx.NO: | |
85 node_handler.on_drop(self,evt) | |
86 | |
87 def gen_html(self, obj, evt): | |
88 self.html_str += "<p>" + obj.tohtml() | |
89 | |
90 def tohtml(self): | |
91 self.html_str = "<table border=\"1\" ><tr><td>" | |
92 self.html_str += "<b>"+self.master_dom.getAttribute("name") + "</b>" | |
93 self.html_str += "</td></tr>\n" | |
94 self.html_str += "<tr><td>" | |
95 | |
96 child = self.tree.GetFirstChild(self.mytree_node) | |
97 self.traverse(child[0], self.gen_html, 0, None) | |
98 | |
99 self.html_str += "</td></tr></table>" | |
100 return self.html_str | |
101 | |
102 def get_size_constraint(self): | |
103 return 2 | |
104 | |
105 | |
106 ########################## | |
107 ## group node handler | |
108 ########################## | |
109 class group_handler(container_handler): | |
110 """ group nodehandler to be used as a placeholder for other nodehandlers. | |
111 This handler will continue parsing child xml data. | |
112 <nodehandler name='?' module='core' class='group_handler' /> | |
113 """ | |
114 def __init__(self,xml_dom,tree_node): | |
115 container_handler.__init__(self,xml_dom,tree_node) | |
116 | |
117 def load_children(self): | |
118 self.atts = None | |
119 children = self.master_dom._get_childNodes() | |
120 for c in children: | |
121 if c._get_tagName() == "group_atts": | |
122 self.atts = c | |
123 else: | |
124 self.tree.load_xml(c,self.mytree_node) | |
125 if not self.atts: | |
126 elem = self.xml.minidom.Element('group_atts') | |
127 elem.setAttribute("cols","1") | |
128 elem.setAttribute("border","1") | |
129 self.atts = self.master_dom.appendChild(elem) | |
130 | |
131 def get_design_panel(self,parent): | |
132 return group_edit_panel(parent,self) | |
133 | |
134 def on_use(self,evt): | |
135 return | |
136 | |
137 def gen_html(self, obj, evt): | |
138 if self.i not in self.tdatas: | |
139 self.tdatas[self.i] = '' | |
140 self.tdatas[self.i] += "<P>" + obj.tohtml() | |
141 self.i += 1 | |
142 if self.i >= self.cols: | |
143 self.i = 0 | |
144 | |
145 def tohtml(self): | |
146 cols = self.atts.getAttribute("cols") | |
147 border = self.atts.getAttribute("border") | |
148 self.html_str = "<table border=\""+border+"\" ><tr><td colspan=\""+cols+"\">" | |
149 self.html_str += "<font size=4>"+self.master_dom.getAttribute("name") + "</font>" | |
150 self.html_str += "</td></tr>\n<tr>" | |
151 | |
152 self.cols = int(cols) | |
153 self.i = 0 | |
154 self.tdatas = {} | |
155 | |
156 child = self.tree.GetFirstChild(self.mytree_node) | |
157 if child[0].IsOk(): | |
158 self.traverse(child[0], self.gen_html, 0, None) | |
159 | |
160 for td in self.tdatas: | |
161 self.html_str += "<td valign=\"top\" >" + self.tdatas[td] + "</td>\n"; | |
162 self.html_str += "</tr></table>" | |
163 return self.html_str | |
164 | |
165 GROUP_COLS = wx.NewId() | |
166 GROUP_BOR = wx.NewId() | |
167 | |
168 class group_edit_panel(wx.Panel): | |
169 def __init__(self, parent, handler): | |
170 wx.Panel.__init__(self, parent, -1) | |
171 self.handler = handler | |
172 sizer = wx.BoxSizer(wx.VERTICAL) | |
173 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) | |
174 } | |
175 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) | |
176 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) | |
177 sizer.Add(wx.Size(10,10)) | |
178 | |
179 radio_c = wx.RadioBox(self, GROUP_COLS, "Columns", choices=["1","2","3","4"]) | |
180 cols = handler.atts.getAttribute("cols") | |
181 if cols != "": | |
182 radio_c.SetSelection(int(cols)-1) | |
183 | |
184 radio_b = wx.RadioBox(self, GROUP_BOR, "Border", choices=["no","yes"]) | |
185 border = handler.atts.getAttribute("border") | |
186 if border != "": | |
187 radio_b.SetSelection(int(border)) | |
188 | |
189 sizer.Add(radio_c, 0, wx.EXPAND) | |
190 sizer.Add(wx.Size(10,10)) | |
191 sizer.Add(radio_b, 0, wx.EXPAND) | |
192 | |
193 self.sizer = sizer | |
194 self.outline = wx.StaticBox(self,-1,"Group") | |
195 self.SetSizer(self.sizer) | |
196 self.SetAutoLayout(True) | |
197 self.Fit() | |
198 parent.SetSize(self.GetBestSize()) | |
199 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) | |
200 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GROUP_BOR) | |
201 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GROUP_COLS) | |
202 | |
203 def on_radio_box(self,evt): | |
204 id = evt.GetId() | |
205 index = evt.GetInt() | |
206 if id == GROUP_COLS: | |
207 self.handler.atts.setAttribute("cols",str(index+1)) | |
208 elif id == GROUP_BOR: | |
209 self.handler.atts.setAttribute("border",str(index)) | |
210 | |
211 def on_text(self,evt): | |
212 id = evt.GetId() | |
213 if id == P_TITLE: | |
214 txt = self.text[id].GetValue() | |
215 if txt != "": | |
216 self.handler.master_dom.setAttribute('name',txt) | |
217 self.handler.rename(txt) | |
218 | |
219 | |
220 | |
221 ########################## | |
222 ## tabber node handler | |
223 ########################## | |
224 class tabber_handler(container_handler): | |
225 """ <nodehandler name='?' module='containers' class='tabber_handler' />""" | |
226 | |
227 def __init__(self,xml_dom,tree_node): | |
228 container_handler.__init__(self,xml_dom,tree_node) | |
229 | |
230 def get_design_panel(self,parent): | |
231 return tabbed_panel(parent,self,1) | |
232 | |
233 def get_use_panel(self,parent): | |
234 return tabbed_panel(parent,self,2) | |
235 | |
236 | |
237 class tabbed_panel(orpgTabberWnd): | |
238 def __init__(self, parent, handler, mode): | |
239 orpgTabberWnd.__init__(self, parent, style=FNB.FNB_NO_X_BUTTON) | |
240 self.handler = handler | |
241 self.parent = parent | |
242 tree = self.handler.tree | |
243 child = tree.GetFirstChild(handler.mytree_node) | |
244 if child[0].IsOk(): | |
245 handler.traverse(child[0], self.pick_panel, 0, mode, False) | |
246 | |
247 parent.SetSize(self.GetBestSize()) | |
248 | |
249 def pick_panel(self, obj, mode): | |
250 if mode == 1: | |
251 panel = obj.get_design_panel(self) | |
252 else: | |
253 panel = obj.get_use_panel(self) | |
254 | |
255 name = obj.master_dom.getAttribute("name") | |
256 | |
257 if panel: | |
258 self.AddPage(panel, name, False) | |
259 | |
260 ################################# | |
261 ## Splitter container | |
262 ################################# | |
263 | |
264 class splitter_handler(container_handler): | |
265 """ <nodehandler name='?' module='containers' class='splitter_handler' />""" | |
266 | |
267 def __init__(self,xml_dom,tree_node): | |
268 container_handler.__init__(self,xml_dom,tree_node) | |
269 | |
270 def load_children(self): | |
271 self.atts = None | |
272 children = self.master_dom._get_childNodes() | |
273 for c in children: | |
274 if c._get_tagName() == "splitter_atts": | |
275 self.atts = c | |
276 else: | |
277 self.tree.load_xml(c,self.mytree_node) | |
278 if not self.atts: | |
279 elem = self.xml.minidom.Element('splitter_atts') | |
280 elem.setAttribute("horizontal","0") | |
281 self.atts = self.master_dom.appendChild(elem) | |
282 | |
283 def get_design_panel(self,parent): | |
284 return self.build_splitter_wnd(parent, 1) | |
285 | |
286 def get_use_panel(self,parent): | |
287 return self.build_splitter_wnd(parent, 2) | |
288 | |
289 def on_drop(self,evt): | |
290 drag_obj = self.tree.drag_obj | |
291 container_handler.on_drop(self,evt) | |
292 | |
293 def build_splitter_wnd(self, parent, mode): | |
294 self.split = self.atts.getAttribute("horizontal") | |
295 | |
296 self.pane = splitter_panel(parent, self) | |
297 | |
298 self.splitter = wx.lib.splitter.MultiSplitterWindow(self.pane, -1, style=wx.SP_LIVE_UPDATE|wx.SP_3DSASH|wx.SP_NO_XP_THEME) | |
299 | |
300 if self.split == '1': | |
301 self.splitter.SetOrientation(wx.VERTICAL) | |
302 else: | |
303 self.splitter.SetOrientation(wx.HORIZONTAL) | |
304 | |
305 self.bestSizex = -1 | |
306 self.bestSizey = -1 | |
307 | |
308 cookie = 0 | |
309 (child, cookie) = self.tree.GetFirstChild(self.mytree_node) | |
310 if child.IsOk(): | |
311 self.traverse(child, self.doSplit, 0, mode, False) | |
312 | |
313 self.pane.sizer.Add(self.splitter, 1, wx.EXPAND) | |
314 | |
315 | |
316 if mode != 1: | |
317 self.pane.hozCheck.Hide() | |
318 | |
319 self.pane.SetSize((self.bestSizex, self.bestSizey)) | |
320 self.pane.Layout() | |
321 parent.SetSize(self.pane.GetSize()) | |
322 return self.pane | |
323 | |
324 def doSplit(self, obj, mode): | |
325 if mode == 1: | |
326 tmp = obj.get_design_panel(self.splitter) | |
327 else: | |
328 tmp = obj.get_use_panel(self.splitter) | |
329 | |
330 if self.split == '1': | |
331 sash = tmp.GetBestSize()[1]+1 | |
332 self.bestSizey += sash+11 | |
333 if self.bestSizex < tmp.GetBestSize()[0]: | |
334 self.bestSizex = tmp.GetBestSize()[0]+10 | |
335 else: | |
336 sash = tmp.GetBestSize()[0]+1 | |
337 self.bestSizex += sash | |
338 if self.bestSizey < tmp.GetBestSize()[1]: | |
339 self.bestSizey = tmp.GetBestSize()[1]+31 | |
340 | |
341 self.splitter.AppendWindow(tmp, sash) | |
342 | |
343 def get_size_constraint(self): | |
344 return 1 | |
345 | |
346 class splitter_panel(wx.Panel): | |
347 def __init__(self, parent, handler): | |
348 wx.Panel.__init__(self, parent, -1) | |
349 self.handler = handler | |
350 sizer = wx.BoxSizer(wx.VERTICAL) | |
351 | |
352 self.hozCheck = wx.CheckBox(self, -1, "Horizontal Split") | |
353 hoz = self.handler.atts.getAttribute("horizontal") | |
354 | |
355 if hoz == '1': | |
356 self.hozCheck.SetValue(True) | |
357 #self.splitsize = wx.BoxSizer(wx.HORIZONTAL) | |
358 else: | |
359 self.hozCheck.SetValue(False) | |
360 #self.splitsize = wx.BoxSizer(wx.VERTICAL) | |
361 | |
362 sizer.Add(self.hozCheck, 0, wx.EXPAND) | |
363 sizer.Add(wx.Size(10,0)) | |
364 #sizer.Add(self.splitsize, 1, wx.EXPAND) | |
365 | |
366 self.sizer = sizer | |
367 self.SetSizer(self.sizer) | |
368 self.SetAutoLayout(True) | |
369 | |
370 self.Bind(wx.EVT_CHECKBOX, self.on_check_box, id=self.hozCheck.GetId()) | |
371 | |
372 def on_check_box(self,evt): | |
373 state = self.hozCheck.GetValue() | |
374 if state: | |
375 self.handler.atts.setAttribute("horizontal", "1") | |
376 else: | |
377 self.handler.atts.setAttribute("horizontal", "0") |