Mercurial > traipse_dev
comparison orpg/gametree/gametree.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | c54768cffbd4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: gametree.py | |
21 # Author: Chris Davis | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $ | |
25 # | |
26 # Description: The file contains code fore the game tree shell | |
27 # | |
28 | |
29 __version__ = "$Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $" | |
30 | |
31 from orpg.orpg_wx import * | |
32 from orpg.orpg_windows import * | |
33 from orpg.orpgCore import open_rpg | |
34 import orpg.dirpath | |
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 | |
49 import urllib | |
50 import time | |
51 import os | |
52 | |
53 STD_MENU_DELETE = wx.NewId() | |
54 STD_MENU_DESIGN = wx.NewId() | |
55 STD_MENU_USE = wx.NewId() | |
56 STD_MENU_PP = wx.NewId() | |
57 STD_MENU_RENAME = wx.NewId() | |
58 STD_MENU_SEND = wx.NewId() | |
59 STD_MENU_SAVE = wx.NewId() | |
60 STD_MENU_ICON = wx.NewId() | |
61 STD_MENU_CLONE = wx.NewId() | |
62 STD_MENU_ABOUT = wx.NewId() | |
63 STD_MENU_HTML = wx.NewId() | |
64 STD_MENU_EMAIL = wx.NewId() | |
65 STD_MENU_CHAT = wx.NewId() | |
66 STD_MENU_WHISPER = wx.NewId() | |
67 STD_MENU_WIZARD = wx.NewId() | |
68 STD_MENU_NODE_SUBMENU = wx.NewId() | |
69 STD_MENU_NODE_USEFUL = wx.NewId() | |
70 STD_MENU_NODE_USELESS = wx.NewId() | |
71 STD_MENU_NODE_INDIFFERENT = wx.NewId() | |
72 STD_MENU_MAP = wx.NewId() | |
73 TOP_IFILE = wx.NewId() | |
74 TOP_INSERT_URL = wx.NewId() | |
75 TOP_NEW_TREE = wx.NewId() | |
76 TOP_SAVE_TREE = wx.NewId() | |
77 TOP_SAVE_TREE_AS = wx.NewId() | |
78 TOP_TREE_PROP = wx.NewId() | |
79 TOP_FEATURES = wx.NewId() | |
80 | |
81 class game_tree(wx.TreeCtrl): | |
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) | |
84 self.log = open_rpg.get_component('log') | |
85 self.log.log("Enter game_tree", ORPG_DEBUG) | |
86 self.validate = open_rpg.get_component('validate') | |
87 self.xml = open_rpg.get_component('xml') | |
88 self.settings = open_rpg.get_component('settings') | |
89 self.session = open_rpg.get_component('session') | |
90 self.chat = open_rpg.get_component('chat') | |
91 self.mainframe = open_rpg.get_component('frame') | |
92 self.build_img_list() | |
93 self.build_std_menu() | |
94 self.nodehandlers = {} | |
95 self.nodes = {} | |
96 self.init_nodehandlers() | |
97 self.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick) | |
98 self.Bind(wx.EVT_RIGHT_DOWN, self.on_rclick) | |
99 self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.on_drag, id=id) | |
100 self.Bind(wx.EVT_LEFT_UP, self.on_left_up) | |
101 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) | |
102 self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.on_label_change, id=self.GetId()) | |
103 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_KEY_UP, self.on_key_up) | |
106 self.id = 1 | |
107 self.dragging = False | |
108 self.root_dir = orpg.dirpath.dir_struct["home"] | |
109 self.last_save_dir = orpg.dirpath.dir_struct["user"] | |
110 | |
111 #Create tree from default if it does not exist | |
112 self.validate.config_file("tree.xml","default_tree.xml") | |
113 open_rpg.add_component("tree", self) | |
114 #build tree | |
115 self.root = self.AddRoot("Game Tree",self.icons['gear']) | |
116 self.was_labeling = 0 | |
117 self.rename_flag = 0 | |
118 self.image_cache = {} | |
119 self.log.log("Exit game_tree", ORPG_DEBUG) | |
120 | |
121 def add_nodehandler(self, nodehandler, nodeclass): | |
122 self.log.log("Enter game_tree->add_nodehandler(self, nodehandler, nodeclass)", ORPG_DEBUG) | |
123 if not self.nodehandlers.has_key(nodehandler): | |
124 self.nodehandlers[nodehandler] = nodeclass | |
125 else: | |
126 self.log.log("Nodehandler for " + nodehandler + " already exists!", ORPG_DEBUG, True) | |
127 self.log.log("Exit game_tree->add_nodehandler(self, nodehandler, nodeclass)", ORPG_DEBUG) | |
128 | |
129 def remove_nodehandler(self, nodehandler): | |
130 self.log.log("Enter game_tree->remove_nodehandler(self, nodehandler)", ORPG_DEBUG) | |
131 if self.nodehandlers.has_key(nodehandler): | |
132 del self.nodehandlers[nodehandler] | |
133 else: | |
134 self.log.log("No nodehandler for " + nodehandler + " exists!", ORPG_DEBUG, True) | |
135 self.log.log("Exit game_tree->remove_nodehandler(self, nodehandler)", ORPG_DEBUG) | |
136 | |
137 def init_nodehandlers(self): | |
138 self.log.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('tabber_handler', orpg.gametree.nodehandlers.containers.tabber_handler) | |
141 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('textctrl_handler', orpg.gametree.nodehandlers.forms.textctrl_handler) | |
144 self.add_nodehandler('listbox_handler', orpg.gametree.nodehandlers.forms.listbox_handler) | |
145 self.add_nodehandler('link_handler', orpg.gametree.nodehandlers.forms.link_handler) | |
146 self.add_nodehandler('webimg_handler', orpg.gametree.nodehandlers.forms.webimg_handler) | |
147 self.add_nodehandler('dnd3echar_handler', orpg.gametree.nodehandlers.dnd3e.dnd3echar_handler) | |
148 self.add_nodehandler('dnd35char_handler', orpg.gametree.nodehandlers.dnd35.dnd35char_handler) | |
149 self.add_nodehandler('macro_handler', orpg.gametree.nodehandlers.chatmacro.macro_handler) | |
150 self.add_nodehandler('map_miniature_handler', orpg.gametree.nodehandlers.map_miniature_nodehandler.map_miniature_handler) | |
151 self.add_nodehandler('minilib_handler', orpg.gametree.nodehandlers.minilib.minilib_handler) | |
152 self.add_nodehandler('mini_handler', orpg.gametree.nodehandlers.minilib.mini_handler) | |
153 self.add_nodehandler('rpg_grid_handler', orpg.gametree.nodehandlers.rpg_grid.rpg_grid_handler) | |
154 self.add_nodehandler('d20char_handler', orpg.gametree.nodehandlers.d20.d20char_handler) | |
155 self.add_nodehandler('SWd20char_handler', orpg.gametree.nodehandlers.StarWarsd20.SWd20char_handler) | |
156 self.add_nodehandler('voxchat_handler', orpg.gametree.nodehandlers.voxchat.voxchat_handler) | |
157 self.add_nodehandler('file_loader', core.file_loader) | |
158 self.add_nodehandler('node_loader', core.node_loader) | |
159 self.add_nodehandler('url_loader', core.url_loader) | |
160 self.add_nodehandler('min_map', core.min_map) | |
161 self.log.log("Exit game_tree->init_nodehandlers(self)", ORPG_DEBUG) | |
162 | |
163 # event = wxKeyEvent | |
164 # set to be called by wxWindows by EVT_CHAR macro in __init__ | |
165 def on_key_up(self, evt): | |
166 self.log.log("Enter game_tree->on_key_up(self, evt)", ORPG_DEBUG) | |
167 key_code = evt.GetKeyCode() | |
168 if self.dragging and (key_code == wx.WXK_SHIFT): | |
169 curSelection = self.GetSelection() | |
170 cur = wx.StockCursor(wx.CURSOR_ARROW) | |
171 self.SetCursor(cur) | |
172 self.dragging = False | |
173 obj = self.GetPyData(curSelection) | |
174 self.SelectItem(curSelection) | |
175 if(isinstance(obj,core.node_handler)): | |
176 obj.on_drop(evt) | |
177 self.drag_obj = None | |
178 evt.Skip() | |
179 self.log.log("Exit game_tree->on_key_up(self, evt)", ORPG_DEBUG) | |
180 | |
181 def on_char(self, evt): | |
182 self.log.log("Enter game_tree->on_char(self, evt)", ORPG_DEBUG) | |
183 key_code = evt.GetKeyCode() | |
184 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 curSelection = self.GetSelection() | |
187 obj = self.GetPyData(curSelection) | |
188 self.SelectItem(curSelection) | |
189 if(isinstance(obj,core.node_handler)): | |
190 self.dragging = True | |
191 cur = wx.StockCursor(wx.CURSOR_HAND) | |
192 self.SetCursor(cur) | |
193 self.drag_obj = obj | |
194 elif key_code == wx.WXK_LEFT: | |
195 self.Collapse(curSelection) | |
196 | |
197 elif key_code == wx.WXK_DELETE: # Handle the delete key | |
198 if curSelection: | |
199 nextSelect = self.GetItemParent(curSelection) | |
200 self.on_del(evt) | |
201 try: | |
202 if self.GetItemText(nextSelect) != "": | |
203 self.SelectItem(nextSelect) | |
204 except: | |
205 pass | |
206 elif key_code == wx.WXK_F2: | |
207 self.rename_flag = 1 | |
208 self.EditLabel(curSelection) | |
209 evt.Skip() | |
210 self.log.log("Exit game_tree->on_char(self, evt)", ORPG_DEBUG) | |
211 | |
212 ## locate_valid_tree | |
213 ## GUI based dialogs to locate/fix missing treefile issues --Snowdog 3/05 | |
214 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 self.log.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 if response == wx.YES: | |
219 file = None | |
220 filetypes = "Gametree (*.xml)|*.xml|All files (*.*)|*.*" | |
221 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 dlg.Destroy() | |
224 if not file: self.load_tree(error=1) | |
225 else: self.load_tree(file) | |
226 self.log.log("Exit game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) | |
227 return | |
228 else: | |
229 self.validate.config_file("tree.xml","default_tree.xml") | |
230 self.load_tree(error=1) | |
231 self.log.log("Exit game_tree->locate_valid_tree(self, error, msg, dir, filename)", ORPG_DEBUG) | |
232 return | |
233 | |
234 def load_tree(self, filename=orpg.dirpath.dir_struct["user"]+'tree.xml', error=0): | |
235 self.log.log("Enter game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | |
236 self.settings.set_setting("gametree", filename) | |
237 tmp = None | |
238 xml_dom = None | |
239 xml_doc = None | |
240 try: | |
241 self.log.log("Reading Gametree file: " + filename + "...", ORPG_INFO, True) | |
242 tmp = open(filename,"r") | |
243 xml_doc = self.xml.parseXml(tmp.read()) | |
244 tmp.close() | |
245 if xml_doc == None: | |
246 pass | |
247 else: | |
248 xml_dom = xml_doc._get_documentElement() | |
249 self.log.log("done.", ORPG_INFO, True) | |
250 | |
251 except IOError: | |
252 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\ | |
253 "Would you like to locate it?\n"\ | |
254 "(Selecting 'No' will cause a new default gametree to be generated)" | |
255 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.log.log(emsg, ORPG_GENERAL) | |
258 self.log.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | |
259 return | |
260 | |
261 if not xml_dom: | |
262 os.rename(filename,filename+".corrupt") | |
263 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] | |
264 emsg = "Your gametree is being regenerated.\n\n"\ | |
265 "To salvage a recent version of your gametree\n"\ | |
266 "exit OpenRPG and copy the lastgood.xml file in\n"\ | |
267 "your myfiles directory to "+fn+ "\n"\ | |
268 "in your myfiles directory.\n\n"\ | |
269 "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 "(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.log.log(emsg, ORPG_GENERAL) | |
274 self.log.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | |
275 return | |
276 | |
277 if xml_dom._get_tagName() != "gametree": | |
278 fn = filename[ ((filename.rfind(os.sep))+len(os.sep)):] | |
279 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 "(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.log.log(emsg, ORPG_DEBUG) | |
284 self.log.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | |
285 return | |
286 | |
287 # get gametree version - we could write conversion code here! | |
288 self.master_dom = xml_dom | |
289 self.log.log("Master Dom Set", ORPG_DEBUG) | |
290 | |
291 try: | |
292 version = self.master_dom.getAttribute("version") | |
293 # see if we should load the gametree | |
294 loadfeatures = int(self.settings.get_setting("LoadGameTreeFeatures")) | |
295 if loadfeatures: | |
296 xml_dom = self.xml.parseXml(open(orpg.dirpath.dir_struct["template"]+"feature.xml","r").read()) | |
297 xml_dom = xml_dom._get_documentElement() | |
298 xml_dom = self.master_dom.appendChild(xml_dom) | |
299 self.settings.set_setting("LoadGameTreeFeatures","0") | |
300 | |
301 ## load tree | |
302 self.log.log("Features loaded (if required)", ORPG_DEBUG) | |
303 self.CollapseAndReset(self.root) | |
304 children = self.master_dom._get_childNodes() | |
305 self.log.log("Parsing Gametree Nodes ", ORPG_INFO, True) | |
306 for c in children: | |
307 print '.', | |
308 self.load_xml(c,self.root) | |
309 self.log.log("done", ORPG_INFO, True) | |
310 self.Expand(self.root) | |
311 self.SetPyData(self.root,self.master_dom) | |
312 if error != 1: | |
313 infile = open(filename, "rb") | |
314 outfile = open(orpg.dirpath.dir_struct["user"]+"lastgood.xml", "wb") | |
315 outfile.write(infile.read()) | |
316 else: | |
317 self.log.log("Not overwriting lastgood.xml file.", ORPG_INFO, True) | |
318 | |
319 except Exception, e: | |
320 self.log.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 os.rename(filename,filename+".corrupt") | |
323 self.validate.config_file("tree.xml","default_tree.xml") | |
324 self.load_tree(error=1) | |
325 self.log.log("Exit game_tree->load_tree(self, filename, error)", ORPG_DEBUG) | |
326 | |
327 def build_std_menu(self, obj=None): | |
328 self.log.log("Enter game_tree->build_std_menu(self, obj)", ORPG_DEBUG) | |
329 | |
330 # build useful menu | |
331 useful_menu = wx.Menu() | |
332 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_INDIFFERENT,"&Indifferent") | |
335 # build standard menu | |
336 self.std_menu = wx.Menu() | |
337 self.std_menu.SetTitle("game tree") | |
338 self.std_menu.Append(STD_MENU_USE,"&Use") | |
339 self.std_menu.Append(STD_MENU_DESIGN,"&Design") | |
340 self.std_menu.Append(STD_MENU_PP,"&Pretty Print") | |
341 self.std_menu.AppendSeparator() | |
342 self.std_menu.Append(STD_MENU_SEND,"Send To Player") | |
343 self.std_menu.Append(STD_MENU_MAP,"Send To Map") | |
344 self.std_menu.Append(STD_MENU_CHAT,"Send To Chat") | |
345 self.std_menu.Append(STD_MENU_WHISPER,"Whisper To Player") | |
346 self.std_menu.AppendSeparator() | |
347 self.std_menu.Append(STD_MENU_ICON,"Change &Icon") | |
348 self.std_menu.Append(STD_MENU_DELETE,"D&elete") | |
349 self.std_menu.Append(STD_MENU_CLONE,"&Clone") | |
350 self.std_menu.AppendMenu(STD_MENU_NODE_SUBMENU,"Node &Usefulness",useful_menu) | |
351 self.std_menu.AppendSeparator() | |
352 self.std_menu.Append(STD_MENU_SAVE,"&Save Node") | |
353 self.std_menu.Append(STD_MENU_HTML,"E&xport as HTML") | |
354 self.std_menu.AppendSeparator() | |
355 self.std_menu.Append(STD_MENU_ABOUT,"&About") | |
356 self.Bind(wx.EVT_MENU, self.on_send_to, id=STD_MENU_SEND) | |
357 self.Bind(wx.EVT_MENU, self.indifferent, id=STD_MENU_NODE_INDIFFERENT) | |
358 self.Bind(wx.EVT_MENU, self.useful, id=STD_MENU_NODE_USEFUL) | |
359 self.Bind(wx.EVT_MENU, self.useless, id=STD_MENU_NODE_USELESS) | |
360 self.Bind(wx.EVT_MENU, self.on_del, id=STD_MENU_DELETE) | |
361 self.Bind(wx.EVT_MENU, self.on_send_to_map, id=STD_MENU_MAP) | |
362 self.Bind(wx.EVT_MENU, self.on_node_design, id=STD_MENU_DESIGN) | |
363 self.Bind(wx.EVT_MENU, self.on_node_use, id=STD_MENU_USE) | |
364 self.Bind(wx.EVT_MENU, self.on_node_pp, id=STD_MENU_PP) | |
365 self.Bind(wx.EVT_MENU, self.on_save, id=STD_MENU_SAVE) | |
366 self.Bind(wx.EVT_MENU, self.on_icon, id=STD_MENU_ICON) | |
367 self.Bind(wx.EVT_MENU, self.on_clone, id=STD_MENU_CLONE) | |
368 self.Bind(wx.EVT_MENU, self.on_about, id=STD_MENU_ABOUT) | |
369 self.Bind(wx.EVT_MENU, self.on_send_to_chat, id=STD_MENU_CHAT) | |
370 self.Bind(wx.EVT_MENU, self.on_whisper_to, id=STD_MENU_WHISPER) | |
371 self.Bind(wx.EVT_MENU, self.on_export_html, id=STD_MENU_HTML) | |
372 self.top_menu = wx.Menu() | |
373 self.top_menu.SetTitle("game tree") | |
374 self.top_menu.Append(TOP_IFILE,"&Insert File") | |
375 self.top_menu.Append(TOP_INSERT_URL,"Insert &URL") | |
376 self.top_menu.Append(TOP_FEATURES, "Insert &Features Node") | |
377 self.top_menu.Append(TOP_NEW_TREE, "&Load New Tree") | |
378 self.top_menu.Append(TOP_SAVE_TREE,"&Save Tree") | |
379 self.top_menu.Append(TOP_SAVE_TREE_AS,"Save Tree &As...") | |
380 self.top_menu.Append(TOP_TREE_PROP,"&Tree Properties") | |
381 self.Bind(wx.EVT_MENU, self.on_insert_file, id=TOP_IFILE) | |
382 self.Bind(wx.EVT_MENU, self.on_insert_url, id=TOP_INSERT_URL) | |
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, 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_tree_prop, id=TOP_TREE_PROP) | |
387 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 | |
390 def do_std_menu(self, evt, obj): | |
391 self.log.log("Enter game_tree->do_std_menu(self, evt, obj)", ORPG_DEBUG) | |
392 try: | |
393 self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu()) | |
394 except: | |
395 self.std_menu.Enable(STD_MENU_MAP, obj.map_aware()) | |
396 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone()) | |
397 self.PopupMenu(self.std_menu) | |
398 self.log.log("Exit game_tree->do_std_menu(self, evt, obj)", ORPG_DEBUG) | |
399 | |
400 def strip_html(self, player): | |
401 self.log.log("Enter game_tree->strip_html(self, player)", ORPG_DEBUG) | |
402 ret_string = "" | |
403 x = 0 | |
404 in_tag = 0 | |
405 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] == "<" : | |
408 in_tag = 1 | |
409 elif player[0][x] == ">" : | |
410 in_tag = 0 | |
411 else : | |
412 pass | |
413 else : | |
414 ret_string = ret_string + player[0][x] | |
415 self.log.log(ret_string, ORPG_DEBUG) | |
416 self.log.log("Exit game_tree->strip_html(self, player)", ORPG_DEBUG) | |
417 return ret_string | |
418 | |
419 def on_receive_data(self, data, player): | |
420 self.log.log("Enter game_tree->on_receive_data(self, data, player)", ORPG_DEBUG) | |
421 beg = string.find(data,"<tree>") | |
422 end = string.rfind(data,"</tree>") | |
423 data = data[6:end] | |
424 self.insert_xml(data) | |
425 self.log.log("Exit game_tree->on_receive_data(self, data, player)", ORPG_DEBUG) | |
426 | |
427 def on_send_to_chat(self, evt): | |
428 self.log.log("Enter game_tree->on_send_to_chat(self, evt)", ORPG_DEBUG) | |
429 item = self.GetSelection() | |
430 obj = self.GetPyData(item) | |
431 obj.on_send_to_chat(evt) | |
432 self.log.log("Exit game_tree->on_send_to_chat(self, evt)", ORPG_DEBUG) | |
433 | |
434 def on_whisper_to(self, evt): | |
435 self.log.log("Enter game_tree->on_whisper_to(self, evt)", ORPG_DEBUG) | |
436 players = self.session.get_players() | |
437 opts = [] | |
438 myid = self.session.get_id() | |
439 me = None | |
440 for p in players: | |
441 if p[2] != myid: | |
442 opts.append("("+p[2]+") " + self.strip_html(p)) | |
443 else: | |
444 me = p | |
445 if len(opts): | |
446 players.remove(me) | |
447 if len(opts): | |
448 dlg = orpgMultiCheckBoxDlg( self.GetParent(),opts,"Select Players:","Whisper To",[] ) | |
449 if dlg.ShowModal() == wx.ID_OK: | |
450 item = self.GetSelection() | |
451 obj = self.GetPyData(item) | |
452 selections = dlg.get_selections() | |
453 if len(selections) == len(opts): | |
454 self.chat.ParsePost(obj.tohtml(),True,True) | |
455 else: | |
456 player_ids = [] | |
457 for s in selections: | |
458 player_ids.append(players[s][2]) | |
459 self.chat.whisper_to_players(obj.tohtml(),player_ids) | |
460 self.log.log("Exit game_tree->on_whisper_to(self, evt)", ORPG_DEBUG) | |
461 | |
462 def on_export_html(self, evt): | |
463 self.log.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 if f.ShowModal() == wx.ID_OK: | |
466 item = self.GetSelection() | |
467 obj = self.GetPyData(item) | |
468 type = f.GetFilterIndex() | |
469 file = open(f.GetPath(),"w") | |
470 data = "<html><head><title>"+obj.master_dom.getAttribute("name")+"</title></head>" | |
471 data += "<body bgcolor=\"#FFFFFF\" >"+obj.tohtml()+"</body></html>" | |
472 for tag in ("</tr>","</td>","</th>","</table>","</html>","</body>"): | |
473 data = data.replace(tag,tag+"\n") | |
474 file.write(data) | |
475 file.close() | |
476 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | |
477 f.Destroy() | |
478 os.chdir(self.root_dir) | |
479 self.log.log("Exit game_tree->on_export_html(self, evt)", ORPG_DEBUG) | |
480 | |
481 def indifferent(self, evt): | |
482 self.log.log("Enter game_tree->indifferent(self, evt)", ORPG_DEBUG) | |
483 item = self.GetSelection() | |
484 obj = self.GetPyData(item) | |
485 obj.usefulness("indifferent") | |
486 self.log.log("Exit game_tree->indifferent(self, evt)", ORPG_DEBUG) | |
487 | |
488 def useful(self, evt): | |
489 self.log.log("Enter game_tree->useful(self, evt)", ORPG_DEBUG) | |
490 item = self.GetSelection() | |
491 obj = self.GetPyData(item) | |
492 obj.usefulness("useful") | |
493 self.log.log("Exit game_tree->useful(self, evt)", ORPG_DEBUG) | |
494 | |
495 def useless(self, evt): | |
496 self.log.log("Enter game_tree->useless(self, evt)", ORPG_DEBUG) | |
497 item = self.GetSelection() | |
498 obj = self.GetPyData(item) | |
499 obj.usefulness("useless") | |
500 self.log.log("Exit game_tree->useless(self, evt)", ORPG_DEBUG) | |
501 | |
502 def on_email(self,evt): | |
503 pass | |
504 | |
505 def on_send_to(self, evt): | |
506 self.log.log("Enter game_tree->on_send_to(self, evt)", ORPG_DEBUG) | |
507 players = self.session.get_players() | |
508 opts = [] | |
509 myid = self.session.get_id() | |
510 me = None | |
511 for p in players: | |
512 if p[2] != myid: | |
513 opts.append("("+p[2]+") " + self.strip_html(p)) | |
514 else: | |
515 me = p | |
516 if len(opts): | |
517 players.remove(me) | |
518 dlg = orpgMultiCheckBoxDlg( None, opts, "Select Players:", "Send To", [] ) | |
519 if dlg.ShowModal() == wx.ID_OK: | |
520 item = self.GetSelection() | |
521 obj = self.GetPyData(item) | |
522 xmldata = "<tree>" + self.xml.toxml(obj) + "</tree>" | |
523 selections = dlg.get_selections() | |
524 if len(selections) == len(opts): | |
525 self.session.send(xmldata) | |
526 else: | |
527 for s in selections: | |
528 self.session.send(xmldata,players[s][2]) | |
529 dlg.Destroy() | |
530 self.log.log("Exit game_tree->on_send_to(self, evt)", ORPG_DEBUG) | |
531 | |
532 def on_icon(self, evt): | |
533 self.log.log("Enter game_tree->on_icon(self, evt)", ORPG_DEBUG) | |
534 icons = self.icons.keys() | |
535 icons.sort() | |
536 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons) | |
537 if dlg.ShowModal() == wx.ID_OK: | |
538 key = dlg.GetStringSelection() | |
539 item = self.GetSelection() | |
540 obj = self.GetPyData(item) | |
541 obj.change_icon(key) | |
542 dlg.Destroy() | |
543 self.log.log("Exit game_tree->on_icon(self, evt)", ORPG_DEBUG) | |
544 | |
545 def on_wizard(self, evt): | |
546 self.log.log("Enter game_tree->on_wizard(self, evt)", ORPG_DEBUG) | |
547 item = self.GetSelection() | |
548 obj = self.GetPyData(item) | |
549 name = "New " + obj.master_dom.getAttribute("name") | |
550 icon = obj.master_dom.getAttribute("icon") | |
551 xml_data = "<nodehandler name=\""+name+"\" icon=\"" + icon + "\" module=\"core\" class=\"node_loader\" >" | |
552 xml_data += self.xml.toxml(obj) | |
553 xml_data += "</nodehandler>" | |
554 self.insert_xml(xml_data) | |
555 self.log.log(xml_data, ORPG_DEBUG) | |
556 self.log.log("Exit game_tree->on_wizard(self, evt)", ORPG_DEBUG) | |
557 | |
558 def on_clone(self, evt): | |
559 self.log.log("Enter game_tree->on_clone(self, evt)", ORPG_DEBUG) | |
560 item = self.GetSelection() | |
561 obj = self.GetPyData(item) | |
562 if obj.can_clone(): | |
563 parent_node = self.GetItemParent(item) | |
564 prev_sib = self.GetPrevSibling(item) | |
565 if not prev_sib.IsOk(): | |
566 prev_sib = parent_node | |
567 xml_dom = self.xml.parseXml(self.xml.toxml(obj)) | |
568 xml_dom = xml_dom._get_firstChild() | |
569 parent = obj.master_dom._get_parentNode() | |
570 xml_dom = parent.insertBefore(xml_dom, obj.master_dom) | |
571 self.load_xml(xml_dom, parent_node, prev_sib) | |
572 self.log.log("Exit game_tree->on_clone(self, evt)", ORPG_DEBUG) | |
573 | |
574 def on_save(self, evt): | |
575 """save node to a xml file""" | |
576 self.log.log("Enter game_tree->on_save(self, evt)", ORPG_DEBUG) | |
577 item = self.GetSelection() | |
578 obj = self.GetPyData(item) | |
579 obj.on_save(evt) | |
580 os.chdir(self.root_dir) | |
581 self.log.log("Exit game_tree->on_save(self, evt)", ORPG_DEBUG) | |
582 | |
583 def on_save_tree_as(self, evt): | |
584 self.log.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 if f.ShowModal() == wx.ID_OK: | |
587 self.save_tree(f.GetPath()) | |
588 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | |
589 f.Destroy() | |
590 os.chdir(self.root_dir) | |
591 self.log.log("Exit game_tree->on_save_tree_as(self, evt)", ORPG_DEBUG) | |
592 | |
593 def on_save_tree(self, evt=None): | |
594 self.log.log("Enter game_tree->on_save_tree(self, evt)", ORPG_DEBUG) | |
595 filename = self.settings.get_setting("gametree") | |
596 self.save_tree(filename) | |
597 self.log.log("Exit game_tree->on_save_tree(self, evt)", ORPG_DEBUG) | |
598 | |
599 def save_tree(self, filename=orpg.dirpath.dir_struct["user"]+'tree.xml'): | |
600 self.log.log("Enter game_tree->save_tree(self, filename)", ORPG_DEBUG) | |
601 self.master_dom.setAttribute("version",GAMETREE_VERSION) | |
602 self.settings.set_setting("gametree",filename) | |
603 file = open(filename,"w") | |
604 file.write(self.xml.toxml(self.master_dom,1)) | |
605 file.close() | |
606 self.log.log("Exit game_tree->save_tree(self, filename)", ORPG_DEBUG) | |
607 | |
608 def on_load_new_tree(self, evt): | |
609 self.log.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 if f.ShowModal() == wx.ID_OK: | |
612 self.load_tree(f.GetPath()) | |
613 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | |
614 f.Destroy() | |
615 os.chdir(self.root_dir) | |
616 self.log.log("Exit game_tree->on_load_new_tree(self, evt)", ORPG_DEBUG) | |
617 | |
618 def on_insert_file(self, evt): | |
619 """loads xml file into the tree""" | |
620 self.log.log("Enter game_tree->on_insert_file(self, evt)", ORPG_DEBUG) | |
621 if self.last_save_dir == ".": | |
622 self.last_save_dir = orpg.dirpath.dir_struct["user"] | |
623 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN) | |
624 if f.ShowModal() == wx.ID_OK: | |
625 self.insert_xml(open(f.GetPath(),"r").read()) | |
626 self.last_save_dir, throwaway = os.path.split( f.GetPath() ) | |
627 f.Destroy() | |
628 os.chdir(self.root_dir) | |
629 self.log.log("Exit game_tree->on_insert_file(self, evt)", ORPG_DEBUG) | |
630 | |
631 def on_insert_url(self, evt): | |
632 """loads xml url into the tree""" | |
633 self.log.log("Enter game_tree->on_insert_url(self, evt)", ORPG_DEBUG) | |
634 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://") | |
635 if dlg.ShowModal() == wx.ID_OK: | |
636 path = dlg.GetValue() | |
637 file = urllib.urlopen(path) | |
638 self.insert_xml(file.read()) | |
639 dlg.Destroy() | |
640 self.log.log("Exit game_tree->on_insert_url(self, evt)", ORPG_DEBUG) | |
641 | |
642 def on_insert_features(self, evt): | |
643 self.log.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.log.log("Exit game_tree->on_insert_features(self, evt)", ORPG_DEBUG) | |
646 | |
647 def on_tree_prop(self, evt): | |
648 self.log.log("Enter game_tree->on_tree_prop(self, evt)", ORPG_DEBUG) | |
649 dlg = gametree_prop_dlg(self, self.settings) | |
650 if dlg.ShowModal() == wx.ID_OK: | |
651 pass | |
652 dlg.Destroy() | |
653 self.log.log("Exit game_tree->on_tree_prop(self, evt)", ORPG_DEBUG) | |
654 | |
655 def on_node_design(self, evt): | |
656 self.log.log("Enter game_tree->on_node_design(self, evt)", ORPG_DEBUG) | |
657 | |
658 item = self.GetSelection() | |
659 obj = self.GetPyData(item) | |
660 obj.on_design(evt) | |
661 | |
662 self.log.log("Exit game_tree->on_node_design(self, evt)", ORPG_DEBUG) | |
663 | |
664 def on_node_use(self, evt): | |
665 self.log.log("Enter game_tree->on_node_use(self, evt)", ORPG_DEBUG) | |
666 | |
667 item = self.GetSelection() | |
668 obj = self.GetPyData(item) | |
669 obj.on_use(evt) | |
670 | |
671 self.log.log("Exit game_tree->on_node_use(self, evt)", ORPG_DEBUG) | |
672 | |
673 def on_node_pp(self, evt): | |
674 self.log.log("Enter game_tree->on_node_pp(self, evt)", ORPG_DEBUG) | |
675 | |
676 item = self.GetSelection() | |
677 obj = self.GetPyData(item) | |
678 obj.on_html_view(evt) | |
679 | |
680 self.log.log("Exit game_tree->on_node_pp(self, evt)", ORPG_DEBUG) | |
681 | |
682 def on_del(self, evt): | |
683 self.log.log("Enter game_tree->on_del(self, evt)", ORPG_DEBUG) | |
684 status_value = "none" | |
685 try: | |
686 item = self.GetSelection() | |
687 if item: | |
688 obj = self.GetPyData(item) | |
689 parent_obj = obj | |
690 try: | |
691 status_value = parent_obj.master_dom.getAttribute('status') | |
692 name = parent_obj.master_dom.getAttribute('name') | |
693 except: | |
694 status_value = "none" | |
695 parent_obj = parent_obj.master_dom._get_parentNode() | |
696 while status_value!="useful" and status_value!="useless": | |
697 try: | |
698 status_value = parent_obj.getAttribute('status') | |
699 name = parent_obj.getAttribute('name') | |
700 if status_value == "useless": | |
701 break | |
702 elif status_value == "useful": | |
703 break | |
704 except: | |
705 status_value = "none" | |
706 try: | |
707 parent_obj = parent_obj._get_parentNode() | |
708 except: | |
709 break | |
710 if status_value == "useful": | |
711 dlg = wx.MessageDialog(self, `name` + " And everything beneath it are considered useful. \n\nAre you sure you want to delete this item?",'Important Item',wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) | |
712 if dlg.ShowModal() == wx.ID_YES: | |
713 obj.delete() | |
714 else: | |
715 obj.delete() | |
716 except: | |
717 if self.GetSelection() == self.GetRootItem(): | |
718 msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK) | |
719 else: | |
720 msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK) | |
721 msg.ShowModal() | |
722 msg.Destroy() | |
723 | |
724 self.log.log("Exit game_tree->on_del(self, evt)", ORPG_DEBUG) | |
725 | |
726 def on_about(self, evt): | |
727 self.log.log("Enter game_tree->on_about(self, evt)", ORPG_DEBUG) | |
728 | |
729 item = self.GetSelection() | |
730 obj = self.GetPyData(item) | |
731 about = MyAboutBox(self,obj.about()) | |
732 about.ShowModal() | |
733 about.Destroy() | |
734 | |
735 self.log.log("Exit game_tree->on_about(self, evt)", ORPG_DEBUG) | |
736 | |
737 def on_send_to_map(self, evt): | |
738 self.log.log("Enter game_tree->on_send_to_map(self, evt)", ORPG_DEBUG) | |
739 | |
740 item = self.GetSelection() | |
741 obj = self.GetPyData(item) | |
742 if hasattr(obj,"on_send_to_map"): | |
743 obj.on_send_to_map(evt) | |
744 | |
745 self.log.log("Exit game_tree->on_send_to_map(self, evt)", ORPG_DEBUG) | |
746 | |
747 def insert_xml(self, txt): | |
748 self.log.log("Enter game_tree->insert_xml(self, txt)", ORPG_DEBUG) | |
749 #Updated to allow safe merging of gametree files | |
750 #without leaving an unusable and undeletable node. | |
751 # -- Snowdog 8/03 | |
752 xml_dom = self.xml.parseXml(txt) | |
753 if xml_dom == None: | |
754 wx.MessageBox("Import Failed: Invalid or missing node data") | |
755 self.log.log("Import Failed: Invalid or missing node data", ORPG_DEBUG) | |
756 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | |
757 return | |
758 xml_temp = xml_dom._get_documentElement() | |
759 | |
760 if not xml_temp: | |
761 wx.MessageBox("Error Importing Node or Tree") | |
762 self.log.log("Error Importing Node or Tree", ORPG_DEBUG) | |
763 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | |
764 return | |
765 | |
766 if xml_temp._get_tagName() == "gametree": | |
767 children = xml_temp._get_childNodes() | |
768 for c in children: | |
769 self.load_xml(c, self.root) | |
770 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | |
771 return | |
772 | |
773 if not xml_dom: | |
774 wx.MessageBox("XML Error") | |
775 self.log.log("XML Error", ORPG_DEBUG) | |
776 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | |
777 return | |
778 | |
779 xml_dom = xml_dom._get_firstChild() | |
780 child = self.master_dom._get_firstChild() | |
781 xml_dom = self.master_dom.insertBefore(xml_dom,child) | |
782 self.load_xml(xml_dom,self.root,self.root) | |
783 self.log.log("Exit game_tree->insert_xml(self, txt)", ORPG_DEBUG) | |
784 | |
785 def build_img_list(self): | |
786 """make image list""" | |
787 self.log.log("Enter game_tree->build_img_list(self)", ORPG_DEBUG) | |
788 helper = img_helper() | |
789 self.icons = { } | |
790 self._imageList= wx.ImageList(16,16,False) | |
791 man = open(orpg.dirpath.dir_struct["icon"]+"icons.xml","r") | |
792 xml_dom = self.xml.parseXml(man.read()) | |
793 man.close() | |
794 xml_dom = xml_dom._get_documentElement() | |
795 node_list = xml_dom._get_childNodes() | |
796 for n in node_list: | |
797 key = n.getAttribute("name") | |
798 path = orpg.dirpath.dir_struct["icon"] + n.getAttribute("file") | |
799 img = helper.load_file(path) | |
800 self.icons[key] = self._imageList.Add(img) | |
801 self.SetImageList(self._imageList) | |
802 self.log.log("Exit game_tree->build_img_list(self)", ORPG_DEBUG) | |
803 | |
804 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 #add the first tree node | |
807 i = 0 | |
808 text = xml_dom.getAttribute("name") | |
809 icon = xml_dom.getAttribute("icon") | |
810 if self.icons.has_key(icon): | |
811 i = self.icons[icon] | |
812 name = xml_dom._get_nodeName() | |
813 self.log.log("Text, icon and name set\n" + text + "\n" + icon + "\n" + name, ORPG_DEBUG) | |
814 if prev_node: | |
815 if prev_node == parent_node: | |
816 new_tree_node = self.PrependItem(parent_node, text, i, i) | |
817 else: | |
818 new_tree_node = self.InsertItem(parent_node,prev_node, text, i, i) | |
819 else: | |
820 new_tree_node = self.AppendItem(parent_node, text, i, i) | |
821 | |
822 self.log.log("Node Added to tree", ORPG_DEBUG) | |
823 #create a nodehandler or continue loading xml into tree | |
824 if name == "nodehandler": | |
825 #wx.BeginBusyCursor() | |
826 self.log.log("We have a Nodehandler", ORPG_DEBUG) | |
827 try: | |
828 py_class = xml_dom.getAttribute("class") | |
829 self.log.log("nodehandler class: " + py_class, ORPG_DEBUG) | |
830 if not self.nodehandlers.has_key(py_class): | |
831 raise Exception, "Unknown Nodehandler for " + py_class | |
832 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.log.log("Node Data set", ORPG_DEBUG) | |
835 bmp = self.nodes[self.id].get_scaled_bitmap(16,16) | |
836 if bmp: | |
837 self.cached_load_of_image(bmp,new_tree_node,) | |
838 self.log.log("Node Icon loaded", ORPG_DEBUG) | |
839 self.id = self.id + 1 | |
840 except Exception, er: | |
841 self.log.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.log.log("Error Info: " + xml_dom.getAttribute("class") + "\n" + str(er), ORPG_GENERAL, True) | |
844 self.Delete(new_tree_node) | |
845 parent = xml_dom._get_parentNode() | |
846 parent.removeChild(xml_dom) | |
847 #wx.EndBusyCursor() | |
848 self.log.log("Exit game_tree->load_xml(self, xml_dom, parent_node, prev_node)", ORPG_DEBUG) | |
849 return new_tree_node | |
850 | |
851 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 image_list = self.GetImageList() | |
854 img = wx.ImageFromBitmap(bmp_in) | |
855 img_data = img.GetData() | |
856 image_index = None | |
857 for key in self.image_cache.keys(): | |
858 if self.image_cache[key] == str(img_data): | |
859 image_index = key | |
860 break | |
861 | |
862 if image_index is None: | |
863 image_index = image_list.Add(bmp_in) | |
864 self.image_cache[image_index] = img_data | |
865 self.SetItemImage(new_tree_node,image_index) | |
866 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 return image_index | |
869 | |
870 | |
871 def on_rclick(self, evt): | |
872 self.log.log("Enter game_tree->on_rclick(self, evt)", ORPG_DEBUG) | |
873 pt = evt.GetPosition() | |
874 (item, flag) = self.HitTest(pt) | |
875 if item.IsOk(): | |
876 obj = self.GetPyData(item) | |
877 self.SelectItem(item) | |
878 if(isinstance(obj,core.node_handler)): | |
879 obj.on_rclick(evt) | |
880 else: | |
881 self.PopupMenu(self.top_menu) | |
882 else: | |
883 self.PopupMenu(self.top_menu,pt) | |
884 self.log.log("Exit game_tree->on_rclick(self, evt)", ORPG_DEBUG) | |
885 | |
886 def on_ldclick(self, evt): | |
887 self.log.log("Enter game_tree->on_ldclick(self, evt)", ORPG_DEBUG) | |
888 self.rename_flag = 0 | |
889 pt = evt.GetPosition() | |
890 (item, flag) = self.HitTest(pt) | |
891 if item.IsOk(): | |
892 obj = self.GetPyData(item) | |
893 self.SelectItem(item) | |
894 if(isinstance(obj,core.node_handler)): | |
895 if not obj.on_ldclick(evt): | |
896 action = self.settings.get_setting("treedclick") | |
897 if action == "use": | |
898 obj.on_use(evt) | |
899 elif action == "design": | |
900 obj.on_design(evt) | |
901 elif action == "print": | |
902 obj.on_html_view(evt) | |
903 elif action == "chat": | |
904 self.on_send_to_chat(evt) | |
905 self.log.log("Exit game_tree->on_ldclick(self, evt)", ORPG_DEBUG) | |
906 | |
907 def on_left_down(self, evt): | |
908 self.log.log("Enter game_tree->on_left_down(self, evt)", ORPG_DEBUG) | |
909 pt = evt.GetPosition() | |
910 (item, flag) = self.HitTest(pt) | |
911 if item.IsOk() and self.was_labeling: | |
912 self.SelectItem(item) | |
913 self.rename_flag = 0 | |
914 self.was_labeling = 0 | |
915 elif (flag & wx.TREE_HITTEST_ONITEMLABEL) == wx.TREE_HITTEST_ONITEMLABEL and self.IsSelected(item): | |
916 # this next if tests to ensure that the mouse up occurred over a label, and not the icon | |
917 self.rename_flag = 1 | |
918 else: | |
919 self.SelectItem(item) | |
920 evt.Skip() | |
921 self.log.log("Exit game_tree->on_left_down(self, evt)", ORPG_DEBUG) | |
922 | |
923 def on_left_up(self, evt): | |
924 self.log.log("Enter game_tree->on_left_up(self, evt)", ORPG_DEBUG) | |
925 if self.dragging: | |
926 cur = wx.StockCursor(wx.CURSOR_ARROW) | |
927 self.SetCursor(cur) | |
928 self.dragging = False | |
929 pt = evt.GetPosition() | |
930 (item, flag) = self.HitTest(pt) | |
931 if item.IsOk(): | |
932 obj = self.GetPyData(item) | |
933 self.SelectItem(item) | |
934 if(isinstance(obj,core.node_handler)): | |
935 obj.on_drop(evt) | |
936 self.drag_obj = None | |
937 self.log.log("Exit game_tree->on_left_up(self, evt)", ORPG_DEBUG) | |
938 | |
939 def on_label_change(self, evt): | |
940 self.log.log("Enter game_tree->on_label_change(self, evt)", ORPG_DEBUG) | |
941 item = evt.GetItem() | |
942 txt = evt.GetLabel() | |
943 self.was_labeling = 0 | |
944 self.rename_flag = 0 | |
945 if txt != "": | |
946 obj = self.GetPyData(item) | |
947 obj.master_dom.setAttribute('name',txt) | |
948 else: | |
949 evt.Veto() | |
950 self.log.log("Exit game_tree->on_label_change(self, evt)", ORPG_DEBUG) | |
951 | |
952 def on_label_begin(self, evt): | |
953 self.log.log("Enter game_tree->on_label_begin(self, evt)", ORPG_DEBUG) | |
954 if not self.rename_flag: | |
955 evt.Veto() | |
956 else: | |
957 self.was_labeling = 1 | |
958 item = evt.GetItem() | |
959 if item == self.GetRootItem(): | |
960 evt.Veto() | |
961 self.log.log("Exit game_tree->on_label_begin(self, evt)", ORPG_DEBUG) | |
962 | |
963 def on_drag(self, evt): | |
964 self.log.log("Enter game_tree->on_drag(self, evt)", ORPG_DEBUG) | |
965 self.rename_flag = 0 | |
966 item = self.GetSelection() | |
967 obj = self.GetPyData(item) | |
968 self.SelectItem(item) | |
969 if(isinstance(obj,core.node_handler) and obj.drag): | |
970 self.dragging = True | |
971 cur = wx.StockCursor(wx.CURSOR_HAND) | |
972 self.SetCursor(cur) | |
973 self.drag_obj = obj | |
974 self.log.log("Exit game_tree->on_drag(self, evt)", ORPG_DEBUG) | |
975 | |
976 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 | |
979 parent_node = self.GetItemParent(node) | |
980 if compare_node == parent_node: | |
981 | |
982 self.log.log("parent node", ORPG_DEBUG) | |
983 self.log.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | |
984 return 1 | |
985 elif parent_node == self.root: | |
986 | |
987 self.log.log("not parent", ORPG_DEBUG) | |
988 self.log.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | |
989 return 0 | |
990 else: | |
991 | |
992 self.log.log("Exit game_tree->is_parent_node(self, node, compare_node)", ORPG_DEBUG) | |
993 return self.is_parent_node(parent_node, compare_node) | |
994 | |
995 CTRL_TREE_FILE = wx.NewId() | |
996 CTRL_YES = wx.NewId() | |
997 CTRL_NO = wx.NewId() | |
998 CTRL_USE = wx.NewId() | |
999 CTRL_DESIGN = wx.NewId() | |
1000 CTRL_CHAT = wx.NewId() | |
1001 CTRL_PRINT = wx.NewId() | |
1002 | |
1003 class gametree_prop_dlg(wx.Dialog): | |
1004 def __init__(self, parent, settings): | |
1005 wx.Dialog.__init__(self, parent, wx.ID_ANY, "Game Tree Properties") | |
1006 self.settings = settings | |
1007 | |
1008 #sizers | |
1009 sizers = {} | |
1010 sizers['but'] = wx.BoxSizer(wx.HORIZONTAL) | |
1011 sizers['main'] = wx.BoxSizer(wx.VERTICAL) | |
1012 | |
1013 #box sizers | |
1014 box_sizers = {} | |
1015 box_sizers["save"] = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Save On Exit"), wx.HORIZONTAL) | |
1016 box_sizers["file"] = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Tree File"), wx.HORIZONTAL) | |
1017 box_sizers["dclick"] = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Double Click Action"), wx.HORIZONTAL) | |
1018 self.ctrls = { CTRL_TREE_FILE : FileBrowseButtonWithHistory(self, wx.ID_ANY, labelText="" ) , | |
1019 CTRL_YES : wx.RadioButton(self, CTRL_YES, "Yes", style=wx.RB_GROUP), | |
1020 CTRL_NO : wx.RadioButton(self, CTRL_NO, "No"), | |
1021 CTRL_USE : wx.RadioButton(self, CTRL_USE, "Use", style=wx.RB_GROUP), | |
1022 CTRL_DESIGN : wx.RadioButton(self, CTRL_DESIGN, "Desgin"), | |
1023 CTRL_CHAT : wx.RadioButton(self, CTRL_CHAT, "Chat"), | |
1024 CTRL_PRINT : wx.RadioButton(self, CTRL_PRINT, "Pretty Print") | |
1025 } | |
1026 self.ctrls[CTRL_TREE_FILE].SetValue(settings.get_setting("gametree")) | |
1027 opt = settings.get_setting("SaveGameTreeOnExit") | |
1028 self.ctrls[CTRL_YES].SetValue(opt=="1") | |
1029 self.ctrls[CTRL_NO].SetValue(opt=="0") | |
1030 opt = settings.get_setting("treedclick") | |
1031 self.ctrls[CTRL_DESIGN].SetValue(opt=="design") | |
1032 self.ctrls[CTRL_USE].SetValue(opt=="use") | |
1033 self.ctrls[CTRL_CHAT].SetValue(opt=="chat") | |
1034 self.ctrls[CTRL_PRINT].SetValue(opt=="print") | |
1035 box_sizers['save'].Add(self.ctrls[CTRL_YES],0, wx.EXPAND) | |
1036 box_sizers['save'].Add(wx.Size(10,10)) | |
1037 box_sizers['save'].Add(self.ctrls[CTRL_NO],0, wx.EXPAND) | |
1038 box_sizers['file'].Add(self.ctrls[CTRL_TREE_FILE], 0, wx.EXPAND) | |
1039 box_sizers['dclick'].Add(self.ctrls[CTRL_USE],0, wx.EXPAND) | |
1040 box_sizers['dclick'].Add(wx.Size(10,10)) | |
1041 box_sizers['dclick'].Add(self.ctrls[CTRL_DESIGN],0, wx.EXPAND) | |
1042 box_sizers['dclick'].Add(wx.Size(10,10)) | |
1043 box_sizers['dclick'].Add(self.ctrls[CTRL_CHAT],0, wx.EXPAND) | |
1044 box_sizers['dclick'].Add(wx.Size(10,10)) | |
1045 box_sizers['dclick'].Add(self.ctrls[CTRL_PRINT],0, wx.EXPAND) | |
1046 | |
1047 # buttons | |
1048 sizers['but'].Add(wx.Button(self, wx.ID_OK, "Apply"), 1, wx.EXPAND) | |
1049 sizers['but'].Add(wx.Size(10,10)) | |
1050 sizers['but'].Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.EXPAND) | |
1051 sizers['main'].Add(box_sizers['save'], 1, wx.EXPAND) | |
1052 sizers['main'].Add(box_sizers['file'], 1, wx.EXPAND) | |
1053 sizers['main'].Add(box_sizers['dclick'], 1, wx.EXPAND) | |
1054 sizers['main'].Add(sizers['but'], 0, wx.EXPAND|wx.ALIGN_BOTTOM ) | |
1055 | |
1056 #sizers['main'].SetDimension(10,10,csize[0]-20,csize[1]-20) | |
1057 self.SetSizer(sizers['main']) | |
1058 self.SetAutoLayout(True) | |
1059 self.Fit() | |
1060 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK) | |
1061 | |
1062 def on_ok(self,evt): | |
1063 self.settings.set_setting("gametree",self.ctrls[CTRL_TREE_FILE].GetValue()) | |
1064 self.settings.set_setting("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue())) | |
1065 if self.ctrls[CTRL_USE].GetValue(): | |
1066 self.settings.set_setting("treedclick","use") | |
1067 elif self.ctrls[CTRL_DESIGN].GetValue(): | |
1068 self.settings.set_setting("treedclick","design") | |
1069 elif self.ctrls[CTRL_PRINT].GetValue(): | |
1070 self.settings.set_setting("treedclick","print") | |
1071 elif self.ctrls[CTRL_CHAT].GetValue(): | |
1072 self.settings.set_setting("treedclick","chat") | |
1073 self.EndModal(wx.ID_OK) |