annotate orpg/gametree/nodehandlers/core.py @ 156:3b6888bb53b5 beta

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