annotate orpg/gametree/gametree.py @ 202:f1a67667d78b alpha

Traipse Alpha 'OpenRPG' {100427-03} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Patch-2) New Features: New Namespace method with two new syntaxes New Namespace Internal is context sensitive, always! New Namespace External is 'as narrow as you make it' New Namespace FutureCheck helps ensure you don't receive an incorrect node New PluginDB access for URL2Link plugin New to Forms, they now show their content in Design Mode Fixes: Fix to Server GUI startup errors Fix to Server GUI Rooms tab updating Fix to Chat and Settings if non existant die roller is picked Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated Fix to Alias Lib's Export to Tree, Open, Save features Fix to alias node, now works properly Fix to Splitter node, minor GUI cleanup Fix to Backgrounds not loading through remote loader Fix to Node name errors Fix to rolling dice in chat Whispers Fix to Splitters Sizing issues Fix to URL2Link plugin, modified regex compilation should remove memory leak Fix to mapy.py, a roll back due to zoomed grid issues Fix to whiteboard_handler, Circles work by you clicking the center of the circle Fix to Servers parse_incoming_dom which was outdated and did not respect XML Fix to a broken link in the server welcome message Daily: I was having problems with Chat tabs. All fixed now.
author sirebral
date Tue, 27 Apr 2010 06:56:52 -0500
parents 0bc44a57ae6c
children 4dc11df853bf
rev   line source
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
2 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
3 # openrpg-dev@lists.sourceforge.net
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
4 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
5 # This program is free software; you can redistribute it and/or modify
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
6 # it under the terms of the GNU General Public License as published by
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
8 # (at your option) any later version.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
9 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
10 # This program is distributed in the hope that it will be useful,
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
13 # GNU General Public License for more details.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
14 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
15 # You should have received a copy of the GNU General Public License
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
16 # along with this program; if not, write to the Free Software
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
18 # --
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
19 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
20 # File: gametree.py
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
21 # Author: Chris Davis
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
22 # Maintainer:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
23 # Version:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
24 # $Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
25 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
26 # Description: The file contains code fore the game tree shell
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
27 #
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
28 # Traipse EZ_Tree Reference System (TaS - Prof.Ebral):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
29 #
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
30 # The new EZ_Tree Reference System being implemented takes full advantage of
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
31 # Python's OOP Language. The entire tree code is being reused, but a new ID is
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
32 # being created which 'shuts off' some of the features of the tree and adds new ones.
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
33 # This new feature will allow users to quickly add a Reference button to new node
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
34 # handlers. The button will show a faximile of the tree and users can then create a
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
35 # node reference with ease!
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
36 #
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
37
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
38 from __future__ import with_statement
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
39
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
40 __version__ = "$Id: gametree.py,v 1.68 2007/12/07 20:39:48 digitalxero Exp $"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
41
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
42 from orpg.orpg_wx import *
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
43 from orpg.orpg_windows import *
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
44 from orpg.orpgCore import component
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
45 from orpg.dirpath import dir_struct
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
46 from nodehandlers import core
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
47 import string, urllib, time, os
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
48
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
49 from orpg.orpg_xml import xml
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
50 from orpg.tools.validate import validate
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
51 from orpg.tools.orpg_log import logger, debug
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
52 from orpg.tools.orpg_settings import settings
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
53 from orpg.gametree.nodehandlers import containers, forms, dnd3e, dnd35, chatmacro
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
54 from orpg.gametree.nodehandlers import map_miniature_nodehandler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
55 from orpg.gametree.nodehandlers import minilib, rpg_grid, d20, StarWarsd20, voxchat
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
56
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
57 from gametree_version import GAMETREE_VERSION
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
58
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
59 from xml.etree.ElementTree import ElementTree, Element, parse
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
60 from xml.etree.ElementTree import fromstring, tostring, XML, iselement
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
61 from xml.parsers.expat import ExpatError
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
62
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
63 STD_MENU_DELETE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
64 STD_MENU_DESIGN = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
65 STD_MENU_USE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
66 STD_MENU_PP = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
67 STD_MENU_RENAME = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
68 STD_MENU_SEND = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
69 STD_MENU_SAVE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
70 STD_MENU_ICON = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
71 STD_MENU_CLONE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
72 STD_MENU_ABOUT = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
73 STD_MENU_HTML = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
74 STD_MENU_EMAIL = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
75 STD_MENU_CHAT = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
76 STD_MENU_WHISPER = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
77 STD_MENU_WIZARD = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
78 STD_MENU_NODE_SUBMENU = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
79 STD_MENU_NODE_USEFUL = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
80 STD_MENU_NODE_USELESS = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
81 STD_MENU_NODE_INDIFFERENT = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
82 STD_MENU_MAP = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
83 TOP_IFILE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
84 TOP_INSERT_URL = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
85 TOP_NEW_TREE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
86 TOP_SAVE_TREE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
87 TOP_SAVE_TREE_AS = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
88 TOP_TREE_PROP = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
89 TOP_FEATURES = wx.NewId()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
90 EZ_REF = wx.NewId()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
91
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
92 class game_tree(wx.TreeCtrl):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
93
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
94 def __init__(self, parent, id):
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
95 wx.TreeCtrl.__init__(self,parent,id, wx.DefaultPosition,
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
96 wx.DefaultSize,style=wx.TR_EDIT_LABELS | wx.TR_HAS_BUTTONS)
153
31fc0fc52a3a Traipse Alpha 'OpenRPG' {091125-01}
sirebral
parents: 151
diff changeset
97 self.chat = component.get('chat')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
98 self.session = component.get('session')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
99 self.mainframe = component.get('frame')
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
100 self.ez_ref = True if id == EZ_REF else False
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
101 self.build_img_list()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
102 if not self.ez_ref: self.build_std_menu()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
103 self.nodehandlers = {}
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
104 self.nodes = {}
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
105 self.init_nodehandlers()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
106 if not self.ez_ref:
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
107 self.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
108 self.Bind(wx.EVT_RIGHT_DOWN, self.on_rclick)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
109 self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.on_drag, id=id)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
110 self.Bind(wx.EVT_LEFT_UP, self.on_left_up)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
111 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
112 self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.on_label_change, id=self.GetId())
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
113 self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.on_label_begin, id=self.GetId())
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
114 self.Bind(wx.EVT_CHAR, self.on_char)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
115 self.Bind(wx.EVT_KEY_UP, self.on_key_up)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
116 self.id = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
117 self.dragging = False
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
118 self.last_save_dir = dir_struct["user"]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
119 self.tree_map = {}
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
120
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
121 #Create tree from default if it does not exist
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
122 validate.config_file("tree.xml","default_tree.xml")
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
123
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
124 ## The EZ_Tree Reference creates a duplicate component called tree_back. This is because the
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
125 ## tree wont parse fully without adding the component, and when a dupplicate component is created
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
126 ## the older one is deleted. If there are an C++ errors the tree_back can be used as a failsafe
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
127
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 173
diff changeset
128 if not self.ez_ref: component.add("tree", self); component.add('tree_fs', self) ## Fail Safe
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
129 component.add('tree', self)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
130
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
131 #build tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
132 self.root = self.AddRoot("Game Tree", self.icons['gear'])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
133 self.was_labeling = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
134 self.rename_flag = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
135 self.image_cache = {}
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
136 logger.debug("Exit game_tree")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
137
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
138 def add_nodehandler(self, nodehandler, nodeclass):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
139 if not self.nodehandlers.has_key(nodehandler): self.nodehandlers[nodehandler] = nodeclass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
140 else: logger.debug("Nodehandler for " + nodehandler + " already exists!")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
141
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
142 def remove_nodehandler(self, nodehandler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
143 if self.nodehandlers.has_key(nodehandler): del self.nodehandlers[nodehandler]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
144 else: logger.debug("No nodehandler for " + nodehandler + " exists!")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
145
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
146 def init_nodehandlers(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
147 self.add_nodehandler('group_handler', containers.group_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
148 self.add_nodehandler('tabber_handler', containers.tabber_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
149 self.add_nodehandler('splitter_handler', containers.splitter_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
150 self.add_nodehandler('form_handler', forms.form_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
151 self.add_nodehandler('textctrl_handler', forms.textctrl_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
152 self.add_nodehandler('listbox_handler', forms.listbox_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
153 self.add_nodehandler('link_handler', forms.link_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
154 self.add_nodehandler('webimg_handler', forms.webimg_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
155 self.add_nodehandler('dnd3echar_handler', dnd3e.dnd3echar_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
156 self.add_nodehandler('dnd35char_handler', dnd35.dnd35char_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
157 self.add_nodehandler('macro_handler', chatmacro.macro_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
158 self.add_nodehandler('map_miniature_handler', map_miniature_nodehandler.map_miniature_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
159 self.add_nodehandler('minilib_handler', minilib.minilib_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
160 self.add_nodehandler('mini_handler', minilib.mini_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
161 self.add_nodehandler('rpg_grid_handler', rpg_grid.rpg_grid_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
162 self.add_nodehandler('d20char_handler', d20.d20char_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
163 self.add_nodehandler('SWd20char_handler', StarWarsd20.SWd20char_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
164 self.add_nodehandler('voxchat_handler', voxchat.voxchat_handler)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
165 self.add_nodehandler('file_loader', core.file_loader)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
166 self.add_nodehandler('node_loader', core.node_loader)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
167 self.add_nodehandler('url_loader', core.url_loader)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
168 self.add_nodehandler('min_map', core.min_map)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
169
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
170 def on_key_up(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
171 key_code = evt.GetKeyCode()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
172 if self.dragging and (key_code == wx.WXK_SHIFT):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
173 curSelection = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
174 cur = wx.StockCursor(wx.CURSOR_ARROW)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
175 self.SetCursor(cur)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
176 self.dragging = False
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
177 obj = self.GetPyData(curSelection)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
178 self.SelectItem(curSelection)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
179 if(isinstance(obj,core.node_handler)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
180 obj.on_drop(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
181 self.drag_obj = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
182 evt.Skip()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
183
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
184 def on_char(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
185 key_code = evt.GetKeyCode()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
186 curSelection = self.GetSelection() # Get the current selection
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
187 if evt.ShiftDown() and ((key_code == wx.WXK_UP) or (key_code == wx.WXK_DOWN)) and not self.dragging:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
188 curSelection = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
189 obj = self.GetPyData(curSelection)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
190 self.SelectItem(curSelection)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
191 if(isinstance(obj,core.node_handler)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
192 self.dragging = True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
193 cur = wx.StockCursor(wx.CURSOR_HAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
194 self.SetCursor(cur)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
195 self.drag_obj = obj
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
196 elif key_code == wx.WXK_LEFT: self.Collapse(curSelection)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
197 elif key_code == wx.WXK_DELETE: # Handle the delete key
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
198 if curSelection:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
199 nextSelect = self.GetItemParent(curSelection)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
200 self.on_del(evt)
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
201 try:
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
202 if self.GetItemText(nextSelect) != "": self.SelectItem(nextSelect)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
203 except: pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
204 elif key_code == wx.WXK_F2:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
205 self.rename_flag = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
206 self.EditLabel(curSelection)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
207 evt.Skip()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
208
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
209 def locate_valid_tree(self, error, msg): ## --Snowdog 3/05
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
210 """prompts the user to locate a new tree file or create a new one"""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
211 response = wx.MessageDialog(self, msg, error, wx.YES|wx.NO|wx.ICON_ERROR)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
212 if response == wx.YES:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
213 file = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
214 dlg = wx.FileDialog(self, "Locate Gametree file", dir_struct["user"],
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
215 filename[ ((filename.rfind(os.sep))+len(os.sep)):],
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
216 "Gametree (*.xml)|*.xml|All files (*.*)|*.*",
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
217 wx.OPEN | wx.CHANGE_DIR)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
218 if dlg.ShowModal() == wx.ID_OK: file = dlg.GetPath()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
219 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
220 if not file: self.load_tree(error=1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
221 else: self.load_tree(file)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
222 return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
223 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
224 validate.config_file("tree.xml","default_tree.xml")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
225 self.load_tree(error=1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
226 return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
227
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
228 def load_tree(self, filename=dir_struct["user"]+'tree.xml', error=0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
229 settings.change("gametree", filename)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
230 if not os.path.exists(filename):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
231 emsg = "Gametree Missing!\n"+filename+" cannot be found.\n\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
232 "Would you like to locate it?\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
233 "(Selecting 'No' will cause a new default gametree to be generated)"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
234 self.locate_valid_tree("Gametree Error", emsg)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
235 return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
236 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
237 tree = parse(filename)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
238 self.xml_root = tree.getroot()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
239 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
240 self.xml_root = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
241
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
242 if not self.xml_root:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
243 os.rename(filename,filename+".corrupt")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
244 emsg = "Your gametree is being regenerated.\n\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
245 "To salvage a recent version of your gametree\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
246 "exit OpenRPG and copy the lastgood.xml file in\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
247 "your myfiles directory to "+filename+ "\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
248 "in your myfiles directory.\n\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
249 "lastgood.xml WILL BE OVERWRITTEN NEXT TIME YOU RUN OPENRPG.\n\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
250 "Would you like to select a different gametree file to use?\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
251 "(Selecting 'No' will cause a new default gametree to be generated)"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
252 self.locate_valid_tree("Corrupt Gametree!", emsg)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
253 return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
254
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
255 if self.xml_root.tag != "gametree":
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
256 emsg = filename+" does not appear to be a valid gametree file.\n\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
257 "Would you like to select a different gametree file to use?\n"\
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
258 "(Selecting 'No' will cause a new default gametree to be generated)"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
259 self.locate_valid_tree("Invalid Gametree!", emsg)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
260 return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
261 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
262 # version = self.xml_root.get("version")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
263 # see if we should load the gametree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
264 loadfeatures = int(settings.get_setting("LoadGameTreeFeatures"))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
265 if loadfeatures:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
266 features_tree = parse(orpg.dirpath.dir_struct["template"]+"feature.xml")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
267 self.xml_root.append(features_tree.getroot())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
268 settings.change("LoadGameTreeFeatures","0")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
269
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
270 ## load tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
271 logger.debug("Features loaded (if required)")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
272 self.CollapseAndReset(self.root)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
273 logger.note("Parsing Gametree Nodes ", True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
274 for xml_child in self.xml_root:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
275 logger.note('.', True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
276 self.load_xml(xml_child,self.root)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
277 logger.note("done", True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
278
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
279 self.Expand(self.root)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
280 self.SetPyData(self.root,self.xml_root)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
281 if error != 1:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
282 with open(filename, "rb") as infile:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
283 with open(dir_struct["user"]+"lastgood.xml", "wb") as outfile:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
284 outfile.write(infile.read())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
285 else: logger.info("Not overwriting lastgood.xml file.", True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
286
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
287 except Exception, e:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
288 logger.exception(traceback.format_exc())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
289 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.")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
290 os.rename(filename,filename+".corrupt")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
291 validate.config_file("tree.xml","default_tree.xml")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
292 self.load_tree(error=1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
293
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
294 def build_std_menu(self, obj=None):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
295 # build useful menu
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
296 useful_menu = wx.Menu()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
297 useful_menu.Append(STD_MENU_NODE_USEFUL,"Use&ful")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
298 useful_menu.Append(STD_MENU_NODE_USELESS,"Use&less")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
299 useful_menu.Append(STD_MENU_NODE_INDIFFERENT,"&Indifferent")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
300
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
301 # build standard menu
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
302 self.std_menu = wx.Menu()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
303 self.std_menu.SetTitle("game tree")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
304 self.std_menu.Append(STD_MENU_USE,"&Use")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
305 self.std_menu.Append(STD_MENU_DESIGN,"&Design")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
306 self.std_menu.Append(STD_MENU_PP,"&Pretty Print")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
307 self.std_menu.AppendSeparator()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
308 self.std_menu.Append(STD_MENU_SEND,"Send To Player")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
309 self.std_menu.Append(STD_MENU_MAP,"Send To Map")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
310 self.std_menu.Append(STD_MENU_CHAT,"Send To Chat")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
311 self.std_menu.Append(STD_MENU_WHISPER,"Whisper To Player")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
312 self.std_menu.AppendSeparator()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
313 self.std_menu.Append(STD_MENU_ICON,"Change &Icon")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
314 self.std_menu.Append(STD_MENU_DELETE,"D&elete")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
315 self.std_menu.Append(STD_MENU_CLONE,"&Clone")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
316 self.std_menu.AppendMenu(STD_MENU_NODE_SUBMENU,"Node &Usefulness",useful_menu)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
317 self.std_menu.AppendSeparator()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
318 self.std_menu.Append(STD_MENU_SAVE,"&Save Node")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
319 self.std_menu.Append(STD_MENU_HTML,"E&xport as HTML")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
320 self.std_menu.AppendSeparator()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
321 self.std_menu.Append(STD_MENU_ABOUT,"&About")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
322 self.Bind(wx.EVT_MENU, self.on_send_to, id=STD_MENU_SEND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
323 self.Bind(wx.EVT_MENU, self.indifferent, id=STD_MENU_NODE_INDIFFERENT)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
324 self.Bind(wx.EVT_MENU, self.useful, id=STD_MENU_NODE_USEFUL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
325 self.Bind(wx.EVT_MENU, self.useless, id=STD_MENU_NODE_USELESS)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
326 self.Bind(wx.EVT_MENU, self.on_del, id=STD_MENU_DELETE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
327 self.Bind(wx.EVT_MENU, self.on_send_to_map, id=STD_MENU_MAP)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
328 self.Bind(wx.EVT_MENU, self.on_node_design, id=STD_MENU_DESIGN)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
329 self.Bind(wx.EVT_MENU, self.on_node_use, id=STD_MENU_USE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
330 self.Bind(wx.EVT_MENU, self.on_node_pp, id=STD_MENU_PP)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
331 self.Bind(wx.EVT_MENU, self.on_save, id=STD_MENU_SAVE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
332 self.Bind(wx.EVT_MENU, self.on_icon, id=STD_MENU_ICON)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
333 self.Bind(wx.EVT_MENU, self.on_clone, id=STD_MENU_CLONE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
334 self.Bind(wx.EVT_MENU, self.on_about, id=STD_MENU_ABOUT)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
335 self.Bind(wx.EVT_MENU, self.on_send_to_chat, id=STD_MENU_CHAT)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
336 self.Bind(wx.EVT_MENU, self.on_whisper_to, id=STD_MENU_WHISPER)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
337 self.Bind(wx.EVT_MENU, self.on_export_html, id=STD_MENU_HTML)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
338 self.top_menu = wx.Menu()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
339 self.top_menu.SetTitle("game tree")
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 173
diff changeset
340 self.top_menu.Append(TOP_IFILE,"&Insert Node File")
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 173
diff changeset
341 self.top_menu.Append(TOP_INSERT_URL,"Insert Node &URL")
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
342 self.top_menu.Append(TOP_FEATURES, "Insert &Features Node")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
343 self.top_menu.Append(TOP_NEW_TREE, "&Load New Tree")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
344 self.top_menu.Append(TOP_SAVE_TREE,"&Save Tree")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
345 self.top_menu.Append(TOP_SAVE_TREE_AS,"Save Tree &As...")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
346 self.top_menu.Append(TOP_TREE_PROP,"&Tree Properties")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
347 self.Bind(wx.EVT_MENU, self.on_insert_file, id=TOP_IFILE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
348 self.Bind(wx.EVT_MENU, self.on_insert_url, id=TOP_INSERT_URL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
349 self.Bind(wx.EVT_MENU, self.on_save_tree_as, id=TOP_SAVE_TREE_AS)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
350 self.Bind(wx.EVT_MENU, self.on_save_tree, id=TOP_SAVE_TREE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
351 self.Bind(wx.EVT_MENU, self.on_load_new_tree, id=TOP_NEW_TREE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
352 self.Bind(wx.EVT_MENU, self.on_tree_prop, id=TOP_TREE_PROP)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
353 self.Bind(wx.EVT_MENU, self.on_insert_features, id=TOP_FEATURES)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
354
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
355 def do_std_menu(self, evt, obj):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
356 try: self.std_menu.Enable(STD_MENU_MAP, obj.checkToMapMenu())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
357 except: self.std_menu.Enable(STD_MENU_MAP, obj.map_aware())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
358 self.std_menu.Enable(STD_MENU_CLONE, obj.can_clone())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
359 self.PopupMenu(self.std_menu)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
360
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
361 def strip_html(self, player):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
362 ret_string = ""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
363 x = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
364 in_tag = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
365 for x in xrange(len(player[0])) :
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
366 if player[0][x] == "<" or player[0][x] == ">" or in_tag == 1 :
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
367 if player[0][x] == "<" : in_tag = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
368 elif player[0][x] == ">" : in_tag = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
369 else: pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
370 else: ret_string = ret_string + player[0][x]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
371 logger.debug(ret_string)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
372 return ret_string
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
373
133
37d26a98883f Traipse Alpha 'OpenRPG' {091010-00}
sirebral
parents: 132
diff changeset
374 def on_receive_data(self, data):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
375 self.insert_xml(data)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
376
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
377 def on_send_to_chat(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
378 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
379 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
380 obj.on_send_to_chat(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
381
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
382 def on_whisper_to(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
383 players = self.session.get_players()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
384 opts = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
385 myid = self.session.get_id()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
386 me = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
387 for p in players:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
388 if p[2] != myid: opts.append("("+p[2]+") " + self.strip_html(p))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
389 else: me = p
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
390 if len(opts): players.remove(me)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
391 if len(opts):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
392 dlg = orpgMultiCheckBoxDlg( self.GetParent(),opts,"Select Players:","Whisper To",[] )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
393 if dlg.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
394 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
395 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
396 selections = dlg.get_selections()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
397 if len(selections) == len(opts): self.chat.ParsePost(obj.tohtml(),True,True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
398 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
399 player_ids = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
400 for s in selections: player_ids.append(players[s][2])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
401 self.chat.whisper_to_players(obj.tohtml(),player_ids)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
402
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
403 def on_export_html(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
404 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","HTML (*.html)|*.html",wx.SAVE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
405 if f.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
406 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
407 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
408 type = f.GetFilterIndex()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
409 with open(f.GetPath(),"w") as f:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
410 data = "<html><head><title>"+obj.xml.get("name")+"</title></head>"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
411 data += "<body bgcolor='#FFFFFF' >"+obj.tohtml()+"</body></html>"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
412 for tag in ("</tr>","</td>","</th>","</table>","</html>","</body>"): data = data.replace(tag,tag+"\n")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
413 f.write(data)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
414 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
415 f.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
416 os.chdir(dir_struct["home"])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
417
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
418 def indifferent(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
419 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
420 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
421 obj.usefulness("indifferent")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
422
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
423 def useful(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
424 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
425 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
426 obj.usefulness("useful")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
427
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
428 def useless(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
429 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
430 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
431 obj.usefulness("useless")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
432
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
433 def on_email(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
434 pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
435
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
436 def on_send_to(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
437 players = self.session.get_players()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
438 opts = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
439 myid = self.session.get_id()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
440 me = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
441 for p in players:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
442 if p[2] != myid: opts.append("("+p[2]+") " + self.strip_html(p))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
443 else: me = p
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
444 if len(opts):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
445 players.remove(me)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
446 dlg = orpgMultiCheckBoxDlg( None, opts, "Select Players:", "Send To", [] )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
447 if dlg.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
448 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
449 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
450 xmldata = "<tree>" + tostring(obj.xml) + "</tree>"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
451 selections = dlg.get_selections()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
452 if len(selections) == len(opts): self.session.send(xmldata)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
453 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
454 for s in selections: self.session.send(xmldata,players[s][2])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
455 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
456
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
457 def on_icon(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
458 icons = self.icons.keys()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
459 icons.sort()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
460 dlg = wx.SingleChoiceDialog(self,"Choose Icon?","Change Icon",icons)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
461 if dlg.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
462 key = dlg.GetStringSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
463 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
464 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
465 obj.change_icon(key)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
466 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
467
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
468 def on_wizard(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
469 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
470 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
471 name = "New " + obj.xml_root.get("name")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
472 icon = obj.xml_root.get("icon")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
473 xml_data = "<nodehandler name='"+name+"' icon='" + icon + "' module='core' class='node_loader' >"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
474 xml_data += xml.toxml(obj)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
475 xml_data += "</nodehandler>"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
476 self.insert_xml(xml_data)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
477 logger.debug(xml_data)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
478
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
479 def on_clone(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
480 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
481 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
482 if obj.can_clone():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
483 parent_node = self.GetItemParent(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
484 prev_sib = self.GetPrevSibling(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
485 if not prev_sib.IsOk(): prev_sib = parent_node
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
486 clone_xml = XML(tostring(obj.xml))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
487 if parent_node == self.root: parent_xml = self.GetPyData(parent_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
488 else: parent_xml = self.GetPyData(parent_node).xml
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
489 for i in range(len(parent_xml)):
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
490 if parent_xml[i] is obj.xml:
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
491 name = self.clone_renaming(parent_xml, parent_xml[i].get('name'))
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
492 clone_xml.set('name', name)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
493 parent_xml.insert(i, clone_xml)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
494 break
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
495 self.load_xml(clone_xml, parent_node, prev_sib)
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
496
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
497 def clone_renaming(self, node, name):
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
498 node_list = node.getchildren()
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
499 parent = node
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
500 append = name.split('_')
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
501 try: append_d = int(append[len(append)-1]); del append[len(append)-1]
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
502 except: append_d = False
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
503 if append_d:
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
504 append_d += 1; name = ''
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
505 for a in append: name += a+'_'
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
506 name = name+str(append_d)
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
507 if not append_d:
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
508 append_d = 1; name = ''
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
509 for a in append: name += a+'_'
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
510 name = name+str(append_d)
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
511 for n in node_list:
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
512 if n.get('name') == name: name = self.clone_renaming(parent, name)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
513 return name
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
514
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
515 def on_save(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
516 """save node to a xml file"""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
517 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
518 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
519 obj.on_save(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
520 os.chdir(dir_struct["home"])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
521
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
522 def on_save_tree_as(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
523 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.SAVE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
524 if f.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
525 self.save_tree(f.GetPath())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
526 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
527 f.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
528 os.chdir(dir_struct["home"])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
529
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
530 def on_save_tree(self, evt=None):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
531 filename = settings.get_setting("gametree")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
532 self.save_tree(filename)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
533
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
534 def save_tree(self, filename=dir_struct["user"]+'tree.xml'):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
535 self.xml_root.set("version", GAMETREE_VERSION)
133
37d26a98883f Traipse Alpha 'OpenRPG' {091010-00}
sirebral
parents: 132
diff changeset
536 settings.change("gametree", filename)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
537 ElementTree(self.xml_root).write(filename)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
538
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
539 def on_load_new_tree(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
540 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
541 if f.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
542 self.load_tree(f.GetPath())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
543 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
544 f.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
545 os.chdir(dir_struct["home"])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
546
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
547 def on_insert_file(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
548 """loads xml file into the tree"""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
549 if self.last_save_dir == ".":
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
550 self.last_save_dir = dir_struct["user"]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
551 f = wx.FileDialog(self,"Select a file", self.last_save_dir,"","*.xml",wx.OPEN)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
552 if f.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
553 self.insert_xml(open(f.GetPath(),"r").read())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
554 self.last_save_dir, throwaway = os.path.split( f.GetPath() )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
555 f.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
556 os.chdir(dir_struct["home"])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
557
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
558 def on_insert_url(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
559 """loads xml url into the tree"""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
560 dlg = wx.TextEntryDialog(self,"URL?","Insert URL", "http://")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
561 if dlg.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
562 path = dlg.GetValue()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
563 file = urllib.urlopen(path)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
564 self.insert_xml(file.read())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
565 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
566
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
567 def on_insert_features(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
568 self.insert_xml(open(dir_struct["template"]+"feature.xml","r").read())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
569
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
570 def on_tree_prop(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
571 dlg = gametree_prop_dlg(self, settings)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
572 if dlg.ShowModal() == wx.ID_OK: pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
573 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
574
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
575 def on_node_design(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
576 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
577 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
578 obj.on_design(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
579
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
580 def on_node_use(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
581 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
582 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
583 obj.on_use(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
584
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
585 def on_node_pp(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
586 item = self.GetSelection()
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
587 obj = self.GetPyData(item)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
588 obj.on_html_view(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
589
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
590 def on_del(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
591 status_value = "none"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
592 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
593 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
594 if item:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
595 handler = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
596 status_value = handler.xml.get('status')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
597 name = handler.xml.get('name')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
598 parent_item = self.GetItemParent(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
599 while parent_item.IsOk() and status_value!="useful" and status_value!="useless":
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
600 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
601 parent_handler = self.GetPyData(parent_item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
602 status_value = parent_handler.get('status')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
603 name = parent_handler.get('name')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
604 if status_value == "useless": break
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
605 elif status_value == "useful": break
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
606 except: status_value = "none"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
607 parent_item = self.GetItemParent(parent_item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
608 if status_value == "useful":
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
609 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)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
610 if dlg.ShowModal() == wx.ID_YES: handler.delete()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
611 else: handler.delete()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
612 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
613 if self.GetSelection() == self.GetRootItem(): msg = wx.MessageDialog(None,"You can't delete the root item.","Delete Error",wx.OK)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
614 else: msg = wx.MessageDialog(None,"Unknown error deleting node.","Delete Error",wx.OK)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
615 msg.ShowModal()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
616 msg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
617
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
618 def on_about(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
619 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
620 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
621 text = str(obj.about())
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 136
diff changeset
622 #about = MyAboutBox(self, obj.about())
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
623 wx.MessageBox(text, 'About')#.ShowModal()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
624 #about.ShowModal()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
625 #about.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
626
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
627 def on_send_to_map(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
628 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
629 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
630 if hasattr(obj,"on_send_to_map"): obj.on_send_to_map(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
631
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
632 def insert_xml(self, txt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
633 #Updated to allow safe merging of gametree files
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
634 #without leaving an unusable and undeletable node.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
635 # -- Snowdog 8/03
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
636 if not txt:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
637 wx.MessageBox("Import Failed: Invalid or missing node data")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
638 logger.general("Import Failed: Invalid or missing node data")
133
37d26a98883f Traipse Alpha 'OpenRPG' {091010-00}
sirebral
parents: 132
diff changeset
639 return
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
640 try: new_xml = XML(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
641 except ExpatError:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
642 wx.MessageBox("Error Importing Node or Tree")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
643 logger.general("Error Importing Node or Tree")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
644 return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
645 if new_xml.tag == "gametree":
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
646 for xml_child in new_xml: self.load_xml(xml_child, self.root)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
647 return
133
37d26a98883f Traipse Alpha 'OpenRPG' {091010-00}
sirebral
parents: 132
diff changeset
648 if new_xml.tag == "tree":
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
649 self.xml_root.append(new_xml.find('nodehandler'))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
650 for xml_child in new_xml: self.load_xml(xml_child, self.root)
133
37d26a98883f Traipse Alpha 'OpenRPG' {091010-00}
sirebral
parents: 132
diff changeset
651 return
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
652 self.xml_root.append(new_xml)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
653 self.load_xml(new_xml, self.root, self.root)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
654
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
655 def build_img_list(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
656 """make image list"""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
657 helper = img_helper()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
658 self.icons = { }
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
659 self._imageList= wx.ImageList(16,16,False)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
660 icons_xml = parse(orpg.dirpath.dir_struct["icon"]+"icons.xml")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
661 for icon in icons_xml.getroot():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
662 key = icon.get("name")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
663 path = orpg.dirpath.dir_struct["icon"] + icon.get("file")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
664 img = helper.load_file(path)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
665 self.icons[key] = self._imageList.Add(img)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
666 self.SetImageList(self._imageList)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
667
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
668 def get_tree_map(self, parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
669 ## Could be a little cleaner ##
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
670 family_tree = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
671 test = parent
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
672 while test != self.root:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
673 parent = self.GetItemText(test)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
674 test = self.GetItemParent(test)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
675 family_tree.append(parent)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
676 return family_tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
677
133
37d26a98883f Traipse Alpha 'OpenRPG' {091010-00}
sirebral
parents: 132
diff changeset
678 def load_xml(self, xml_element, parent_node, prev_node=None):
136
b4e02e8cd314 Traipse Alpha 'OpenRPG' {091016-00}
sirebral
parents: 133
diff changeset
679 if parent_node == self.root:
b4e02e8cd314 Traipse Alpha 'OpenRPG' {091016-00}
sirebral
parents: 133
diff changeset
680 self.tree_map[xml_element.get('name')] = {}
b4e02e8cd314 Traipse Alpha 'OpenRPG' {091016-00}
sirebral
parents: 133
diff changeset
681 self.tree_map[xml_element.get('name')]['node'] = xml_element
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
682 xml_element.set('map', '')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
683 if parent_node != self.root:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
684 ## Loading XML seems to lag on Grids and Images need a cache for load speed ##
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
685 family_tree = self.get_tree_map(parent_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
686 family_tree.reverse()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
687 map_str = '' #'!@'
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
688 for member in family_tree: map_str += member +'::'
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
689 map_str = map_str[:len(map_str)-2] #+'@!'
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
690 xml_element.set('map', map_str)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
691
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
692 #add the first tree node
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
693 i = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
694 name = xml_element.get("name")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
695 icon = xml_element.get("icon")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
696 if self.icons.has_key(icon): i = self.icons[icon]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
697
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
698 if prev_node:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
699 if prev_node == parent_node: new_tree_node = self.PrependItem(parent_node, name, i, i)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
700 else: new_tree_node = self.InsertItem(parent_node, prev_node, name, i, i)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
701 else: new_tree_node = self.AppendItem(parent_node, name, i, i)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
702
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
703 logger.debug("Node Added to tree")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
704 #create a nodehandler or continue loading xml into tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
705 if xml_element.tag == "nodehandler":
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
706 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
707 py_class = xml_element.get("class")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
708 logger.debug("nodehandler class: " + py_class)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
709 if not self.nodehandlers.has_key(py_class): raise Exception("Unknown Nodehandler for " + py_class)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
710 self.nodes[self.id] = self.nodehandlers[py_class](xml_element, new_tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
711 self.SetPyData(new_tree_node, self.nodes[self.id])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
712 logger.debug("Node Data set")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
713 bmp = self.nodes[self.id].get_scaled_bitmap(16,16)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
714 if bmp: self.cached_load_of_image(bmp,new_tree_node,)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
715 logger.debug("Node Icon loaded")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
716 self.id = self.id + 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
717 except Exception, er:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
718 logger.exception(traceback.format_exc())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
719 # was deleted -- should we delete non-nodehandler nodes then?
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
720 #self.Delete(new_tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
721 #parent = xml_dom._get_parentNode()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
722 #parent.removeChild(xml_dom)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
723 return new_tree_node
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
724
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
725 def cached_load_of_image(self, bmp_in, new_tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
726 image_list = self.GetImageList()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
727 img = wx.ImageFromBitmap(bmp_in)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
728 img_data = img.GetData()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
729 image_index = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
730 for key in self.image_cache.keys():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
731 if self.image_cache[key] == str(img_data):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
732 image_index = key
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
733 break
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
734 if image_index is None:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
735 image_index = image_list.Add(bmp_in)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
736 self.image_cache[image_index] = img_data
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
737 self.SetItemImage(new_tree_node,image_index)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
738 self.SetItemImage(new_tree_node,image_index, wx.TreeItemIcon_Selected)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
739 return image_index
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
740
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
741 def on_rclick(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
742 pt = evt.GetPosition()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
743 (item, flag) = self.HitTest(pt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
744 if item.IsOk():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
745 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
746 self.SelectItem(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
747 if(isinstance(obj,core.node_handler)): obj.on_rclick(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
748 else: self.PopupMenu(self.top_menu)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
749 else: self.PopupMenu(self.top_menu,pt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
750
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
751 def on_ldclick(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
752 self.rename_flag = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
753 pt = evt.GetPosition()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
754 (item, flag) = self.HitTest(pt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
755 if item.IsOk():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
756 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
757 self.SelectItem(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
758 if(isinstance(obj,core.node_handler)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
759 if not obj.on_ldclick(evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
760 action = settings.get_setting("treedclick")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
761 if action == "use": obj.on_use(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
762 elif action == "design": obj.on_design(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
763 elif action == "print": obj.on_html_view(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
764 elif action == "chat": self.on_send_to_chat(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
765
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
766 def on_left_down(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
767 pt = evt.GetPosition()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
768 (item, flag) = self.HitTest(pt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
769 if item.IsOk() and self.was_labeling:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
770 self.SelectItem(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
771 self.rename_flag = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
772 self.was_labeling = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
773 elif (flag & wx.TREE_HITTEST_ONITEMLABEL) == wx.TREE_HITTEST_ONITEMLABEL and self.IsSelected(item):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
774 # this next if tests to ensure that the mouse up occurred over a label, and not the icon
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
775 self.rename_flag = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
776 else: self.SelectItem(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
777 evt.Skip()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
778
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
779 def on_left_up(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
780 if self.dragging:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
781 cur = wx.StockCursor(wx.CURSOR_ARROW)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
782 self.SetCursor(cur)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
783 self.dragging = False
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
784 pt = evt.GetPosition()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
785 (item, flag) = self.HitTest(pt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
786 if item.IsOk():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
787 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
788 self.SelectItem(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
789 if(isinstance(obj,core.node_handler)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
790 obj.on_drop(evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
791 self.drag_obj = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
792
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
793 def traverse(self, root, function, data=None, recurse=True):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
794 child, cookie = self.GetFirstChild(root)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
795 while child.IsOk():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
796 function(child, data)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
797 if recurse: self.traverse(child, function, data)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
798 child, cookie = self.GetNextChild(root, cookie)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
799
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
800 def on_label_change(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
801 item = evt.GetItem()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
802 txt = evt.GetLabel()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
803 self.was_labeling = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
804 self.rename_flag = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
805 if txt != "":
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
806 obj = self.GetPyData(item)
196
0bc44a57ae6c Traipse Alpha 'OpenRPG' {100425-00}
sirebral
parents: 178
diff changeset
807 obj.xml_root.set('name',txt)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
808 else: evt.Veto()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
809
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
810 def on_label_begin(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
811 if not self.rename_flag: evt.Veto()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
812 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
813 self.was_labeling = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
814 item = evt.GetItem()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
815 if item == self.GetRootItem(): evt.Veto()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
816
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
817 def on_drag(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
818 self.rename_flag = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
819 item = self.GetSelection()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
820 obj = self.GetPyData(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
821 self.SelectItem(item)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
822 if(isinstance(obj,core.node_handler) and obj.drag):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
823 self.dragging = True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
824 cur = wx.StockCursor(wx.CURSOR_HAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
825 self.SetCursor(cur)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
826 self.drag_obj = obj
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
827
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
828 def is_parent_node(self, node, compare_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
829 parent_node = self.GetItemParent(node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
830 if compare_node == parent_node:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
831 logger.debug("parent node")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
832 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
833 elif parent_node == self.root:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
834 logger.debug("not parent")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
835 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
836 else: return self.is_parent_node(parent_node, compare_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
837
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
838 CTRL_TREE_FILE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
839 CTRL_YES = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
840 CTRL_NO = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
841 CTRL_USE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
842 CTRL_DESIGN = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
843 CTRL_CHAT = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
844 CTRL_PRINT = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
845
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
846 class gametree_prop_dlg(wx.Dialog):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
847
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
848 def __init__(self, parent, settings):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
849 wx.Dialog.__init__(self, parent, wx.ID_ANY, "Game Tree Properties")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
850
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
851 #sizers
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
852 sizers = {}
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
853 sizers['but'] = wx.BoxSizer(wx.HORIZONTAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
854 sizers['main'] = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
855
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
856 #box sizers
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
857 box_sizers = {}
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
858 box_sizers["save"] = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Save On Exit"), wx.HORIZONTAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
859 box_sizers["file"] = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Tree File"), wx.HORIZONTAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
860 box_sizers["dclick"] = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, "Double Click Action"), wx.HORIZONTAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
861 self.ctrls = { CTRL_TREE_FILE : FileBrowseButtonWithHistory(self, wx.ID_ANY, labelText="" ) ,
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
862 CTRL_YES : wx.RadioButton(self, CTRL_YES, "Yes", style=wx.RB_GROUP),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
863 CTRL_NO : wx.RadioButton(self, CTRL_NO, "No"),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
864 CTRL_USE : wx.RadioButton(self, CTRL_USE, "Use", style=wx.RB_GROUP),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
865 CTRL_DESIGN : wx.RadioButton(self, CTRL_DESIGN, "Desgin"),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
866 CTRL_CHAT : wx.RadioButton(self, CTRL_CHAT, "Chat"),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
867 CTRL_PRINT : wx.RadioButton(self, CTRL_PRINT, "Pretty Print")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
868 }
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
869 self.ctrls[CTRL_TREE_FILE].SetValue(settings.get_setting("gametree"))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
870 opt = settings.get_setting("SaveGameTreeOnExit")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
871 self.ctrls[CTRL_YES].SetValue(opt=="1")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
872 self.ctrls[CTRL_NO].SetValue(opt=="0")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
873 opt = settings.get_setting("treedclick")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
874 self.ctrls[CTRL_DESIGN].SetValue(opt=="design")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
875 self.ctrls[CTRL_USE].SetValue(opt=="use")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
876 self.ctrls[CTRL_CHAT].SetValue(opt=="chat")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
877 self.ctrls[CTRL_PRINT].SetValue(opt=="print")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
878 box_sizers['save'].Add(self.ctrls[CTRL_YES],0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
879 box_sizers['save'].Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
880 box_sizers['save'].Add(self.ctrls[CTRL_NO],0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
881 box_sizers['file'].Add(self.ctrls[CTRL_TREE_FILE], 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
882 box_sizers['dclick'].Add(self.ctrls[CTRL_USE],0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
883 box_sizers['dclick'].Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
884 box_sizers['dclick'].Add(self.ctrls[CTRL_DESIGN],0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
885 box_sizers['dclick'].Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
886 box_sizers['dclick'].Add(self.ctrls[CTRL_CHAT],0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
887 box_sizers['dclick'].Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
888 box_sizers['dclick'].Add(self.ctrls[CTRL_PRINT],0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
889
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
890 # buttons
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
891 sizers['but'].Add(wx.Button(self, wx.ID_OK, "Apply"), 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
892 sizers['but'].Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
893 sizers['but'].Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
894 sizers['main'].Add(box_sizers['save'], 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
895 sizers['main'].Add(box_sizers['file'], 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
896 sizers['main'].Add(box_sizers['dclick'], 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
897 sizers['main'].Add(sizers['but'], 0, wx.EXPAND|wx.ALIGN_BOTTOM )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
898
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
899 #sizers['main'].SetDimension(10,10,csize[0]-20,csize[1]-20)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
900 self.SetSizer(sizers['main'])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
901 self.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
902 self.Fit()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
903 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
904
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
905
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
906 def on_ok(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
907 settings.change("gametree",self.ctrls[CTRL_TREE_FILE].GetValue())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
908 settings.change("SaveGameTreeOnExit",str(self.ctrls[CTRL_YES].GetValue()))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
909 if self.ctrls[CTRL_USE].GetValue(): settings.change("treedclick","use")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
910 elif self.ctrls[CTRL_DESIGN].GetValue(): settings.change("treedclick","design")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
911 elif self.ctrls[CTRL_PRINT].GetValue(): settings.change("treedclick","print")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
912 elif self.ctrls[CTRL_CHAT].GetValue(): settings.change("treedclick","chat")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 153
diff changeset
913 self.EndModal(wx.ID_OK)