annotate orpg/gametree/nodehandlers/forms.py @ 31:fc48380f0c9f ornery-orc

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