annotate orpg/gametree/nodehandlers/core.py @ 159:033887bb8a86 alpha

Traipse Alpha 'OpenRPG' {091126-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 (Keeping up with Beta) New Features: Added Bookmarks Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) Portable Mercurial Tip of the Day added, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added Fixes: 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 Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix. *Whiteboard from Core not showing* default_manifest.xml renamed to default_upmana.xml Fix to Update Manager; cleaner clode for saved repositories
author sirebral
date Thu, 26 Nov 2009 14:24:19 -0600
parents bf799efe7a8a
children 0dde29a41614
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:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
24 # $Id: core.py,v 1.49 2007/12/07 20:39:48 digitalxero Exp $
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
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
29 __version__ = "$Id: core.py,v 1.49 2007/12/07 20:39:48 digitalxero Exp $"
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
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
32
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
33 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
34 from orpg.orpg_windows import *
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
35 from orpg.dirpath import dir_struct
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
36 from orpg.orpgCore import component
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
37 import webbrowser, os
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
38 from orpg.mapper import map
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
39 from wx import DisplaySize
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
40 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
41 import wx
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
42
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
43 from xml.etree.ElementTree import ElementTree, Element, tostring, XML
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
44 from orpg.tools.orpg_log import debug
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
45
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
46 #html defaults
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
47 TH_BG = "#E9E9E9"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
48 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
49 ## base node handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
50 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
51 class node_handler:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
52 """ Base nodehandler with virtual functions and standard implmentations """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
53 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
54 self.xml = xml
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
55 self.mytree_node = tree_node
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
56 self.tree = component.get('tree')
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
57 self.frame = component.get('frame')
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
58 self.chat = component.get('chat')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
59 self.drag = True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
60 self.myeditor = None # designing
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
61 self.myviewer = None # prett print
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
62 self.mywindow = None # using
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
63 # call version hook
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
64 self.on_version(self.xml.get("version"))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
65 # set to current version
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
66 self.xml.set("version",NODEHANDLER_VERSION)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
67 # null events
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
68 self.frame_size = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
69 self.frame_pos = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
70 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
71 frame = self.xml.get("frame")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
72 if len(frame):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
73 (sx,sy,px,py) = [int(value) for value in frame.split(',')]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
74 self.frame_size = (sx, sy)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
75 (maxx, maxy) = DisplaySize()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
76 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
77 except: pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
78
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
79 def on_version(self,old_version):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
80 ## 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
81 ## always call the base class on_version !
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
82 pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
83
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
84 def on_rclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
85 self.tree.do_std_menu(evt,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
86
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
87 def on_ldclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
88 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
89
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
90 def usefulness(self,text):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
91 if text=="useful": self.xml.set('status',"useful")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
92 elif text=="useless": self.xml.set('status',"useless")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
93 elif text=="indifferent": self.xml.set('status',"indifferent")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
94
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
95 def on_design(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
96 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
97 self.myeditor.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
98 self.myeditor.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
99 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
100 del self.myeditor
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
101 if self.create_designframe():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
102 self.myeditor.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
103 self.myeditor.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
104 else: return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
105 wx.CallAfter(self.myeditor.Layout)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
106
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
107 def create_designframe(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
108 title = self.xml.get('name') + " Editor"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
109 self.myeditor = wx.Frame(None, -1, title)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
110 self.myeditor.Freeze()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
111 if wx.Platform == '__WXMSW__':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
112 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
113 self.myeditor.SetIcon(icon)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
114 del icon
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
115
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
116 self.myeditor.panel = self.get_design_panel(self.myeditor)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
117 if self.myeditor.panel == None:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
118 self.myeditor.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
119 return False
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
120 sizer = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
121 sizer.Add(self.myeditor.panel, 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
122
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
123 self.myeditor.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
124 self.myeditor.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
125
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
126 (x, y) = self.myeditor.GetSize()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
127 if x < 400: x = 400
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
128 if y < 400: y = 400
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
129
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
130 self.myeditor.SetSize((x, y))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
131 self.myeditor.Layout()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
132 self.myeditor.Thaw()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
133 return True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
134
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
135 def on_use(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
136 try:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
137 self.mywindow.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
138 self.mywindow.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
139 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
140 del self.mywindow
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
141 if self.create_useframe():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
142 self.mywindow.SetSize(self.frame_size)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
143 if self.frame_pos: self.mywindow.SetPosition(self.frame_pos)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
144 self.mywindow.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
145 self.mywindow.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
146 else: return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
147 wx.CallAfter(self.mywindow.Layout)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
148
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
149 def create_useframe(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
150 caption = self.xml.get('name', '')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
151 self.mywindow = wx.Frame(None, -1, caption)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
152 self.mywindow.Freeze()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
153 if wx.Platform == '__WXMSW__':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
154 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
155 self.mywindow.SetIcon(icon)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
156 del icon
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
157 self.mywindow.panel = self.get_use_panel(self.mywindow)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
158 if self.mywindow.panel == None:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
159 self.mywindow.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
160 return False
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
161 sizer = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
162 sizer.Add(self.mywindow.panel, 2, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
163
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
164 self.mywindow.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
165 self.mywindow.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
166
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
167 if self.frame_size is None:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
168 self.frame_size = self.mywindow.GetSize()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
169 if self.frame_size.x < 400: self.frame_size.x = 400
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
170 if self.frame_size.y < 400: self.frame_size.y = 400
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
171
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
172 self.mywindow.Layout()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
173 self.mywindow.Thaw()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
174 self.mywindow.Bind(wx.EVT_CLOSE, self.close_useframe)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
175 return True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
176
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
177 def close_useframe(self, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
178 self.frame_size = self.mywindow.GetSize()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
179 self.frame_pos = self.mywindow.GetPosition()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
180 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
181 self.xml.set("frame", frame_values)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
182 self.mywindow.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
183
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
184
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
185 def on_html_view(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
186 try: self.myviewer.Raise()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
187 except:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
188 caption = self.xml.get('name')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
189 self.myviewer = wx.Frame(None, -1, caption)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
190 if wx.Platform == '__WXMSW__':
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
191 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
192 self.myviewer.SetIcon(icon)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
193 del icon
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
194 self.myviewer.panel = self.get_html_panel(self.myviewer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
195 self.myviewer.Show()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
196
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
197 def map_aware(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
198 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
199
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
200 def can_clone(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
201 return 1;
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
202
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
203 def on_del(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
204 print "on del"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
205
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
206 def on_new_data(self,xml):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
207 pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
208
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
209 def get_scaled_bitmap(self,x,y):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
210 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
211
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
212 def on_send_to_map(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
213 pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
214
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
215 def on_send_to_chat(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
216 self.chat.ParsePost(self.tohtml(),True,True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
217
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
218 def on_drop(self, evt):
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
219 drag_obj = self.tree.drag_obj
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
220 if drag_obj == self or self.tree.is_parent_node(self.mytree_node, drag_obj.mytree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
221 return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
222 drop_xml = self.tree.drag_obj.delete()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
223 parent_node = self.tree.GetItemParent(self.mytree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
224 prev_sib = self.tree.GetPrevSibling(self.mytree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
225 if parent_node == self.tree.root: parent_xml = self.tree.GetPyData(parent_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
226 else: parent_xml = self.tree.GetPyData(parent_node).xml
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
227 for i in range(len(parent_xml)):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
228 if parent_xml[i] is self.xml:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
229 parent_xml.insert(i, drop_xml)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
230 break
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
231 if not prev_sib.IsOk():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
232 prev_sib = parent_node
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
233 self.tree.load_xml(drop_xml, parent_node, prev_sib)
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
234
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
235 def get_tree(self):
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
236 family = []
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
237 test = treenode
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
238 while test != self.tree.root:
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
239 test = self.tree.GetItemParent(test)
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
240 parent = self.tree.GetItemText(test)
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
241 family.append(parent)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
242 return family
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
243
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
244 def toxml(self,pretty=0):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
245 return tostring(self.xml) #toxml(self.master_dom,pretty)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
246
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
247 def tohtml(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
248 return self.xml.get("name")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
249
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
250 def delete(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
251 """ removes the tree_node and xml_node, and returns the removed xml_node """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
252 parent_node = self.tree.GetItemParent(self.mytree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
253 if parent_node == self.tree.root: parent_xml = self.tree.GetPyData(parent_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
254 else: parent_xml = self.tree.GetPyData(parent_node).xml
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
255 parent_xml.remove(self.xml)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
256 self.tree.Delete(self.mytree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
257 return self.xml
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
258
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
259 def rename(self,name):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
260 if len(name):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
261 self.tree.SetItemText(self.mytree_node,name)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
262 self.xml.set('name', name)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
263
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
264 def change_icon(self,icon):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
265 self.xml.set("icon",icon)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
266 self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
267 self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon], wx.TreeItemIcon_Selected)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
268 self.tree.Refresh()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
269
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
270 def on_save(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
271 f = wx.FileDialog(self.tree,"Select a file", orpg.dirpath.dir_struct["user"],"","XML files (*.xml)|*.xml",wx.SAVE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
272 if f.ShowModal() == wx.ID_OK: ElementTree(self.xml).write(f.GetPath())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
273 f.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
274
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
275 def get_design_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
276 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
277
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
278 def get_use_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
279 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
280
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
281 def get_html_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
282 html_str = "<html><body bgcolor=\"#FFFFFF\" >"+self.tohtml()+"</body></html>"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
283 wnd = wx.html.HtmlWindow(parent,-1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
284 html_str = self.chat.ParseDice(html_str)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
285 wnd.SetPage(html_str)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
286 return wnd
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
287
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
288 def get_size_constraint(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
289 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
290
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
291 def about(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
292 """html_str = "<b>"+ self.xml.get('class')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
293 html_str += " Applet</b><br />by Chris Davis<br />chris@rpgarchive.com"
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
294 return html_str"""
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
295 text = self.xml.get('class') + ' Applet\n'
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
296 text += 'by Chris Davis chris@rpgarchive.com'
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
297 return text
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
298
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 118
diff changeset
299 def get_value(self):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
300 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
301
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
302 P_TITLE = 10
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 132
diff changeset
303 P_BODY = 20
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
304
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
305 class text_edit_panel(wx.Panel):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
306 def __init__(self, parent, handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
307 wx.Panel.__init__(self, parent, -1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
308 self.handler = handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
309 sizer = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
310 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
311 P_BODY : html_text_edit(self,P_BODY,handler.text,self.on_text)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
312 }
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
313 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
314 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
315 sizer.Add(wx.StaticText(self, -1, "Text Body:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
316 sizer.Add(self.text[P_BODY], 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
317 self.sizer = sizer
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
318 self.outline = wx.StaticBox(self,-1,"Text Block")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
319 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
320
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
321 def on_text(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
322 id = evt.GetId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
323 if id == P_TITLE:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
324 txt = self.text[id].GetValue()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
325 # The following block strips out 8-bit characters
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
326 u_txt = ""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
327 bad_txt_found = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
328 for c in txt:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
329 if ord(c) < 128: u_txt += c
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
330 else: bad_txt_found = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
331 if bad_txt_found:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
332 wx.MessageBox("Some non 7-bit ASCII characters found and stripped","Warning!")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
333 txt = u_txt
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
334 if txt != "":
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
335 self.handler.xml.set('name',txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
336 self.handler.rename(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
337 elif id == P_BODY:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
338 txt = self.text[id].get_text()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
339 u_txt = ""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
340 bad_txt_found = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
341 for c in txt:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
342 if ord(c) < 128: u_txt += c
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
343 else: bad_txt_found = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
344 if bad_txt_found:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
345 wx.MessageBox("Some non 7-bit ASCII characters found and stripped","Warning!")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
346 txt = u_txt
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
347 self.handler.text._set_nodeValue(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
348
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
349
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 ## node loader
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
353 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
354 class node_loader(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
355 """ clones childe node and insert it at top of tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
356 <nodehandler name='?' module='core' class='node_loader' />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
357 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
358 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
359 node_handler.__init__(self,xml,tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
360
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
361 def on_rclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
362 pass
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
363
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
364 def on_ldclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
365 title = self.xml.get('name')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
366 new_xml = XML(tostring(self.xml[0]))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
367 self.tree.root_xml.insert(0, new_xml)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
368 tree_node = self.tree.load_xml(new_xml,self.tree.root,self.tree.root)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
369 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
370
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
371 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
372 ## file loader
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
373 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
374
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
375 class file_loader(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
376 """ loads file and insert into game tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
377 <nodehandler name='?' module='core' class='file_loader' >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
378 <file name="file_name.xml" />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
379 </nodehandler>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
380 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
381 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
382 node_handler.__init__(self,xml,tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
383 self.file_node = self.xml[0]
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
384 self.frame = component.get('frame')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
385
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
386 def on_ldclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
387 file_name = self.file_node.get("name")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
388 self.tree.insert_xml(open(orpg.dirpath.dir_struct["nodes"] + file_name,"r").read())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
389 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
390
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
391 def on_design(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
392 tlist = ['Title','File Name']
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
393 vlist = [self.xml.get("name"),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
394 self.file_node.get("name")]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
395 dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
396 if dlg.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
397 vlist = dlg.get_values()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
398 self.file_node.set('name', vlist[1])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
399 self.xml.set('name', vlist[0])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
400 self.tree.SetItemText(self.mytree_node,vlist[0])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
401 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
402
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
403 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
404 ## URL loader
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 class url_loader(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
408 """ loads file from url and insert into game tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
409 <nodehandler name='?' module='core' class='url_loader' >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
410 <file name="http://file_name.xml" />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
411 </nodehandler>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
412 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
413 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
414 node_handler.__init__(self,xml,tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
415 self.file_node = self.xml[0]
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
416 self.frame = component.get('frame')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
417
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
418 def on_ldclick(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
419 file_name = self.file_node.get("url")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
420 file = urllib.urlopen(file_name)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
421 self.tree.insert_xml(file.read())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
422 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
423
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
424 def on_design(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
425 tlist = ['Title','URL']
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
426 print "design filename",self.xml.get('name')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
427 vlist = [self.xml.get("name"),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
428 self.file_node.get("url")]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
429 dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
430 if dlg.ShowModal() == wx.ID_OK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
431 vlist = dlg.get_values()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
432 self.file_node.set('url', vlist[1])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
433 self.xml.set('name', vlist[0])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
434 self.tree.SetItemText(self.mytree_node,vlist[0])
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
435 dlg.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
436
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
437
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
438 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
439 ## minature map loader
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
440 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
441 class min_map(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
442 """ clones childe node and insert it at top of tree
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
443 <nodehandler name='?' module='core' class='min_map' />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
444 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
445 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
446 node_handler.__init__(self,xml,tree_node)
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
447 self.map = component.get('map')
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
448 self.mapdata = self.xml.find('map')
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
449
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
450 def on_ldclick(self,evt):
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
451 if (component.get('session').my_role() != component.get('session').ROLE_GM):
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
452 component.get('chat').InfoPost("You must be a GM to use this feature")
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
453 return
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
454 self.map.new_data(tostring(self.mapdata))
159
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
455 component.get('session').send(tostring(self.mapdata))
033887bb8a86 Traipse Alpha 'OpenRPG' {091126-00}
sirebral
parents: 155
diff changeset
456 self.map.canvas.send_map_data()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
457 return 1