Mercurial > traipse_dev
comparison orpg/gametree/gametree.py @ 71:449a8900f9ac ornery-dev
Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author | sirebral |
---|---|
date | Thu, 20 Aug 2009 03:00:39 -0500 |
parents | c54768cffbd4 |
children | 37a11fea3304 |
comparison
equal
deleted
inserted
replaced
70:52a5fa913008 | 71:449a8900f9ac |
---|---|
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 component | 33 from orpg.orpgCore import component |
34 from orpg.dirpath import dir_struct | 34 from orpg.dirpath import dir_struct |
35 from nodehandlers import core | 35 from nodehandlers import core |
36 import orpg.gametree.nodehandlers.containers | |
37 import orpg.gametree.nodehandlers.forms | |
38 import orpg.gametree.nodehandlers.dnd3e | |
39 import orpg.gametree.nodehandlers.dnd35 | |
40 import orpg.gametree.nodehandlers.chatmacro | |
41 import orpg.gametree.nodehandlers.map_miniature_nodehandler | |
42 import orpg.gametree.nodehandlers.minilib | |
43 import orpg.gametree.nodehandlers.rpg_grid | |
44 import orpg.gametree.nodehandlers.d20 | |
45 import orpg.gametree.nodehandlers.StarWarsd20 | |
46 import orpg.gametree.nodehandlers.voxchat | |
47 from gametree_version import GAMETREE_VERSION | |
48 import string | 36 import string |
49 import urllib | 37 import urllib |
50 import time | 38 import time |
51 import os | 39 import os |
40 | |
41 from orpg.tools.orpg_log import logger | |
42 from orpg.tools.decorators import debugging | |
43 from orpg.gametree.nodehandlers import containers, forms, dnd3e, dnd35, chatmacro | |
44 from orpg.gametree.nodehandlers import map_miniature_nodehandler | |
45 from orpg.gametree.nodehandlers import minilib, rpg_grid, d20, StarWarsd20, voxchat | |
46 | |
47 from gametree_version import GAMETREE_VERSION | |
52 | 48 |
53 STD_MENU_DELETE = wx.NewId() | 49 STD_MENU_DELETE = wx.NewId() |
54 STD_MENU_DESIGN = wx.NewId() | 50 STD_MENU_DESIGN = wx.NewId() |
55 STD_MENU_USE = wx.NewId() | 51 STD_MENU_USE = wx.NewId() |
56 STD_MENU_PP = wx.NewId() | 52 STD_MENU_PP = wx.NewId() |
77 TOP_SAVE_TREE_AS = wx.NewId() | 73 TOP_SAVE_TREE_AS = wx.NewId() |
78 TOP_TREE_PROP = wx.NewId() | 74 TOP_TREE_PROP = wx.NewId() |
79 TOP_FEATURES = wx.NewId() | 75 TOP_FEATURES = wx.NewId() |
80 | 76 |
81 class game_tree(wx.TreeCtrl): | 77 class game_tree(wx.TreeCtrl): |
78 @debugging | |
82 def __init__(self, parent, id): | 79 def __init__(self, parent, id): |
83 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition, | 80 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition, |
84 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS) | 81 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS) |
85 self.orpgLog = component.get('log') | 82 self.orpgLog = component.get('log') |
86 self.orpgLog.log("Enter game_tree", ORPG_DEBUG) | |
87 self.validate = component.get('validate') | 83 self.validate = component.get('validate') |
88 self.xml = component.get('xml') | 84 self.xml = component.get('xml') |
89 self.settings = component.get('settings') | 85 self.settings = component.get('settings') |
90 self.session = component.get('session') | 86 self.session = component.get('session') |
91 self.chat = component.get('chat') | 87 self.chat = component.get('chat') |
104 self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.on_label_begin, id=self.GetId()) | 100 self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.on_label_begin, id=self.GetId()) |
105 self.Bind(wx.EVT_CHAR, self.on_char) | 101 self.Bind(wx.EVT_CHAR, self.on_char) |
106 self.Bind(wx.EVT_KEY_UP, self.on_key_up) | 102 self.Bind(wx.EVT_KEY_UP, self.on_key_up) |
107 self.id = 1 | 103 self.id = 1 |
108 self.dragging = False | 104 self.dragging = False |
109 self.root_dir = dir_struct["home"] | |
110 self.last_save_dir = dir_struct["user"] | 105 self.last_save_dir = dir_struct["user"] |
111 | 106 |
112 #Create tree from default if it does not exist | 107 #Create tree from default if it does not exist |
113 self.validate.config_file("tree.xml","default_tree.xml") | 108 self.validate.config_file("tree.xml","default_tree.xml") |
114 component.add("tree", self) | 109 component.add("tree", self) |
117 self.was_labeling = 0 | 112 self.was_labeling = 0 |
118 self.rename_flag = 0 | 113 self.rename_flag = 0 |
119 self.image_cache = {} | 114 self.image_cache = {} |
120 self.orpgLog.log("Exit game_tree", ORPG_DEBUG) | 115 self.orpgLog.log("Exit game_tree", ORPG_DEBUG) |
121 | 116 |
117 @debugging | |
122 def add_nodehandler(self, nodehandler, nodeclass): | 118 def add_nodehandler(self, nodehandler, nodeclass): |
123 self.orpgLog.log("Enter game_tree->add_nodehandler(self, nodehandler, nodeclass)", ORPG_DEBUG) | |
124 if not self.nodehandlers.has_key(nodehandler): | 119 if not self.nodehandlers.has_key(nodehandler): |
125 self.nodehandlers[nodehandler] = nodeclass | 120 self.nodehandlers[nodehandler] = nodeclass |
126 else: | 121 else: |
127 self.orpgLog.log("Nodehandler for " + nodehandler + " already exists!", ORPG_DEBUG, True) | 122 self.orpgLog.log("Nodehandler for " + nodehandler + " already exists!", ORPG_DEBUG, True) |
128 self.orpgLog.log("Exit game_tree->add_nodehandler(self, nodehandler, nodeclass)", ORPG_DEBUG) | 123 |
129 | 124 @debugging |
130 def remove_nodehandler(self, nodehandler): | 125 def remove_nodehandler(self, nodehandler): |
131 self.orpgLog.log("Enter game_tree->remove_nodehandler(self, nodehandler)", ORPG_DEBUG) | |
132 if self.nodehandlers.has_key(nodehandler): | 126 if self.nodehandlers.has_key(nodehandler): |
133 del self.nodehandlers[nodehandler] | 127 del self.nodehandlers[nodehandler] |
134 else: | 128 else: |
135 self.orpgLog.log("No nodehandler for " + nodehandler + " exists!", ORPG_DEBUG, True) | 129 self.orpgLog.log("No nodehandler for " + nodehandler + " exists!", ORPG_DEBUG, True) |
136 self.orpgLog.log("Exit game_tree->remove_nodehandler(self, nodehandler)", ORPG_DEBUG) | 130 |
137 | 131 @debugging |
138 def init_nodehandlers(self): | 132 def init_nodehandlers(self): |
139 self.orpgLog.log("Enter game_tree->init_nodehandlers(self)", ORPG_DEBUG) | 133 self.add_nodehandler('group_handler', containers.group_handler) |
140 self.add_nodehandler('group_handler', orpg.gametree.nodehandlers.containers.group_handler) | 134 self.add_nodehandler('tabber_handler', containers.tabber_handler) |
141 self.add_nodehandler('tabber_handler', orpg.gametree.nodehandlers.containers.tabber_handler) | 135 self.add_nodehandler('splitter_handler', containers.splitter_handler) |
142 self.add_nodehandler('splitter_handler', orpg.gametree.nodehandlers.containers.splitter_handler) | 136 self.add_nodehandler('form_handler', forms.form_handler) |
143 self.add_nodehandler('form_handler', orpg.gametree.nodehandlers.forms.form_handler) | 137 self.add_nodehandler('textctrl_handler', forms.textctrl_handler) |
144 self.add_nodehandler('textctrl_handler', orpg.gametree.nodehandlers.forms.textctrl_handler) | 138 self.add_nodehandler('listbox_handler', forms.listbox_handler) |
145 self.add_nodehandler('listbox_handler', orpg.gametree.nodehandlers.forms.listbox_handler) | 139 self.add_nodehandler('link_handler', forms.link_handler) |
146 self.add_nodehandler('link_handler', orpg.gametree.nodehandlers.forms.link_handler) | 140 self.add_nodehandler('webimg_handler', forms.webimg_handler) |
147 self.add_nodehandler('webimg_handler', orpg.gametree.nodehandlers.forms.webimg_handler) | 141 self.add_nodehandler('dnd3echar_handler', dnd3e.dnd3echar_handler) |
148 self.add_nodehandler('dnd3echar_handler', orpg.gametree.nodehandlers.dnd3e.dnd3echar_handler) | 142 self.add_nodehandler('dnd35char_handler', dnd35.dnd35char_handler) |
149 self.add_nodehandler('dnd35char_handler', orpg.gametree.nodehandlers.dnd35.dnd35char_handler) | 143 self.add_nodehandler('macro_handler', chatmacro.macro_handler) |
150 self.add_nodehandler('macro_handler', orpg.gametree.nodehandlers.chatmacro.macro_handler) | 144 self.add_nodehandler('map_miniature_handler', map_miniature_nodehandler.map_miniature_handler) |
151 self.add_nodehandler('map_miniature_handler', orpg.gametree.nodehandlers.map_miniature_nodehandler.map_miniature_handler) | 145 self.add_nodehandler('minilib_handler', minilib.minilib_handler) |
152 self.add_nodehandler('minilib_handler', orpg.gametree.nodehandlers.minilib.minilib_handler) | 146 self.add_nodehandler('mini_handler', minilib.mini_handler) |
153 self.add_nodehandler('mini_handler', orpg.gametree.nodehandlers.minilib.mini_handler) | 147 self.add_nodehandler('rpg_grid_handler', rpg_grid.rpg_grid_handler) |
154 self.add_nodehandler('rpg_grid_handler', orpg.gametree.nodehandlers.rpg_grid.rpg_grid_handler) | 148 self.add_nodehandler('d20char_handler', d20.d20char_handler) |
155 self.add_nodehandler('d20char_handler', orpg.gametree.nodehandlers.d20.d20char_handler) | 149 self.add_nodehandler('SWd20char_handler', StarWarsd20.SWd20char_handler) |
156 self.add_nodehandler('SWd20char_handler', orpg.gametree.nodehandlers.StarWarsd20.SWd20char_handler) | 150 self.add_nodehandler('voxchat_handler', voxchat.voxchat_handler) |
157 self.add_nodehandler('voxchat_handler', orpg.gametree.nodehandlers.voxchat.voxchat_handler) | |
158 self.add_nodehandler('file_loader', core.file_loader) | 151 self.add_nodehandler('file_loader', core.file_loader) |
159 self.add_nodehandler('node_loader', core.node_loader) | 152 self.add_nodehandler('node_loader', core.node_loader) |
160 self.add_nodehandler('url_loader', core.url_loader) | 153 self.add_nodehandler('url_loader', core.url_loader) |
161 self.add_nodehandler('min_map', core.min_map) | 154 self.add_nodehandler('min_map', core.min_map) |
162 self.orpgLog.log("Exit game_tree->init_nodehandlers(self)", ORPG_DEBUG) | |
163 | 155 |
164 # event = wxKeyEvent | 156 # event = wxKeyEvent |
165 # set to be called by wxWindows by EVT_CHAR macro in __init__ | 157 # set to be called by wxWindows by EVT_CHAR macro in __init__ |
158 @debugging | |
166 def on_key_up(self, evt): | 159 def on_key_up(self, evt): |
167 self.orpgLog.log("Enter game_tree->on_key_up(self, evt)", ORPG_DEBUG) | |
168 key_code = evt.GetKeyCode() | 160 key_code = evt.GetKeyCode() |
169 if self.dragging and (key_code == wx.WXK_SHIFT): | 161 if self.dragging and (key_code == wx.WXK_SHIFT): |
170 curSelection = self.GetSelection() | 162 curSelection = self.GetSelection() |
171 cur = wx.StockCursor(wx.CURSOR_ARROW) | 163 cur = wx.StockCursor(wx.CURSOR_ARROW) |
172 self.SetCursor(cur) | 164 self.SetCursor(cur) |
175 self.SelectItem(curSelection) | 167 self.SelectItem(curSelection) |
176 if(isinstance(obj,core.node_handler)): | 168 if(isinstance(obj,core.node_handler)): |
177 obj.on_drop(evt) | 169 obj.on_drop(evt) |
178 self.drag_obj = None | 170 self.drag_obj = None |
179 evt.Skip() | 171 evt.Skip() |
180 self.orpgLog.log("Exit game_tree->on_key_up(self, evt)", ORPG_DEBUG) | 172 |
181 | 173 @debugging |
182 def on_char(self, evt): | 174 def on_char(self, evt): |
183 self.orpgLog.log("Enter game_tree->on_char(self, evt)", ORPG_DEBUG) | |
184 key_code = evt.GetKeyCode() | 175 key_code = evt.GetKeyCode() |
185 curSelection = self.GetSelection() # Get the current selection | 176 curSelection = self.GetSelection() # Get the current selection |
186 if evt.ShiftDown() and ((key_code == wx.WXK_UP) or (key_code == wx.WXK_DOWN)) and not self.dragging: | 177 if evt.ShiftDown() and ((key_code == wx.WXK_UP) or (key_code == wx.WXK_DOWN)) and not self.dragging: |
187 curSelection = self.GetSelection() | 178 curSelection = self.GetSelection() |
188 obj = self.GetPyData(curSelection) | 179 obj = self.GetPyData(curSelection) |
192 cur = wx.StockCursor(wx.CURSOR_HAND) | 183 cur = wx.StockCursor(wx.CURSOR_HAND) |
193 self.SetCursor(cur) | 184 self.SetCursor(cur) |
194 self.drag_obj = obj | 185 self.drag_obj = obj |
195 elif key_code == wx.WXK_LEFT: | 186 elif key_code == wx.WXK_LEFT: |
196 self.Collapse(curSelection) | 187 self.Collapse(curSelection) |
197 | |
198 elif key_code == wx.WXK_DELETE: # Handle the delete key | 188 elif key_code == wx.WXK_DELETE: # Handle the delete key |
199 if curSelection: | 189 if curSelection: |
200 nextSelect = self.GetItemParent(curSelection) | 190 nextSelect = self.GetItemParent(curSelection) |
201 self.on_del(evt) | 191 self.on_del(evt) |
202 try: | 192 try: |
206 pass | 196 pass |
207 elif key_code == wx.WXK_F2: | 197 elif key_code == wx.WXK_F2: |
208 self.rename_flag = 1 | 198 self.rename_flag = 1 |
209 self.EditLabel(curSelection) | 199 self.EditLabel(curSelection) |
210 evt.Skip() | 200 evt.Skip() |
211 self.orpgLog.log("Exit game_tree->on_char(self, evt)", ORPG_DEBUG) | 201 |
212 | 202 @debugging |
213 ## locate_valid_tree | 203 def locate_valid_tree(self, error, msg, dir, filename): ## --Snowdog 3/05 |
214 ## GUI based dialogs to locate/fix missing treefile issues --Snowdog 3/05 | |
215 def locate_valid_tree(self, error, msg, dir, filename): | |
216 """prompts the user to locate a new tree file or create a new one""" | 204 """prompts the user to locate a new tree file or create a new one""" |
217 self.orpgLog.log("Enter game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) | |
218 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR) | 205 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR) |
219 if response == wx.YES: | 206 if response == wx.YES: |
220 file = None | 207 file = None |
221 filetypes = "Gametree (*.xml)|*.xml|All files (*.*)|*.*" | 208 filetypes = "Gametree (*.xml)|*.xml|All files (*.*)|*.*" |
222 dlg = wx.FileDialog(self, "Locate Gametree file", dir, filename, filetypes,wx.OPEN | wx.CHANGE_DIR) | 209 dlg = wx.FileDialog(self, "Locate Gametree file", dir, filename, filetypes,wx.OPEN | wx.CHANGE_DIR) |
223 if dlg.ShowModal() == wx.ID_OK: file = dlg.GetPath() | 210 if dlg.ShowModal() == wx.ID_OK: file = dlg.GetPath() |
224 dlg.Destroy() | 211 dlg.Destroy() |
225 if not file: self.load_tree(error=1) | 212 if not file: self.load_tree(error=1) |
226 else: self.load_tree(file) | 213 else: self.load_tree(file) |
227 self.orpgLog.log("Exit game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) | |
228 return | 214 return |
229 else: | 215 else: |
230 self.validate.config_file("tree.xml","default_tree.xml") | 216 self.validate.config_file("tree.xml","default_tree.xml") |
231 self.load_tree(error=1) | 217 self.load_tree(error=1) |
232 self.orpgLog.log("Exit game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) | |
233 return | 218 return |
234 | 219 |
220 @debugging | |
235 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0): | 221 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0): |
236 self.orpgLog.log("Enter game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | |
237 self.settings.set_setting("gametree", filename) | 222 self.settings.set_setting("gametree", filename) |
238 tmp = None | 223 tmp = None |
239 xml_dom = None | 224 xml_dom = None |
240 xml_doc = None | 225 xml_doc = None |
241 try: | 226 try: |
254 "Would you like to locate it?\n"\ | 239 "Would you like to locate it?\n"\ |
255 "(Selecting 'No' will cause a new default gametree to be generated)" | 240 "(Selecting 'No' will cause a new default gametree to be generated)" |
256 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] | 241 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] |
257 self.locate_valid_tree("Gametree Error", emsg, dir_struct["user"], fn) | 242 self.locate_valid_tree("Gametree Error", emsg, dir_struct["user"], fn) |
258 self.orpgLog.log(emsg, ORPG_GENERAL) | 243 self.orpgLog.log(emsg, ORPG_GENERAL) |
259 self.orpgLog.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | |
260 return | 244 return |
261 | 245 |
262 if not xml_dom: | 246 if not xml_dom: |
263 os.rename(filename,filename+".corrupt") | 247 os.rename(filename,filename+".corrupt") |
264 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] | 248 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] |
270 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\ | 254 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\ |
271 "Would you like to select a different gametree file to use?\n"\ | 255 "Would you like to select a different gametree file to use?\n"\ |
272 "(Selecting 'No' will cause a new default gametree to be generated)" | 256 "(Selecting 'No' will cause a new default gametree to be generated)" |
273 self.locate_valid_tree("Corrupt Gametree!", emsg, dir_struct["user"], fn) | 257 self.locate_valid_tree("Corrupt Gametree!", emsg, dir_struct["user"], fn) |
274 self.orpgLog.log(emsg, ORPG_GENERAL) | 258 self.orpgLog.log(emsg, ORPG_GENERAL) |
275 self.orpgLog.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | |
276 return | 259 return |
277 | 260 |
278 if xml_dom._get_tagName() != "gametree": | 261 if xml_dom._get_tagName() != "gametree": |
279 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] | 262 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] |
280 emsg = fn+" does not appear to be a valid gametree file.\n\n"\ | 263 emsg = fn+" does not appear to be a valid gametree file.\n\n"\ |
321 self.orpgLog.log(traceback.format_exc(), ORPG_GENERAL) | 304 self.orpgLog.log(traceback.format_exc(), ORPG_GENERAL) |
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.") | 305 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.") |
323 os.rename(filename,filename+".corrupt") | 306 os.rename(filename,filename+".corrupt") |
324 self.validate.config_file("tree.xml","default_tree.xml") | 307 self.validate.config_file("tree.xml","default_tree.xml") |
325 self.load_tree(error=1) | 308 self.load_tree(error=1) |
326 self.orpgLog.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | 309 |
327 | 310 @debugging |
328 def build_std_menu(self, obj=None): | 311 def build_std_menu(self, obj=None): |
329 self.orpgLog.log("Enter game_tree->build_std_menu(self, obj)", ORPG_DEBUG) | |
330 | |
331 # build useful menu | 312 # build useful menu |
332 useful_menu = wx.Menu() | 313 useful_menu = wx.Menu() |
333 useful_menu.Append(STD_MENU_NODE_USEFUL,"Use&ful") | 314 useful_menu.Append(STD_MENU_NODE_USEFUL,"Use&ful") |
334 useful_menu.Append(STD_MENU_NODE_USELESS,"Use&less") | 315 useful_menu.Append(STD_MENU_NODE_USELESS,"Use&less") |
335 useful_menu.Append(STD_MENU_NODE_INDIFFERENT,"&Indifferent") | 316 useful_menu.Append(STD_MENU_NODE_INDIFFERENT,"&Indifferent") |
317 | |
336 # build standard menu | 318 # build standard menu |
337 self.std_menu = wx.Menu() | 319 self.std_menu = wx.Menu() |
338 self.std_menu.SetTitle("game tree") | 320 self.std_menu.SetTitle("game tree") |
339 self.std_menu.Append(STD_MENU_USE,"&Use") | 321 self.std_menu.Append(STD_MENU_USE,"&Use") |
340 self.std_menu.Append(STD_MENU_DESIGN,"&Design") | 322 self.std_menu.Append(STD_MENU_DESIGN,"&Design") |
384 self.Bind(wx.EVT_MENU, self.on_save_tree_as, id=TOP_SAVE_TREE_AS) | 366 self.Bind(wx.EVT_MENU, self.on_save_tree_as, id=TOP_SAVE_TREE_AS) |
385 self.Bind(wx.EVT_MENU, self.on_save_tree, id=TOP_SAVE_TREE) | 367 self.Bind(wx.EVT_MENU, self.on_save_tree, id=TOP_SAVE_TREE) |
386 self.Bind(wx.EVT_MENU, self.on_load_new_tree, id=TOP_NEW_TREE) | 368 self.Bind(wx.EVT_MENU, self.on_load_new_tree, id=TOP_NEW_TREE) |
387 self.Bind(wx.EVT_MENU, self.on_tree_prop, id=TOP_TREE_PROP) | 369 self.Bind(wx.EVT_MENU, self.on_tree_prop, id=TOP_TREE_PROP) |
388 self.Bind(wx.EVT_MENU, self.on_insert_features, id=TOP_FEATURES) | 370 self.Bind(wx.EVT_MENU, self.on_insert_features, id=TOP_FEATURES) |
389 self.orpgLog.log("Exit game_tree->build_std_menu(self, obj)", ORPG_DEBUG) | 371 |
390 | 372 @debugging |
391 def do_std_menu(self, evt, obj): | 373 def do_std_menu(self, evt, obj): |
392 self.orpgLog.log("Enter game_tree->do_std_menu(self, evt, obj)", ORPG_DEBUG) | 374 try: self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu()) |
393 try: | 375 except: self.std_menu.Enable(STD_MENU_MAP, obj.map_aware()) |
394 self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu()) | |
395 except: | |
396 self.std_menu.Enable(STD_MENU_MAP, obj.map_aware()) | |
397 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone()) | 376 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone()) |
398 self.PopupMenu(self.std_menu) | 377 self.PopupMenu(self.std_menu) |
399 self.orpgLog.log("Exit game_tree->do_std_menu(self, evt, obj)", ORPG_DEBUG) | 378 |
400 | 379 @debugging |
401 def strip_html(self, player): | 380 def strip_html(self, player): |
402 self.orpgLog.log("Enter game_tree->strip_html(self, player)", ORPG_DEBUG) | |
403 ret_string = "" | 381 ret_string = "" |
404 x = 0 | 382 x = 0 |
405 in_tag = 0 | 383 in_tag = 0 |
406 for x in xrange(len(player[0])) : | 384 for x in xrange(len(player[0])) : |
407 if player[0][x] == "<" or player[0][x] == ">" or in_tag == 1 : | 385 if player[0][x] == "<" or player[0][x] == ">" or in_tag == 1 : |
412 else : | 390 else : |
413 pass | 391 pass |
414 else : | 392 else : |
415 ret_string = ret_string + player[0][x] | 393 ret_string = ret_string + player[0][x] |
416 self.orpgLog.log(ret_string, ORPG_DEBUG) | 394 self.orpgLog.log(ret_string, ORPG_DEBUG) |
417 self.orpgLog.log("Exit game_tree->strip_html(self, player)", ORPG_DEBUG) | |
418 return ret_string | 395 return ret_string |
419 | 396 |
397 @debugging | |
420 def on_receive_data(self, data, player): | 398 def on_receive_data(self, data, player): |
421 self.orpgLog.log("Enter game_tree->on_receive_data(self, data, player)", ORPG_DEBUG) | |
422 beg = string.find(data,"<tree>") | 399 beg = string.find(data,"<tree>") |
423 end = string.rfind(data,"</tree>") | 400 end = string.rfind(data,"</tree>") |
424 data = data[6:end] | 401 data = data[6:end] |
425 self.insert_xml(data) | 402 self.insert_xml(data) |
426 self.orpgLog.log("Exit game_tree->on_receive_data(self, data, player)", ORPG_DEBUG) | 403 |
427 | 404 @debugging |
428 def on_send_to_chat(self, evt): | 405 def on_send_to_chat(self, evt): |
429 self.orpgLog.log("Enter game_tree->on_send_to_chat(self, evt)", ORPG_DEBUG) | |
430 item = self.GetSelection() | 406 item = self.GetSelection() |
431 obj = self.GetPyData(item) | 407 obj = self.GetPyData(item) |
432 obj.on_send_to_chat(evt) | 408 obj.on_send_to_chat(evt) |
433 self.orpgLog.log("Exit game_tree->on_send_to_chat(self, evt)", ORPG_DEBUG) | 409 |
434 | 410 @debugging |
435 def on_whisper_to(self, evt): | 411 def on_whisper_to(self, evt): |
436 self.orpgLog.log("Enter game_tree->on_whisper_to(self, evt)", ORPG_DEBUG) | |
437 players = self.session.get_players() | 412 players = self.session.get_players() |
438 opts = [] | 413 opts = [] |
439 myid = self.session.get_id() | 414 myid = self.session.get_id() |
440 me = None | 415 me = None |
441 for p in players: | 416 for p in players: |
456 else: | 431 else: |
457 player_ids = [] | 432 player_ids = [] |
458 for s in selections: | 433 for s in selections: |
459 player_ids.append(players[s][2]) | 434 player_ids.append(players[s][2]) |
460 self.chat.whisper_to_players(obj.tohtml(),player_ids) | 435 self.chat.whisper_to_players(obj.tohtml(),player_ids) |
461 self.orpgLog.log("Exit game_tree->on_whisper_to(self, evt)", ORPG_DEBUG) | 436 |
462 | 437 @debugging |
463 def on_export_html(self, evt): | 438 def on_export_html(self, evt): |
464 self.orpgLog.log("Enter game_tree->on_export_html(self, evt)", ORPG_DEBUG) | |
465 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE) | 439 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE) |
466 if f.ShowModal() == wx.ID_OK: | 440 if f.ShowModal() == wx.ID_OK: |
467 item = self.GetSelection() | 441 item = self.GetSelection() |
468 obj = self.GetPyData(item) | 442 obj = self.GetPyData(item) |
469 type = f.GetFilterIndex() | 443 type = f.GetFilterIndex() |
474 data = data.replace(tag,tag+"\n") | 448 data = data.replace(tag,tag+"\n") |
475 file.write(data) | 449 file.write(data) |
476 file.close() | 450 file.close() |
477 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | 451 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) |
478 f.Destroy() | 452 f.Destroy() |
479 os.chdir(self.root_dir) | 453 os.chdir(dir_struct["home"]) |
480 self.orpgLog.log("Exit game_tree->on_export_html(self, evt)", ORPG_DEBUG) | 454 |
481 | 455 @debugging |
482 def indifferent(self, evt): | 456 def indifferent(self, evt): |
483 self.orpgLog.log("Enter game_tree->indifferent(self, evt)", ORPG_DEBUG) | |
484 item = self.GetSelection() | 457 item = self.GetSelection() |
485 obj = self.GetPyData(item) | 458 obj = self.GetPyData(item) |
486 obj.usefulness("indifferent") | 459 obj.usefulness("indifferent") |
487 self.orpgLog.log("Exit game_tree->indifferent(self, evt)", ORPG_DEBUG) | 460 |
488 | 461 @debugging |
489 def useful(self, evt): | 462 def useful(self, evt): |
490 self.orpgLog.log("Enter game_tree->useful(self, evt)", ORPG_DEBUG) | |
491 item = self.GetSelection() | 463 item = self.GetSelection() |
492 obj = self.GetPyData(item) | 464 obj = self.GetPyData(item) |
493 obj.usefulness("useful") | 465 obj.usefulness("useful") |
494 self.orpgLog.log("Exit game_tree->useful(self, evt)", ORPG_DEBUG) | 466 |
495 | 467 @debugging |
496 def useless(self, evt): | 468 def useless(self, evt): |
497 self.orpgLog.log("Enter game_tree->useless(self, evt)", ORPG_DEBUG) | |
498 item = self.GetSelection() | 469 item = self.GetSelection() |
499 obj = self.GetPyData(item) | 470 obj = self.GetPyData(item) |
500 obj.usefulness("useless") | 471 obj.usefulness("useless") |
501 self.orpgLog.log("Exit game_tree->useless(self, evt)", ORPG_DEBUG) | 472 |
502 | 473 @debugging |
503 def on_email(self,evt): | 474 def on_email(self,evt): |
504 pass | 475 pass |
505 | 476 |
477 @debugging | |
506 def on_send_to(self, evt): | 478 def on_send_to(self, evt): |
507 self.orpgLog.log("Enter game_tree->on_send_to(self, evt)", ORPG_DEBUG) | |
508 players = self.session.get_players() | 479 players = self.session.get_players() |
509 opts = [] | 480 opts = [] |
510 myid = self.session.get_id() | 481 myid = self.session.get_id() |
511 me = None | 482 me = None |
512 for p in players: | 483 for p in players: |
526 self.session.send(xmldata) | 497 self.session.send(xmldata) |
527 else: | 498 else: |
528 for s in selections: | 499 for s in selections: |
529 self.session.send(xmldata,players[s][2]) | 500 self.session.send(xmldata,players[s][2]) |
530 dlg.Destroy() | 501 dlg.Destroy() |
531 self.orpgLog.log("Exit game_tree->on_send_to(self, evt)", ORPG_DEBUG) | 502 |
532 | 503 @debugging |
533 def on_icon(self, evt): | 504 def on_icon(self, evt): |
534 self.orpgLog.log("Enter game_tree->on_icon(self, evt)", ORPG_DEBUG) | |
535 icons = self.icons.keys() | 505 icons = self.icons.keys() |
536 icons.sort() | 506 icons.sort() |
537 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons) | 507 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons) |
538 if dlg.ShowModal() == wx.ID_OK: | 508 if dlg.ShowModal() == wx.ID_OK: |
539 key = dlg.GetStringSelection() | 509 key = dlg.GetStringSelection() |
540 item = self.GetSelection() | 510 item = self.GetSelection() |
541 obj = self.GetPyData(item) | 511 obj = self.GetPyData(item) |
542 obj.change_icon(key) | 512 obj.change_icon(key) |
543 dlg.Destroy() | 513 dlg.Destroy() |
544 self.orpgLog.log("Exit game_tree->on_icon(self, evt)", ORPG_DEBUG) | 514 |
545 | 515 @debugging |
546 def on_wizard(self, evt): | 516 def on_wizard(self, evt): |
547 self.orpgLog.log("Enter game_tree->on_wizard(self, evt)", ORPG_DEBUG) | |
548 item = self.GetSelection() | 517 item = self.GetSelection() |
549 obj = self.GetPyData(item) | 518 obj = self.GetPyData(item) |
550 name = "New " + obj.master_dom.getAttribute("name") | 519 name = "New " + obj.master_dom.getAttribute("name") |
551 icon = obj.master_dom.getAttribute("icon") | 520 icon = obj.master_dom.getAttribute("icon") |
552 xml_data = "<nodehandler name=\""+name+"\" icon=\"" + icon + "\" module=\"core\" class=\"node_loader\" >" | 521 xml_data = "<nodehandler name=\""+name+"\" icon=\"" + icon + "\" module=\"core\" class=\"node_loader\" >" |
553 xml_data += self.xml.toxml(obj) | 522 xml_data += self.xml.toxml(obj) |
554 xml_data += "</nodehandler>" | 523 xml_data += "</nodehandler>" |
555 self.insert_xml(xml_data) | 524 self.insert_xml(xml_data) |
556 self.orpgLog.log(xml_data, ORPG_DEBUG) | 525 self.orpgLog.log(xml_data, ORPG_DEBUG) |
557 self.orpgLog.log("Exit game_tree->on_wizard(self, evt)", ORPG_DEBUG) | 526 |
558 | 527 @debugging |
559 def on_clone(self, evt): | 528 def on_clone(self, evt): |
560 self.orpgLog.log("Enter game_tree->on_clone(self, evt)", ORPG_DEBUG) | |
561 item = self.GetSelection() | 529 item = self.GetSelection() |
562 obj = self.GetPyData(item) | 530 obj = self.GetPyData(item) |
563 if obj.can_clone(): | 531 if obj.can_clone(): |
564 parent_node = self.GetItemParent(item) | 532 parent_node = self.GetItemParent(item) |
565 prev_sib = self.GetPrevSibling(item) | 533 prev_sib = self.GetPrevSibling(item) |
568 xml_dom = self.xml.parseXml(self.xml.toxml(obj)) | 536 xml_dom = self.xml.parseXml(self.xml.toxml(obj)) |
569 xml_dom = xml_dom._get_firstChild() | 537 xml_dom = xml_dom._get_firstChild() |
570 parent = obj.master_dom._get_parentNode() | 538 parent = obj.master_dom._get_parentNode() |
571 xml_dom = parent.insertBefore(xml_dom, obj.master_dom) | 539 xml_dom = parent.insertBefore(xml_dom, obj.master_dom) |
572 self.load_xml(xml_dom, parent_node, prev_sib) | 540 self.load_xml(xml_dom, parent_node, prev_sib) |
573 self.orpgLog.log("Exit game_tree->on_clone(self, evt)", ORPG_DEBUG) | 541 |
574 | 542 @debugging |
575 def on_save(self, evt): | 543 def on_save(self, evt): |
576 """save node to a xml file""" | 544 """save node to a xml file""" |
577 self.orpgLog.log("Enter game_tree->on_save(self, evt)", ORPG_DEBUG) | |
578 item = self.GetSelection() | 545 item = self.GetSelection() |
579 obj = self.GetPyData(item) | 546 obj = self.GetPyData(item) |
580 obj.on_save(evt) | 547 obj.on_save(evt) |
581 os.chdir(self.root_dir) | 548 os.chdir(dir_struct["home"]) |
582 self.orpgLog.log("Exit game_tree->on_save(self, evt)", ORPG_DEBUG) | 549 |
583 | 550 @debugging |
584 def on_save_tree_as(self, evt): | 551 def on_save_tree_as(self, evt): |
585 self.orpgLog.log("Enter game_tree->on_save_tree_as(self, evt)", ORPG_DEBUG) | |
586 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.SAVE) | 552 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.SAVE) |
587 if f.ShowModal() == wx.ID_OK: | 553 if f.ShowModal() == wx.ID_OK: |
588 self.save_tree(f.GetPath()) | 554 self.save_tree(f.GetPath()) |
589 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | 555 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) |
590 f.Destroy() | 556 f.Destroy() |
591 os.chdir(self.root_dir) | 557 os.chdir(dir_struct["home"]) |
592 self.orpgLog.log("Exit game_tree->on_save_tree_as(self, evt)", ORPG_DEBUG) | 558 |
593 | 559 @debugging |
594 def on_save_tree(self, evt=None): | 560 def on_save_tree(self, evt=None): |
595 self.orpgLog.log("Enter game_tree->on_save_tree(self, evt)", ORPG_DEBUG) | |
596 filename = self.settings.get_setting("gametree") | 561 filename = self.settings.get_setting("gametree") |
597 self.save_tree(filename) | 562 self.save_tree(filename) |
598 self.orpgLog.log("Exit game_tree->on_save_tree(self, evt)", ORPG_DEBUG) | 563 |
599 | 564 @debugging |
600 def save_tree(self, filename=dir_struct["user"]+'tree.xml'): | 565 def save_tree(self, filename=dir_struct["user"]+'tree.xml'): |
601 self.orpgLog.log("Enter game_tree->save_tree(self, filename)", ORPG_DEBUG) | |
602 self.master_dom.setAttribute("version",GAMETREE_VERSION) | 566 self.master_dom.setAttribute("version",GAMETREE_VERSION) |
603 self.settings.set_setting("gametree",filename) | 567 self.settings.set_setting("gametree",filename) |
604 file = open(filename,"w") | 568 file = open(filename,"w") |
605 file.write(self.xml.toxml(self.master_dom,1)) | 569 file.write(self.xml.toxml(self.master_dom,1)) |
606 file.close() | 570 file.close() |
607 self.orpgLog.log("Exit game_tree->save_tree(self, filename)", ORPG_DEBUG) | 571 |
608 | 572 @debugging |
609 def on_load_new_tree(self, evt): | 573 def on_load_new_tree(self, evt): |
610 self.orpgLog.log("Enter game_tree->on_load_new_tree(self, evt)", ORPG_DEBUG) | |
611 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) | 574 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) |
612 if f.ShowModal() == wx.ID_OK: | 575 if f.ShowModal() == wx.ID_OK: |
613 self.load_tree(f.GetPath()) | 576 self.load_tree(f.GetPath()) |
614 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | 577 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) |
615 f.Destroy() | 578 f.Destroy() |
616 os.chdir(self.root_dir) | 579 os.chdir(dir_struct["home"]) |
617 self.orpgLog.log("Exit game_tree->on_load_new_tree(self, evt)", ORPG_DEBUG) | 580 |
618 | 581 @debugging |
619 def on_insert_file(self, evt): | 582 def on_insert_file(self, evt): |
620 """loads xml file into the tree""" | 583 """loads xml file into the tree""" |
621 self.orpgLog.log("Enter game_tree->on_insert_file(self, evt)", ORPG_DEBUG) | |
622 if self.last_save_dir == ".": | 584 if self.last_save_dir == ".": |
623 self.last_save_dir = dir_struct["user"] | 585 self.last_save_dir = dir_struct["user"] |
624 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) | 586 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) |
625 if f.ShowModal() == wx.ID_OK: | 587 if f.ShowModal() == wx.ID_OK: |
626 self.insert_xml(open(f.GetPath(),"r").read()) | 588 self.insert_xml(open(f.GetPath(),"r").read()) |
627 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | 589 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) |
628 f.Destroy() | 590 f.Destroy() |
629 os.chdir(self.root_dir) | 591 os.chdir(dir_struct["home"]) |
630 self.orpgLog.log("Exit game_tree->on_insert_file(self, evt)", ORPG_DEBUG) | 592 |
631 | 593 @debugging |
632 def on_insert_url(self, evt): | 594 def on_insert_url(self, evt): |
633 """loads xml url into the tree""" | 595 """loads xml url into the tree""" |
634 self.orpgLog.log("Enter game_tree->on_insert_url(self, evt)", ORPG_DEBUG) | |
635 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://") | 596 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://") |
636 if dlg.ShowModal() == wx.ID_OK: | 597 if dlg.ShowModal() == wx.ID_OK: |
637 path = dlg.GetValue() | 598 path = dlg.GetValue() |
638 file = urllib.urlopen(path) | 599 file = urllib.urlopen(path) |
639 self.insert_xml(file.read()) | 600 self.insert_xml(file.read()) |
640 dlg.Destroy() | 601 dlg.Destroy() |
641 self.orpgLog.log("Exit game_tree->on_insert_url(self, evt)", ORPG_DEBUG) | 602 |
642 | 603 @debugging |
643 def on_insert_features(self, evt): | 604 def on_insert_features(self, evt): |
644 self.orpgLog.log("Enter game_tree->on_insert_features(self, evt)", ORPG_DEBUG) | |
645 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read()) | 605 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read()) |
646 self.orpgLog.log("Exit game_tree->on_insert_features(self, evt)", ORPG_DEBUG) | 606 |
647 | 607 @debugging |
648 def on_tree_prop(self, evt): | 608 def on_tree_prop(self, evt): |
649 self.orpgLog.log("Enter game_tree->on_tree_prop(self, evt)", ORPG_DEBUG) | |
650 dlg = gametree_prop_dlg(self, self.settings) | 609 dlg = gametree_prop_dlg(self, self.settings) |
651 if dlg.ShowModal() == wx.ID_OK: | 610 if dlg.ShowModal() == wx.ID_OK: |
652 pass | 611 pass |
653 dlg.Destroy() | 612 dlg.Destroy() |
654 self.orpgLog.log("Exit game_tree->on_tree_prop(self, evt)", ORPG_DEBUG) | 613 |
655 | 614 @debugging |
656 def on_node_design(self, evt): | 615 def on_node_design(self, evt): |
657 self.orpgLog.log("Enter game_tree->on_node_design(self, evt)", ORPG_DEBUG) | |
658 | |
659 item = self.GetSelection() | 616 item = self.GetSelection() |
660 obj = self.GetPyData(item) | 617 obj = self.GetPyData(item) |
661 obj.on_design(evt) | 618 obj.on_design(evt) |
662 | 619 |
663 self.orpgLog.log("Exit game_tree->on_node_design(self, evt)", ORPG_DEBUG) | 620 @debugging |
664 | |
665 def on_node_use(self, evt): | 621 def on_node_use(self, evt): |
666 self.orpgLog.log("Enter game_tree->on_node_use(self, evt)", ORPG_DEBUG) | |
667 | |
668 item = self.GetSelection() | 622 item = self.GetSelection() |
669 obj = self.GetPyData(item) | 623 obj = self.GetPyData(item) |
670 obj.on_use(evt) | 624 obj.on_use(evt) |
671 | 625 |
672 self.orpgLog.log("Exit game_tree->on_node_use(self, evt)", ORPG_DEBUG) | 626 @debugging |
673 | |
674 def on_node_pp(self, evt): | 627 def on_node_pp(self, evt): |
675 self.orpgLog.log("Enter game_tree->on_node_pp(self, evt)", ORPG_DEBUG) | |
676 | |
677 item = self.GetSelection() | 628 item = self.GetSelection() |
678 obj = self.GetPyData(item) | 629 obj = self.GetPyData(item) |
679 obj.on_html_view(evt) | 630 obj.on_html_view(evt) |
680 | 631 |
681 self.orpgLog.log("Exit game_tree->on_node_pp(self, evt)", ORPG_DEBUG) | 632 @debugging |
682 | |
683 def on_del(self, evt): | 633 def on_del(self, evt): |
684 self.orpgLog.log("Enter game_tree->on_del(self, evt)", ORPG_DEBUG) | |
685 status_value = "none" | 634 status_value = "none" |
686 try: | 635 try: |
687 item = self.GetSelection() | 636 item = self.GetSelection() |
688 if item: | 637 if item: |
689 obj = self.GetPyData(item) | 638 obj = self.GetPyData(item) |
720 else: | 669 else: |
721 msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK) | 670 msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK) |
722 msg.ShowModal() | 671 msg.ShowModal() |
723 msg.Destroy() | 672 msg.Destroy() |
724 | 673 |
725 self.orpgLog.log("Exit game_tree->on_del(self, evt)", ORPG_DEBUG) | 674 @debugging |
726 | |
727 def on_about(self, evt): | 675 def on_about(self, evt): |
728 self.orpgLog.log("Enter game_tree->on_about(self, evt)", ORPG_DEBUG) | |
729 | |
730 item = self.GetSelection() | 676 item = self.GetSelection() |
731 obj = self.GetPyData(item) | 677 obj = self.GetPyData(item) |
732 about = MyAboutBox(self,obj.about()) | 678 about = MyAboutBox(self,obj.about()) |
733 about.ShowModal() | 679 about.ShowModal() |
734 about.Destroy() | 680 about.Destroy() |
735 | 681 |
736 self.orpgLog.log("Exit game_tree->on_about(self, evt)", ORPG_DEBUG) | 682 @debugging |
737 | |
738 def on_send_to_map(self, evt): | 683 def on_send_to_map(self, evt): |
739 self.orpgLog.log("Enter game_tree->on_send_to_map(self, evt)", ORPG_DEBUG) | |
740 | |
741 item = self.GetSelection() | 684 item = self.GetSelection() |
742 obj = self.GetPyData(item) | 685 obj = self.GetPyData(item) |
743 if hasattr(obj,"on_send_to_map"): | 686 if hasattr(obj,"on_send_to_map"): |
744 obj.on_send_to_map(evt) | 687 obj.on_send_to_map(evt) |
745 | 688 |
746 self.orpgLog.log("Exit game_tree->on_send_to_map(self, evt)", ORPG_DEBUG) | 689 @debugging |
747 | |
748 def insert_xml(self, txt): | 690 def insert_xml(self, txt): |
749 self.orpgLog.log("Enter game_tree->insert_xml(self, txt)", ORPG_DEBUG) | 691 self.orpgLog.log("Enter game_tree->insert_xml(self, txt)", ORPG_DEBUG) |
750 #Updated to allow safe merging of gametree files | 692 #Updated to allow safe merging of gametree files |
751 #without leaving an unusable and undeletable node. | 693 #without leaving an unusable and undeletable node. |
752 # -- Snowdog 8/03 | 694 # -- Snowdog 8/03 |
779 | 721 |
780 xml_dom = xml_dom._get_firstChild() | 722 xml_dom = xml_dom._get_firstChild() |
781 child = self.master_dom._get_firstChild() | 723 child = self.master_dom._get_firstChild() |
782 xml_dom = self.master_dom.insertBefore(xml_dom,child) | 724 xml_dom = self.master_dom.insertBefore(xml_dom,child) |
783 self.load_xml(xml_dom,self.root,self.root) | 725 self.load_xml(xml_dom,self.root,self.root) |
784 self.orpgLog.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | 726 |
785 | 727 @debugging |
786 def build_img_list(self): | 728 def build_img_list(self): |
787 """make image list""" | 729 """make image list""" |
788 self.orpgLog.log("Enter game_tree->build_img_list(self)", ORPG_DEBUG) | |
789 helper = img_helper() | 730 helper = img_helper() |
790 self.icons = { } | 731 self.icons = { } |
791 self._imageList= wx.ImageList(16,16,False) | 732 self._imageList= wx.ImageList(16,16,False) |
792 man = open(dir_struct["icon"]+"icons.xml","r") | 733 man = open(dir_struct["icon"]+"icons.xml","r") |
793 xml_dom = self.xml.parseXml(man.read()) | 734 xml_dom = self.xml.parseXml(man.read()) |
798 key = n.getAttribute("name") | 739 key = n.getAttribute("name") |
799 path = dir_struct["icon"] + n.getAttribute("file") | 740 path = dir_struct["icon"] + n.getAttribute("file") |
800 img = helper.load_file(path) | 741 img = helper.load_file(path) |
801 self.icons[key] = self._imageList.Add(img) | 742 self.icons[key] = self._imageList.Add(img) |
802 self.SetImageList(self._imageList) | 743 self.SetImageList(self._imageList) |
803 self.orpgLog.log("Exit game_tree->build_img_list(self)", ORPG_DEBUG) | 744 |
804 | 745 @debugging |
805 def load_xml(self, xml_dom, parent_node, prev_node=None): | 746 def load_xml(self, xml_dom, parent_node, prev_node=None): |
806 self.orpgLog.log("Enter game_tree->load_xml(self, xml_dom, parent_node, prev_node)", ORPG_DEBUG) | |
807 #add the first tree node | 747 #add the first tree node |
808 i = 0 | 748 i = 0 |
809 text = xml_dom.getAttribute("name") | 749 text = xml_dom.getAttribute("name") |
810 icon = xml_dom.getAttribute("icon") | 750 icon = xml_dom.getAttribute("icon") |
811 if self.icons.has_key(icon): | 751 if self.icons.has_key(icon): |
838 self.cached_load_of_image(bmp,new_tree_node,) | 778 self.cached_load_of_image(bmp,new_tree_node,) |
839 self.orpgLog.log("Node Icon loaded", ORPG_DEBUG) | 779 self.orpgLog.log("Node Icon loaded", ORPG_DEBUG) |
840 self.id = self.id + 1 | 780 self.id = self.id + 1 |
841 except Exception, er: | 781 except Exception, er: |
842 self.orpgLog.log(traceback.format_exc(), ORPG_GENERAL) | 782 self.orpgLog.log(traceback.format_exc(), ORPG_GENERAL) |
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.) | 783 #self.orpgLog.log("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), ORPG_GENERAL, True)?indent? |
844 self.orpgLog.log("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), ORPG_GENERAL, True) | |
845 self.Delete(new_tree_node) | 784 self.Delete(new_tree_node) |
846 parent = xml_dom._get_parentNode() | 785 parent = xml_dom._get_parentNode() |
847 parent.removeChild(xml_dom) | 786 parent.removeChild(xml_dom) |
848 #wx.EndBusyCursor() | |
849 self.orpgLog.log("Exit game_tree->load_xml(self, xml_dom, parent_node, prev_node)", ORPG_DEBUG) | |
850 return new_tree_node | 787 return new_tree_node |
851 | 788 |
789 @debugging | |
852 def cached_load_of_image(self, bmp_in, new_tree_node): | 790 def cached_load_of_image(self, bmp_in, new_tree_node): |
853 self.orpgLog.log("Enter game_tree->cached_load_of_image(self, bmp_in, new_tree_node)", ORPG_DEBUG) | |
854 image_list = self.GetImageList() | 791 image_list = self.GetImageList() |
855 img = wx.ImageFromBitmap(bmp_in) | 792 img = wx.ImageFromBitmap(bmp_in) |
856 img_data = img.GetData() | 793 img_data = img.GetData() |
857 image_index = None | 794 image_index = None |
858 for key in self.image_cache.keys(): | 795 for key in self.image_cache.keys(): |
863 if image_index is None: | 800 if image_index is None: |
864 image_index = image_list.Add(bmp_in) | 801 image_index = image_list.Add(bmp_in) |
865 self.image_cache[image_index] = img_data | 802 self.image_cache[image_index] = img_data |
866 self.SetItemImage(new_tree_node,image_index) | 803 self.SetItemImage(new_tree_node,image_index) |
867 self.SetItemImage(new_tree_node,image_index, wx.TreeItemIcon_Selected) | 804 self.SetItemImage(new_tree_node,image_index, wx.TreeItemIcon_Selected) |
868 self.orpgLog.log("Exit game_tree->cached_load_of_image(self, bmp_in, new_tree_node)", ORPG_DEBUG) | |
869 return image_index | 805 return image_index |
870 | 806 |
871 | 807 @debugging |
872 def on_rclick(self, evt): | 808 def on_rclick(self, evt): |
873 self.orpgLog.log("Enter game_tree->on_rclick(self, evt)", ORPG_DEBUG) | |
874 pt = evt.GetPosition() | 809 pt = evt.GetPosition() |
875 (item, flag) = self.HitTest(pt) | 810 (item, flag) = self.HitTest(pt) |
876 if item.IsOk(): | 811 if item.IsOk(): |
877 obj = self.GetPyData(item) | 812 obj = self.GetPyData(item) |
878 self.SelectItem(item) | 813 self.SelectItem(item) |
880 obj.on_rclick(evt) | 815 obj.on_rclick(evt) |
881 else: | 816 else: |
882 self.PopupMenu(self.top_menu) | 817 self.PopupMenu(self.top_menu) |
883 else: | 818 else: |
884 self.PopupMenu(self.top_menu,pt) | 819 self.PopupMenu(self.top_menu,pt) |
885 self.orpgLog.log("Exit game_tree->on_rclick(self, evt)", ORPG_DEBUG) | 820 |
886 | 821 @debugging |
887 def on_ldclick(self, evt): | 822 def on_ldclick(self, evt): |
888 self.orpgLog.log("Enter game_tree->on_ldclick(self, evt)", ORPG_DEBUG) | |
889 self.rename_flag = 0 | 823 self.rename_flag = 0 |
890 pt = evt.GetPosition() | 824 pt = evt.GetPosition() |
891 (item, flag) = self.HitTest(pt) | 825 (item, flag) = self.HitTest(pt) |
892 if item.IsOk(): | 826 if item.IsOk(): |
893 obj = self.GetPyData(item) | 827 obj = self.GetPyData(item) |
901 obj.on_design(evt) | 835 obj.on_design(evt) |
902 elif action == "print": | 836 elif action == "print": |
903 obj.on_html_view(evt) | 837 obj.on_html_view(evt) |
904 elif action == "chat": | 838 elif action == "chat": |
905 self.on_send_to_chat(evt) | 839 self.on_send_to_chat(evt) |
906 self.orpgLog.log("Exit game_tree->on_ldclick(self, evt)", ORPG_DEBUG) | 840 |
907 | 841 @debugging |
908 def on_left_down(self, evt): | 842 def on_left_down(self, evt): |
909 self.orpgLog.log("Enter game_tree->on_left_down(self, evt)", ORPG_DEBUG) | |
910 pt = evt.GetPosition() | 843 pt = evt.GetPosition() |
911 (item, flag) = self.HitTest(pt) | 844 (item, flag) = self.HitTest(pt) |
912 if item.IsOk() and self.was_labeling: | 845 if item.IsOk() and self.was_labeling: |
913 self.SelectItem(item) | 846 self.SelectItem(item) |
914 self.rename_flag = 0 | 847 self.rename_flag = 0 |
917 # this next if tests to ensure that the mouse up occurred over a label, and not the icon | 850 # this next if tests to ensure that the mouse up occurred over a label, and not the icon |
918 self.rename_flag = 1 | 851 self.rename_flag = 1 |
919 else: | 852 else: |
920 self.SelectItem(item) | 853 self.SelectItem(item) |
921 evt.Skip() | 854 evt.Skip() |
922 self.orpgLog.log("Exit game_tree->on_left_down(self, evt)", ORPG_DEBUG) | 855 |
923 | 856 @debugging |
924 def on_left_up(self, evt): | 857 def on_left_up(self, evt): |
925 self.orpgLog.log("Enter game_tree->on_left_up(self, evt)", ORPG_DEBUG) | |
926 if self.dragging: | 858 if self.dragging: |
927 cur = wx.StockCursor(wx.CURSOR_ARROW) | 859 cur = wx.StockCursor(wx.CURSOR_ARROW) |
928 self.SetCursor(cur) | 860 self.SetCursor(cur) |
929 self.dragging = False | 861 self.dragging = False |
930 pt = evt.GetPosition() | 862 pt = evt.GetPosition() |
933 obj = self.GetPyData(item) | 865 obj = self.GetPyData(item) |
934 self.SelectItem(item) | 866 self.SelectItem(item) |
935 if(isinstance(obj,core.node_handler)): | 867 if(isinstance(obj,core.node_handler)): |
936 obj.on_drop(evt) | 868 obj.on_drop(evt) |
937 self.drag_obj = None | 869 self.drag_obj = None |
938 self.orpgLog.log("Exit game_tree->on_left_up(self, evt)", ORPG_DEBUG) | 870 |
939 | 871 @debugging |
940 def on_label_change(self, evt): | 872 def on_label_change(self, evt): |
941 self.orpgLog.log("Enter game_tree->on_label_change(self, evt)", ORPG_DEBUG) | |
942 item = evt.GetItem() | 873 item = evt.GetItem() |
943 txt = evt.GetLabel() | 874 txt = evt.GetLabel() |
944 self.was_labeling = 0 | 875 self.was_labeling = 0 |
945 self.rename_flag = 0 | 876 self.rename_flag = 0 |
946 if txt != "": | 877 if txt != "": |
947 obj = self.GetPyData(item) | 878 obj = self.GetPyData(item) |
948 obj.master_dom.setAttribute('name',txt) | 879 obj.master_dom.setAttribute('name',txt) |
949 else: | 880 else: |
950 evt.Veto() | 881 evt.Veto() |
951 self.orpgLog.log("Exit game_tree->on_label_change(self, evt)", ORPG_DEBUG) | 882 |
952 | 883 @debugging |
953 def on_label_begin(self, evt): | 884 def on_label_begin(self, evt): |
954 self.orpgLog.log("Enter game_tree->on_label_begin(self, evt)", ORPG_DEBUG) | |
955 if not self.rename_flag: | 885 if not self.rename_flag: |
956 evt.Veto() | 886 evt.Veto() |
957 else: | 887 else: |
958 self.was_labeling = 1 | 888 self.was_labeling = 1 |
959 item = evt.GetItem() | 889 item = evt.GetItem() |
960 if item == self.GetRootItem(): | 890 if item == self.GetRootItem(): |
961 evt.Veto() | 891 evt.Veto() |
962 self.orpgLog.log("Exit game_tree->on_label_begin(self, evt)", ORPG_DEBUG) | 892 |
963 | 893 @debugging |
964 def on_drag(self, evt): | 894 def on_drag(self, evt): |
965 self.orpgLog.log("Enter game_tree->on_drag(self, evt)", ORPG_DEBUG) | |
966 self.rename_flag = 0 | 895 self.rename_flag = 0 |
967 item = self.GetSelection() | 896 item = self.GetSelection() |
968 obj = self.GetPyData(item) | 897 obj = self.GetPyData(item) |
969 self.SelectItem(item) | 898 self.SelectItem(item) |
970 if(isinstance(obj,core.node_handler) and obj.drag): | 899 if(isinstance(obj,core.node_handler) and obj.drag): |
971 self.dragging = True | 900 self.dragging = True |
972 cur = wx.StockCursor(wx.CURSOR_HAND) | 901 cur = wx.StockCursor(wx.CURSOR_HAND) |
973 self.SetCursor(cur) | 902 self.SetCursor(cur) |
974 self.drag_obj = obj | 903 self.drag_obj = obj |
975 self.orpgLog.log("Exit game_tree->on_drag(self, evt)", ORPG_DEBUG) | 904 |
976 | 905 @debugging |
977 def is_parent_node(self, node, compare_node): | 906 def is_parent_node(self, node, compare_node): |
978 self.orpgLog.log("Enter game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | |
979 | |
980 parent_node = self.GetItemParent(node) | 907 parent_node = self.GetItemParent(node) |
981 if compare_node == parent_node: | 908 if compare_node == parent_node: |
982 | |
983 self.orpgLog.log("parent node", ORPG_DEBUG) | 909 self.orpgLog.log("parent node", ORPG_DEBUG) |
984 self.orpgLog.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | |
985 return 1 | 910 return 1 |
986 elif parent_node == self.root: | 911 elif parent_node == self.root: |
987 | |
988 self.orpgLog.log("not parent", ORPG_DEBUG) | 912 self.orpgLog.log("not parent", ORPG_DEBUG) |
989 self.orpgLog.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | |
990 return 0 | 913 return 0 |
991 else: | 914 else: |
992 | |
993 self.orpgLog.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | |
994 return self.is_parent_node(parent_node, compare_node) | 915 return self.is_parent_node(parent_node, compare_node) |
995 | 916 |
996 CTRL_TREE_FILE = wx.NewId() | 917 CTRL_TREE_FILE = wx.NewId() |
997 CTRL_YES = wx.NewId() | 918 CTRL_YES = wx.NewId() |
998 CTRL_NO = wx.NewId() | 919 CTRL_NO = wx.NewId() |
1000 CTRL_DESIGN = wx.NewId() | 921 CTRL_DESIGN = wx.NewId() |
1001 CTRL_CHAT = wx.NewId() | 922 CTRL_CHAT = wx.NewId() |
1002 CTRL_PRINT = wx.NewId() | 923 CTRL_PRINT = wx.NewId() |
1003 | 924 |
1004 class gametree_prop_dlg(wx.Dialog): | 925 class gametree_prop_dlg(wx.Dialog): |
926 @debugging | |
1005 def __init__(self, parent, settings): | 927 def __init__(self, parent, settings): |
1006 wx.Dialog.__init__(self, parent, wx.ID_ANY, "Game Tree Properties") | 928 wx.Dialog.__init__(self, parent, wx.ID_ANY, "Game Tree Properties") |
1007 self.settings = settings | 929 self.settings = settings |
1008 | 930 |
1009 #sizers | 931 #sizers |
1058 self.SetSizer(sizers['main']) | 980 self.SetSizer(sizers['main']) |
1059 self.SetAutoLayout(True) | 981 self.SetAutoLayout(True) |
1060 self.Fit() | 982 self.Fit() |
1061 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK) | 983 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK) |
1062 | 984 |
985 @debugging | |
1063 def on_ok(self,evt): | 986 def on_ok(self,evt): |
1064 self.settings.set_setting("gametree",self.ctrls[CTRL_TREE_FILE].GetValue()) | 987 self.settings.set_setting("gametree",self.ctrls[CTRL_TREE_FILE].GetValue()) |
1065 self.settings.set_setting("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue())) | 988 self.settings.set_setting("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue())) |
1066 if self.ctrls[CTRL_USE].GetValue(): | 989 if self.ctrls[CTRL_USE].GetValue(): |
1067 self.settings.set_setting("treedclick","use") | 990 self.settings.set_setting("treedclick","use") |