Mercurial > traipse_dev
comparison orpg/gametree/nodehandlers/core.py @ 135:dcf4fbe09b70 beta
Traipse Beta 'OpenRPG' {091010-00}
Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on
code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to
offer more advanced features and enhance the productivity of the user.
Update Summary (Beta)
Added Bookmarks
Fix to Remote Admin Commands
Minor fix to text based Server
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
default_manifest.xml renamed to default_upmana.xml
Cleaner clode for saved repositories
New TrueDebug Class in orpg_log (See documentation for usage)
Mercurial's hgweb folder is ported to upmana
**Pretty important update that can help remove thousands of dead children from your gametree.
**Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and
look for dead children!!
**New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author | sirebral |
---|---|
date | Tue, 10 Nov 2009 14:11:28 -0600 |
parents | 449a8900f9ac |
children | 6081bdc2b8d5 |
comparison
equal
deleted
inserted
replaced
101:394ebb3b6a0f | 135:dcf4fbe09b70 |
---|---|
27 # | 27 # |
28 | 28 |
29 __version__ = "$Id: core.py,v 1.49 2007/12/07 20:39:48 digitalxero Exp $" | 29 __version__ = "$Id: core.py,v 1.49 2007/12/07 20:39:48 digitalxero Exp $" |
30 | 30 |
31 from nodehandler_version import NODEHANDLER_VERSION | 31 from nodehandler_version import NODEHANDLER_VERSION |
32 | |
32 try: | 33 try: |
33 from orpg.orpg_windows import * | 34 from orpg.orpg_windows import * |
34 from orpg.dirpath import dir_struct | 35 from orpg.dirpath import dir_struct |
35 from orpg.orpgCore import component | 36 from orpg.orpgCore import component |
36 import webbrowser | 37 import webbrowser |
37 from orpg.mapper import map | 38 from orpg.mapper import map |
38 import os | 39 import os |
40 from wx import DisplaySize | |
39 except: | 41 except: |
40 import wx | 42 import wx |
41 | 43 |
44 from xml.etree.ElementTree import ElementTree, Element, tostring, XML | |
45 from orpg.tools.orpg_log import debug | |
42 | 46 |
43 #html defaults | 47 #html defaults |
44 TH_BG = "#E9E9E9" | 48 TH_BG = "#E9E9E9" |
45 ########################## | 49 ########################## |
46 ## base node handler | 50 ## base node handler |
47 ########################## | 51 ########################## |
48 class node_handler: | 52 class node_handler: |
49 """ Base nodehandler with virtual functions and standard implmentations """ | 53 """ Base nodehandler with virtual functions and standard implmentations """ |
50 def __init__(self,xml_dom,tree_node): | 54 def __init__(self,xml,tree_node): |
51 self.master_dom = xml_dom | 55 self.xml = xml |
52 self.mytree_node = tree_node | 56 self.mytree_node = tree_node |
53 self.tree = component.get('tree') | 57 self.tree = open_rpg.get_component('tree') |
54 self.frame = component.get('frame') | 58 self.frame = open_rpg.get_component('frame') |
55 self.chat = component.get('chat') | 59 self.chat = open_rpg.get_component('chat') |
56 self.xml = component.get('xml') #Not used? | |
57 self.drag = True | 60 self.drag = True |
58 self.myeditor = None # designing | 61 self.myeditor = None # designing |
59 self.myviewer = None # pretty print | 62 self.myviewer = None # prett print |
60 self.mywindow = None # using | 63 self.mywindow = None # using |
61 # call version hook | 64 # call version hook |
62 self.on_version(self.master_dom.getAttribute("version")) | 65 self.on_version(self.xml.get("version")) |
63 # set to current version | 66 # set to current version |
64 self.master_dom.setAttribute("version",NODEHANDLER_VERSION) | 67 self.xml.set("version",NODEHANDLER_VERSION) |
65 # null events | 68 # null events |
69 self.frame_size = None | |
70 self.frame_pos = None | |
71 try: | |
72 frame = self.xml.get("frame") | |
73 if len(frame): | |
74 (sx,sy,px,py) = [int(value) for value in frame.split(',')] | |
75 self.frame_size = (sx, sy) | |
76 (maxx, maxy) = DisplaySize() | |
77 if px < maxx-80 and py < maxy-50:#if it's off screen ignore the saved pos | |
78 self.frame_pos = (px, py) | |
79 except: | |
80 pass | |
66 | 81 |
67 def on_version(self,old_version): | 82 def on_version(self,old_version): |
68 ## added version control code here or implement a new on_version in your derived class. | 83 ## added version control code here or implement a new on_version in your derived class. |
69 ## always call the base class on_version ! | 84 ## always call the base class on_version ! |
70 pass | 85 pass |
73 self.tree.do_std_menu(evt,self) | 88 self.tree.do_std_menu(evt,self) |
74 | 89 |
75 def on_ldclick(self,evt): | 90 def on_ldclick(self,evt): |
76 return 0 | 91 return 0 |
77 | 92 |
78 def traverse(self, traverseroot, function, cookie=0, event=None, recursive=True): | |
79 """ walk tree control """ | |
80 if traverseroot.IsOk(): | |
81 # step in subtree if there are items or ... | |
82 if self.tree.ItemHasChildren(traverseroot) and recursive: | |
83 firstchild, cookie = self.tree.GetFirstChild(traverseroot) | |
84 obj = self.tree.GetPyData(firstchild) | |
85 function(obj, event) | |
86 self.traverse(firstchild, function, cookie, event, recursive) | |
87 | |
88 # ... loop siblings | |
89 obj = self.tree.GetPyData(traverseroot) | |
90 function(obj, event) | |
91 | |
92 child = self.tree.GetNextSibling(traverseroot) | |
93 if child.IsOk(): | |
94 self.traverse(child, function, cookie, event, recursive) | |
95 | |
96 | |
97 def usefulness(self,text): | 93 def usefulness(self,text): |
98 if text=="useful": | 94 if text=="useful": |
99 self.master_dom.setAttribute('status',"useful") | 95 self.xml.set('status',"useful") |
100 elif text=="useless": | 96 elif text=="useless": |
101 self.master_dom.setAttribute('status',"useless") | 97 self.xml.set('status',"useless") |
102 elif text=="indifferent": | 98 elif text=="indifferent": |
103 self.master_dom.setAttribute('status',"indifferent") | 99 self.xml.set('status',"indifferent") |
104 | 100 |
105 def on_design(self,evt): | 101 def on_design(self,evt): |
106 try: | 102 try: |
107 self.myeditor.Show() | 103 self.myeditor.Show() |
108 self.myeditor.Raise() | 104 self.myeditor.Raise() |
112 self.myeditor.Show() | 108 self.myeditor.Show() |
113 self.myeditor.Raise() | 109 self.myeditor.Raise() |
114 else: return | 110 else: return |
115 wx.CallAfter(self.myeditor.Layout) | 111 wx.CallAfter(self.myeditor.Layout) |
116 | 112 |
117 | |
118 def create_designframe(self): | 113 def create_designframe(self): |
119 title = self.master_dom.getAttribute('name') + " Editor" | 114 title = self.xml.get('name') + " Editor" |
120 self.myeditor = wx.Frame(None, -1, title) | 115 self.myeditor = wx.Frame(None, -1, title) |
121 self.myeditor.Freeze() | 116 self.myeditor.Freeze() |
122 if wx.Platform == '__WXMSW__': | 117 if wx.Platform == '__WXMSW__': |
123 icon = wx.Icon(dir_struct["icon"] + 'grid.ico', wx.BITMAP_TYPE_ICO) | 118 icon = wx.Icon(orpg.dirpath.dir_struct["icon"] + 'grid.ico', wx.BITMAP_TYPE_ICO) |
124 self.myeditor.SetIcon(icon) | 119 self.myeditor.SetIcon(icon) |
125 del icon | 120 del icon |
126 | 121 |
127 self.myeditor.panel = self.get_design_panel(self.myeditor) | 122 self.myeditor.panel = self.get_design_panel(self.myeditor) |
128 if self.myeditor.panel == None: | 123 if self.myeditor.panel == None: |
133 | 128 |
134 self.myeditor.SetSizer(sizer) | 129 self.myeditor.SetSizer(sizer) |
135 self.myeditor.SetAutoLayout(True) | 130 self.myeditor.SetAutoLayout(True) |
136 | 131 |
137 (x, y) = self.myeditor.GetSize() | 132 (x, y) = self.myeditor.GetSize() |
138 if x < 400: | 133 if x < 400: x = 400 |
139 x = 400 | 134 if y < 400: y = 400 |
140 if y < 400: | |
141 y = 400 | |
142 | 135 |
143 self.myeditor.SetSize((x, y)) | 136 self.myeditor.SetSize((x, y)) |
144 self.myeditor.Layout() | 137 self.myeditor.Layout() |
145 self.myeditor.Thaw() | 138 self.myeditor.Thaw() |
146 | |
147 return True | 139 return True |
148 | 140 |
149 def on_use(self,evt): | 141 def on_use(self,evt): |
150 try: | 142 try: |
151 self.mywindow.Show() | 143 self.mywindow.Show() |
152 self.mywindow.Raise() | 144 self.mywindow.Raise() |
153 except: | 145 except: |
154 del self.mywindow | 146 del self.mywindow |
155 if self.create_useframe(): | 147 if self.create_useframe(): |
148 self.mywindow.SetSize(self.frame_size) | |
149 if self.frame_pos: | |
150 self.mywindow.SetPosition(self.frame_pos) | |
156 self.mywindow.Show() | 151 self.mywindow.Show() |
157 self.mywindow.Raise() | 152 self.mywindow.Raise() |
158 else: | 153 else: |
159 return | 154 return |
160 wx.CallAfter(self.mywindow.Layout) | 155 wx.CallAfter(self.mywindow.Layout) |
161 | 156 |
162 def create_useframe(self): | 157 def create_useframe(self): |
163 caption = self.master_dom.getAttribute('name') | 158 caption = self.xml.get('name', '') |
164 self.mywindow = wx.Frame(None, -1, caption) | 159 self.mywindow = wx.Frame(None, -1, caption) |
165 self.mywindow.Freeze() | 160 self.mywindow.Freeze() |
166 | 161 |
167 if wx.Platform == '__WXMSW__': | 162 if wx.Platform == '__WXMSW__': |
168 icon = wx.Icon(dir_struct["icon"] + 'note.ico', wx.BITMAP_TYPE_ICO) | 163 icon = wx.Icon(orpg.dirpath.dir_struct["icon"] + 'note.ico', wx.BITMAP_TYPE_ICO) |
169 self.mywindow.SetIcon(icon) | 164 self.mywindow.SetIcon(icon) |
170 del icon | 165 del icon |
171 self.mywindow.panel = self.get_use_panel(self.mywindow) | 166 self.mywindow.panel = self.get_use_panel(self.mywindow) |
172 if self.mywindow.panel == None: | 167 if self.mywindow.panel == None: |
173 self.mywindow.Destroy() | 168 self.mywindow.Destroy() |
176 sizer.Add(self.mywindow.panel, 2, wx.EXPAND) | 171 sizer.Add(self.mywindow.panel, 2, wx.EXPAND) |
177 | 172 |
178 self.mywindow.SetSizer(sizer) | 173 self.mywindow.SetSizer(sizer) |
179 self.mywindow.SetAutoLayout(True) | 174 self.mywindow.SetAutoLayout(True) |
180 | 175 |
181 (x, y) = self.mywindow.GetSize() | 176 if self.frame_size is None: |
182 if x < 400: | 177 self.frame_size = self.mywindow.GetSize() |
183 x = 400 | 178 if self.frame_size.x < 400: self.frame_size.x = 400 |
184 if y < 400: | 179 if self.frame_size.y < 400: self.frame_size.y = 400 |
185 y = 400 | 180 |
186 | |
187 self.mywindow.SetSize((x, y)) | |
188 self.mywindow.Layout() | 181 self.mywindow.Layout() |
189 self.mywindow.Thaw() | 182 self.mywindow.Thaw() |
190 | 183 self.mywindow.Bind(wx.EVT_CLOSE, self.close_useframe) |
191 return True | 184 return True |
192 | 185 |
186 def close_useframe(self, evt): | |
187 self.frame_size = self.mywindow.GetSize() | |
188 self.frame_pos = self.mywindow.GetPosition() | |
189 frame_values = str(self.frame_size.x)+','+str(self.frame_size.y)+','+str(self.frame_pos.x)+','+str(self.frame_pos.y) | |
190 self.xml.set("frame", frame_values) | |
191 self.mywindow.Destroy() | |
192 | |
193 | 193 |
194 def on_html_view(self,evt): | 194 def on_html_view(self,evt): |
195 try: | 195 try: self.myviewer.Raise() |
196 self.myviewer.Raise() | |
197 except: | 196 except: |
198 caption = self.master_dom.getAttribute('name') | 197 caption = self.xml.get('name') |
199 self.myviewer = wx.Frame(None, -1, caption) | 198 self.myviewer = wx.Frame(None, -1, caption) |
200 if wx.Platform == '__WXMSW__': | 199 if wx.Platform == '__WXMSW__': |
201 icon = wx.Icon(dir_struct["icon"] + 'grid.ico', wx.BITMAP_TYPE_ICO) | 200 icon = wx.Icon(orpg.dirpath.dir_struct["icon"] + 'grid.ico', wx.BITMAP_TYPE_ICO) |
202 self.myviewer.SetIcon(icon) | 201 self.myviewer.SetIcon(icon) |
203 del icon | 202 del icon |
204 self.myviewer.panel = self.get_html_panel(self.myviewer) | 203 self.myviewer.panel = self.get_html_panel(self.myviewer) |
205 self.myviewer.Show() | 204 self.myviewer.Show() |
206 | 205 |
211 return 1; | 210 return 1; |
212 | 211 |
213 def on_del(self,evt): | 212 def on_del(self,evt): |
214 print "on del" | 213 print "on del" |
215 | 214 |
216 def on_new_data(self,xml_dom): | 215 def on_new_data(self,xml): |
217 pass | 216 pass |
218 | 217 |
219 def get_scaled_bitmap(self,x,y): | 218 def get_scaled_bitmap(self,x,y): |
220 return None | 219 return None |
221 | 220 |
223 pass | 222 pass |
224 | 223 |
225 def on_send_to_chat(self,evt): | 224 def on_send_to_chat(self,evt): |
226 self.chat.ParsePost(self.tohtml(),True,True) | 225 self.chat.ParsePost(self.tohtml(),True,True) |
227 | 226 |
228 def on_drop(self,evt): | 227 def on_drop(self, evt): |
229 drag_obj = self.tree.drag_obj | 228 drag_obj = self.tree.drag_obj |
230 if drag_obj == self or self.tree.is_parent_node(self.mytree_node,drag_obj.mytree_node): | 229 if drag_obj == self or self.tree.is_parent_node(self.mytree_node, drag_obj.mytree_node): |
231 return | 230 return |
232 #if self.is_my_child(self.mytree_node,drag_obj.mytree_node): | 231 drop_xml = self.tree.drag_obj.delete() |
233 # return | |
234 xml_dom = self.tree.drag_obj.delete() | |
235 parent = self.master_dom._get_parentNode() | |
236 xml_dom = parent.insertBefore(xml_dom,self.master_dom) | |
237 parent_node = self.tree.GetItemParent(self.mytree_node) | 232 parent_node = self.tree.GetItemParent(self.mytree_node) |
238 prev_sib = self.tree.GetPrevSibling(self.mytree_node) | 233 prev_sib = self.tree.GetPrevSibling(self.mytree_node) |
234 if parent_node == self.tree.root: parent_xml = self.tree.GetPyData(parent_node) | |
235 else: parent_xml = self.tree.GetPyData(parent_node).xml | |
236 for i in range(len(parent_xml)): | |
237 if parent_xml[i] is self.xml: | |
238 parent_xml.insert(i, drop_xml) | |
239 break | |
239 if not prev_sib.IsOk(): | 240 if not prev_sib.IsOk(): |
240 prev_sib = parent_node | 241 prev_sib = parent_node |
241 self.tree.load_xml(xml_dom, parent_node, prev_sib) | 242 self.tree.load_xml(drop_xml, parent_node, prev_sib) |
243 | |
244 def get_tree(self): | |
245 family = [] | |
246 test = treenode | |
247 while test != self.tree.root: | |
248 test = self.tree.GetItemParent(test) | |
249 parent = self.tree.GetItemText(test) | |
250 family.append(parent) | |
251 return family | |
242 | 252 |
243 def toxml(self,pretty=0): | 253 def toxml(self,pretty=0): |
244 return component.get('xml').toxml(self.master_dom,pretty) | 254 return tostring(self.xml) #toxml(self.master_dom,pretty) |
245 | 255 |
246 def tohtml(self): | 256 def tohtml(self): |
247 return self.master_dom.getAttribute("name") | 257 return self.xml.get("name") |
248 | 258 |
249 def delete(self): | 259 def delete(self): |
250 """ removes the tree_node and xml_node, and returns the removed xml_node """ | 260 """ removes the tree_node and xml_node, and returns the removed xml_node """ |
251 | 261 parent_node = self.tree.GetItemParent(self.mytree_node) |
262 if parent_node == self.tree.root: | |
263 parent_xml = self.tree.GetPyData(parent_node) | |
264 else: | |
265 parent_xml = self.tree.GetPyData(parent_node).xml | |
266 parent_xml.remove(self.xml) | |
252 self.tree.Delete(self.mytree_node) | 267 self.tree.Delete(self.mytree_node) |
253 parent = self.master_dom._get_parentNode() | 268 return self.xml |
254 return parent.removeChild(self.master_dom) | |
255 | 269 |
256 def rename(self,name): | 270 def rename(self,name): |
257 if len(name): | 271 if len(name): |
258 self.tree.SetItemText(self.mytree_node,name) | 272 self.tree.SetItemText(self.mytree_node,name) |
259 self.master_dom.setAttribute('name', name) | 273 self.xml.set('name', name) |
260 | 274 |
261 def change_icon(self,icon): | 275 def change_icon(self,icon): |
262 self.master_dom.setAttribute("icon",icon) | 276 self.xml.set("icon",icon) |
263 self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon]) | 277 self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon]) |
264 self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon], wx.TreeItemIcon_Selected) | 278 self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon], wx.TreeItemIcon_Selected) |
265 self.tree.Refresh() | 279 self.tree.Refresh() |
266 | 280 |
267 def on_save(self,evt): | 281 def on_save(self,evt): |
268 f = wx.FileDialog(self.tree,"Select a file", dir_struct["user"],"","XML files (*.xml)|*.xml",wx.SAVE) | 282 f = wx.FileDialog(self.tree,"Select a file", orpg.dirpath.dir_struct["user"],"","XML files (*.xml)|*.xml",wx.SAVE) |
269 if f.ShowModal() == wx.ID_OK: | 283 if f.ShowModal() == wx.ID_OK: |
270 type = f.GetFilterIndex() | 284 ElementTree(self.xml).write(f.GetPath()) |
271 if f.GetPath()[:len(f.GetPath())-4] != '.xml': file = open(f.GetPath()+'.xml',"w") | |
272 else: file = open(f.GetPath(),"w") | |
273 file.write(self.toxml(1)) | |
274 file.close() | |
275 f.Destroy() | 285 f.Destroy() |
276 | 286 |
277 def get_design_panel(self,parent): | 287 def get_design_panel(self,parent): |
278 return None | 288 return None |
279 | 289 |
282 | 292 |
283 def get_html_panel(self,parent): | 293 def get_html_panel(self,parent): |
284 html_str = "<html><body bgcolor=\"#FFFFFF\" >"+self.tohtml()+"</body></html>" | 294 html_str = "<html><body bgcolor=\"#FFFFFF\" >"+self.tohtml()+"</body></html>" |
285 wnd = wx.html.HtmlWindow(parent,-1) | 295 wnd = wx.html.HtmlWindow(parent,-1) |
286 html_str = self.chat.ParseDice(html_str) | 296 html_str = self.chat.ParseDice(html_str) |
287 wnd.SetPage(html_str) | 297 wnd.SetPage(html_str) |
288 return wnd | 298 return wnd |
289 | 299 |
290 def get_size_constraint(self): | 300 def get_size_constraint(self): |
291 return 0 | 301 return 0 |
292 | 302 |
293 def about(self): | 303 def about(self): |
294 html_str = "<b>"+ self.master_dom.getAttribute('class') | 304 html_str = "<b>"+ self.xml.get('class') |
295 html_str += " Applet</b><br />by Chris Davis<br />chris@rpgarchive.com" | 305 html_str += " Applet</b><br />by Chris Davis<br />chris@rpgarchive.com" |
296 return html_str | 306 return html_str |
307 | |
308 def get_value(self): | |
309 return None | |
310 | |
297 | 311 |
298 P_TITLE = 10 | 312 P_TITLE = 10 |
299 P_BODY = 20 | 313 P_BODY = 20 |
300 class text_edit_panel(wx.Panel): | 314 class text_edit_panel(wx.Panel): |
301 def __init__(self, parent, handler): | 315 def __init__(self, parent, handler): |
302 wx.Panel.__init__(self, parent, -1) | 316 wx.Panel.__init__(self, parent, -1) |
303 self.handler = handler | 317 self.handler = handler |
304 sizer = wx.BoxSizer(wx.VERTICAL) | 318 sizer = wx.BoxSizer(wx.VERTICAL) |
305 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')), | 319 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')), |
306 P_BODY : html_text_edit(self,P_BODY,handler.text._get_nodeValue(),self.on_text) | 320 P_BODY : html_text_edit(self,P_BODY,handler.text,self.on_text) |
307 } | 321 } |
308 #P_BODY : wx.TextCtrl(self, P_BODY,handler.text._get_nodeValue(), style=wx.TE_MULTILINE) | |
309 | |
310 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) | 322 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) |
311 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) | 323 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) |
312 sizer.Add(wx.StaticText(self, -1, "Text Body:"), 0, wx.EXPAND) | 324 sizer.Add(wx.StaticText(self, -1, "Text Body:"), 0, wx.EXPAND) |
313 sizer.Add(self.text[P_BODY], 1, wx.EXPAND) | 325 sizer.Add(self.text[P_BODY], 1, wx.EXPAND) |
314 self.sizer = sizer | 326 self.sizer = sizer |
329 bad_txt_found = 1 | 341 bad_txt_found = 1 |
330 if bad_txt_found: | 342 if bad_txt_found: |
331 wx.MessageBox("Some non 7-bit ASCII characters found and stripped","Warning!") | 343 wx.MessageBox("Some non 7-bit ASCII characters found and stripped","Warning!") |
332 txt = u_txt | 344 txt = u_txt |
333 if txt != "": | 345 if txt != "": |
334 self.handler.master_dom.setAttribute('name',txt) | 346 self.handler.xml.set('name',txt) |
335 self.handler.rename(txt) | 347 self.handler.rename(txt) |
336 elif id == P_BODY: | 348 elif id == P_BODY: |
337 txt = self.text[id].get_text() | 349 txt = self.text[id].get_text() |
338 u_txt = "" | 350 u_txt = "" |
339 bad_txt_found = 0 | 351 bad_txt_found = 0 |
355 ########################## | 367 ########################## |
356 class node_loader(node_handler): | 368 class node_loader(node_handler): |
357 """ clones childe node and insert it at top of tree | 369 """ clones childe node and insert it at top of tree |
358 <nodehandler name='?' module='core' class='node_loader' /> | 370 <nodehandler name='?' module='core' class='node_loader' /> |
359 """ | 371 """ |
360 def __init__(self,xml_dom,tree_node): | 372 def __init__(self,xml,tree_node): |
361 node_handler.__init__(self,xml_dom,tree_node) | 373 node_handler.__init__(self,xml,tree_node) |
362 | 374 |
363 def on_rclick(self,evt): | 375 def on_rclick(self,evt): |
364 pass | 376 pass |
365 | 377 |
366 def on_ldclick(self,evt): | 378 def on_ldclick(self,evt): |
367 title = self.master_dom.getAttribute('name') | 379 title = self.xml.get('name') |
368 new_node = self.master_dom._get_firstChild() | 380 new_xml = XML(tostring(self.xml[0])) |
369 new_node = new_node.cloneNode(True) | 381 self.tree.root_xml.insert(0, new_xml) |
370 child = self.tree.master_dom._get_firstChild() | 382 tree_node = self.tree.load_xml(new_xml,self.tree.root,self.tree.root) |
371 new_node = self.tree.master_dom.insertBefore(new_node,child) | |
372 tree_node = self.tree.load_xml(new_node,self.tree.root,self.tree.root) | |
373 obj = self.tree.GetPyData(tree_node) | |
374 return 1 | 383 return 1 |
384 #obj = self.tree.GetPyData(tree_node) | |
375 #obj.on_design(None) | 385 #obj.on_design(None) |
376 | 386 |
377 ########################## | 387 ########################## |
378 ## file loader | 388 ## file loader |
379 ########################## | 389 ########################## |
382 """ loads file and insert into game tree | 392 """ loads file and insert into game tree |
383 <nodehandler name='?' module='core' class='file_loader' > | 393 <nodehandler name='?' module='core' class='file_loader' > |
384 <file name="file_name.xml" /> | 394 <file name="file_name.xml" /> |
385 </nodehandler> | 395 </nodehandler> |
386 """ | 396 """ |
387 def __init__(self,xml_dom,tree_node): | 397 def __init__(self,xml,tree_node): |
388 node_handler.__init__(self,xml_dom,tree_node) | 398 node_handler.__init__(self,xml,tree_node) |
389 self.file_node = self.master_dom._get_firstChild() | 399 self.file_node = self.xml[0] |
390 self.frame = component.get('frame') | 400 self.frame = open_rpg.get_component('frame') |
391 | 401 |
392 def on_ldclick(self,evt): | 402 def on_ldclick(self,evt): |
393 file_name = self.file_node.getAttribute("name") | 403 file_name = self.file_node.get("name") |
394 self.tree.insert_xml(open(dir_struct["nodes"] + file_name,"r").read()) | 404 self.tree.insert_xml(open(orpg.dirpath.dir_struct["nodes"] + file_name,"r").read()) |
395 return 1 | 405 return 1 |
396 | 406 |
397 def on_design(self,evt): | 407 def on_design(self,evt): |
398 tlist = ['Title','File Name'] | 408 tlist = ['Title','File Name'] |
399 vlist = [self.master_dom.getAttribute("name"), | 409 vlist = [self.xml.get("name"), |
400 self.file_node.getAttribute("name")] | 410 self.file_node.get("name")] |
401 dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit") | 411 dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit") |
402 if dlg.ShowModal() == wx.ID_OK: | 412 if dlg.ShowModal() == wx.ID_OK: |
403 vlist = dlg.get_values() | 413 vlist = dlg.get_values() |
404 self.file_node.setAttribute('name', vlist[1]) | 414 self.file_node.set('name', vlist[1]) |
405 self.master_dom.setAttribute('name', vlist[0]) | 415 self.xml.set('name', vlist[0]) |
406 self.tree.SetItemText(self.mytree_node,vlist[0]) | 416 self.tree.SetItemText(self.mytree_node,vlist[0]) |
407 dlg.Destroy() | 417 dlg.Destroy() |
408 | 418 |
409 ########################## | 419 ########################## |
410 ## URL loader | 420 ## URL loader |
414 """ loads file from url and insert into game tree | 424 """ loads file from url and insert into game tree |
415 <nodehandler name='?' module='core' class='url_loader' > | 425 <nodehandler name='?' module='core' class='url_loader' > |
416 <file name="http://file_name.xml" /> | 426 <file name="http://file_name.xml" /> |
417 </nodehandler> | 427 </nodehandler> |
418 """ | 428 """ |
419 def __init__(self,xml_dom,tree_node): | 429 def __init__(self,xml,tree_node): |
420 node_handler.__init__(self,xml_dom,tree_node) | 430 node_handler.__init__(self,xml,tree_node) |
421 self.file_node = self.master_dom._get_firstChild() | 431 self.file_node = self.xml[0] |
422 self.frame = component.get('frame') | 432 self.frame = open_rpg.get_component('frame') |
423 | 433 |
424 def on_ldclick(self,evt): | 434 def on_ldclick(self,evt): |
425 file_name = self.file_node.getAttribute("url") | 435 file_name = self.file_node.get("url") |
426 file = urllib.urlopen(file_name) | 436 file = urllib.urlopen(file_name) |
427 self.tree.insert_xml(file.read()) | 437 self.tree.insert_xml(file.read()) |
428 return 1 | 438 return 1 |
429 | 439 |
430 def on_design(self,evt): | 440 def on_design(self,evt): |
431 tlist = ['Title','URL'] | 441 tlist = ['Title','URL'] |
432 print "design filename",self.master_dom.getAttribute('name') | 442 print "design filename",self.xml.get('name') |
433 vlist = [self.master_dom.getAttribute("name"), | 443 vlist = [self.xml.get("name"), |
434 self.file_node.getAttribute("url")] | 444 self.file_node.get("url")] |
435 dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit") | 445 dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit") |
436 if dlg.ShowModal() == wx.ID_OK: | 446 if dlg.ShowModal() == wx.ID_OK: |
437 vlist = dlg.get_values() | 447 vlist = dlg.get_values() |
438 self.file_node.setAttribute('url', vlist[1]) | 448 self.file_node.set('url', vlist[1]) |
439 self.master_dom.setAttribute('name', vlist[0]) | 449 self.xml.set('name', vlist[0]) |
440 self.tree.SetItemText(self.mytree_node,vlist[0]) | 450 self.tree.SetItemText(self.mytree_node,vlist[0]) |
441 dlg.Destroy() | 451 dlg.Destroy() |
442 | 452 |
443 | 453 |
444 ########################## | 454 ########################## |
446 ########################## | 456 ########################## |
447 class min_map(node_handler): | 457 class min_map(node_handler): |
448 """ clones childe node and insert it at top of tree | 458 """ clones childe node and insert it at top of tree |
449 <nodehandler name='?' module='core' class='min_map' /> | 459 <nodehandler name='?' module='core' class='min_map' /> |
450 """ | 460 """ |
451 def __init__(self,xml_dom,tree_node): | 461 def __init__(self,xml,tree_node): |
452 node_handler.__init__(self,xml_dom,tree_node) | 462 node_handler.__init__(self,xml,tree_node) |
453 self.map = component.get('map') | 463 self.map = open_rpg.get_component('map') |
454 self.mapdata = self.master_dom._get_firstChild() | 464 self.mapdata = self.xml[0] |
455 | 465 |
456 def on_ldclick(self,evt): | 466 def on_ldclick(self,evt): |
457 self.map.new_data(toxml(self.mapdata)) | 467 self.map.new_data(tostring(self.mapdata)) |
458 return 1 | 468 return 1 |