annotate orpg/gametree/gametree.py @ 191:a3d7e05085da beta

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