annotate orpg/gametree/nodehandlers/core.py @ 227:81d0bfd5e800 alpha

Traipse Alpha 'OpenRPG' {100612-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 (Preparing to close updates) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created
author sirebral
date Sat, 12 Jun 2010 03:50:37 -0500
parents 12ba14d30baa
children
rev   line source
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
2 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
3 # openrpg-dev@lists.sourceforge.net
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
4 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
5 # This program is free software; you can redistribute it and/or modify
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
6 # it under the terms of the GNU General Public License as published by
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
8 # (at your option) any later version.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
9 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
10 # This program is distributed in the hope that it will be useful,
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
13 # GNU General Public License for more details.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
14 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
15 # You should have received a copy of the GNU General Public License
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
16 # along with this program; if not, write to the Free Software
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
18 # --
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
19 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
20 # File: core.py
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
21 # Author: Chris Davis
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
22 # Maintainer:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
23 # Version:
227
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents: 180
diff changeset
24 # $Id: core.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
25 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
26 # Description: The file contains code for the core nodehanlers
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
27 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
28
227
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents: 180
diff changeset
29 __version__ = "$Id: core.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
30
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
31 from nodehandler_version import NODEHANDLER_VERSION
227
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents: 180
diff changeset
32 from orpg.tools.InterParse import Parse
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
33
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
34 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
35 from orpg.orpg_windows import *
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
36 from orpg.dirpath import dir_struct
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
37 from orpg.orpgCore import component
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
38 import webbrowser, os
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
39 from orpg.mapper import map
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
40 from wx import DisplaySize
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
41 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
42 import wx
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
43
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
44 from xml.etree.ElementTree import ElementTree, Element, tostring, XML
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
45 from orpg.tools.orpg_log import debug
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
46
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
47 #html defaults
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
48 TH_BG = "#E9E9E9"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
49 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
50 ## base node handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
51 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
52 class node_handler:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
53 """ Base nodehandler with virtual functions and standard implmentations """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
54 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
55 self.xml = xml
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
56 self.mytree_node = tree_node
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
57 self.tree = component.get('tree')
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
58 self.frame = component.get('frame')
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
59 self.chat = component.get('chat')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
60 self.drag = True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
61 self.myeditor = None # designing
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
62 self.myviewer = None # prett print
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
63 self.mywindow = None # using
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
64 # call version hook
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
65 self.on_version(self.xml.get("version"))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
66 # set to current version
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
67 self.xml.set("version",NODEHANDLER_VERSION)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
68 # null events
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
69 self.frame_size = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
70 self.frame_pos = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
71 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
72 frame = self.xml.get("frame")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
73 if len(frame):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
74 (sx,sy,px,py) = [int(value) for value in frame.split(',')]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
75 self.frame_size = (sx, sy)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
76 (maxx, maxy) = DisplaySize()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
77 if px < maxx-80 and py < maxy-50: self.frame_pos = (px, py) #if it's off screen ignore the saved pos
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
78 except: pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
79
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
80 def on_version(self,old_version):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
81 ## added version control code here or implement a new on_version in your derived class.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
82 ## always call the base class on_version !
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
83 pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
84
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
85 def on_rclick(self,evt):
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
86 self.tree.do_std_menu(evt,self)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
87
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
88 def on_ldclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
89 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
90
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
91 def usefulness(self,text):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
92 if text=="useful": self.xml.set('status',"useful")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
93 elif text=="useless": self.xml.set('status',"useless")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
94 elif text=="indifferent": self.xml.set('status',"indifferent")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
95
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
96 def on_design(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
97 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
98 self.myeditor.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
99 self.myeditor.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
100 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
101 del self.myeditor
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
102 if self.create_designframe():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
103 self.myeditor.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
104 self.myeditor.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
105 else: return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
106 wx.CallAfter(self.myeditor.Layout)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
107
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
108 def create_designframe(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
109 title = self.xml.get('name') + " Editor"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
110 self.myeditor = wx.Frame(None, -1, title)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
111 self.myeditor.Freeze()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
112 if wx.Platform == '__WXMSW__':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
113 icon = wx.Icon(orpg.dirpath.dir_struct["icon"] + 'grid.ico', wx.BITMAP_TYPE_ICO)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
114 self.myeditor.SetIcon(icon)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
115 del icon
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
116
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
117 self.myeditor.panel = self.get_design_panel(self.myeditor)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
118 if self.myeditor.panel == None:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
119 self.myeditor.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
120 return False
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
121 sizer = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
122 sizer.Add(self.myeditor.panel, 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
123
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
124 self.myeditor.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
125 self.myeditor.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
126
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
127 (x, y) = self.myeditor.GetSize()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
128 if x < 400: x = 400
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
129 if y < 400: y = 400
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
130
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
131 self.myeditor.SetSize((x, y))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
132 self.myeditor.Layout()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
133 self.myeditor.Thaw()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
134 return True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
135
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 159
diff changeset
136 def on_use(self, evt):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
137 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
138 self.mywindow.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
139 self.mywindow.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
140 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
141 del self.mywindow
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
142 if self.create_useframe():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
143 self.mywindow.SetSize(self.frame_size)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
144 if self.frame_pos: self.mywindow.SetPosition(self.frame_pos)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
145 self.mywindow.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
146 self.mywindow.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
147 else: return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
148 wx.CallAfter(self.mywindow.Layout)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
149
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
150 def create_useframe(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
151 caption = self.xml.get('name', '')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
152 self.mywindow = wx.Frame(None, -1, caption)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
153 self.mywindow.Freeze()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
154 if wx.Platform == '__WXMSW__':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
155 icon = wx.Icon(orpg.dirpath.dir_struct["icon"] + 'note.ico', wx.BITMAP_TYPE_ICO)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
156 self.mywindow.SetIcon(icon)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
157 del icon
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
158 self.mywindow.panel = self.get_use_panel(self.mywindow)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
159 if self.mywindow.panel == None:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
160 self.mywindow.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
161 return False
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
162 sizer = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
163 sizer.Add(self.mywindow.panel, 2, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
164
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
165 self.mywindow.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
166 self.mywindow.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
167
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
168 if self.frame_size is None:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
169 self.frame_size = self.mywindow.GetSize()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
170 if self.frame_size.x < 400: self.frame_size.x = 400
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
171 if self.frame_size.y < 400: self.frame_size.y = 400
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
172
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
173 self.mywindow.Layout()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
174 self.mywindow.Thaw()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
175 self.mywindow.Bind(wx.EVT_CLOSE, self.close_useframe)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
176 return True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
177
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
178 def close_useframe(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
179 self.frame_size = self.mywindow.GetSize()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
180 self.frame_pos = self.mywindow.GetPosition()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
181 frame_values = str(self.frame_size.x)+','+str(self.frame_size.y)+','+str(self.frame_pos.x)+','+str(self.frame_pos.y)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
182 self.xml.set("frame", frame_values)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
183 self.mywindow.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
184
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
185
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
186 def on_html_view(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
187 try: self.myviewer.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
188 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
189 caption = self.xml.get('name')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
190 self.myviewer = wx.Frame(None, -1, caption)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
191 if wx.Platform == '__WXMSW__':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
192 icon = wx.Icon(orpg.dirpath.dir_struct["icon"] + 'grid.ico', wx.BITMAP_TYPE_ICO)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
193 self.myviewer.SetIcon(icon)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
194 del icon
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
195 self.myviewer.panel = self.get_html_panel(self.myviewer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
196 self.myviewer.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
197
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
198 def map_aware(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
199 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
200
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
201 def can_clone(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
202 return 1;
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
203
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
204 def on_del(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
205 print "on del"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
206
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
207 def on_new_data(self,xml):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
208 pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
209
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
210 def get_scaled_bitmap(self,x,y):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
211 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
212
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
213 def on_send_to_map(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
214 pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
215
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
216 def on_send_to_chat(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
217 self.chat.ParsePost(self.tohtml(),True,True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
218
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
219 def on_drop(self, evt):
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
220 drag_obj = self.tree.drag_obj
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
221 if drag_obj == self or self.tree.is_parent_node(self.mytree_node, drag_obj.mytree_node):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
222 return
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
223 drop_xml = self.tree.drag_obj.delete()
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
224 parent_node = self.tree.GetItemParent(self.mytree_node)
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
225 prev_sib = self.tree.GetPrevSibling(self.mytree_node)
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
226 if parent_node == self.tree.root: parent_xml = self.tree.GetPyData(parent_node)
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
227 else: parent_xml = self.tree.GetPyData(parent_node).xml
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
228 for i in range(len(parent_xml)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
229 if parent_xml[i] is self.xml:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
230 parent_xml.insert(i, drop_xml)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
231 break
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
232 if not prev_sib.IsOk():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
233 prev_sib = parent_node
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
234 self.tree.load_xml(drop_xml, parent_node, prev_sib)
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
235
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
236 def get_tree(self):
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
237 family = []
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
238 test = treenode
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
239 while test != self.tree.root:
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
240 test = self.tree.GetItemParent(test)
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
241 parent = self.tree.GetItemText(test)
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
242 family.append(parent)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
243 return family
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
244
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
245 def toxml(self,pretty=0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
246 return tostring(self.xml) #toxml(self.master_dom,pretty)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
247
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
248 def tohtml(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
249 return self.xml.get("name")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
250
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
251 def delete(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
252 """ removes the tree_node and xml_node, and returns the removed xml_node """
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
253 parent_node = self.tree.GetItemParent(self.mytree_node)
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
254 if parent_node == self.tree.root: parent_xml = self.tree.GetPyData(parent_node)
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
255 else: parent_xml = self.tree.GetPyData(parent_node).xml
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
256 parent_xml.remove(self.xml)
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
257 self.tree.Delete(self.mytree_node)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
258 return self.xml
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
259
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
260 def rename(self,name):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
261 if len(name):
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
262 self.tree.SetItemText(self.mytree_node,name)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
263 self.xml.set('name', name)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
264
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
265 def change_icon(self,icon):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
266 self.xml.set("icon",icon)
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
267 self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon])
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
268 self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon], wx.TreeItemIcon_Selected)
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
269 self.tree.Refresh()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
270
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
271 def on_save(self,evt):
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
272 f = wx.FileDialog(self.tree,"Select a file", orpg.dirpath.dir_struct["user"],"","XML files (*.xml)|*.xml",wx.SAVE)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
273 if f.ShowModal() == wx.ID_OK: ElementTree(self.xml).write(f.GetPath())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
274 f.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
275
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
276 def get_design_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
277 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
278
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
279 def get_use_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
280 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
281
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
282 def get_html_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
283 html_str = "<html><body bgcolor=\"#FFFFFF\" >"+self.tohtml()+"</body></html>"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
284 wnd = wx.html.HtmlWindow(parent,-1)
227
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents: 180
diff changeset
285 html_str = Parse.Dice(html_str)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
286 wnd.SetPage(html_str)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
287 return wnd
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
288
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
289 def get_size_constraint(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
290 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
291
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
292 def about(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
293 """html_str = "<b>"+ self.xml.get('class')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
294 html_str += " Applet</b><br />by Chris Davis<br />chris@rpgarchive.com"
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
295 return html_str"""
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
296 text = self.xml.get('class') + ' Applet\n'
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
297 text += 'by Chris Davis chris@rpgarchive.com'
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
298 return text
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
299
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
300 def get_value(self):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
301 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
302
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
303 P_TITLE = 10
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
304 P_BODY = 20
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
305
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
306 class text_edit_panel(wx.Panel):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
307 def __init__(self, parent, handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
308 wx.Panel.__init__(self, parent, -1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
309 self.handler = handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
310 sizer = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
311 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
312 P_BODY : html_text_edit(self,P_BODY,handler.text,self.on_text)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
313 }
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
314 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
315 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
316 sizer.Add(wx.StaticText(self, -1, "Text Body:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
317 sizer.Add(self.text[P_BODY], 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
318 self.sizer = sizer
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
319 self.outline = wx.StaticBox(self,-1,"Text Block")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
320 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
321
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
322 def on_text(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
323 id = evt.GetId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
324 if id == P_TITLE:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
325 txt = self.text[id].GetValue()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
326 # The following block strips out 8-bit characters
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
327 u_txt = ""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
328 bad_txt_found = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
329 for c in txt:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
330 if ord(c) < 128: u_txt += c
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
331 else: bad_txt_found = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
332 if bad_txt_found:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
333 wx.MessageBox("Some non 7-bit ASCII characters found and stripped","Warning!")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
334 txt = u_txt
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
335 if txt != "":
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
336 self.handler.xml.set('name',txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
337 self.handler.rename(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
338 elif id == P_BODY:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
339 txt = self.text[id].get_text()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
340 u_txt = ""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
341 bad_txt_found = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
342 for c in txt:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
343 if ord(c) < 128: u_txt += c
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
344 else: bad_txt_found = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
345 if bad_txt_found:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
346 wx.MessageBox("Some non 7-bit ASCII characters found and stripped","Warning!")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
347 txt = u_txt
227
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents: 180
diff changeset
348 print txt, self.handler, self.handler.xml
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
349 self.handler.text._set_nodeValue(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
350
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
351
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
352
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
353 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
354 ## node loader
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
355 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
356 class node_loader(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
357 """ clones childe node and insert it at top of tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
358 <nodehandler name='?' module='core' class='node_loader' />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
359 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
360 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
361 node_handler.__init__(self,xml,tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
362
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
363 def on_rclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
364 pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
365
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
366 def on_ldclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
367 title = self.xml.get('name')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
368 new_xml = XML(tostring(self.xml[0]))
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
369 self.tree.root_xml.insert(0, new_xml)
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
370 tree_node = self.tree.load_xml(new_xml,self.tree.root,self.tree.root)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
371 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
372
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
373 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
374 ## file loader
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
375 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
376
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
377 class file_loader(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
378 """ loads file and insert into game tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
379 <nodehandler name='?' module='core' class='file_loader' >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
380 <file name="file_name.xml" />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
381 </nodehandler>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
382 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
383 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
384 node_handler.__init__(self,xml,tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
385 self.file_node = self.xml[0]
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
386 self.frame = component.get('frame')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
387
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
388 def on_ldclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
389 file_name = self.file_node.get("name")
227
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents: 180
diff changeset
390 try: self.tree.insert_xml(open(orpg.dirpath.dir_struct["nodes"] + file_name,"r").read())
81d0bfd5e800 Traipse Alpha 'OpenRPG' {100612-00}
sirebral
parents: 180
diff changeset
391 except: wx.MessageBox('Invalid File', 'Error')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
392 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
393
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
394 def on_design(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
395 tlist = ['Title','File Name']
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
396 vlist = [self.xml.get("name"),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
397 self.file_node.get("name")]
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
398 dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit")
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
399 if dlg.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
400 vlist = dlg.get_values()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
401 self.file_node.set('name', vlist[1])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
402 self.xml.set('name', vlist[0])
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
403 self.tree.SetItemText(self.mytree_node,vlist[0])
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
404 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
405
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
406 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
407 ## URL loader
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
408 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
409
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
410 class url_loader(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
411 """ loads file from url and insert into game tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
412 <nodehandler name='?' module='core' class='url_loader' >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
413 <file name="http://file_name.xml" />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
414 </nodehandler>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
415 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
416 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
417 node_handler.__init__(self,xml,tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
418 self.file_node = self.xml[0]
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
419 self.frame = component.get('frame')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
420
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
421 def on_ldclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
422 file_name = self.file_node.get("url")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
423 file = urllib.urlopen(file_name)
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
424 self.tree.insert_xml(file.read())
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
425 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
426
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
427 def on_design(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
428 tlist = ['Title','URL']
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
429 vlist = [self.xml.get("name"),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
430 self.file_node.get("url")]
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
431 dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit")
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
432 if dlg.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
433 vlist = dlg.get_values()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
434 self.file_node.set('url', vlist[1])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
435 self.xml.set('name', vlist[0])
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
436 self.tree.SetItemText(self.mytree_node,vlist[0])
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
437 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
438
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
439
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
440 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
441 ## minature map loader
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
442 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
443 class min_map(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
444 """ clones childe node and insert it at top of tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
445 <nodehandler name='?' module='core' class='min_map' />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
446 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
447 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
448 node_handler.__init__(self,xml,tree_node)
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
449 self.map = component.get('map')
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
450 self.mapdata = self.xml.find('map')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
451
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
452 def on_ldclick(self,evt):
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
453 if (component.get('session').my_role() != component.get('session').ROLE_GM):
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
454 component.get('chat').InfoPost("You must be a GM to use this feature")
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
455 return
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
456 self.map.new_data(tostring(self.mapdata))
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
457 component.get('session').send(tostring(self.mapdata))
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
458 self.map.canvas.send_map_data()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
459 return 1