Mercurial > traipse_dev
comparison orpg/gametree/gametree.py @ 66:c54768cffbd4 ornery-dev
Traipse Dev 'OpenRPG' {090818-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:
*Unstable*
This is the first wave of Code Refinement updates. Includes new material from Core Beta; new debugger material (partially implemented), beginnings of switch to etree, TerminalWriter, and a little more. open_rpg has been renamed to component; functioning now as component.get(), component.add(), component.delete(). This version has known bugs, specifically with the gametree and nodes. I think the XML files where not removed during testing of Core and switching back.
author | sirebral |
---|---|
date | Tue, 18 Aug 2009 06:33:37 -0500 |
parents | 4385a7d0efd1 |
children | 449a8900f9ac |
comparison
equal
deleted
inserted
replaced
65:4840657c23c5 | 66:c54768cffbd4 |
---|---|
28 | 28 |
29 __version__ = "$Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $" | 29 __version__ = "$Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $" |
30 | 30 |
31 from orpg.orpg_wx import * | 31 from orpg.orpg_wx import * |
32 from orpg.orpg_windows import * | 32 from orpg.orpg_windows import * |
33 from orpg.orpgCore import open_rpg | 33 from orpg.orpgCore import component |
34 import orpg.dirpath | 34 from orpg.dirpath import dir_struct |
35 from nodehandlers import core | 35 from nodehandlers import core |
36 import orpg.gametree.nodehandlers.containers | 36 import orpg.gametree.nodehandlers.containers |
37 import orpg.gametree.nodehandlers.forms | 37 import orpg.gametree.nodehandlers.forms |
38 import orpg.gametree.nodehandlers.dnd3e | 38 import orpg.gametree.nodehandlers.dnd3e |
39 import orpg.gametree.nodehandlers.dnd35 | 39 import orpg.gametree.nodehandlers.dnd35 |
78 TOP_TREE_PROP = wx.NewId() | 78 TOP_TREE_PROP = wx.NewId() |
79 TOP_FEATURES = wx.NewId() | 79 TOP_FEATURES = wx.NewId() |
80 | 80 |
81 class game_tree(wx.TreeCtrl): | 81 class game_tree(wx.TreeCtrl): |
82 def __init__(self, parent, id): | 82 def __init__(self, parent, id): |
83 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition, wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS) | 83 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition, |
84 self.log = open_rpg.get_component('log') | 84 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS) |
85 self.log.log("Enter game_tree", ORPG_DEBUG) | 85 self.orpgLog = component.get('log') |
86 self.validate = open_rpg.get_component('validate') | 86 self.orpgLog.log("Enter game_tree", ORPG_DEBUG) |
87 self.xml = open_rpg.get_component('xml') | 87 self.validate = component.get('validate') |
88 self.settings = open_rpg.get_component('settings') | 88 self.xml = component.get('xml') |
89 self.session = open_rpg.get_component('session') | 89 self.settings = component.get('settings') |
90 self.chat = open_rpg.get_component('chat') | 90 self.session = component.get('session') |
91 self.mainframe = open_rpg.get_component('frame') | 91 self.chat = component.get('chat') |
92 self.mainframe = component.get('frame') | |
92 self.build_img_list() | 93 self.build_img_list() |
93 self.build_std_menu() | 94 self.build_std_menu() |
94 self.nodehandlers = {} | 95 self.nodehandlers = {} |
95 self.nodes = {} | 96 self.nodes = {} |
96 self.init_nodehandlers() | 97 self.init_nodehandlers() |
103 self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.on_label_begin, id=self.GetId()) | 104 self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.on_label_begin, id=self.GetId()) |
104 self.Bind(wx.EVT_CHAR, self.on_char) | 105 self.Bind(wx.EVT_CHAR, self.on_char) |
105 self.Bind(wx.EVT_KEY_UP, self.on_key_up) | 106 self.Bind(wx.EVT_KEY_UP, self.on_key_up) |
106 self.id = 1 | 107 self.id = 1 |
107 self.dragging = False | 108 self.dragging = False |
108 self.root_dir = orpg.dirpath.dir_struct["home"] | 109 self.root_dir = dir_struct["home"] |
109 self.last_save_dir = orpg.dirpath.dir_struct["user"] | 110 self.last_save_dir = dir_struct["user"] |
110 | 111 |
111 #Create tree from default if it does not exist | 112 #Create tree from default if it does not exist |
112 self.validate.config_file("tree.xml","default_tree.xml") | 113 self.validate.config_file("tree.xml","default_tree.xml") |
113 open_rpg.add_component("tree", self) | 114 component.add("tree", self) |
114 #build tree | 115 #build tree |
115 self.root = self.AddRoot("Game Tree",self.icons['gear']) | 116 self.root = self.AddRoot("Game Tree",self.icons['gear']) |
116 self.was_labeling = 0 | 117 self.was_labeling = 0 |
117 self.rename_flag = 0 | 118 self.rename_flag = 0 |
118 self.image_cache = {} | 119 self.image_cache = {} |
119 self.log.log("Exit game_tree", ORPG_DEBUG) | 120 self.orpgLog.log("Exit game_tree", ORPG_DEBUG) |
120 | 121 |
121 def add_nodehandler(self, nodehandler, nodeclass): | 122 def add_nodehandler(self, nodehandler, nodeclass): |
122 self.log.log("Enter game_tree->add_nodehandler(self, nodehandler, nodeclass)", ORPG_DEBUG) | 123 self.orpgLog.log("Enter game_tree->add_nodehandler(self, nodehandler, nodeclass)", ORPG_DEBUG) |
123 if not self.nodehandlers.has_key(nodehandler): | 124 if not self.nodehandlers.has_key(nodehandler): |
124 self.nodehandlers[nodehandler] = nodeclass | 125 self.nodehandlers[nodehandler] = nodeclass |
125 else: | 126 else: |
126 self.log.log("Nodehandler for " + nodehandler + " already exists!", ORPG_DEBUG, True) | 127 self.orpgLog.log("Nodehandler for " + nodehandler + " already exists!", ORPG_DEBUG, True) |
127 self.log.log("Exit game_tree->add_nodehandler(self, nodehandler, nodeclass)", ORPG_DEBUG) | 128 self.orpgLog.log("Exit game_tree->add_nodehandler(self, nodehandler, nodeclass)", ORPG_DEBUG) |
128 | 129 |
129 def remove_nodehandler(self, nodehandler): | 130 def remove_nodehandler(self, nodehandler): |
130 self.log.log("Enter game_tree->remove_nodehandler(self, nodehandler)", ORPG_DEBUG) | 131 self.orpgLog.log("Enter game_tree->remove_nodehandler(self, nodehandler)", ORPG_DEBUG) |
131 if self.nodehandlers.has_key(nodehandler): | 132 if self.nodehandlers.has_key(nodehandler): |
132 del self.nodehandlers[nodehandler] | 133 del self.nodehandlers[nodehandler] |
133 else: | 134 else: |
134 self.log.log("No nodehandler for " + nodehandler + " exists!", ORPG_DEBUG, True) | 135 self.orpgLog.log("No nodehandler for " + nodehandler + " exists!", ORPG_DEBUG, True) |
135 self.log.log("Exit game_tree->remove_nodehandler(self, nodehandler)", ORPG_DEBUG) | 136 self.orpgLog.log("Exit game_tree->remove_nodehandler(self, nodehandler)", ORPG_DEBUG) |
136 | 137 |
137 def init_nodehandlers(self): | 138 def init_nodehandlers(self): |
138 self.log.log("Enter game_tree->init_nodehandlers(self)", ORPG_DEBUG) | 139 self.orpgLog.log("Enter game_tree->init_nodehandlers(self)", ORPG_DEBUG) |
139 self.add_nodehandler('group_handler', orpg.gametree.nodehandlers.containers.group_handler) | 140 self.add_nodehandler('group_handler', orpg.gametree.nodehandlers.containers.group_handler) |
140 self.add_nodehandler('tabber_handler', orpg.gametree.nodehandlers.containers.tabber_handler) | 141 self.add_nodehandler('tabber_handler', orpg.gametree.nodehandlers.containers.tabber_handler) |
141 self.add_nodehandler('splitter_handler', orpg.gametree.nodehandlers.containers.splitter_handler) | 142 self.add_nodehandler('splitter_handler', orpg.gametree.nodehandlers.containers.splitter_handler) |
142 self.add_nodehandler('form_handler', orpg.gametree.nodehandlers.forms.form_handler) | 143 self.add_nodehandler('form_handler', orpg.gametree.nodehandlers.forms.form_handler) |
143 self.add_nodehandler('textctrl_handler', orpg.gametree.nodehandlers.forms.textctrl_handler) | 144 self.add_nodehandler('textctrl_handler', orpg.gametree.nodehandlers.forms.textctrl_handler) |
156 self.add_nodehandler('voxchat_handler', orpg.gametree.nodehandlers.voxchat.voxchat_handler) | 157 self.add_nodehandler('voxchat_handler', orpg.gametree.nodehandlers.voxchat.voxchat_handler) |
157 self.add_nodehandler('file_loader', core.file_loader) | 158 self.add_nodehandler('file_loader', core.file_loader) |
158 self.add_nodehandler('node_loader', core.node_loader) | 159 self.add_nodehandler('node_loader', core.node_loader) |
159 self.add_nodehandler('url_loader', core.url_loader) | 160 self.add_nodehandler('url_loader', core.url_loader) |
160 self.add_nodehandler('min_map', core.min_map) | 161 self.add_nodehandler('min_map', core.min_map) |
161 self.log.log("Exit game_tree->init_nodehandlers(self)", ORPG_DEBUG) | 162 self.orpgLog.log("Exit game_tree->init_nodehandlers(self)", ORPG_DEBUG) |
162 | 163 |
163 # event = wxKeyEvent | 164 # event = wxKeyEvent |
164 # set to be called by wxWindows by EVT_CHAR macro in __init__ | 165 # set to be called by wxWindows by EVT_CHAR macro in __init__ |
165 def on_key_up(self, evt): | 166 def on_key_up(self, evt): |
166 self.log.log("Enter game_tree->on_key_up(self, evt)", ORPG_DEBUG) | 167 self.orpgLog.log("Enter game_tree->on_key_up(self, evt)", ORPG_DEBUG) |
167 key_code = evt.GetKeyCode() | 168 key_code = evt.GetKeyCode() |
168 if self.dragging and (key_code == wx.WXK_SHIFT): | 169 if self.dragging and (key_code == wx.WXK_SHIFT): |
169 curSelection = self.GetSelection() | 170 curSelection = self.GetSelection() |
170 cur = wx.StockCursor(wx.CURSOR_ARROW) | 171 cur = wx.StockCursor(wx.CURSOR_ARROW) |
171 self.SetCursor(cur) | 172 self.SetCursor(cur) |
174 self.SelectItem(curSelection) | 175 self.SelectItem(curSelection) |
175 if(isinstance(obj,core.node_handler)): | 176 if(isinstance(obj,core.node_handler)): |
176 obj.on_drop(evt) | 177 obj.on_drop(evt) |
177 self.drag_obj = None | 178 self.drag_obj = None |
178 evt.Skip() | 179 evt.Skip() |
179 self.log.log("Exit game_tree->on_key_up(self, evt)", ORPG_DEBUG) | 180 self.orpgLog.log("Exit game_tree->on_key_up(self, evt)", ORPG_DEBUG) |
180 | 181 |
181 def on_char(self, evt): | 182 def on_char(self, evt): |
182 self.log.log("Enter game_tree->on_char(self, evt)", ORPG_DEBUG) | 183 self.orpgLog.log("Enter game_tree->on_char(self, evt)", ORPG_DEBUG) |
183 key_code = evt.GetKeyCode() | 184 key_code = evt.GetKeyCode() |
184 curSelection = self.GetSelection() # Get the current selection | 185 curSelection = self.GetSelection() # Get the current selection |
185 if evt.ShiftDown() and ((key_code == wx.WXK_UP) or (key_code == wx.WXK_DOWN)) and not self.dragging: | 186 if evt.ShiftDown() and ((key_code == wx.WXK_UP) or (key_code == wx.WXK_DOWN)) and not self.dragging: |
186 curSelection = self.GetSelection() | 187 curSelection = self.GetSelection() |
187 obj = self.GetPyData(curSelection) | 188 obj = self.GetPyData(curSelection) |
205 pass | 206 pass |
206 elif key_code == wx.WXK_F2: | 207 elif key_code == wx.WXK_F2: |
207 self.rename_flag = 1 | 208 self.rename_flag = 1 |
208 self.EditLabel(curSelection) | 209 self.EditLabel(curSelection) |
209 evt.Skip() | 210 evt.Skip() |
210 self.log.log("Exit game_tree->on_char(self, evt)", ORPG_DEBUG) | 211 self.orpgLog.log("Exit game_tree->on_char(self, evt)", ORPG_DEBUG) |
211 | 212 |
212 ## locate_valid_tree | 213 ## locate_valid_tree |
213 ## GUI based dialogs to locate/fix missing treefile issues --Snowdog 3/05 | 214 ## GUI based dialogs to locate/fix missing treefile issues --Snowdog 3/05 |
214 def locate_valid_tree(self, error, msg, dir, filename): | 215 def locate_valid_tree(self, error, msg, dir, filename): |
215 """prompts the user to locate a new tree file or create a new one""" | 216 """prompts the user to locate a new tree file or create a new one""" |
216 self.log.log("Enter game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) | 217 self.orpgLog.log("Enter game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) |
217 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR) | 218 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR) |
218 if response == wx.YES: | 219 if response == wx.YES: |
219 file = None | 220 file = None |
220 filetypes = "Gametree (*.xml)|*.xml|All files (*.*)|*.*" | 221 filetypes = "Gametree (*.xml)|*.xml|All files (*.*)|*.*" |
221 dlg = wx.FileDialog(self, "Locate Gametree file", dir, filename, filetypes,wx.OPEN | wx.CHANGE_DIR) | 222 dlg = wx.FileDialog(self, "Locate Gametree file", dir, filename, filetypes,wx.OPEN | wx.CHANGE_DIR) |
222 if dlg.ShowModal() == wx.ID_OK: file = dlg.GetPath() | 223 if dlg.ShowModal() == wx.ID_OK: file = dlg.GetPath() |
223 dlg.Destroy() | 224 dlg.Destroy() |
224 if not file: self.load_tree(error=1) | 225 if not file: self.load_tree(error=1) |
225 else: self.load_tree(file) | 226 else: self.load_tree(file) |
226 self.log.log("Exit game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) | 227 self.orpgLog.log("Exit game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) |
227 return | 228 return |
228 else: | 229 else: |
229 self.validate.config_file("tree.xml","default_tree.xml") | 230 self.validate.config_file("tree.xml","default_tree.xml") |
230 self.load_tree(error=1) | 231 self.load_tree(error=1) |
231 self.log.log("Exit game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) | 232 self.orpgLog.log("Exit game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) |
232 return | 233 return |
233 | 234 |
234 def load_tree(self, filename=orpg.dirpath.dir_struct["user"]+'tree.xml', error=0): | 235 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0): |
235 self.log.log("Enter game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | 236 self.orpgLog.log("Enter game_tree->load_tree(self, filename, error)", ORPG_DEBUG) |
236 self.settings.set_setting("gametree", filename) | 237 self.settings.set_setting("gametree", filename) |
237 tmp = None | 238 tmp = None |
238 xml_dom = None | 239 xml_dom = None |
239 xml_doc = None | 240 xml_doc = None |
240 try: | 241 try: |
241 self.log.log("Reading Gametree file: " + filename + "...", ORPG_INFO, True) | 242 self.orpgLog.log("Reading Gametree file: " + filename + "...", ORPG_INFO, True) |
242 tmp = open(filename,"r") | 243 tmp = open(filename,"r") |
243 xml_doc = self.xml.parseXml(tmp.read()) | 244 xml_doc = self.xml.parseXml(tmp.read()) |
244 tmp.close() | 245 tmp.close() |
245 if xml_doc == None: | 246 if xml_doc == None: |
246 pass | 247 pass |
247 else: | 248 else: |
248 xml_dom = xml_doc._get_documentElement() | 249 xml_dom = xml_doc._get_documentElement() |
249 self.log.log("done.", ORPG_INFO, True) | 250 self.orpgLog.log("done.", ORPG_INFO, True) |
250 | 251 |
251 except IOError: | 252 except IOError: |
252 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\ | 253 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\ |
253 "Would you like to locate it?\n"\ | 254 "Would you like to locate it?\n"\ |
254 "(Selecting 'No' will cause a new default gametree to be generated)" | 255 "(Selecting 'No' will cause a new default gametree to be generated)" |
255 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] | 256 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] |
256 self.locate_valid_tree("Gametree Error", emsg, orpg.dirpath.dir_struct["user"], fn) | 257 self.locate_valid_tree("Gametree Error", emsg, dir_struct["user"], fn) |
257 self.log.log(emsg, ORPG_GENERAL) | 258 self.orpgLog.log(emsg, ORPG_GENERAL) |
258 self.log.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | 259 self.orpgLog.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) |
259 return | 260 return |
260 | 261 |
261 if not xml_dom: | 262 if not xml_dom: |
262 os.rename(filename,filename+".corrupt") | 263 os.rename(filename,filename+".corrupt") |
263 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] | 264 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] |
267 "your myfiles directory to "+fn+ "\n"\ | 268 "your myfiles directory to "+fn+ "\n"\ |
268 "in your myfiles directory.\n\n"\ | 269 "in your myfiles directory.\n\n"\ |
269 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\ | 270 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\ |
270 "Would you like to select a different gametree file to use?\n"\ | 271 "Would you like to select a different gametree file to use?\n"\ |
271 "(Selecting 'No' will cause a new default gametree to be generated)" | 272 "(Selecting 'No' will cause a new default gametree to be generated)" |
272 self.locate_valid_tree("Corrupt Gametree!", emsg, orpg.dirpath.dir_struct["user"], fn) | 273 self.locate_valid_tree("Corrupt Gametree!", emsg, dir_struct["user"], fn) |
273 self.log.log(emsg, ORPG_GENERAL) | 274 self.orpgLog.log(emsg, ORPG_GENERAL) |
274 self.log.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | 275 self.orpgLog.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) |
275 return | 276 return |
276 | 277 |
277 if xml_dom._get_tagName() != "gametree": | 278 if xml_dom._get_tagName() != "gametree": |
278 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] | 279 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] |
279 emsg = fn+" does not appear to be a valid gametree file.\n\n"\ | 280 emsg = fn+" does not appear to be a valid gametree file.\n\n"\ |
280 "Would you like to select a different gametree file to use?\n"\ | 281 "Would you like to select a different gametree file to use?\n"\ |
281 "(Selecting 'No' will cause a new default gametree to be generated)" | 282 "(Selecting 'No' will cause a new default gametree to be generated)" |
282 self.locate_valid_tree("Invalid Gametree!", emsg, orpg.dirpath.dir_struct["user"], fn) | 283 self.locate_valid_tree("Invalid Gametree!", emsg, dir_struct["user"], fn) |
283 self.log.log(emsg, ORPG_DEBUG) | 284 self.orpgLog.log(emsg, ORPG_DEBUG) |
284 self.log.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | 285 self.orpgLog.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) |
285 return | 286 return |
286 | 287 |
287 # get gametree version - we could write conversion code here! | 288 # get gametree version - we could write conversion code here! |
288 self.master_dom = xml_dom | 289 self.master_dom = xml_dom |
289 self.log.log("Master Dom Set", ORPG_DEBUG) | 290 self.orpgLog.log("Master Dom Set", ORPG_DEBUG) |
290 | 291 |
291 try: | 292 try: |
292 version = self.master_dom.getAttribute("version") | 293 version = self.master_dom.getAttribute("version") |
293 # see if we should load the gametree | 294 # see if we should load the gametree |
294 loadfeatures = int(self.settings.get_setting("LoadGameTreeFeatures")) | 295 loadfeatures = int(self.settings.get_setting("LoadGameTreeFeatures")) |
295 if loadfeatures: | 296 if loadfeatures: |
296 xml_dom = self.xml.parseXml(open(orpg.dirpath.dir_struct["template"]+"feature.xml","r").read()) | 297 xml_dom = self.xml.parseXml(open(dir_struct["template"]+"feature.xml","r").read()) |
297 xml_dom = xml_dom._get_documentElement() | 298 xml_dom = xml_dom._get_documentElement() |
298 xml_dom = self.master_dom.appendChild(xml_dom) | 299 xml_dom = self.master_dom.appendChild(xml_dom) |
299 self.settings.set_setting("LoadGameTreeFeatures","0") | 300 self.settings.set_setting("LoadGameTreeFeatures","0") |
300 | 301 |
301 ## load tree | 302 ## load tree |
302 self.log.log("Features loaded (if required)", ORPG_DEBUG) | 303 self.orpgLog.log("Features loaded (if required)", ORPG_DEBUG) |
303 self.CollapseAndReset(self.root) | 304 self.CollapseAndReset(self.root) |
304 children = self.master_dom._get_childNodes() | 305 children = self.master_dom._get_childNodes() |
305 self.log.log("Parsing Gametree Nodes ", ORPG_INFO, True) | 306 self.orpgLog.log("Parsing Gametree Nodes ", ORPG_INFO, True) |
306 for c in children: | 307 for c in children: |
307 print '.', | 308 print '.', |
308 self.load_xml(c,self.root) | 309 self.load_xml(c,self.root) |
309 self.log.log("done", ORPG_INFO, True) | 310 self.orpgLog.log("done", ORPG_INFO, True) |
310 self.Expand(self.root) | 311 self.Expand(self.root) |
311 self.SetPyData(self.root,self.master_dom) | 312 self.SetPyData(self.root,self.master_dom) |
312 if error != 1: | 313 if error != 1: |
313 infile = open(filename, "rb") | 314 infile = open(filename, "rb") |
314 outfile = open(orpg.dirpath.dir_struct["user"]+"lastgood.xml", "wb") | 315 outfile = open(dir_struct["user"]+"lastgood.xml", "wb") |
315 outfile.write(infile.read()) | 316 outfile.write(infile.read()) |
316 else: | 317 else: |
317 self.log.log("Not overwriting lastgood.xml file.", ORPG_INFO, True) | 318 self.orpgLog.log("Not overwriting lastgood.xml file.", ORPG_INFO, True) |
318 | 319 |
319 except Exception, e: | 320 except Exception, e: |
320 self.log.log(traceback.format_exc(), ORPG_GENERAL) | 321 self.orpgLog.log(traceback.format_exc(), ORPG_GENERAL) |
321 wx.MessageBox("Corrupt Tree!\nYour game tree is being regenerated. To\nsalvage a recent version of your gametree\nexit OpenRPG and copy the lastgood.xml\nfile in your myfiles directory\nto "+filename+ "\nin your myfiles directory.\nlastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.") | 322 wx.MessageBox("Corrupt Tree!\nYour game tree is being regenerated. To\nsalvage a recent version of your gametree\nexit OpenRPG and copy the lastgood.xml\nfile in your myfiles directory\nto "+filename+ "\nin your myfiles directory.\nlastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.") |
322 os.rename(filename,filename+".corrupt") | 323 os.rename(filename,filename+".corrupt") |
323 self.validate.config_file("tree.xml","default_tree.xml") | 324 self.validate.config_file("tree.xml","default_tree.xml") |
324 self.load_tree(error=1) | 325 self.load_tree(error=1) |
325 self.log.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | 326 self.orpgLog.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) |
326 | 327 |
327 def build_std_menu(self, obj=None): | 328 def build_std_menu(self, obj=None): |
328 self.log.log("Enter game_tree->build_std_menu(self, obj)", ORPG_DEBUG) | 329 self.orpgLog.log("Enter game_tree->build_std_menu(self, obj)", ORPG_DEBUG) |
329 | 330 |
330 # build useful menu | 331 # build useful menu |
331 useful_menu = wx.Menu() | 332 useful_menu = wx.Menu() |
332 useful_menu.Append(STD_MENU_NODE_USEFUL,"Use&ful") | 333 useful_menu.Append(STD_MENU_NODE_USEFUL,"Use&ful") |
333 useful_menu.Append(STD_MENU_NODE_USELESS,"Use&less") | 334 useful_menu.Append(STD_MENU_NODE_USELESS,"Use&less") |
383 self.Bind(wx.EVT_MENU, self.on_save_tree_as, id=TOP_SAVE_TREE_AS) | 384 self.Bind(wx.EVT_MENU, self.on_save_tree_as, id=TOP_SAVE_TREE_AS) |
384 self.Bind(wx.EVT_MENU, self.on_save_tree, id=TOP_SAVE_TREE) | 385 self.Bind(wx.EVT_MENU, self.on_save_tree, id=TOP_SAVE_TREE) |
385 self.Bind(wx.EVT_MENU, self.on_load_new_tree, id=TOP_NEW_TREE) | 386 self.Bind(wx.EVT_MENU, self.on_load_new_tree, id=TOP_NEW_TREE) |
386 self.Bind(wx.EVT_MENU, self.on_tree_prop, id=TOP_TREE_PROP) | 387 self.Bind(wx.EVT_MENU, self.on_tree_prop, id=TOP_TREE_PROP) |
387 self.Bind(wx.EVT_MENU, self.on_insert_features, id=TOP_FEATURES) | 388 self.Bind(wx.EVT_MENU, self.on_insert_features, id=TOP_FEATURES) |
388 self.log.log("Exit game_tree->build_std_menu(self, obj)", ORPG_DEBUG) | 389 self.orpgLog.log("Exit game_tree->build_std_menu(self, obj)", ORPG_DEBUG) |
389 | 390 |
390 def do_std_menu(self, evt, obj): | 391 def do_std_menu(self, evt, obj): |
391 self.log.log("Enter game_tree->do_std_menu(self, evt, obj)", ORPG_DEBUG) | 392 self.orpgLog.log("Enter game_tree->do_std_menu(self, evt, obj)", ORPG_DEBUG) |
392 try: | 393 try: |
393 self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu()) | 394 self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu()) |
394 except: | 395 except: |
395 self.std_menu.Enable(STD_MENU_MAP, obj.map_aware()) | 396 self.std_menu.Enable(STD_MENU_MAP, obj.map_aware()) |
396 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone()) | 397 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone()) |
397 self.PopupMenu(self.std_menu) | 398 self.PopupMenu(self.std_menu) |
398 self.log.log("Exit game_tree->do_std_menu(self, evt, obj)", ORPG_DEBUG) | 399 self.orpgLog.log("Exit game_tree->do_std_menu(self, evt, obj)", ORPG_DEBUG) |
399 | 400 |
400 def strip_html(self, player): | 401 def strip_html(self, player): |
401 self.log.log("Enter game_tree->strip_html(self, player)", ORPG_DEBUG) | 402 self.orpgLog.log("Enter game_tree->strip_html(self, player)", ORPG_DEBUG) |
402 ret_string = "" | 403 ret_string = "" |
403 x = 0 | 404 x = 0 |
404 in_tag = 0 | 405 in_tag = 0 |
405 for x in xrange(len(player[0])) : | 406 for x in xrange(len(player[0])) : |
406 if player[0][x] == "<" or player[0][x] == ">" or in_tag == 1 : | 407 if player[0][x] == "<" or player[0][x] == ">" or in_tag == 1 : |
410 in_tag = 0 | 411 in_tag = 0 |
411 else : | 412 else : |
412 pass | 413 pass |
413 else : | 414 else : |
414 ret_string = ret_string + player[0][x] | 415 ret_string = ret_string + player[0][x] |
415 self.log.log(ret_string, ORPG_DEBUG) | 416 self.orpgLog.log(ret_string, ORPG_DEBUG) |
416 self.log.log("Exit game_tree->strip_html(self, player)", ORPG_DEBUG) | 417 self.orpgLog.log("Exit game_tree->strip_html(self, player)", ORPG_DEBUG) |
417 return ret_string | 418 return ret_string |
418 | 419 |
419 def on_receive_data(self, data, player): | 420 def on_receive_data(self, data, player): |
420 self.log.log("Enter game_tree->on_receive_data(self, data, player)", ORPG_DEBUG) | 421 self.orpgLog.log("Enter game_tree->on_receive_data(self, data, player)", ORPG_DEBUG) |
421 beg = string.find(data,"<tree>") | 422 beg = string.find(data,"<tree>") |
422 end = string.rfind(data,"</tree>") | 423 end = string.rfind(data,"</tree>") |
423 data = data[6:end] | 424 data = data[6:end] |
424 self.insert_xml(data) | 425 self.insert_xml(data) |
425 self.log.log("Exit game_tree->on_receive_data(self, data, player)", ORPG_DEBUG) | 426 self.orpgLog.log("Exit game_tree->on_receive_data(self, data, player)", ORPG_DEBUG) |
426 | 427 |
427 def on_send_to_chat(self, evt): | 428 def on_send_to_chat(self, evt): |
428 self.log.log("Enter game_tree->on_send_to_chat(self, evt)", ORPG_DEBUG) | 429 self.orpgLog.log("Enter game_tree->on_send_to_chat(self, evt)", ORPG_DEBUG) |
429 item = self.GetSelection() | 430 item = self.GetSelection() |
430 obj = self.GetPyData(item) | 431 obj = self.GetPyData(item) |
431 obj.on_send_to_chat(evt) | 432 obj.on_send_to_chat(evt) |
432 self.log.log("Exit game_tree->on_send_to_chat(self, evt)", ORPG_DEBUG) | 433 self.orpgLog.log("Exit game_tree->on_send_to_chat(self, evt)", ORPG_DEBUG) |
433 | 434 |
434 def on_whisper_to(self, evt): | 435 def on_whisper_to(self, evt): |
435 self.log.log("Enter game_tree->on_whisper_to(self, evt)", ORPG_DEBUG) | 436 self.orpgLog.log("Enter game_tree->on_whisper_to(self, evt)", ORPG_DEBUG) |
436 players = self.session.get_players() | 437 players = self.session.get_players() |
437 opts = [] | 438 opts = [] |
438 myid = self.session.get_id() | 439 myid = self.session.get_id() |
439 me = None | 440 me = None |
440 for p in players: | 441 for p in players: |
455 else: | 456 else: |
456 player_ids = [] | 457 player_ids = [] |
457 for s in selections: | 458 for s in selections: |
458 player_ids.append(players[s][2]) | 459 player_ids.append(players[s][2]) |
459 self.chat.whisper_to_players(obj.tohtml(),player_ids) | 460 self.chat.whisper_to_players(obj.tohtml(),player_ids) |
460 self.log.log("Exit game_tree->on_whisper_to(self, evt)", ORPG_DEBUG) | 461 self.orpgLog.log("Exit game_tree->on_whisper_to(self, evt)", ORPG_DEBUG) |
461 | 462 |
462 def on_export_html(self, evt): | 463 def on_export_html(self, evt): |
463 self.log.log("Enter game_tree->on_export_html(self, evt)", ORPG_DEBUG) | 464 self.orpgLog.log("Enter game_tree->on_export_html(self, evt)", ORPG_DEBUG) |
464 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE) | 465 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE) |
465 if f.ShowModal() == wx.ID_OK: | 466 if f.ShowModal() == wx.ID_OK: |
466 item = self.GetSelection() | 467 item = self.GetSelection() |
467 obj = self.GetPyData(item) | 468 obj = self.GetPyData(item) |
468 type = f.GetFilterIndex() | 469 type = f.GetFilterIndex() |
474 file.write(data) | 475 file.write(data) |
475 file.close() | 476 file.close() |
476 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | 477 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) |
477 f.Destroy() | 478 f.Destroy() |
478 os.chdir(self.root_dir) | 479 os.chdir(self.root_dir) |
479 self.log.log("Exit game_tree->on_export_html(self, evt)", ORPG_DEBUG) | 480 self.orpgLog.log("Exit game_tree->on_export_html(self, evt)", ORPG_DEBUG) |
480 | 481 |
481 def indifferent(self, evt): | 482 def indifferent(self, evt): |
482 self.log.log("Enter game_tree->indifferent(self, evt)", ORPG_DEBUG) | 483 self.orpgLog.log("Enter game_tree->indifferent(self, evt)", ORPG_DEBUG) |
483 item = self.GetSelection() | 484 item = self.GetSelection() |
484 obj = self.GetPyData(item) | 485 obj = self.GetPyData(item) |
485 obj.usefulness("indifferent") | 486 obj.usefulness("indifferent") |
486 self.log.log("Exit game_tree->indifferent(self, evt)", ORPG_DEBUG) | 487 self.orpgLog.log("Exit game_tree->indifferent(self, evt)", ORPG_DEBUG) |
487 | 488 |
488 def useful(self, evt): | 489 def useful(self, evt): |
489 self.log.log("Enter game_tree->useful(self, evt)", ORPG_DEBUG) | 490 self.orpgLog.log("Enter game_tree->useful(self, evt)", ORPG_DEBUG) |
490 item = self.GetSelection() | 491 item = self.GetSelection() |
491 obj = self.GetPyData(item) | 492 obj = self.GetPyData(item) |
492 obj.usefulness("useful") | 493 obj.usefulness("useful") |
493 self.log.log("Exit game_tree->useful(self, evt)", ORPG_DEBUG) | 494 self.orpgLog.log("Exit game_tree->useful(self, evt)", ORPG_DEBUG) |
494 | 495 |
495 def useless(self, evt): | 496 def useless(self, evt): |
496 self.log.log("Enter game_tree->useless(self, evt)", ORPG_DEBUG) | 497 self.orpgLog.log("Enter game_tree->useless(self, evt)", ORPG_DEBUG) |
497 item = self.GetSelection() | 498 item = self.GetSelection() |
498 obj = self.GetPyData(item) | 499 obj = self.GetPyData(item) |
499 obj.usefulness("useless") | 500 obj.usefulness("useless") |
500 self.log.log("Exit game_tree->useless(self, evt)", ORPG_DEBUG) | 501 self.orpgLog.log("Exit game_tree->useless(self, evt)", ORPG_DEBUG) |
501 | 502 |
502 def on_email(self,evt): | 503 def on_email(self,evt): |
503 pass | 504 pass |
504 | 505 |
505 def on_send_to(self, evt): | 506 def on_send_to(self, evt): |
506 self.log.log("Enter game_tree->on_send_to(self, evt)", ORPG_DEBUG) | 507 self.orpgLog.log("Enter game_tree->on_send_to(self, evt)", ORPG_DEBUG) |
507 players = self.session.get_players() | 508 players = self.session.get_players() |
508 opts = [] | 509 opts = [] |
509 myid = self.session.get_id() | 510 myid = self.session.get_id() |
510 me = None | 511 me = None |
511 for p in players: | 512 for p in players: |
525 self.session.send(xmldata) | 526 self.session.send(xmldata) |
526 else: | 527 else: |
527 for s in selections: | 528 for s in selections: |
528 self.session.send(xmldata,players[s][2]) | 529 self.session.send(xmldata,players[s][2]) |
529 dlg.Destroy() | 530 dlg.Destroy() |
530 self.log.log("Exit game_tree->on_send_to(self, evt)", ORPG_DEBUG) | 531 self.orpgLog.log("Exit game_tree->on_send_to(self, evt)", ORPG_DEBUG) |
531 | 532 |
532 def on_icon(self, evt): | 533 def on_icon(self, evt): |
533 self.log.log("Enter game_tree->on_icon(self, evt)", ORPG_DEBUG) | 534 self.orpgLog.log("Enter game_tree->on_icon(self, evt)", ORPG_DEBUG) |
534 icons = self.icons.keys() | 535 icons = self.icons.keys() |
535 icons.sort() | 536 icons.sort() |
536 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons) | 537 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons) |
537 if dlg.ShowModal() == wx.ID_OK: | 538 if dlg.ShowModal() == wx.ID_OK: |
538 key = dlg.GetStringSelection() | 539 key = dlg.GetStringSelection() |
539 item = self.GetSelection() | 540 item = self.GetSelection() |
540 obj = self.GetPyData(item) | 541 obj = self.GetPyData(item) |
541 obj.change_icon(key) | 542 obj.change_icon(key) |
542 dlg.Destroy() | 543 dlg.Destroy() |
543 self.log.log("Exit game_tree->on_icon(self, evt)", ORPG_DEBUG) | 544 self.orpgLog.log("Exit game_tree->on_icon(self, evt)", ORPG_DEBUG) |
544 | 545 |
545 def on_wizard(self, evt): | 546 def on_wizard(self, evt): |
546 self.log.log("Enter game_tree->on_wizard(self, evt)", ORPG_DEBUG) | 547 self.orpgLog.log("Enter game_tree->on_wizard(self, evt)", ORPG_DEBUG) |
547 item = self.GetSelection() | 548 item = self.GetSelection() |
548 obj = self.GetPyData(item) | 549 obj = self.GetPyData(item) |
549 name = "New " + obj.master_dom.getAttribute("name") | 550 name = "New " + obj.master_dom.getAttribute("name") |
550 icon = obj.master_dom.getAttribute("icon") | 551 icon = obj.master_dom.getAttribute("icon") |
551 xml_data = "<nodehandler name=\""+name+"\" icon=\"" + icon + "\" module=\"core\" class=\"node_loader\" >" | 552 xml_data = "<nodehandler name=\""+name+"\" icon=\"" + icon + "\" module=\"core\" class=\"node_loader\" >" |
552 xml_data += self.xml.toxml(obj) | 553 xml_data += self.xml.toxml(obj) |
553 xml_data += "</nodehandler>" | 554 xml_data += "</nodehandler>" |
554 self.insert_xml(xml_data) | 555 self.insert_xml(xml_data) |
555 self.log.log(xml_data, ORPG_DEBUG) | 556 self.orpgLog.log(xml_data, ORPG_DEBUG) |
556 self.log.log("Exit game_tree->on_wizard(self, evt)", ORPG_DEBUG) | 557 self.orpgLog.log("Exit game_tree->on_wizard(self, evt)", ORPG_DEBUG) |
557 | 558 |
558 def on_clone(self, evt): | 559 def on_clone(self, evt): |
559 self.log.log("Enter game_tree->on_clone(self, evt)", ORPG_DEBUG) | 560 self.orpgLog.log("Enter game_tree->on_clone(self, evt)", ORPG_DEBUG) |
560 item = self.GetSelection() | 561 item = self.GetSelection() |
561 obj = self.GetPyData(item) | 562 obj = self.GetPyData(item) |
562 if obj.can_clone(): | 563 if obj.can_clone(): |
563 parent_node = self.GetItemParent(item) | 564 parent_node = self.GetItemParent(item) |
564 prev_sib = self.GetPrevSibling(item) | 565 prev_sib = self.GetPrevSibling(item) |
567 xml_dom = self.xml.parseXml(self.xml.toxml(obj)) | 568 xml_dom = self.xml.parseXml(self.xml.toxml(obj)) |
568 xml_dom = xml_dom._get_firstChild() | 569 xml_dom = xml_dom._get_firstChild() |
569 parent = obj.master_dom._get_parentNode() | 570 parent = obj.master_dom._get_parentNode() |
570 xml_dom = parent.insertBefore(xml_dom, obj.master_dom) | 571 xml_dom = parent.insertBefore(xml_dom, obj.master_dom) |
571 self.load_xml(xml_dom, parent_node, prev_sib) | 572 self.load_xml(xml_dom, parent_node, prev_sib) |
572 self.log.log("Exit game_tree->on_clone(self, evt)", ORPG_DEBUG) | 573 self.orpgLog.log("Exit game_tree->on_clone(self, evt)", ORPG_DEBUG) |
573 | 574 |
574 def on_save(self, evt): | 575 def on_save(self, evt): |
575 """save node to a xml file""" | 576 """save node to a xml file""" |
576 self.log.log("Enter game_tree->on_save(self, evt)", ORPG_DEBUG) | 577 self.orpgLog.log("Enter game_tree->on_save(self, evt)", ORPG_DEBUG) |
577 item = self.GetSelection() | 578 item = self.GetSelection() |
578 obj = self.GetPyData(item) | 579 obj = self.GetPyData(item) |
579 obj.on_save(evt) | 580 obj.on_save(evt) |
580 os.chdir(self.root_dir) | 581 os.chdir(self.root_dir) |
581 self.log.log("Exit game_tree->on_save(self, evt)", ORPG_DEBUG) | 582 self.orpgLog.log("Exit game_tree->on_save(self, evt)", ORPG_DEBUG) |
582 | 583 |
583 def on_save_tree_as(self, evt): | 584 def on_save_tree_as(self, evt): |
584 self.log.log("Enter game_tree->on_save_tree_as(self, evt)", ORPG_DEBUG) | 585 self.orpgLog.log("Enter game_tree->on_save_tree_as(self, evt)", ORPG_DEBUG) |
585 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.SAVE) | 586 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.SAVE) |
586 if f.ShowModal() == wx.ID_OK: | 587 if f.ShowModal() == wx.ID_OK: |
587 self.save_tree(f.GetPath()) | 588 self.save_tree(f.GetPath()) |
588 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | 589 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) |
589 f.Destroy() | 590 f.Destroy() |
590 os.chdir(self.root_dir) | 591 os.chdir(self.root_dir) |
591 self.log.log("Exit game_tree->on_save_tree_as(self, evt)", ORPG_DEBUG) | 592 self.orpgLog.log("Exit game_tree->on_save_tree_as(self, evt)", ORPG_DEBUG) |
592 | 593 |
593 def on_save_tree(self, evt=None): | 594 def on_save_tree(self, evt=None): |
594 self.log.log("Enter game_tree->on_save_tree(self, evt)", ORPG_DEBUG) | 595 self.orpgLog.log("Enter game_tree->on_save_tree(self, evt)", ORPG_DEBUG) |
595 filename = self.settings.get_setting("gametree") | 596 filename = self.settings.get_setting("gametree") |
596 self.save_tree(filename) | 597 self.save_tree(filename) |
597 self.log.log("Exit game_tree->on_save_tree(self, evt)", ORPG_DEBUG) | 598 self.orpgLog.log("Exit game_tree->on_save_tree(self, evt)", ORPG_DEBUG) |
598 | 599 |
599 def save_tree(self, filename=orpg.dirpath.dir_struct["user"]+'tree.xml'): | 600 def save_tree(self, filename=dir_struct["user"]+'tree.xml'): |
600 self.log.log("Enter game_tree->save_tree(self, filename)", ORPG_DEBUG) | 601 self.orpgLog.log("Enter game_tree->save_tree(self, filename)", ORPG_DEBUG) |
601 self.master_dom.setAttribute("version",GAMETREE_VERSION) | 602 self.master_dom.setAttribute("version",GAMETREE_VERSION) |
602 self.settings.set_setting("gametree",filename) | 603 self.settings.set_setting("gametree",filename) |
603 file = open(filename,"w") | 604 file = open(filename,"w") |
604 file.write(self.xml.toxml(self.master_dom,1)) | 605 file.write(self.xml.toxml(self.master_dom,1)) |
605 file.close() | 606 file.close() |
606 self.log.log("Exit game_tree->save_tree(self, filename)", ORPG_DEBUG) | 607 self.orpgLog.log("Exit game_tree->save_tree(self, filename)", ORPG_DEBUG) |
607 | 608 |
608 def on_load_new_tree(self, evt): | 609 def on_load_new_tree(self, evt): |
609 self.log.log("Enter game_tree->on_load_new_tree(self, evt)", ORPG_DEBUG) | 610 self.orpgLog.log("Enter game_tree->on_load_new_tree(self, evt)", ORPG_DEBUG) |
610 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) | 611 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) |
611 if f.ShowModal() == wx.ID_OK: | 612 if f.ShowModal() == wx.ID_OK: |
612 self.load_tree(f.GetPath()) | 613 self.load_tree(f.GetPath()) |
613 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | 614 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) |
614 f.Destroy() | 615 f.Destroy() |
615 os.chdir(self.root_dir) | 616 os.chdir(self.root_dir) |
616 self.log.log("Exit game_tree->on_load_new_tree(self, evt)", ORPG_DEBUG) | 617 self.orpgLog.log("Exit game_tree->on_load_new_tree(self, evt)", ORPG_DEBUG) |
617 | 618 |
618 def on_insert_file(self, evt): | 619 def on_insert_file(self, evt): |
619 """loads xml file into the tree""" | 620 """loads xml file into the tree""" |
620 self.log.log("Enter game_tree->on_insert_file(self, evt)", ORPG_DEBUG) | 621 self.orpgLog.log("Enter game_tree->on_insert_file(self, evt)", ORPG_DEBUG) |
621 if self.last_save_dir == ".": | 622 if self.last_save_dir == ".": |
622 self.last_save_dir = orpg.dirpath.dir_struct["user"] | 623 self.last_save_dir = dir_struct["user"] |
623 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) | 624 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) |
624 if f.ShowModal() == wx.ID_OK: | 625 if f.ShowModal() == wx.ID_OK: |
625 self.insert_xml(open(f.GetPath(),"r").read()) | 626 self.insert_xml(open(f.GetPath(),"r").read()) |
626 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | 627 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) |
627 f.Destroy() | 628 f.Destroy() |
628 os.chdir(self.root_dir) | 629 os.chdir(self.root_dir) |
629 self.log.log("Exit game_tree->on_insert_file(self, evt)", ORPG_DEBUG) | 630 self.orpgLog.log("Exit game_tree->on_insert_file(self, evt)", ORPG_DEBUG) |
630 | 631 |
631 def on_insert_url(self, evt): | 632 def on_insert_url(self, evt): |
632 """loads xml url into the tree""" | 633 """loads xml url into the tree""" |
633 self.log.log("Enter game_tree->on_insert_url(self, evt)", ORPG_DEBUG) | 634 self.orpgLog.log("Enter game_tree->on_insert_url(self, evt)", ORPG_DEBUG) |
634 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://") | 635 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://") |
635 if dlg.ShowModal() == wx.ID_OK: | 636 if dlg.ShowModal() == wx.ID_OK: |
636 path = dlg.GetValue() | 637 path = dlg.GetValue() |
637 file = urllib.urlopen(path) | 638 file = urllib.urlopen(path) |
638 self.insert_xml(file.read()) | 639 self.insert_xml(file.read()) |
639 dlg.Destroy() | 640 dlg.Destroy() |
640 self.log.log("Exit game_tree->on_insert_url(self, evt)", ORPG_DEBUG) | 641 self.orpgLog.log("Exit game_tree->on_insert_url(self, evt)", ORPG_DEBUG) |
641 | 642 |
642 def on_insert_features(self, evt): | 643 def on_insert_features(self, evt): |
643 self.log.log("Enter game_tree->on_insert_features(self, evt)", ORPG_DEBUG) | 644 self.orpgLog.log("Enter game_tree->on_insert_features(self, evt)", ORPG_DEBUG) |
644 self.insert_xml(open(orpg.dirpath.dir_struct["template"]+"feature.xml","r").read()) | 645 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read()) |
645 self.log.log("Exit game_tree->on_insert_features(self, evt)", ORPG_DEBUG) | 646 self.orpgLog.log("Exit game_tree->on_insert_features(self, evt)", ORPG_DEBUG) |
646 | 647 |
647 def on_tree_prop(self, evt): | 648 def on_tree_prop(self, evt): |
648 self.log.log("Enter game_tree->on_tree_prop(self, evt)", ORPG_DEBUG) | 649 self.orpgLog.log("Enter game_tree->on_tree_prop(self, evt)", ORPG_DEBUG) |
649 dlg = gametree_prop_dlg(self, self.settings) | 650 dlg = gametree_prop_dlg(self, self.settings) |
650 if dlg.ShowModal() == wx.ID_OK: | 651 if dlg.ShowModal() == wx.ID_OK: |
651 pass | 652 pass |
652 dlg.Destroy() | 653 dlg.Destroy() |
653 self.log.log("Exit game_tree->on_tree_prop(self, evt)", ORPG_DEBUG) | 654 self.orpgLog.log("Exit game_tree->on_tree_prop(self, evt)", ORPG_DEBUG) |
654 | 655 |
655 def on_node_design(self, evt): | 656 def on_node_design(self, evt): |
656 self.log.log("Enter game_tree->on_node_design(self, evt)", ORPG_DEBUG) | 657 self.orpgLog.log("Enter game_tree->on_node_design(self, evt)", ORPG_DEBUG) |
657 | 658 |
658 item = self.GetSelection() | 659 item = self.GetSelection() |
659 obj = self.GetPyData(item) | 660 obj = self.GetPyData(item) |
660 obj.on_design(evt) | 661 obj.on_design(evt) |
661 | 662 |
662 self.log.log("Exit game_tree->on_node_design(self, evt)", ORPG_DEBUG) | 663 self.orpgLog.log("Exit game_tree->on_node_design(self, evt)", ORPG_DEBUG) |
663 | 664 |
664 def on_node_use(self, evt): | 665 def on_node_use(self, evt): |
665 self.log.log("Enter game_tree->on_node_use(self, evt)", ORPG_DEBUG) | 666 self.orpgLog.log("Enter game_tree->on_node_use(self, evt)", ORPG_DEBUG) |
666 | 667 |
667 item = self.GetSelection() | 668 item = self.GetSelection() |
668 obj = self.GetPyData(item) | 669 obj = self.GetPyData(item) |
669 obj.on_use(evt) | 670 obj.on_use(evt) |
670 | 671 |
671 self.log.log("Exit game_tree->on_node_use(self, evt)", ORPG_DEBUG) | 672 self.orpgLog.log("Exit game_tree->on_node_use(self, evt)", ORPG_DEBUG) |
672 | 673 |
673 def on_node_pp(self, evt): | 674 def on_node_pp(self, evt): |
674 self.log.log("Enter game_tree->on_node_pp(self, evt)", ORPG_DEBUG) | 675 self.orpgLog.log("Enter game_tree->on_node_pp(self, evt)", ORPG_DEBUG) |
675 | 676 |
676 item = self.GetSelection() | 677 item = self.GetSelection() |
677 obj = self.GetPyData(item) | 678 obj = self.GetPyData(item) |
678 obj.on_html_view(evt) | 679 obj.on_html_view(evt) |
679 | 680 |
680 self.log.log("Exit game_tree->on_node_pp(self, evt)", ORPG_DEBUG) | 681 self.orpgLog.log("Exit game_tree->on_node_pp(self, evt)", ORPG_DEBUG) |
681 | 682 |
682 def on_del(self, evt): | 683 def on_del(self, evt): |
683 self.log.log("Enter game_tree->on_del(self, evt)", ORPG_DEBUG) | 684 self.orpgLog.log("Enter game_tree->on_del(self, evt)", ORPG_DEBUG) |
684 status_value = "none" | 685 status_value = "none" |
685 try: | 686 try: |
686 item = self.GetSelection() | 687 item = self.GetSelection() |
687 if item: | 688 if item: |
688 obj = self.GetPyData(item) | 689 obj = self.GetPyData(item) |
719 else: | 720 else: |
720 msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK) | 721 msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK) |
721 msg.ShowModal() | 722 msg.ShowModal() |
722 msg.Destroy() | 723 msg.Destroy() |
723 | 724 |
724 self.log.log("Exit game_tree->on_del(self, evt)", ORPG_DEBUG) | 725 self.orpgLog.log("Exit game_tree->on_del(self, evt)", ORPG_DEBUG) |
725 | 726 |
726 def on_about(self, evt): | 727 def on_about(self, evt): |
727 self.log.log("Enter game_tree->on_about(self, evt)", ORPG_DEBUG) | 728 self.orpgLog.log("Enter game_tree->on_about(self, evt)", ORPG_DEBUG) |
728 | 729 |
729 item = self.GetSelection() | 730 item = self.GetSelection() |
730 obj = self.GetPyData(item) | 731 obj = self.GetPyData(item) |
731 about = MyAboutBox(self,obj.about()) | 732 about = MyAboutBox(self,obj.about()) |
732 about.ShowModal() | 733 about.ShowModal() |
733 about.Destroy() | 734 about.Destroy() |
734 | 735 |
735 self.log.log("Exit game_tree->on_about(self, evt)", ORPG_DEBUG) | 736 self.orpgLog.log("Exit game_tree->on_about(self, evt)", ORPG_DEBUG) |
736 | 737 |
737 def on_send_to_map(self, evt): | 738 def on_send_to_map(self, evt): |
738 self.log.log("Enter game_tree->on_send_to_map(self, evt)", ORPG_DEBUG) | 739 self.orpgLog.log("Enter game_tree->on_send_to_map(self, evt)", ORPG_DEBUG) |
739 | 740 |
740 item = self.GetSelection() | 741 item = self.GetSelection() |
741 obj = self.GetPyData(item) | 742 obj = self.GetPyData(item) |
742 if hasattr(obj,"on_send_to_map"): | 743 if hasattr(obj,"on_send_to_map"): |
743 obj.on_send_to_map(evt) | 744 obj.on_send_to_map(evt) |
744 | 745 |
745 self.log.log("Exit game_tree->on_send_to_map(self, evt)", ORPG_DEBUG) | 746 self.orpgLog.log("Exit game_tree->on_send_to_map(self, evt)", ORPG_DEBUG) |
746 | 747 |
747 def insert_xml(self, txt): | 748 def insert_xml(self, txt): |
748 self.log.log("Enter game_tree->insert_xml(self, txt)", ORPG_DEBUG) | 749 self.orpgLog.log("Enter game_tree->insert_xml(self, txt)", ORPG_DEBUG) |
749 #Updated to allow safe merging of gametree files | 750 #Updated to allow safe merging of gametree files |
750 #without leaving an unusable and undeletable node. | 751 #without leaving an unusable and undeletable node. |
751 # -- Snowdog 8/03 | 752 # -- Snowdog 8/03 |
752 xml_dom = self.xml.parseXml(txt) | 753 xml_dom = self.xml.parseXml(txt) |
753 if xml_dom == None: | 754 if xml_dom == None: |
754 wx.MessageBox("Import Failed: Invalid or missing node data") | 755 wx.MessageBox("Import Failed: Invalid or missing node data") |
755 self.log.log("Import Failed: Invalid or missing node data", ORPG_DEBUG) | 756 self.orpgLog.log("Import Failed: Invalid or missing node data", ORPG_DEBUG) |
756 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | 757 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) |
757 return | 758 return |
758 xml_temp = xml_dom._get_documentElement() | 759 xml_temp = xml_dom._get_documentElement() |
759 | 760 |
760 if not xml_temp: | 761 if not xml_temp: |
761 wx.MessageBox("Error Importing Node or Tree") | 762 wx.MessageBox("Error Importing Node or Tree") |
762 self.log.log("Error Importing Node or Tree", ORPG_DEBUG) | 763 self.orpgLog.log("Error Importing Node or Tree", ORPG_DEBUG) |
763 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | 764 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) |
764 return | 765 return |
765 | 766 |
766 if xml_temp._get_tagName() == "gametree": | 767 if xml_temp._get_tagName() == "gametree": |
767 children = xml_temp._get_childNodes() | 768 children = xml_temp._get_childNodes() |
768 for c in children: | 769 for c in children: |
769 self.load_xml(c, self.root) | 770 self.load_xml(c, self.root) |
770 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | 771 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) |
771 return | 772 return |
772 | 773 |
773 if not xml_dom: | 774 if not xml_dom: |
774 wx.MessageBox("XML Error") | 775 wx.MessageBox("XML Error") |
775 self.log.log("XML Error", ORPG_DEBUG) | 776 self.orpgLog.log("XML Error", ORPG_DEBUG) |
776 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | 777 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) |
777 return | 778 return |
778 | 779 |
779 xml_dom = xml_dom._get_firstChild() | 780 xml_dom = xml_dom._get_firstChild() |
780 child = self.master_dom._get_firstChild() | 781 child = self.master_dom._get_firstChild() |
781 xml_dom = self.master_dom.insertBefore(xml_dom,child) | 782 xml_dom = self.master_dom.insertBefore(xml_dom,child) |
782 self.load_xml(xml_dom,self.root,self.root) | 783 self.load_xml(xml_dom,self.root,self.root) |
783 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | 784 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) |
784 | 785 |
785 def build_img_list(self): | 786 def build_img_list(self): |
786 """make image list""" | 787 """make image list""" |
787 self.log.log("Enter game_tree->build_img_list(self)", ORPG_DEBUG) | 788 self.orpgLog.log("Enter game_tree->build_img_list(self)", ORPG_DEBUG) |
788 helper = img_helper() | 789 helper = img_helper() |
789 self.icons = { } | 790 self.icons = { } |
790 self._imageList= wx.ImageList(16,16,False) | 791 self._imageList= wx.ImageList(16,16,False) |
791 man = open(orpg.dirpath.dir_struct["icon"]+"icons.xml","r") | 792 man = open(dir_struct["icon"]+"icons.xml","r") |
792 xml_dom = self.xml.parseXml(man.read()) | 793 xml_dom = self.xml.parseXml(man.read()) |
793 man.close() | 794 man.close() |
794 xml_dom = xml_dom._get_documentElement() | 795 xml_dom = xml_dom._get_documentElement() |
795 node_list = xml_dom._get_childNodes() | 796 node_list = xml_dom._get_childNodes() |
796 for n in node_list: | 797 for n in node_list: |
797 key = n.getAttribute("name") | 798 key = n.getAttribute("name") |
798 path = orpg.dirpath.dir_struct["icon"] + n.getAttribute("file") | 799 path = dir_struct["icon"] + n.getAttribute("file") |
799 img = helper.load_file(path) | 800 img = helper.load_file(path) |
800 self.icons[key] = self._imageList.Add(img) | 801 self.icons[key] = self._imageList.Add(img) |
801 self.SetImageList(self._imageList) | 802 self.SetImageList(self._imageList) |
802 self.log.log("Exit game_tree->build_img_list(self)", ORPG_DEBUG) | 803 self.orpgLog.log("Exit game_tree->build_img_list(self)", ORPG_DEBUG) |
803 | 804 |
804 def load_xml(self, xml_dom, parent_node, prev_node=None): | 805 def load_xml(self, xml_dom, parent_node, prev_node=None): |
805 self.log.log("Enter game_tree->load_xml(self, xml_dom, parent_node, prev_node)", ORPG_DEBUG) | 806 self.orpgLog.log("Enter game_tree->load_xml(self, xml_dom, parent_node, prev_node)", ORPG_DEBUG) |
806 #add the first tree node | 807 #add the first tree node |
807 i = 0 | 808 i = 0 |
808 text = xml_dom.getAttribute("name") | 809 text = xml_dom.getAttribute("name") |
809 icon = xml_dom.getAttribute("icon") | 810 icon = xml_dom.getAttribute("icon") |
810 if self.icons.has_key(icon): | 811 if self.icons.has_key(icon): |
811 i = self.icons[icon] | 812 i = self.icons[icon] |
812 name = xml_dom._get_nodeName() | 813 name = xml_dom._get_nodeName() |
813 self.log.log("Text, icon and name set\n" + text + "\n" + icon + "\n" + name, ORPG_DEBUG) | 814 self.orpgLog.log("Text, icon and name set\n" + text + "\n" + icon + "\n" + name, ORPG_DEBUG) |
814 if prev_node: | 815 if prev_node: |
815 if prev_node == parent_node: | 816 if prev_node == parent_node: |
816 new_tree_node = self.PrependItem(parent_node, text, i, i) | 817 new_tree_node = self.PrependItem(parent_node, text, i, i) |
817 else: | 818 else: |
818 new_tree_node = self.InsertItem(parent_node,prev_node, text, i, i) | 819 new_tree_node = self.InsertItem(parent_node,prev_node, text, i, i) |
819 else: | 820 else: |
820 new_tree_node = self.AppendItem(parent_node, text, i, i) | 821 new_tree_node = self.AppendItem(parent_node, text, i, i) |
821 | 822 |
822 self.log.log("Node Added to tree", ORPG_DEBUG) | 823 self.orpgLog.log("Node Added to tree", ORPG_DEBUG) |
823 #create a nodehandler or continue loading xml into tree | 824 #create a nodehandler or continue loading xml into tree |
824 if name == "nodehandler": | 825 if name == "nodehandler": |
825 #wx.BeginBusyCursor() | 826 #wx.BeginBusyCursor() |
826 self.log.log("We have a Nodehandler", ORPG_DEBUG) | 827 self.orpgLog.log("We have a Nodehandler", ORPG_DEBUG) |
827 try: | 828 try: |
828 py_class = xml_dom.getAttribute("class") | 829 py_class = xml_dom.getAttribute("class") |
829 self.log.log("nodehandler class: " + py_class, ORPG_DEBUG) | 830 self.orpgLog.log("nodehandler class: " + py_class, ORPG_DEBUG) |
830 if not self.nodehandlers.has_key(py_class): | 831 if not self.nodehandlers.has_key(py_class): |
831 raise Exception, "Unknown Nodehandler for " + py_class | 832 raise Exception, "Unknown Nodehandler for " + py_class |
832 self.nodes[self.id] = self.nodehandlers[py_class](xml_dom, new_tree_node) | 833 self.nodes[self.id] = self.nodehandlers[py_class](xml_dom, new_tree_node) |
833 self.SetPyData(new_tree_node, self.nodes[self.id]) | 834 self.SetPyData(new_tree_node, self.nodes[self.id]) |
834 self.log.log("Node Data set", ORPG_DEBUG) | 835 self.orpgLog.log("Node Data set", ORPG_DEBUG) |
835 bmp = self.nodes[self.id].get_scaled_bitmap(16,16) | 836 bmp = self.nodes[self.id].get_scaled_bitmap(16,16) |
836 if bmp: | 837 if bmp: |
837 self.cached_load_of_image(bmp,new_tree_node,) | 838 self.cached_load_of_image(bmp,new_tree_node,) |
838 self.log.log("Node Icon loaded", ORPG_DEBUG) | 839 self.orpgLog.log("Node Icon loaded", ORPG_DEBUG) |
839 self.id = self.id + 1 | 840 self.id = self.id + 1 |
840 except Exception, er: | 841 except Exception, er: |
841 self.log.log(traceback.format_exc(), ORPG_GENERAL) | 842 self.orpgLog.log(traceback.format_exc(), ORPG_GENERAL) |
842 #self.log.log("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), "Tree Node Load Error", ORPG_GENERAL, True) # Arbitrary fix! TaS. (gametree should thread in the future.) | 843 #self.orpgLog.log("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), "Tree Node Load Error", ORPG_GENERAL, True) # Arbitrary fix! TaS. (gametree should thread in the future.) |
843 self.log.log("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), ORPG_GENERAL, True) | 844 self.orpgLog.log("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), ORPG_GENERAL, True) |
844 self.Delete(new_tree_node) | 845 self.Delete(new_tree_node) |
845 parent = xml_dom._get_parentNode() | 846 parent = xml_dom._get_parentNode() |
846 parent.removeChild(xml_dom) | 847 parent.removeChild(xml_dom) |
847 #wx.EndBusyCursor() | 848 #wx.EndBusyCursor() |
848 self.log.log("Exit game_tree->load_xml(self, xml_dom, parent_node, prev_node)", ORPG_DEBUG) | 849 self.orpgLog.log("Exit game_tree->load_xml(self, xml_dom, parent_node, prev_node)", ORPG_DEBUG) |
849 return new_tree_node | 850 return new_tree_node |
850 | 851 |
851 def cached_load_of_image(self, bmp_in, new_tree_node): | 852 def cached_load_of_image(self, bmp_in, new_tree_node): |
852 self.log.log("Enter game_tree->cached_load_of_image(self, bmp_in, new_tree_node)", ORPG_DEBUG) | 853 self.orpgLog.log("Enter game_tree->cached_load_of_image(self, bmp_in, new_tree_node)", ORPG_DEBUG) |
853 image_list = self.GetImageList() | 854 image_list = self.GetImageList() |
854 img = wx.ImageFromBitmap(bmp_in) | 855 img = wx.ImageFromBitmap(bmp_in) |
855 img_data = img.GetData() | 856 img_data = img.GetData() |
856 image_index = None | 857 image_index = None |
857 for key in self.image_cache.keys(): | 858 for key in self.image_cache.keys(): |
862 if image_index is None: | 863 if image_index is None: |
863 image_index = image_list.Add(bmp_in) | 864 image_index = image_list.Add(bmp_in) |
864 self.image_cache[image_index] = img_data | 865 self.image_cache[image_index] = img_data |
865 self.SetItemImage(new_tree_node,image_index) | 866 self.SetItemImage(new_tree_node,image_index) |
866 self.SetItemImage(new_tree_node,image_index, wx.TreeItemIcon_Selected) | 867 self.SetItemImage(new_tree_node,image_index, wx.TreeItemIcon_Selected) |
867 self.log.log("Exit game_tree->cached_load_of_image(self, bmp_in, new_tree_node)", ORPG_DEBUG) | 868 self.orpgLog.log("Exit game_tree->cached_load_of_image(self, bmp_in, new_tree_node)", ORPG_DEBUG) |
868 return image_index | 869 return image_index |
869 | 870 |
870 | 871 |
871 def on_rclick(self, evt): | 872 def on_rclick(self, evt): |
872 self.log.log("Enter game_tree->on_rclick(self, evt)", ORPG_DEBUG) | 873 self.orpgLog.log("Enter game_tree->on_rclick(self, evt)", ORPG_DEBUG) |
873 pt = evt.GetPosition() | 874 pt = evt.GetPosition() |
874 (item, flag) = self.HitTest(pt) | 875 (item, flag) = self.HitTest(pt) |
875 if item.IsOk(): | 876 if item.IsOk(): |
876 obj = self.GetPyData(item) | 877 obj = self.GetPyData(item) |
877 self.SelectItem(item) | 878 self.SelectItem(item) |
879 obj.on_rclick(evt) | 880 obj.on_rclick(evt) |
880 else: | 881 else: |
881 self.PopupMenu(self.top_menu) | 882 self.PopupMenu(self.top_menu) |
882 else: | 883 else: |
883 self.PopupMenu(self.top_menu,pt) | 884 self.PopupMenu(self.top_menu,pt) |
884 self.log.log("Exit game_tree->on_rclick(self, evt)", ORPG_DEBUG) | 885 self.orpgLog.log("Exit game_tree->on_rclick(self, evt)", ORPG_DEBUG) |
885 | 886 |
886 def on_ldclick(self, evt): | 887 def on_ldclick(self, evt): |
887 self.log.log("Enter game_tree->on_ldclick(self, evt)", ORPG_DEBUG) | 888 self.orpgLog.log("Enter game_tree->on_ldclick(self, evt)", ORPG_DEBUG) |
888 self.rename_flag = 0 | 889 self.rename_flag = 0 |
889 pt = evt.GetPosition() | 890 pt = evt.GetPosition() |
890 (item, flag) = self.HitTest(pt) | 891 (item, flag) = self.HitTest(pt) |
891 if item.IsOk(): | 892 if item.IsOk(): |
892 obj = self.GetPyData(item) | 893 obj = self.GetPyData(item) |
900 obj.on_design(evt) | 901 obj.on_design(evt) |
901 elif action == "print": | 902 elif action == "print": |
902 obj.on_html_view(evt) | 903 obj.on_html_view(evt) |
903 elif action == "chat": | 904 elif action == "chat": |
904 self.on_send_to_chat(evt) | 905 self.on_send_to_chat(evt) |
905 self.log.log("Exit game_tree->on_ldclick(self, evt)", ORPG_DEBUG) | 906 self.orpgLog.log("Exit game_tree->on_ldclick(self, evt)", ORPG_DEBUG) |
906 | 907 |
907 def on_left_down(self, evt): | 908 def on_left_down(self, evt): |
908 self.log.log("Enter game_tree->on_left_down(self, evt)", ORPG_DEBUG) | 909 self.orpgLog.log("Enter game_tree->on_left_down(self, evt)", ORPG_DEBUG) |
909 pt = evt.GetPosition() | 910 pt = evt.GetPosition() |
910 (item, flag) = self.HitTest(pt) | 911 (item, flag) = self.HitTest(pt) |
911 if item.IsOk() and self.was_labeling: | 912 if item.IsOk() and self.was_labeling: |
912 self.SelectItem(item) | 913 self.SelectItem(item) |
913 self.rename_flag = 0 | 914 self.rename_flag = 0 |
916 # this next if tests to ensure that the mouse up occurred over a label, and not the icon | 917 # this next if tests to ensure that the mouse up occurred over a label, and not the icon |
917 self.rename_flag = 1 | 918 self.rename_flag = 1 |
918 else: | 919 else: |
919 self.SelectItem(item) | 920 self.SelectItem(item) |
920 evt.Skip() | 921 evt.Skip() |
921 self.log.log("Exit game_tree->on_left_down(self, evt)", ORPG_DEBUG) | 922 self.orpgLog.log("Exit game_tree->on_left_down(self, evt)", ORPG_DEBUG) |
922 | 923 |
923 def on_left_up(self, evt): | 924 def on_left_up(self, evt): |
924 self.log.log("Enter game_tree->on_left_up(self, evt)", ORPG_DEBUG) | 925 self.orpgLog.log("Enter game_tree->on_left_up(self, evt)", ORPG_DEBUG) |
925 if self.dragging: | 926 if self.dragging: |
926 cur = wx.StockCursor(wx.CURSOR_ARROW) | 927 cur = wx.StockCursor(wx.CURSOR_ARROW) |
927 self.SetCursor(cur) | 928 self.SetCursor(cur) |
928 self.dragging = False | 929 self.dragging = False |
929 pt = evt.GetPosition() | 930 pt = evt.GetPosition() |
932 obj = self.GetPyData(item) | 933 obj = self.GetPyData(item) |
933 self.SelectItem(item) | 934 self.SelectItem(item) |
934 if(isinstance(obj,core.node_handler)): | 935 if(isinstance(obj,core.node_handler)): |
935 obj.on_drop(evt) | 936 obj.on_drop(evt) |
936 self.drag_obj = None | 937 self.drag_obj = None |
937 self.log.log("Exit game_tree->on_left_up(self, evt)", ORPG_DEBUG) | 938 self.orpgLog.log("Exit game_tree->on_left_up(self, evt)", ORPG_DEBUG) |
938 | 939 |
939 def on_label_change(self, evt): | 940 def on_label_change(self, evt): |
940 self.log.log("Enter game_tree->on_label_change(self, evt)", ORPG_DEBUG) | 941 self.orpgLog.log("Enter game_tree->on_label_change(self, evt)", ORPG_DEBUG) |
941 item = evt.GetItem() | 942 item = evt.GetItem() |
942 txt = evt.GetLabel() | 943 txt = evt.GetLabel() |
943 self.was_labeling = 0 | 944 self.was_labeling = 0 |
944 self.rename_flag = 0 | 945 self.rename_flag = 0 |
945 if txt != "": | 946 if txt != "": |
946 obj = self.GetPyData(item) | 947 obj = self.GetPyData(item) |
947 obj.master_dom.setAttribute('name',txt) | 948 obj.master_dom.setAttribute('name',txt) |
948 else: | 949 else: |
949 evt.Veto() | 950 evt.Veto() |
950 self.log.log("Exit game_tree->on_label_change(self, evt)", ORPG_DEBUG) | 951 self.orpgLog.log("Exit game_tree->on_label_change(self, evt)", ORPG_DEBUG) |
951 | 952 |
952 def on_label_begin(self, evt): | 953 def on_label_begin(self, evt): |
953 self.log.log("Enter game_tree->on_label_begin(self, evt)", ORPG_DEBUG) | 954 self.orpgLog.log("Enter game_tree->on_label_begin(self, evt)", ORPG_DEBUG) |
954 if not self.rename_flag: | 955 if not self.rename_flag: |
955 evt.Veto() | 956 evt.Veto() |
956 else: | 957 else: |
957 self.was_labeling = 1 | 958 self.was_labeling = 1 |
958 item = evt.GetItem() | 959 item = evt.GetItem() |
959 if item == self.GetRootItem(): | 960 if item == self.GetRootItem(): |
960 evt.Veto() | 961 evt.Veto() |
961 self.log.log("Exit game_tree->on_label_begin(self, evt)", ORPG_DEBUG) | 962 self.orpgLog.log("Exit game_tree->on_label_begin(self, evt)", ORPG_DEBUG) |
962 | 963 |
963 def on_drag(self, evt): | 964 def on_drag(self, evt): |
964 self.log.log("Enter game_tree->on_drag(self, evt)", ORPG_DEBUG) | 965 self.orpgLog.log("Enter game_tree->on_drag(self, evt)", ORPG_DEBUG) |
965 self.rename_flag = 0 | 966 self.rename_flag = 0 |
966 item = self.GetSelection() | 967 item = self.GetSelection() |
967 obj = self.GetPyData(item) | 968 obj = self.GetPyData(item) |
968 self.SelectItem(item) | 969 self.SelectItem(item) |
969 if(isinstance(obj,core.node_handler) and obj.drag): | 970 if(isinstance(obj,core.node_handler) and obj.drag): |
970 self.dragging = True | 971 self.dragging = True |
971 cur = wx.StockCursor(wx.CURSOR_HAND) | 972 cur = wx.StockCursor(wx.CURSOR_HAND) |
972 self.SetCursor(cur) | 973 self.SetCursor(cur) |
973 self.drag_obj = obj | 974 self.drag_obj = obj |
974 self.log.log("Exit game_tree->on_drag(self, evt)", ORPG_DEBUG) | 975 self.orpgLog.log("Exit game_tree->on_drag(self, evt)", ORPG_DEBUG) |
975 | 976 |
976 def is_parent_node(self, node, compare_node): | 977 def is_parent_node(self, node, compare_node): |
977 self.log.log("Enter game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | 978 self.orpgLog.log("Enter game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) |
978 | 979 |
979 parent_node = self.GetItemParent(node) | 980 parent_node = self.GetItemParent(node) |
980 if compare_node == parent_node: | 981 if compare_node == parent_node: |
981 | 982 |
982 self.log.log("parent node", ORPG_DEBUG) | 983 self.orpgLog.log("parent node", ORPG_DEBUG) |
983 self.log.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | 984 self.orpgLog.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) |
984 return 1 | 985 return 1 |
985 elif parent_node == self.root: | 986 elif parent_node == self.root: |
986 | 987 |
987 self.log.log("not parent", ORPG_DEBUG) | 988 self.orpgLog.log("not parent", ORPG_DEBUG) |
988 self.log.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | 989 self.orpgLog.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) |
989 return 0 | 990 return 0 |
990 else: | 991 else: |
991 | 992 |
992 self.log.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | 993 self.orpgLog.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) |
993 return self.is_parent_node(parent_node, compare_node) | 994 return self.is_parent_node(parent_node, compare_node) |
994 | 995 |
995 CTRL_TREE_FILE = wx.NewId() | 996 CTRL_TREE_FILE = wx.NewId() |
996 CTRL_YES = wx.NewId() | 997 CTRL_YES = wx.NewId() |
997 CTRL_NO = wx.NewId() | 998 CTRL_NO = wx.NewId() |