annotate orpg/gametree/nodehandlers/forms.py @ 195:b633f4c64aae alpha

Traipse Alpha 'OpenRPG' {100219-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 (Patch-2) New Features: New Namespace method with two new syntaxes Fixes: Fix to Server GUI startup errors Fix to Server GUI Rooms tab updating Fix to Chat and Settings if non existant die roller is picked Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated Fix to Alias Lib's Export to Tree, Open, Save features Fix to alias node, now works properly Fix to Splitter node, minor GUI cleanup
author sirebral
date Sat, 24 Apr 2010 08:37:20 -0500
parents 4b2884f29a72
children 0bc44a57ae6c
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: forms.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:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
24 # $Id: forms.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
25 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
26 # Description: The file contains code for the form based 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
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
29 __version__ = "$Id: forms.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
30
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
31 from containers import *
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
32 import orpg.minidom as minidom
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
33 from orpg.orpg_xml import xml
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
34 from wx.lib.scrolledpanel import ScrolledPanel
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
35 from orpg.tools.settings import settings
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
36 from orpg.tools.InterParse import Parse
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
37
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
38 def bool2int(b):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
39 #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
40 #by running the results of that through this function, we convert it.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
41 #if it was an int already, nothing changes. The difference between 1.0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
42 #and 1, i.e. between ints and floats, is potentially dangerous when we
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
43 #use str() on it, but it seems to work fine right now.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
44 if b: return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
45 else: return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
46
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
47 #################################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
48 ## form container
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
49 #################################
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 form_handler(container_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
52 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
53 <nodehandler name='?' module='forms' class='form_handler' >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
54 <form width='100' height='100' />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
55 </nodehandler>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
56 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
57 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
58 container_handler.__init__(self, xml, tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
59
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
60 def load_children(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
61 self.atts = None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
62 for child_xml in self.xml:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
63 if child_xml.tag == "form": self.xml.remove(child_xml)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
64 elif child_xml: self.tree.load_xml(child_xml, self.mytree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
65 if not self.xml.get('width'): self.xml.set('width', '400')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
66 if not self.xml.get('height'): self.xml.set('height', '600')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
67
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
68 def get_design_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
69 return form_edit_panel(parent,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
70
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
71 def get_use_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
72 return form_panel(parent,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
73
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
74 def on_drop(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
75 # make sure its a contorl node
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
76 container_handler.on_drop(self,evt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
77
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
78 class form_panel(ScrolledPanel):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
79 def __init__(self, parent, handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
80 ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
81 self.height = int(handler.xml.get("height"))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
82 self.width = int(handler.xml.get("width"))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
83 self.SetSize((0,0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
84 self.handler = handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
85 self.parent = parent
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
86 self.main_sizer = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
87 handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
88 self.SetSizer(self.main_sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
89 self.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
90 self.SetupScrolling()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
91 parent.SetSize(self.GetSize())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
92 self.Fit()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
93
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
94 def SetSize(self, xy):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
95 (x, y) = self.GetSize()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
96 (nx, ny) = xy
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
97 if x < nx:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
98 x = nx+10
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
99 y += ny+11
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
100 ScrolledPanel.SetSize(self, (x, y))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
101
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
102 def create_child_wnd(self, treenode, evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
103 node = self.handler.tree.GetPyData(treenode)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
104 panel = node.get_use_panel(self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
105 size = node.get_size_constraint()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
106 if panel:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
107 self.main_sizer.Add(panel, size, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
108 self.main_sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
109
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
110 F_HEIGHT = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
111 F_WIDTH = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
112 class form_edit_panel(wx.Panel):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
113 def __init__(self, parent, handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
114 wx.Panel.__init__(self, parent, -1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
115 self.handler = handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
116 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
117 wh_sizer = wx.BoxSizer(wx.HORIZONTAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
118 self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
119 F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.xml.get('height')),
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
120 F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.xml.get('width'))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
121 }
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
122
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
123 wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
124 wh_sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
125 wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
126 wh_sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
127 wh_sizer.Add(wx.StaticText(self, -1, "Height:"), 0, wx.ALIGN_CENTER)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
128 wh_sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
129 wh_sizer.Add(self.text[F_HEIGHT], 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
130
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
131 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
132 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
133 sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
134 sizer.Add(wh_sizer,0,wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
135
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
136 self.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
137 self.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
138 self.Fit()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
139 parent.SetSize(self.GetBestSize())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
140
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
141 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
142 self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
143 self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
144
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
145 def on_text(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
146 id = evt.GetId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
147 txt = self.text[id].GetValue()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
148 if not len(txt): return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
149 if id == P_TITLE:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
150 self.handler.xml.set('name',txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
151 self.handler.rename(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
152 elif id == F_HEIGHT or id == F_WIDTH:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
153 try: int(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
154 except: return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
155 if id == F_HEIGHT: self.handler.xml.set("height",txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
156 elif id == F_WIDTH: self.handler.xml.set("width",txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
157
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
158 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
159 ## control handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
160 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
161 class control_handler(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
162 """ A nodehandler for form controls.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
163 <nodehandler name='?' module='forms' class='control_handler' />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
164 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
165 def __init__(self, xml, tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
166 node_handler.__init__(self, xml, tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
167
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
168 def get_size_constraint(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
169 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
170
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
171 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
172 ## textctrl handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
173 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
174 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
175 # Updated by Snowdog (April 2003)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
176 # Now includes Raw Send Mode (like the chat macro uses)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
177 # and an option to remove the title from text when sent
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
178 # to the chat in the normal non-chat macro mode.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
179 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
180 class textctrl_handler(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
181 """ <nodehandler class="textctrl_handler" module="form" name="">
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
182 <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
183 </nodehandler>
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 __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
186 node_handler.__init__(self,xml,tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
187 self.text_elem = self.xml.find('text')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
188 if self.text_elem.get("send_button") == "": self.text_elem.set("send_button","0")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
189 if self.text_elem.get("raw_mode") == "": self.text_elem.set("raw_mode","0")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
190 if self.text_elem.get("hide_title") == "": self.text_elem.set("hide_title","0")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
191
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
192 def get_design_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
193 return textctrl_edit_panel(parent,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
194
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
195 def get_use_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
196 return text_panel(parent,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
197
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
198 def get_size_constraint(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
199 return int(self.text_elem.get("multiline",0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
200
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
201 def is_multi_line(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
202 return int(self.text_elem.get("multiline",0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
203
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
204 def is_raw_send(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
205 return int(self.text_elem.get("raw_mode",0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
206
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
207 def is_hide_title(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
208 return int(self.text_elem.get("hide_title",0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
209
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
210 def has_send_button(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
211 return int(self.text_elem.get("send_button",0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
212
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
213 def tohtml(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
214 txt = self.get_value()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
215 txt = string.replace(txt,'\n',"<br />")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
216 if not self.is_hide_title(): txt = "<b>"+self.xml.get("name")+":</b> "+txt
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
217 return txt
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
218
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
219 def get_value(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
220 return self.text_elem.text
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
221
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
222 def set_value(self, new_value):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
223 self.text_elem.text = str(new_value)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
224
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
225 FORM_TEXT_CTRL = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
226 FORM_SEND_BUTTON = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
227
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
228 class text_panel(wx.Panel):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
229 def __init__(self, parent, handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
230 wx.Panel.__init__(self, parent, -1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
231 self.chat = handler.chat
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
232 self.handler = handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
233 if handler.is_multi_line():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
234 text_style = wx.TE_MULTILINE
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
235 sizer_style = wx.EXPAND
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
236 sizer = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
237 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
238 sizer_style = wx.ALIGN_CENTER
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
239 text_style = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
240 sizer = wx.BoxSizer(wx.HORIZONTAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
241
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
242 txt = handler.get_value()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
243 if txt == None: txt = ''
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
244 self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
245 sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
246 sizer.Add(wx.Size(5,0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
247 sizer.Add(self.text, 1, sizer_style)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
248
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
249 if handler.has_send_button(): sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
250
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
251 self.sizer = sizer
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
252 self.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
253 self.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
254
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
255 parent.SetSize(self.GetBestSize())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
256 self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL)
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 131
diff changeset
257 self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON)
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 131
diff changeset
258
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 131
diff changeset
259 def on_text(self, evt):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
260 txt = self.text.GetValue()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
261 #txt = strip_text(txt) ##Does not seem to exist.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
262 self.handler.text_elem.text = txt
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 on_send(self, evt):
132
fe4dc5817d5e Traipse Alpha 'OpenRPG' {091005-00}
sirebral
parents: 131
diff changeset
265 txt = self.text.GetValue()
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
266 txt = Parse.ParseLogic(txt, self.handler.xml)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
267 if not self.handler.is_raw_send():
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
268 Parse.Post(self.handler.tohtml(), True, True)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
269 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
270 actionlist = txt.split("\n")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
271 for line in actionlist:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
272 line = Parse.ParseLogic(line, self.handler.xml)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
273 if(line != ""):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
274 if line[0] != "/": ## it's not a slash command
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
275 Parse.Post(line, True, True)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
276 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
277 action = line
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
278 self.chat.chat_cmds.docmd(action)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
279 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
280
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
281 F_MULTI = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
282 F_SEND_BUTTON = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
283 F_RAW_SEND = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
284 F_HIDE_TITLE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
285 F_TEXT = wx.NewId()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
286 T_BUT_REF = wx.NewId()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
287
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
288 class textctrl_edit_panel(wx.Panel):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
289 def __init__(self, parent, handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
290 wx.Panel.__init__(self, parent, -1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
291 self.handler = handler
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
292 self.parent = parent
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
293 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
294
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
295 self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
296 self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
297 self.multi.SetValue(handler.is_multi_line())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
298 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
299 self.raw_send.SetValue(handler.is_raw_send())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
300 self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
301 self.hide_title.SetValue(handler.is_hide_title())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
302 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
303 self.send_button.SetValue(handler.has_send_button())
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
304 button_ref = wx.Button(self, T_BUT_REF, "Reference")
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
305
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
306 sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
307 sizer.Add(self.title, 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
308 sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
309 sizer.Add(self.multi, 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
310 sizer.Add(self.raw_send, 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
311 sizer.Add(self.hide_title, 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
312 sizer.Add(self.send_button, 0 , wx.EXPAND)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
313 sizer.Add(button_ref, 0)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
314 sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
315 if handler.is_multi_line():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
316 sizer_style = wx.EXPAND
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
317 text_style = wx.TE_MULTILINE
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
318 multi = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
319 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
320 sizer_style=wx.EXPAND
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
321 text_style = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
322 multi = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
323 self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
324 sizer.Add(wx.Size(5,0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
325 sizer.Add(self.text, multi, sizer_style)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
326 self.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
327 self.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
328
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
329 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
330 self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
331 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
332 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
333 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
334 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
335 self.Bind(wx.EVT_BUTTON, self.on_reference, id=T_BUT_REF)
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
336 self.parent.Bind(wx.EVT_CLOSE, self.tree_failsafe)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
337
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
338 ## EZ_Tree Core TaS - Prof.Ebral ##
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
339 def on_reference(self, evt, car=None):
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 176
diff changeset
340 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
341 self.ez_tree = orpg.gametree.gametree
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
342 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
343 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 176
diff changeset
344 component.get('tree_fs').save_tree(settings.get("gametree"))
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
345 self.temp_wnd.load_tree(settings.get("gametree"))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
346 self.do_tree.Show()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
347
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
348 def tree_failsafe(self, evt):
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
349 self.parent.Destroy()
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
350 component.add('tree', component.get('tree_fs')) ## Backup
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
351
176
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
352 def get_grid_ref(self, obj, complete):
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
353 self.temp_wnd.Freeze()
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
354 self.grid_ref = complete
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 176
diff changeset
355 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Mini Grid')
176
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
356 self.temp_grid = obj.get_use_panel(self.mini_grid)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
357 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
358 self.mini_grid.Show()
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
359
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
360 def on_grid_ldclick(self, evt):
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
361 complete = self.grid_ref
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
362 row = str(evt.GetRow()+1)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
363 col = str(evt.GetCol()+1)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
364 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
365 self.text.AppendText(complete); self.on_text(evt)
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 176
diff changeset
366 self.mini_grid.Destroy()
176
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
367
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
368 def on_ldclick(self, evt):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
369 self.rename_flag = 0
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
370 pt = evt.GetPosition()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
371 (item, flag) = self.temp_wnd.HitTest(pt)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
372 if item.IsOk():
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
373 obj = self.temp_wnd.GetPyData(item)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
374 self.temp_wnd.SelectItem(item)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
375 start = self.handler.xml.get('map').split('::')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
376 end = obj.xml.get('map').split('::')
175
fd6415b8243e Traipse Alpha 'OpenRPG' {100112-01}
sirebral
parents: 174
diff changeset
377 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
174
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
378 elif end[0] == '' or start[0] != end[0]: do = 'Root'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
379 elif start == end: do = 'Child'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
380 elif start != end: do = 'Parent'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
381 if do == 'Root':
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
382 complete = "!@"
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
383 for e in end:
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
384 if e != '': complete += e +'::'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
385 complete = complete + obj.xml.get('name') + '@!'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
386 elif do == 'Parent':
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
387 while start[0] == end[0]:
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
388 del end[0], start[0]
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
389 if len(start) == 0 or len(end) == 0: break
181
fa18af3e04b9 Traipse Alpha 'OpenRPG' {100115-01}
sirebral
parents: 180
diff changeset
390 complete = "!#"
174
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
391 for e in end: complete += e +'::'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
392 complete = complete + obj.xml.get('name') + '#!'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
393 elif do == 'Child':
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
394 while start[0] == end[0]:
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
395 del end[0], start[0]
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
396 if len(start) == 0 or len(end) == 0: break
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
397 complete = "!!"
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
398 for e in end: complete += e +'::'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
399 complete = complete + obj.xml.get('name') + '!!'
176
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
400 if do != 'None':
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
401 if obj.xml.get('class') == 'rpg_grid_handler':
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
402 self.get_grid_ref(obj, complete)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
403 else: self.text.AppendText(complete); self.on_text(evt)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
404 self.do_tree.Destroy()
174
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
405 if do == 'None':
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
406 wx.MessageBox('Invalid Reference', 'Error')
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
407 ##### #####
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
408
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
409 def on_text(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
410 id = evt.GetId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
411 if id == P_TITLE:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
412 txt = self.title.GetValue()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
413 if not len(txt): return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
414 self.handler.xml.set('name',txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
415 self.handler.rename(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
416 if id == F_TEXT:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
417 txt = self.text.GetValue()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
418 #txt = strip_text(txt) ##Does not seem to exist.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
419 self.handler.text_elem.text = txt
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
420
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
421 def on_button(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
422 self.handler.text_elem.set("multiline",str(bool2int(evt.Checked())))
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_raw_button(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
425 self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked())))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
426
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
427 def on_hide_button(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
428 self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked())))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
429
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
430 def on_send_button(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
431 self.handler.text_elem.set("send_button",str(bool2int(evt.Checked())))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
432
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
433
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
434 #######################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
435 ## listbox handler
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 # Updated by Snowdog (April 2003)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
439 # Now includesan option to remove the title from
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
440 # text when sent to the chat.
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
441 #
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
442 L_DROP = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
443 L_LIST = 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
444 L_RADIO = 2
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
445 L_CHECK = 3
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
446 L_ROLLER = 4
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
447
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
448 class listbox_handler(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
449 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
450 <nodehandler class="listbox_handler" module="forms" name="">
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
451 <list type="1" send_button='0' hide_title='0'>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
452 <option value="" selected="" >Option Text I</option>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
453 <option value="" selected="" >Option Text II</option>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
454 </list>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
455 </nodehandler>
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
456 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
457 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
458 node_handler.__init__(self,xml,tree_node)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
459 self.list_reload()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
460 #print xml
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
461 #print self.tree.GetItemParent(tree_node)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
462 if self.list.get("send_button") == "": self.list.set("send_button","0")
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
463 if self.list.get("hide_title") == "": self.list.set("hide_title","0")
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
464 if self.list.get("raw_mode") == "": self.list.set("raw_mode","0")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
465
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
466 def list_reload(self):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
467 self.list = self.xml.find('list')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
468 self.options = self.list.findall('option')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
469 self.captions = []
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
470 for opt in self.options:
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
471 if opt.get('caption') == None: opt.set('caption', '')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
472 self.captions.append(opt.get('caption'))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
473
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
474 def get_design_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
475 return listbox_edit_panel(parent,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
476
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
477 def get_use_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
478 return listbox_panel(parent,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
479
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
480 def get_type(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
481 return int(self.list.get("type"))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
482
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
483 def set_type(self,type):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
484 self.list.set("type",str(type))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
485
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
486 def is_hide_title(self):
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
487 return int(self.list.get("hide_title", 0))
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
488
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
489 def is_raw_send(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
490 return int(self.list.get("raw_mode",0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
491
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
492 # single selection methods
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
493 def get_selected_node(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
494 for opt in self.options:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
495 if opt.get("selected") == "1": return opt
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
496 return None
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
497
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
498 def get_selected_index(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
499 i = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
500 for opt in self.options:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
501 if opt.get("selected") == "1": return i
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
502 i += 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
503 return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
504
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
505 def get_selected_text(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
506 node = self.get_selected_node()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
507 if node: return node.text
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
508 else: return ""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
509
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
510 # mult selection methods
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
511 def get_selections(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
512 opts = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
513 for opt in self.options:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
514 if opt.get("selected") == "1": opts.append(opt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
515 return opts
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
516
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
517 def get_selections_text(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
518 opts = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
519 for opt in self.options:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
520 if opt.get("selected") == "1": opts.append(opt.text)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
521 return opts
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
522
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
523 def get_selections_index(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
524 opts = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
525 i = 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
526 for opt in self.options:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
527 if opt.get("selected") == "1": opts.append(i)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
528 i += 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
529 return opts
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
530
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
531 # setting selection method
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
532 def set_selected_node(self,index,selected=1):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
533 if self.get_type() != L_CHECK: self.clear_selections()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
534 self.options[index].set("selected", str(bool2int(selected)))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
535
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
536 def clear_selections(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
537 for opt in self.options: opt.set("selected","0")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
538
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
539 # misc methods
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
540 def get_options(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
541 opts = []
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
542 for opt in self.options: opts.append(opt.text)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
543 return opts
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
544
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
545 def get_captions(self):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
546 captions = []
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
547 for opt in self.options: captions.append(opt.get("caption"))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
548 self.captions = captions
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
549 return captions
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
550
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
551 def get_option(self, index):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
552 return self.options[index].text
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
553
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
554 def get_caption(self, index):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
555 captions = self.get_captions()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
556 return captions[index] or ''
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
557
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
558 def add_option(self, caption, value):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
559 elem = Element('option')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
560 elem.set("value","0")
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
561 elem.set('caption', caption)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
562 elem.set("selected","0")
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
563 elem.text = value
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
564 self.list.append(elem)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
565 self.list_reload()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
566
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
567 def remove_option(self,index):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
568 self.list.remove(self.options[index])
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
569 self.list_reload()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
570
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
571 def edit_option(self, index, value):
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
572 self.options[index].text = value
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
573
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
574 def edit_caption(self, index, value):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
575 self.options[index].set('caption', value)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
576 self.captions[index] = value
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
577
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
578 def has_send_button(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
579 if self.list.get("send_button") == '0': return False
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
580 else: return True
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
581
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
582 def get_size_constraint(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
583 if self.get_type() == L_DROP: return 0
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
584 else: return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
585
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
586 def tohtml(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
587 opts = self.get_selections_text()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
588 text = ""
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
589 if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> "
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
590 comma = ", "
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
591 text += comma.join(opts)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
592 return text
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
593
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
594 def get_value(self):
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
595 return "\n".join(self.get_selections_text())
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
596
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
597 def on_send_to_chat(self, evt):
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
598 txt = self.get_selected_text()
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
599 txt = Parse.ParseLogic(txt, self.xml)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
600 if not self.is_raw_send():
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
601 Parse.Post(self.tohtml(), True, True)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
602 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
603 actionlist = self.get_selections_text()
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
604 for line in actionlist:
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
605 line = Parse.ParseLogic(line, self.xml)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
606 if(line != ""):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
607 if line[0] != "/": ## it's not a slash command
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
608 Parse.Post(line, True, True)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
609 else:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
610 action = line
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
611 self.chat.chat_cmds.docmd(action)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
612 return 1
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
613
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
614
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
615 F_LIST = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
616 F_SEND = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
617
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
618
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
619 class listbox_panel(wx.Panel):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
620 def __init__(self, parent, handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
621 wx.Panel.__init__(self, parent, -1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
622 self.handler = handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
623 self.chat = handler.chat
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
624 opts = []
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
625 values = handler.get_options()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
626 captions = handler.get_captions()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
627 for value in values:
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
628 if captions[values.index(value)] != '': opts.append(captions[values.index(value)])
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
629 else: opts.append(value)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
630 cur_opt = handler.get_selected_text()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
631 type = handler.get_type()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
632 label = handler.xml.get('name')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
633
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
634 if type == L_DROP:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
635 self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
636 if self.list.GetSize()[0] > 200:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
637 self.list.Destroy()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
638 self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
639 elif type == L_LIST: self.list = wx.ListBox(self,F_LIST,choices=opts)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
640 elif type == L_RADIO: self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
641 elif type == L_CHECK:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
642 self.list = wx.CheckListBox(self,F_LIST,choices=opts)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
643 self.set_checks()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
644
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
645 for i in handler.get_selections_text():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
646 if type == L_DROP: self.list.SetValue( i )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
647 else: self.list.SetStringSelection( i )
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
648 if type == L_DROP: sizer = wx.BoxSizer(wx.HORIZONTAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
649 else: sizer = wx.BoxSizer(wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
650
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
651 if type != L_RADIO:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
652 sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
653 sizer.Add(wx.Size(5,0))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
654 sizer.Add(self.list, 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
655 if handler.has_send_button():
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
656 sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
657 self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
658 self.sizer = sizer
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
659 self.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
660 self.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
661 self.Fit()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
662 parent.SetSize(self.GetBestSize())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
663
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
664 if type == L_DROP: self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
665 elif type == L_LIST: self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
666 elif type == L_RADIO: self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
667 elif type == L_CHECK:self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
668 self.type = type
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
669
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
670 def on_change(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
671 self.handler.set_selected_node(self.list.GetSelection())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
672
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
673 def on_check(self,evt):
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
674 for i in xrange(self.list.GetCount()): self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i)))
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
675
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
676 def set_checks(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
677 for i in self.handler.get_selections_index(): self.list.Check(i)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
678
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
679
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
680 BUT_ADD = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
681 BUT_REM = wx.NewId()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
682 BUT_REF = wx.NewId()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
683 BUT_EDIT = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
684 F_TYPE = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
685 F_NO_TITLE = wx.NewId()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
686 LIST_CTRL = wx.NewId()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
687
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
688 class listbox_edit_panel(wx.Panel):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
689 def __init__(self, parent, handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
690 wx.Panel.__init__(self, parent, -1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
691 self.handler = handler
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
692 self.parent = parent
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
693 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
694
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
695 self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
696 self.listbox = wx.ListCtrl(self, LIST_CTRL, style=wx.LC_REPORT)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
697 self.listbox.InsertColumn(0, 'Caption')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
698 self.listbox.InsertColumn(1, 'Value')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
699 self.listbox.SetColumnWidth(0, 75)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
700 self.listbox.SetColumnWidth(1, 300)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
701 self.reload_options()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
702
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
703 opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List']
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
704 self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
705 self.type_radios.SetSelection(handler.get_type())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
706
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
707 self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button")
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
708 self.send_button.SetValue(handler.has_send_button())
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
709
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
710 self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
711 self.raw_send.SetValue(handler.is_raw_send())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
712
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
713 self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
714 self.hide_title.SetValue(handler.is_hide_title())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
715
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
716 but_sizer = wx.BoxSizer(wx.HORIZONTAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
717 but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
718 but_sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
719 but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
720 but_sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
721 but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
722
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
723 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
724 sizer.Add(self.text, 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
725 sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
726 sizer.Add(self.type_radios, 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
727 sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
728 sizer.Add(self.send_button, 0 , wx.EXPAND)
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
729 sizer.Add(self.hide_title, 0, wx.EXPAND)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
730 sizer.Add(self.raw_send, 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
731 sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
732 sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
733 sizer.Add(self.listbox,1,wx.EXPAND);
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
734 sizer.Add(but_sizer,0,wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
735
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
736 self.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
737 self.SetAutoLayout(True)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
738 self.Fit()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
739 parent.SetSize(self.GetBestSize())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
740
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
741 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
742 self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
743 self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
744 self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
745 self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
746 self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE)
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
747 self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON)
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
748 self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
749
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
750 def on_type(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
751 self.handler.set_type(evt.GetInt())
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
752
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
753 def on_add(self,evt):
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
754 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
755 edit_panel = wx.Panel(self.dlg, -1)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
756 sizer = wx.GridBagSizer(1, 1)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
757 edit_panel.SetSizer(sizer)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
758 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
759 self.caption_entry = wx.TextCtrl(edit_panel, -1, '')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
760 value_text = wx.StaticText(edit_panel, -1, 'Value')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
761 self.value_entry = wx.TextCtrl(edit_panel, -1, '')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
762 button_ok = wx.Button(edit_panel, wx.ID_OK)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
763 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
764 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
765 sizer.Add(caption_text, (0,0))
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
766 sizer.Add(self.caption_entry, (0,1), span=(1,4), flag=wx.EXPAND)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
767 sizer.Add(value_text, (1,0))
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
768 sizer.Add(self.value_entry, (1,1), span=(1,4), flag=wx.EXPAND)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
769 sizer.Add(button_ok, (3,0))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
770 sizer.Add(button_cancel, (3,1))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
771 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
772 sizer.AddGrowableCol(3)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
773 sizer.AddGrowableRow(2)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
774 self.dlg.SetSize((275, 125))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
775 self.dlg.SetMinSize((275, 125))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
776 self.dlg.Layout()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
777 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
778 self.Bind(wx.EVT_BUTTON, self.on_add_option, id=wx.ID_OK)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
779 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
780 self.dlg.Show()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
781
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
782 def on_add_option(self, evt):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
783 self.handler.add_option(self.caption_entry.GetValue(), self.value_entry.GetValue())
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
784 self.reload_options()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
785 self.dlg.Destroy()
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
786 component.add('tree', component.get('tree_fs')) ## Backup
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
787 return
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
788
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
789 ## EZ_Tree Core TaS - Prof.Ebral ##
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
790 def on_reference(self, evt, car=None):
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 176
diff changeset
791 self.do_tree = wx.Frame(self, -1, 'EZ Tree')
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
792 self.ez_tree = orpg.gametree.gametree
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
793 self.temp_wnd = self.ez_tree.game_tree(self.do_tree, self.ez_tree.EZ_REF)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
794 self.temp_wnd.Bind(wx.EVT_LEFT_DCLICK, self.on_ldclick)
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 176
diff changeset
795 component.get('tree_fs').save_tree(settings.get("gametree"))
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
796 self.temp_wnd.load_tree(settings.get("gametree"))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
797 self.do_tree.Show()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
798
176
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
799 def get_grid_ref(self, obj, complete):
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
800 self.temp_wnd.Freeze()
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
801 self.grid_ref = complete
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 176
diff changeset
802 self.mini_grid = wx.Frame(self, -1, 'EZ Tree Grid')
176
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
803 self.temp_grid = obj.get_use_panel(self.mini_grid)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
804 self.temp_grid.grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_grid_ldclick)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
805 self.mini_grid.Show()
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
806
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
807 def on_grid_ldclick(self, evt):
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
808 complete = self.grid_ref
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
809 row = str(evt.GetRow()+1)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
810 col = str(evt.GetCol()+1)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
811 complete = complete[:len(complete)-2] + '::'+'('+row+','+col+')'+complete[len(complete)-2:]
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
812 self.value_entry.AppendText(complete)
178
ff19dd30064b Traipse Alpha 'OpenRPG' {100114-02}
sirebral
parents: 176
diff changeset
813 self.mini_grid.Destroy()
176
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
814
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
815 def on_ldclick(self, evt):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
816 self.rename_flag = 0
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
817 pt = evt.GetPosition()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
818 (item, flag) = self.temp_wnd.HitTest(pt)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
819 if item.IsOk():
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
820 obj = self.temp_wnd.GetPyData(item)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
821 self.temp_wnd.SelectItem(item)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
822 start = self.handler.xml.get('map').split('::')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
823 end = obj.xml.get('map').split('::')
176
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
824 if obj.xml.get('class') not in ['rpg_grid_handler', 'textctrl_handler']: do = 'None'
174
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
825 elif end[0] == '' or start[0] != end[0]: do = 'Root'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
826 elif start == end: do = 'Child'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
827 elif start != end: do = 'Parent'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
828 if do == 'Root':
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
829 complete = "!@"
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
830 for e in end:
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
831 if e != '': complete += e +'::'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
832 complete = complete + obj.xml.get('name') + '@!'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
833 elif do == 'Parent':
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
834 while start[0] == end[0]:
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
835 del end[0], start[0]
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
836 if len(start) == 0 or len(end) == 0: break
181
fa18af3e04b9 Traipse Alpha 'OpenRPG' {100115-01}
sirebral
parents: 180
diff changeset
837 complete = "!#"
174
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
838 for e in end: complete += e +'::'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
839 complete = complete + obj.xml.get('name') + '#!'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
840 elif do == 'Child':
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
841 while start[0] == end[0]:
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
842 del end[0], start[0]
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
843 if len(start) == 0 or len(end) == 0: break
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
844 complete = "!!"
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
845 for e in end: complete += e +'::'
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
846 complete = complete + obj.xml.get('name') + '!!'
176
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
847 if do != 'None':
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
848 if obj.xml.get('class') == 'rpg_grid_handler':
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
849 self.get_grid_ref(obj, complete)
537a6bbac9bd Traipse Alpha 'OpenRPG' {100113-00}
sirebral
parents: 175
diff changeset
850 else: self.value_entry.AppendText(complete); self.reload_options()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
851 self.do_tree.Destroy()
174
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
852 if do == 'None':
ff6cbd2b7620 Traipse Alpha 'OpenRPG' {100112-00}
sirebral
parents: 173
diff changeset
853 wx.MessageBox('Invalid Reference', 'Error')
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
854 ##### #####
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
855
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
856 def on_edit_ok(self, evt):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
857 self.handler.edit_caption(self.index, self.caption_entry.GetValue())
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
858 self.handler.edit_option(self.index, self.value_entry.GetValue())
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
859 self.reload_options()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
860 self.dlg.Destroy()
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
861 component.add('tree', component.get('tree_fs')) ## Backup
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
862 return
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
863
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
864 def on_edit_cancel(self, evt):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
865 self.dlg.Destroy()
180
12ba14d30baa Traipse Alpha 'OpenRPG' {100115-00}
sirebral
parents: 178
diff changeset
866 component.add('tree', component.get('tree_fs')) ## Backup
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
867 return
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
868
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
869 def on_remove(self,evt):
182
4b2884f29a72 Traipse Alpha 'OpenRPG' {100115-02}
sirebral
parents: 181
diff changeset
870 index = self.listbox.GetFocusedItem()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
871 if index >= 0:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
872 self.handler.remove_option(index)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
873 self.reload_options()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
874
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
875 def on_edit(self,evt):
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
876 self.index = self.listbox.GetFocusedItem()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
877 if self.index >= 0:
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
878 self.dlg = wx.Frame(self, -1, 'Text', size=(300,150))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
879 edit_panel = wx.Panel(self.dlg, -1)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
880 sizer = wx.GridBagSizer(1, 2)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
881 edit_panel.SetSizer(sizer)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
882 caption_text = wx.StaticText(edit_panel, -1, 'Caption')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
883 self.caption_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_caption(self.index))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
884 value_text = wx.StaticText(edit_panel, -1, 'Value')
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
885 self.value_entry = wx.TextCtrl(edit_panel, -1, self.handler.get_option(self.index))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
886 button_ok = wx.Button(edit_panel, wx.ID_OK)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
887 button_cancel = wx.Button(edit_panel, wx.ID_CANCEL)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
888 button_ref = wx.Button(edit_panel, BUT_REF, "Reference")
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
889 sizer.Add(caption_text, (0,0))
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
890 sizer.Add(self.caption_entry, (0,1), span=(1,4), flag=wx.EXPAND)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
891 sizer.Add(value_text, (1,0))
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
892 sizer.Add(self.value_entry, (1,1), span=(1,4), flag=wx.EXPAND)
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
893 sizer.Add(button_ok, (3,0))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
894 sizer.Add(button_cancel, (3,1))
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
895 sizer.Add(button_ref, (3,2), flag=wx.EXPAND)
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
896 sizer.AddGrowableCol(3)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
897 sizer.AddGrowableRow(2)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
898 self.dlg.SetSize((275, 125))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
899 self.dlg.SetMinSize((275, 125))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents: 182
diff changeset
900 self.dlg.Layout()
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
901 self.Bind(wx.EVT_BUTTON, self.on_reference, id=BUT_REF)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
902 self.Bind(wx.EVT_BUTTON, self.on_edit_ok, id=wx.ID_OK)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
903 self.Bind(wx.EVT_BUTTON, self.on_edit_cancel, id=wx.ID_CANCEL)
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
904 self.dlg.Show()
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
905
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
906 def reload_options(self):
173
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
907 self.listbox.DeleteAllItems()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
908 values = self.handler.get_options()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
909 captions = self.handler.get_captions()
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
910 for index in range(len(values)):
0dde29a41614 Traipse Alpha 'OpenRPG' {100107-00}
sirebral
parents: 155
diff changeset
911 self.listbox.Append((captions[index], values[index]))
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
912
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
913 def on_text(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
914 id = evt.GetId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
915 txt = self.text.GetValue()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
916 if not len(txt): return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
917 if id == P_TITLE:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
918 self.handler.xml.set('name',txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
919 self.handler.rename(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
920
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
921 def on_send_button(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
922 self.handler.list.set("send_button", str( bool2int(evt.Checked()) ))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
923
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
924 def on_hide_button(self,evt):
141
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
925 self.handler.list.set("hide_title", str( bool2int(evt.Checked()) ))
2ffc5de126c8 Traipse Alpha 'OpenRPG' {091123-01}
sirebral
parents: 132
diff changeset
926
155
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
927 def on_raw_button(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
928 self.handler.list.set("raw_mode",str(bool2int(evt.Checked())))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
929
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
930
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
931 ###############################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
932 ## link image handlers
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
933 ###############################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
934
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
935 class link_handler(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
936 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
937 <nodehandler name='?' module='forms' class='link_handler' >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
938 <link href='http//??.??' />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
939 </nodehandler >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
940 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
941 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
942 node_handler.__init__(self,xml,tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
943 self.link = self.xml[0]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
944
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
945 def on_use(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
946 href = self.link.get("href")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
947 wb = webbrowser.get()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
948 wb.open(href)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
949
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
950 def get_design_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
951 return link_edit_panel(parent,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
952
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
953 def get_use_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
954 return link_panel(parent,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
955
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
956 def tohtml(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
957 href = self.link.get("href")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
958 title = self.xml.get("name")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
959 return "<a href='"+href+"' >"+title+"</a>"
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
960
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
961 class link_panel(wx.StaticText):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
962 def __init__(self,parent,handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
963 self.handler = handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
964 label = handler.xml.get('name')
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
965 wx.StaticText.__init__(self,parent,-1,label)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
966 self.SetForegroundColour(wx.BLUE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
967 self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
968
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
969 P_URL = wx.NewId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
970
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
971 class link_edit_panel(wx.Panel):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
972 def __init__(self, parent, handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
973 wx.Panel.__init__(self, parent, -1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
974 self.handler = handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
975 sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
976
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
977 self.text = {}
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
978 self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name'))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
979 self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href'))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
980
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
981 sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
982 sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
983 sizer.Add(wx.Size(10,10))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
984 sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
985 sizer.Add(self.text[P_URL], 0, wx.EXPAND)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
986 self.SetSizer(sizer)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
987 self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
988 self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
989
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
990 def on_text(self,evt):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
991 id = evt.GetId()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
992 txt = self.text[id].GetValue()
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
993 if not len(txt): return
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
994 if id == P_TITLE:
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
995 self.handler.xml.set('name',txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
996 self.handler.rename(txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
997 elif id == P_URL: self.handler.link.set('href',txt)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
998
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
999 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1000 ## webimg node handler
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1001 ##########################
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1002 class webimg_handler(node_handler):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1003 """ A nodehandler for URLs. Will open URL in a wxHTMLFrame
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1004 <nodehandler name='?' module='forms' class='webimg_handler' >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1005 <link href='http//??.??' />
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1006 </nodehandler >
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1007 """
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1008 def __init__(self,xml,tree_node):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1009 node_handler.__init__(self,xml,tree_node)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1010 self.link = self.xml[0]
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1011
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1012 def get_design_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1013 return link_edit_panel(parent,self)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1014
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1015 def get_use_panel(self,parent):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1016 img = img_helper().load_url(self.link.get("href"))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1017 if not img is None: return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight()))
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1018 return wx.EmptyBitmap(1, 1)
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1019
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1020 def tohtml(self):
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1021 href = self.link.get("href")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1022 title = self.xml.get("name")
bf799efe7a8a Traipse Alpha 'OpenRPG' {091125-02}
sirebral
parents: 151
diff changeset
1023 return "<img src='"+href+"' alt="+title+" >"