# HG changeset patch # User sirebral # Date 1257305436 21600 # Node ID 90d19eb438302bc2aafc57b34305d878afdf5979 # Parent d54e1328dbb14956b41788604b0a4bbdb821e218 Traipse Alpha 'OpenRPG' {091003-03} 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 (Cleaning up for Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana **Pretty important update that can help remove thousands of dead children from your gametree. **Children, , , , , , , etc... are all tags now. Check your gametree and look for dead children!! (Apparently I pasted from the OpenRPG folder. Wrong! Pro's or not, they need to eventually see the read text in their own debugger console.) Dead Node Children, now that's a O O -v-v- Happy Halloween! diff -r d54e1328dbb1 -r 90d19eb43830 orpg/gametree/nodehandlers/containers.py --- a/orpg/gametree/nodehandlers/containers.py Tue Nov 03 21:06:03 2009 -0600 +++ b/orpg/gametree/nodehandlers/containers.py Tue Nov 03 21:30:36 2009 -0600 @@ -1,366 +1,356 @@ -# Copyright (C) 2000-2001 The OpenRPG Project -# -# openrpg-dev@lists.sourceforge.net -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -- -# -# File: containers.py -# Author: Chris Davis -# Maintainer: -# Version: -# $Id: containers.py,v 1.43 2007/08/08 19:17:17 digitalxero Exp $ -# -# Description: The file contains code for the container nodehandlers -# - - -from core import * -import wx.lib.splitter - - -########################## -## base contiainer -########################## - -class container_handler(node_handler): - """ should not be used! only a base class! - - """ - def __init__(self,xml,tree_node): - node_handler.__init__(self,xml,tree_node) - self.load_children() - - def load_children(self): - for child_xml in self.xml: - self.tree.load_xml(child_xml,self.mytree_node) - - def check_map_aware(self, treenode, evt): - node = self.tree.GetPyData(treenode) - if hasattr(node,"map_aware") and node.map_aware(): - node.on_send_to_map(evt) - - def on_send_to_map(self, evt): - self.tree.traverse(self.mytree_node, self.check_map_aware, evt) - - def checkChildToMap(self, treenode, evt): - node = self.tree.GetPyData(treenode) - if hasattr(node,"map_aware") and node.map_aware(): - self.mapcheck = True - - def checkToMapMenu(self): - self.mapcheck = False - self.tree.traverse(self.mytree_node, self.checkChildToMap) - return self.mapcheck - - def on_drop(self,evt): - drag_obj = self.tree.drag_obj - if drag_obj == self or self.tree.is_parent_node(self.mytree_node,drag_obj.mytree_node): - return - opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL) - if opt == wx.YES: - drop_xml = self.tree.drag_obj.delete() - self.xml.insert(0, drop_xml) - self.tree.load_xml(drop_xml, self.mytree_node) - self.tree.Expand(self.mytree_node) - elif opt == wx.NO: - node_handler.on_drop(self,evt) - - def gen_html(self, treenode, evt): - node = self.tree.GetPyData(treenode) - self.html_str += "

" + node.tohtml() - - def tohtml(self): - self.html_str = "\n" - self.html_str += "
" - self.html_str += ""+self.xml.get("name") + "" - self.html_str += "
" - - self.tree.traverse(self.mytree_node, self.gen_html, recurse=False) - - self.html_str += "
" - return self.html_str - - def get_size_constraint(self): - return 2 - - - - -########################## -## group node handler -########################## -class group_handler(container_handler): - """ group nodehandler to be used as a placeholder for other nodehandlers. - This handler will continue parsing child xml data. - - """ - def __init__(self,xml,tree_node): - container_handler.__init__(self,xml,tree_node) - - def load_children(self): - self.atts = None - for child_xml in self.xml: - if child_xml.tag == "group_atts": - self.atts = child_xml - else: - self.tree.load_xml(child_xml,self.mytree_node) - if not self.atts: - self.atts = ET.Element('group_atts') - self.atts.set("cols","1") - self.atts.set("border","1") - self.xml.append(self.atts) - - def get_design_panel(self,parent): - return group_edit_panel(parent,self) - - def on_use(self,evt): - return - - def gen_html(self, treenode, evt): - node = self.tree.GetPyData(treenode) - if self.i not in self.tdatas: - self.tdatas[self.i] = '' - self.tdatas[self.i] += "

" + node.tohtml() - self.i += 1 - if self.i >= self.cols: - self.i = 0 - - def tohtml(self): - cols = self.atts.get("cols") - border = self.atts.get("border") - self.html_str = "\n" - - self.cols = int(cols) - self.i = 0 - self.tdatas = {} - - self.tree.traverse(self.mytree_node, self.gen_html, recurse=False) - - for td in self.tdatas: - self.html_str += "\n"; - self.html_str += "
" - self.html_str += ""+self.xml.get("name") + "" - self.html_str += "
" + self.tdatas[td] + "
" - return self.html_str - -GROUP_COLS = wx.NewId() -GROUP_BOR = wx.NewId() - -class group_edit_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - sizer = wx.BoxSizer(wx.VERTICAL) - self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) - } - sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) - sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - - radio_c = wx.RadioBox(self, GROUP_COLS, "Columns", choices=["1","2","3","4"]) - cols = handler.atts.get("cols") - if cols != "": - radio_c.SetSelection(int(cols)-1) - - radio_b = wx.RadioBox(self, GROUP_BOR, "Border", choices=["no","yes"]) - border = handler.atts.get("border") - if border != "": - radio_b.SetSelection(int(border)) - - sizer.Add(radio_c, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(radio_b, 0, wx.EXPAND) - - self.sizer = sizer - self.outline = wx.StaticBox(self,-1,"Group") - self.SetSizer(self.sizer) - self.SetAutoLayout(True) - self.Fit() - parent.SetSize(self.GetBestSize()) - self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) - self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GROUP_BOR) - self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GROUP_COLS) - - def on_radio_box(self,evt): - id = evt.GetId() - index = evt.GetInt() - if id == GROUP_COLS: - self.handler.atts.set("cols",str(index+1)) - elif id == GROUP_BOR: - self.handler.atts.set("border",str(index)) - - def on_text(self,evt): - id = evt.GetId() - if id == P_TITLE: - txt = self.text[id].GetValue() - if txt != "": - self.handler.xml.set('name',txt) - self.handler.rename(txt) - - - -########################## -## tabber node handler -########################## -class tabber_handler(container_handler): - """ """ - - def __init__(self,xml,tree_node): - container_handler.__init__(self,xml,tree_node) - - def get_design_panel(self,parent): - return tabbed_panel(parent,self,1) - - def get_use_panel(self,parent): - return tabbed_panel(parent,self,2) - - -class tabbed_panel(orpgTabberWnd): - def __init__(self, parent, handler, mode): - orpgTabberWnd.__init__(self, parent, style=FNB.FNB_NO_X_BUTTON) - self.handler = handler - self.parent = parent - handler.tree.traverse(handler.mytree_node, self.pick_panel, mode, False) - - parent.SetSize(self.GetBestSize()) - - def pick_panel(self, treenode, mode): - node = self.handler.tree.GetPyData(treenode) - if mode == 1: - panel = node.get_design_panel(self) - else: - panel = node.get_use_panel(self) - - name = node.xml.get("name") - - if panel: - self.AddPage(panel, name, False) - -################################# -## Splitter container -################################# - -class splitter_handler(container_handler): - """ """ - - def __init__(self,xml,tree_node): - container_handler.__init__(self,xml,tree_node) - - def load_children(self): - self.atts = None - for child_xml in self.xml: - if child_xml.tag == "splitter_atts": - self.atts = child_xml - else: - self.tree.load_xml(child_xml,self.mytree_node) - if not self.atts: - self.atts = ET.Element('splitter_atts') - self.atts.set("horizontal","0") - self.xml.append(self.atts) - - def get_design_panel(self,parent): - return self.build_splitter_wnd(parent, 1) - - def get_use_panel(self,parent): - return self.build_splitter_wnd(parent, 2) - - def on_drop(self,evt): - drag_obj = self.tree.drag_obj - container_handler.on_drop(self,evt) - - def build_splitter_wnd(self, parent, mode): - self.split = self.atts.get("horizontal") - - self.pane = splitter_panel(parent, self) - - self.splitter = wx.lib.splitter.MultiSplitterWindow(self.pane, -1, style=wx.SP_LIVE_UPDATE|wx.SP_3DSASH|wx.SP_NO_XP_THEME) - - if self.split == '1': - self.splitter.SetOrientation(wx.VERTICAL) - else: - self.splitter.SetOrientation(wx.HORIZONTAL) - - self.bestSizex = -1 - self.bestSizey = -1 - - self.tree.traverse(self.mytree_node, self.doSplit, mode, False) - - self.pane.sizer.Add(self.splitter, 1, wx.EXPAND) - - - if mode != 1: - self.pane.hozCheck.Hide() - - self.pane.SetSize((self.bestSizex, self.bestSizey)) - self.pane.Layout() - parent.SetSize(self.pane.GetSize()) - return self.pane - - def doSplit(self, treenode, mode): - node = self.tree.GetPyData(treenode) - if mode == 1: - tmp = node.get_design_panel(self.splitter) - else: - tmp = node.get_use_panel(self.splitter) - - if self.split == '1': - sash = tmp.GetBestSize()[1]+1 - self.bestSizey += sash+11 - if self.bestSizex < tmp.GetBestSize()[0]: - self.bestSizex = tmp.GetBestSize()[0]+10 - else: - sash = tmp.GetBestSize()[0]+1 - self.bestSizex += sash - if self.bestSizey < tmp.GetBestSize()[1]: - self.bestSizey = tmp.GetBestSize()[1]+31 - - self.splitter.AppendWindow(tmp, sash) - - def get_size_constraint(self): - return 1 - -class splitter_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - sizer = wx.BoxSizer(wx.VERTICAL) - - self.hozCheck = wx.CheckBox(self, -1, "Horizontal Split") - hoz = self.handler.atts.get("horizontal") - - if hoz == '1': - self.hozCheck.SetValue(True) - #self.splitsize = wx.BoxSizer(wx.HORIZONTAL) - else: - self.hozCheck.SetValue(False) - #self.splitsize = wx.BoxSizer(wx.VERTICAL) - - sizer.Add(self.hozCheck, 0, wx.EXPAND) - sizer.Add(wx.Size(10,0)) - #sizer.Add(self.splitsize, 1, wx.EXPAND) - - self.sizer = sizer - self.SetSizer(self.sizer) - self.SetAutoLayout(True) - - self.Bind(wx.EVT_CHECKBOX, self.on_check_box, id=self.hozCheck.GetId()) - - def on_check_box(self,evt): - state = self.hozCheck.GetValue() - if state: - self.handler.atts.set("horizontal", "1") - else: - self.handler.atts.set("horizontal", "0") +# Copyright (C) 2000-2001 The OpenRPG Project +# +# openrpg-dev@lists.sourceforge.net +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# -- +# +# File: containers.py +# Author: Chris Davis +# Maintainer: +# Version: +# $Id: containers.py,v 1.43 2007/08/08 19:17:17 digitalxero Exp $ +# +# Description: The file contains code for the container nodehandlers +# + + +from core import * +from wx.lib.splitter import MultiSplitterWindow + + +########################## +## base contiainer +########################## + +class container_handler(node_handler): + """ should not be used! only a base class! + + """ + def __init__(self, xml, tree_node): + node_handler.__init__(self, xml, tree_node) + self.load_children() + + def load_children(self): + for child_xml in self.xml: + self.tree.load_xml(child_xml,self.mytree_node) + + def check_map_aware(self, treenode, evt): + node = self.tree.GetPyData(treenode) + if hasattr(node,"map_aware") and node.map_aware(): + node.on_send_to_map(evt) + + def on_send_to_map(self, evt): + self.tree.traverse(self.mytree_node, self.check_map_aware, evt) + + def checkChildToMap(self, treenode, evt): + node = self.tree.GetPyData(treenode) + if hasattr(node,"map_aware") and node.map_aware(): + self.mapcheck = True + + def checkToMapMenu(self): + self.mapcheck = False + self.tree.traverse(self.mytree_node, self.checkChildToMap) + return self.mapcheck + + def on_drop(self,evt): + drag_obj = self.tree.drag_obj + if drag_obj == self or self.tree.is_parent_node(self.mytree_node,drag_obj.mytree_node): + return + opt = wx.MessageBox("Add node as child?","Container Node",wx.YES_NO|wx.CANCEL) + if opt == wx.YES: + drop_xml = self.tree.drag_obj.delete() + self.xml.insert(0, drop_xml) + self.tree.load_xml(drop_xml, self.mytree_node) + self.tree.Expand(self.mytree_node) + elif opt == wx.NO: + node_handler.on_drop(self,evt) + + def gen_html(self, treenode, evt): + node = self.tree.GetPyData(treenode) + self.html_str += "

" + node.tohtml() + + def tohtml(self): + self.html_str = "\n" + self.html_str += "
" + self.html_str += ""+self.xml.get("name") + "" + self.html_str += "
" + + self.tree.traverse(self.mytree_node, self.gen_html, recurse=False) + + self.html_str += "
" + return self.html_str + + def get_size_constraint(self): + return 2 + + +########################## +## group node handler +########################## +class group_handler(container_handler): + """ group nodehandler to be used as a placeholder for other nodehandlers. + This handler will continue parsing child xml data. + + """ + def __init__(self, xml, tree_node): + container_handler.__init__(self, xml, tree_node) + + def load_children(self): + self.atts = None + for child_xml in self.xml: + if child_xml.get == "group_atts": #having the group attributes as a child is bad! + self.xml.remove(child_xml) + elif child_xml: + self.tree.load_xml(child_xml, self.mytree_node) + if not self.xml.get('cols'): self.xml.set('cols', '1') + if not self.xml.get('border'): self.xml.set('border', '1') + """ + if not self.atts: + self.atts = Element('group_atts') + self.atts.set("cols","1") + self.atts.set("border","1") + self.xml.append(self.atts)""" + + def get_design_panel(self,parent): + return group_edit_panel(parent,self) + + def on_use(self,evt): + return + + def gen_html(self, treenode, evt): + node = self.tree.GetPyData(treenode) + if self.i not in self.tdatas: + self.tdatas[self.i] = '' + self.tdatas[self.i] += "

" + node.tohtml() + self.i += 1 + if self.i >= self.cols: + self.i = 0 + + def tohtml(self): + cols = self.xml.get("cols") + border = self.xml.get("border") + self.html_str = "\n" + self.cols = int(cols) + self.i = 0 + self.tdatas = {} + self.tree.traverse(self.mytree_node, self.gen_html, recurse=False) + for td in self.tdatas: + self.html_str += "\n"; + self.html_str += "
" + self.html_str += ""+self.xml.get("name") + "" + self.html_str += "
" + self.tdatas[td] + "
" + return self.html_str + +GROUP_COLS = wx.NewId() +GROUP_BOR = wx.NewId() + +class group_edit_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.handler = handler + sizer = wx.BoxSizer(wx.VERTICAL) + self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) + } + sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) + sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + + radio_c = wx.RadioBox(self, GROUP_COLS, "Columns", choices=["1","2","3","4"]) + cols = handler.xml.get("cols") + if cols != "": + radio_c.SetSelection(int(cols)-1) + + radio_b = wx.RadioBox(self, GROUP_BOR, "Border", choices=["no","yes"]) + border = handler.xml.get("border") + if border != "": + radio_b.SetSelection(int(border)) + + sizer.Add(radio_c, 0, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(radio_b, 0, wx.EXPAND) + + self.sizer = sizer + self.outline = wx.StaticBox(self,-1,"Group") + self.SetSizer(self.sizer) + self.SetAutoLayout(True) + self.Fit() + parent.SetSize(self.GetBestSize()) + self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) + self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GROUP_BOR) + self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GROUP_COLS) + + def on_radio_box(self,evt): + id = evt.GetId() + index = evt.GetInt() + if id == GROUP_COLS: + self.handler.xml.set("cols",str(index+1)) + elif id == GROUP_BOR: + self.handler.xml.set("border",str(index)) + + def on_text(self,evt): + id = evt.GetId() + if id == P_TITLE: + txt = self.text[id].GetValue() + if txt != "": + self.handler.xml.set('name',txt) + self.handler.rename(txt) + + + +########################## +## tabber node handler +########################## +class tabber_handler(container_handler): + """ """ + + def __init__(self, xml, tree_node): + container_handler.__init__(self, xml, tree_node) + + def get_design_panel(self,parent): + return tabbed_panel(parent,self,1) + + def get_use_panel(self,parent): + return tabbed_panel(parent,self,2) + + +class tabbed_panel(orpgTabberWnd): + def __init__(self, parent, handler, mode): + orpgTabberWnd.__init__(self, parent, style=FNB.FNB_NO_X_BUTTON) + self.handler = handler + self.parent = parent + handler.tree.traverse(handler.mytree_node, self.pick_panel, mode, False) + + parent.SetSize(self.GetBestSize()) + + def pick_panel(self, treenode, mode): + node = self.handler.tree.GetPyData(treenode) + if mode == 1: panel = node.get_design_panel(self) + else: panel = node.get_use_panel(self) + name = node.xml.get("name") + if panel: self.AddPage(panel, name, False) + +################################# +## Splitter container +################################# + +class splitter_handler(container_handler): + """ """ + + def __init__(self,xml,tree_node): + container_handler.__init__(self,xml,tree_node) + + def load_children(self): + self.atts = None + for child_xml in self.xml: + if child_xml.tag == "splitter_atts": self.xml.remove(child_xml) #Same here! + elif child_xml: self.tree.load_xml(child_xml,self.mytree_node) + if not self.xml.get('horizontal'): self.xml.set('horizontal', '0') + """if not self.atts: + self.atts = Element('splitter_atts') + self.atts.set("horizontal","0") + self.xml.append(self.atts)""" + + def get_design_panel(self,parent): + return self.build_splitter_wnd(parent, 1) + + def get_use_panel(self,parent): + return self.build_splitter_wnd(parent, 2) + + def on_drop(self,evt): + drag_obj = self.tree.drag_obj + container_handler.on_drop(self,evt) + + def build_splitter_wnd(self, parent, mode): + self.split = self.xml.get("horizontal") + + self.pane = splitter_panel(parent, self) + + self.splitter = MultiSplitterWindow(self.pane, -1, style=wx.SP_LIVE_UPDATE|wx.SP_3DSASH|wx.SP_NO_XP_THEME) + + if self.split == '1': + self.splitter.SetOrientation(wx.VERTICAL) + else: + self.splitter.SetOrientation(wx.HORIZONTAL) + + self.bestSizex = -1 + self.bestSizey = -1 + + self.tree.traverse(self.mytree_node, self.doSplit, mode, False) + + self.pane.sizer.Add(self.splitter, 1, wx.EXPAND) + + + if mode != 1: + self.pane.hozCheck.Hide() + + self.pane.SetSize((self.bestSizex, self.bestSizey)) + self.pane.Layout() + parent.SetSize(self.pane.GetSize()) + return self.pane + + def doSplit(self, treenode, mode): + node = self.tree.GetPyData(treenode) + if mode == 1: tmp = node.get_design_panel(self.splitter) + else: tmp = node.get_use_panel(self.splitter) + + if self.split == '1': + sash = tmp.GetBestSize()[1]+1 + self.bestSizey += sash+11 + if self.bestSizex < tmp.GetBestSize()[0]: + self.bestSizex = tmp.GetBestSize()[0]+10 + else: + sash = tmp.GetBestSize()[0]+1 + self.bestSizex += sash + if self.bestSizey < tmp.GetBestSize()[1]: + self.bestSizey = tmp.GetBestSize()[1]+31 + + self.splitter.AppendWindow(tmp, sash) + + def get_size_constraint(self): + return 1 + +class splitter_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.handler = handler + sizer = wx.BoxSizer(wx.VERTICAL) + + self.hozCheck = wx.CheckBox(self, -1, "Horizontal Split") + hoz = self.handler.xml.get("horizontal") + + if hoz == '1': + self.hozCheck.SetValue(True) + #self.splitsize = wx.BoxSizer(wx.HORIZONTAL) + else: + self.hozCheck.SetValue(False) + #self.splitsize = wx.BoxSizer(wx.VERTICAL) + + sizer.Add(self.hozCheck, 0, wx.EXPAND) + sizer.Add(wx.Size(10,0)) + #sizer.Add(self.splitsize, 1, wx.EXPAND) + + self.sizer = sizer + self.SetSizer(self.sizer) + self.SetAutoLayout(True) + + self.Bind(wx.EVT_CHECKBOX, self.on_check_box, id=self.hozCheck.GetId()) + + def on_check_box(self,evt): + state = self.hozCheck.GetValue() + if state: + self.handler.xml.set("horizontal", "1") + else: + self.handler.xml.set("horizontal", "0") diff -r d54e1328dbb1 -r 90d19eb43830 orpg/gametree/nodehandlers/forms.py --- a/orpg/gametree/nodehandlers/forms.py Tue Nov 03 21:06:03 2009 -0600 +++ b/orpg/gametree/nodehandlers/forms.py Tue Nov 03 21:30:36 2009 -0600 @@ -1,1131 +1,796 @@ -# Copyright (C) 2000-2001 The OpenRPG Project -# -# openrpg-dev@lists.sourceforge.net -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -- -# -# File: forms.py -# Author: Chris Davis -# Maintainer: -# Version: -# $Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $ -# -# Description: The file contains code for the form based nodehanlers -# - -__version__ = "$Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $" - -from containers import * -import wx.lib.scrolledpanel - -def bool2int(b): - #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0. - #by running the results of that through this function, we convert it. - #if it was an int already, nothing changes. The difference between 1.0 - #and 1, i.e. between ints and floats, is potentially dangerous when we - #use str() on it, but it seems to work fine right now. - if b: - return 1 - else: - return 0 - -################################# -## form container -################################# - -class form_handler(container_handler): - """ - -

- - """ - - def __init__(self,xml,tree_node): - container_handler.__init__(self,xml,tree_node) - - def load_children(self): - self.atts = None - for child_xml in self.xml: - if child_xml.tag == "form": - self.atts = child_xml - else: - self.tree.load_xml(child_xml,self.mytree_node) - if not self.atts: - self.atts = ET.Element('form') - self.atts.set("width","400") - self.atts.set("height","600") - self.xml.append(self.atts) - - def get_design_panel(self,parent): - return form_edit_panel(parent,self) - - def get_use_panel(self,parent): - return form_panel(parent,self) - - def on_drop(self,evt): - # make sure its a contorl node - container_handler.on_drop(self,evt) - - -class form_panel(wx.lib.scrolledpanel.ScrolledPanel): - def __init__(self, parent, handler): - wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL) - self.height = int(handler.atts.get("height")) - self.width = int(handler.atts.get("width")) - - - self.SetSize((0,0)) - self.handler = handler - self.parent = parent - self.main_sizer = wx.BoxSizer(wx.VERTICAL) - handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False) - - self.SetSizer(self.main_sizer) - self.SetAutoLayout(True) - - self.SetupScrolling() - - parent.SetSize(self.GetSize()) - self.Fit() - - - def SetSize(self, xy): - (x, y) = self.GetSize() - (nx, ny) = xy - if x < nx: - x = nx+10 - y += ny+11 - wx.lib.scrolledpanel.ScrolledPanel.SetSize(self, (x, y)) - - - def create_child_wnd(self, treenode, evt): - node = self.handler.tree.GetPyData(treenode) - panel = node.get_use_panel(self) - size = node.get_size_constraint() - if panel: - self.main_sizer.Add(panel, size, wx.EXPAND) - self.main_sizer.Add(wx.Size(10,10)) - - - -F_HEIGHT = wx.NewId() -F_WIDTH = wx.NewId() -class form_edit_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL) - wh_sizer = wx.BoxSizer(wx.HORIZONTAL) - self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')), - F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.atts.get('height')), - F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.atts.get('width')) - } - - wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER) - wh_sizer.Add(wx.Size(10,10)) - wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND) - wh_sizer.Add(wx.Size(10,10)) - wh_sizer.Add(wx.StaticText(self, -1, "Height:"), 0, wx.ALIGN_CENTER) - wh_sizer.Add(wx.Size(10,10)) - wh_sizer.Add(self.text[F_HEIGHT], 0, wx.EXPAND) - - sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) - sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(wh_sizer,0,wx.EXPAND) - - self.SetSizer(sizer) - self.SetAutoLayout(True) - self.Fit() - parent.SetSize(self.GetBestSize()) - - self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) - self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT) - self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH) - - def on_text(self,evt): - id = evt.GetId() - txt = self.text[id].GetValue() - if not len(txt): return - if id == P_TITLE: - self.handler.xml.set('name',txt) - self.handler.rename(txt) - elif id == F_HEIGHT or id == F_WIDTH: - try: - int(txt) - except: - return 0 - if id == F_HEIGHT: - self.handler.atts.set("height",txt) - elif id == F_WIDTH: - self.handler.atts.set("width",txt) - - - - - -########################## -## control handler -########################## -class control_handler(node_handler): - """ A nodehandler for form controls. - - """ - def __init__(self,xml,tree_node): - node_handler.__init__(self,xml,tree_node) - - def get_size_constraint(self): - return 0 - - -########################## -## textctrl handler -########################## - # - # Updated by Snowdog (April 2003) - # Now includes Raw Send Mode (like the chat macro uses) - # and an option to remove the title from text when sent - # to the chat in the normal non-chat macro mode. - # -class textctrl_handler(node_handler): - """ - Text In Node - - """ - def __init__(self,xml,tree_node): - node_handler.__init__(self,xml,tree_node) - self.text_elem = self.xml.find('text') - if self.text_elem.get("send_button") == "": - self.text_elem.set("send_button","0") - if self.text_elem.get("raw_mode") == "": - self.text_elem.set("raw_mode","0") - if self.text_elem.get("hide_title") == "": - self.text_elem.set("hide_title","0") - - def get_design_panel(self,parent): - return textctrl_edit_panel(parent,self) - - def get_use_panel(self,parent): - return text_panel(parent,self) - - def get_size_constraint(self): - return int(self.text_elem.get("multiline",0)) - - def is_multi_line(self): - return int(self.text_elem.get("multiline",0)) - - def is_raw_send(self): - return int(self.text_elem.get("raw_mode",0)) - - def is_hide_title(self): - return int(self.text_elem.get("hide_title",0)) - - def has_send_button(self): - return int(self.text_elem.get("send_button",0)) - - def tohtml(self): - txt = self.get_value() - txt = string.replace(txt,'\n',"
") - if not self.is_hide_title(): - txt = ""+self.xml.get("name")+": "+txt - return txt - - def get_value(self): - return getText(self.text_elem) - - def set_value(self, new_value): - self.text_elem.text = str(new_value) - - - -FORM_TEXT_CTRL = wx.NewId() -FORM_SEND_BUTTON = wx.NewId() - -class text_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.chat = handler.chat - self.handler = handler - if handler.is_multi_line(): - text_style = wx.TE_MULTILINE - sizer_style = wx.EXPAND - sizer = wx.BoxSizer(wx.VERTICAL) - else: - sizer_style = wx.ALIGN_CENTER - text_style = 0 - sizer = wx.BoxSizer(wx.HORIZONTAL) - - txt = handler.get_value() -## if self.handler.tree.ContainsReference(txt): -## txt = self.handler.tree.ReplaceReferences(txt, False) -## text_style |= wx.TE_READONLY - - self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style) - sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style) - sizer.Add(wx.Size(5,0)) - sizer.Add(self.text, 1, sizer_style) - - if handler.has_send_button(): - sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style) - - self.sizer = sizer - self.SetSizer(sizer) - self.SetAutoLayout(True) - - parent.SetSize(self.GetBestSize()) - self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL) - self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) - - def on_text(self,evt): - txt = self.text.GetValue() - txt = strip_text(txt) - self.handler.text_elem.text = txt - - def on_send(self,evt): - txt = self.text.GetValue() - if not self.handler.is_raw_send(): - #self.chat.ParsePost(self.tohtml(),True,True) - self.chat.ParsePost(self.handler.tohtml(),True,True) - return 1 - actionlist = txt.split("\n") - for line in actionlist: - if(line != ""): - if line[0] != "/": ## it's not a slash command - self.chat.ParsePost(line,True,True) - else: - action = line - self.chat.chat_cmds.docmd(action) - return 1 - -F_MULTI = wx.NewId() -F_SEND_BUTTON = wx.NewId() -F_RAW_SEND = wx.NewId() -F_HIDE_TITLE = wx.NewId() -F_TEXT = wx.NewId() - -class textctrl_edit_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL) - - self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) - self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line") - self.multi.SetValue(handler.is_multi_line()) - self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro") - self.raw_send.SetValue(handler.is_raw_send()) - self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title") - self.hide_title.SetValue(handler.is_hide_title()) - self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button") - self.send_button.SetValue(handler.has_send_button()) - - sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND) - sizer.Add(self.title, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(self.multi, 0, wx.EXPAND) - sizer.Add(self.raw_send, 0, wx.EXPAND) - sizer.Add(self.hide_title, 0, wx.EXPAND) - sizer.Add(self.send_button, 0 , wx.EXPAND) - sizer.Add(wx.Size(10,10)) - if handler.is_multi_line(): - sizer_style = wx.EXPAND - text_style = wx.TE_MULTILINE - multi = 1 - else: - sizer_style=wx.EXPAND - text_style = 0 - multi = 0 - self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style) - sizer.Add(wx.Size(5,0)) - sizer.Add(self.text, multi, sizer_style) - self.SetSizer(sizer) - self.SetAutoLayout(True) - - self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) - self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT) - self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI) - self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND) - self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE) - self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON) - - def on_text(self,evt): - id = evt.GetId() - if id == P_TITLE: - txt = self.title.GetValue() - if not len(txt): return - self.handler.xml.set('name',txt) - self.handler.rename(txt) - if id == F_TEXT: - txt = self.text.GetValue() - txt = strip_text(txt) - self.handler.text_elem.text = txt - - def on_button(self,evt): - self.handler.text_elem.set("multiline",str(bool2int(evt.Checked()))) - - def on_raw_button(self,evt): - self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked()))) - - def on_hide_button(self,evt): - self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked()))) - - def on_send_button(self,evt): - self.handler.text_elem.set("send_button",str(bool2int(evt.Checked()))) - - -####################### -## listbox handler -####################### - # - # Updated by Snowdog (April 2003) - # Now includesan option to remove the title from - # text when sent to the chat. - # -L_DROP = 0 -L_LIST = 1 -L_RADIO = 2 -L_CHECK = 3 -L_ROLLER = 4 - -class listbox_handler(node_handler): - """ - - - - - - - """ - def __init__(self,xml,tree_node): - node_handler.__init__(self,xml,tree_node) - self.list = self.xml.find('list') - self.options = self.list.findall('option') - if self.list.get("send_button") == "": - self.list.set("send_button","0") - if self.list.get("hide_title") == "": - self.list.set("hide_title","0") - - def get_design_panel(self,parent): - return listbox_edit_panel(parent,self) - - def get_use_panel(self,parent): - return listbox_panel(parent,self) - - def get_type(self): - return int(self.list.get("type")) - - def set_type(self,type): - self.list.set("type",str(type)) - - def is_hide_title(self): - return int(self.list.get("hide_title",0)) - - # single selection methods - def get_selected_node(self): - for opt in self.options: - if opt.get("selected") == "1": return opt - return None - - def get_selected_index(self): - i = 0 - for opt in self.options: - if opt.get("selected") == "1": - return i - i += 1 - return 0 - - def get_selected_text(self): - node = self.get_selected_node() - if node: - return getText(node) - else: - return "" - - - # mult selection methods - - def get_selections(self): - opts = [] - for opt in self.options: - if opt.get("selected") == "1": - opts.append(opt) - return opts - - def get_selections_text(self): - opts = [] - for opt in self.options: - if opt.get("selected") == "1": - opts.append(getText(opt)) - return opts - - def get_selections_index(self): - opts = [] - i = 0 - for opt in self.options: - if opt.get("selected") == "1": - opts.append(i) - i += 1 - return opts - - # setting selection method - - def set_selected_node(self,index,selected=1): - if self.get_type() != L_CHECK: - self.clear_selections() - self.options[index].set("selected", str(bool2int(selected))) - - def clear_selections(self): - for opt in self.options: - opt.set("selected","0") - - # misc methods - - def get_options(self): - opts = [] - for opt in self.options: - opts.append(getText(opt)) - return opts - - def get_option(self,index): - return getText(self.options[index]) - - def add_option(self,opt): - elem = ET.Element('option') - elem.set("value","0") - elem.set("selected","0") - elem.text = opt - self.list.append(elem) - self.options = self.list.findall('option') - - def remove_option(self,index): - self.list.remove(self.options[index]) - self.options = self.list.findall('option') - - def edit_option(self,index,value): - self.options[index].text = value - - def has_send_button(self): - if self.list.get("send_button") == '0': - return False - else: - return True - - def get_size_constraint(self): - if self.get_type() == L_DROP: - return 0 - else: - return 1 - - def tohtml(self): - opts = self.get_selections_text() - text = "" - if not self.is_hide_title(): - text = ""+self.xml.get("name")+": " - comma = ", " - text += comma.join(opts) - return text - - def get_value(self): - return "\n".join(self.get_selections_text()) - -F_LIST = wx.NewId() -F_SEND = wx.NewId() - - -class listbox_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - self.chat = handler.chat - opts = handler.get_options() - cur_opt = handler.get_selected_text() - type = handler.get_type() - label = handler.xml.get('name') - - if type == L_DROP: - self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY) - if self.list.GetSize()[0] > 200: - self.list.Destroy() - self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY) - elif type == L_LIST: - self.list = wx.ListBox(self,F_LIST,choices=opts) - elif type == L_RADIO: - self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3) - elif type == L_CHECK: - self.list = wx.CheckListBox(self,F_LIST,choices=opts) - self.set_checks() - - for i in handler.get_selections_text(): - if type == L_DROP: - self.list.SetValue( i ) - else: - self.list.SetStringSelection( i ) - - if type == L_DROP: - sizer = wx.BoxSizer(wx.HORIZONTAL) - - else: - sizer = wx.BoxSizer(wx.VERTICAL) - - if type != L_RADIO: - sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND) - sizer.Add(wx.Size(5,0)) - - sizer.Add(self.list, 1, wx.EXPAND) - - if handler.has_send_button(): - sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND) - self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND) - - self.sizer = sizer - self.SetSizer(sizer) - self.SetAutoLayout(True) - self.Fit() - - parent.SetSize(self.GetBestSize()) - - if type == L_DROP: - self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST) - elif type == L_LIST: - self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST) - elif type == L_RADIO: - self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST) - elif type == L_CHECK: - self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST) - - - self.type = type - - - def on_change(self,evt): - self.handler.set_selected_node(self.list.GetSelection()) - - def on_check(self,evt): - for i in xrange(self.list.GetCount()): - self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i))) - - def set_checks(self): - for i in self.handler.get_selections_index(): - self.list.Check(i) - - - -BUT_ADD = wx.NewId() -BUT_REM = wx.NewId() -BUT_EDIT = wx.NewId() -F_TYPE = wx.NewId() -F_NO_TITLE = wx.NewId() - -class listbox_edit_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL) - - self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) - - opts = handler.get_options() - self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB) - opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List'] - self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts) - self.type_radios.SetSelection(handler.get_type()) - - self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button") - self.send_button.SetValue(handler.has_send_button()) - - self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title") - self.hide_title.SetValue(handler.is_hide_title()) - - but_sizer = wx.BoxSizer(wx.HORIZONTAL) - but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND) - but_sizer.Add(wx.Size(10,10)) - but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND) - but_sizer.Add(wx.Size(10,10)) - but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND) - - sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) - sizer.Add(self.text, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(self.type_radios, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(self.send_button, 0 , wx.EXPAND) - sizer.Add(self.hide_title, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND) - sizer.Add(self.listbox,1,wx.EXPAND); - sizer.Add(but_sizer,0,wx.EXPAND) - - self.SetSizer(sizer) - self.SetAutoLayout(True) - self.Fit() - parent.SetSize(self.GetBestSize()) - - self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) - self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT) - self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM) - self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD) - self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE) - self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE) - self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON) - - def on_type(self,evt): - self.handler.set_type(evt.GetInt()) - - def on_add(self,evt): - dlg = wx.TextEntryDialog(self, 'Enter option?','Add Option', '') - if dlg.ShowModal() == wx.ID_OK: - self.handler.add_option(dlg.GetValue()) - dlg.Destroy() - self.reload_options() - - def on_remove(self,evt): - index = self.listbox.GetSelection() - if index >= 0: - self.handler.remove_option(index) - self.reload_options() - - def on_edit(self,evt): - index = self.listbox.GetSelection() - if index >= 0: - txt = self.handler.get_option(index) - dlg = wx.TextEntryDialog(self, 'Enter option?','Edit Option', txt) - if dlg.ShowModal() == wx.ID_OK: - self.handler.edit_option(index,dlg.GetValue()) - dlg.Destroy() - self.reload_options() - - def reload_options(self): - self.listbox.Clear() - for opt in self.handler.get_options(): - self.listbox.Append(opt) - - def on_text(self,evt): - id = evt.GetId() - txt = self.text.GetValue() - if not len(txt): return - if id == P_TITLE: - self.handler.xml.set('name',txt) - self.handler.rename(txt) - - def on_send_button(self,evt): - self.handler.list.set("send_button", str( bool2int(evt.Checked()) )) - - def on_hide_button(self,evt): - self.handler.list.set("hide_title", str( bool2int(evt.Checked()) )) - - -############################### -## link image handlers -############################### - -class link_handler(node_handler): - """ A nodehandler for URLs. Will open URL in a wxHTMLFrame - - - - """ - def __init__(self,xml,tree_node): - node_handler.__init__(self,xml,tree_node) - self.link = self.xml[0] - - def on_use(self,evt): - href = self.link.get("href") - wb = webbrowser.get() - wb.open(href) - - def get_design_panel(self,parent): - return link_edit_panel(parent,self) - - def get_use_panel(self,parent): - return link_panel(parent,self) - - def tohtml(self): - href = self.link.get("href") - title = self.xml.get("name") - return ""+title+"" - -class link_panel(wx.StaticText): - def __init__(self,parent,handler): - self.handler = handler - label = handler.xml.get('name') - wx.StaticText.__init__(self,parent,-1,label) - self.SetForegroundColour(wx.BLUE) - self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use) - - -P_URL = wx.NewId() - -class link_edit_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL) - - self.text = {} - self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) - self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href')) - - sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) - sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND) - sizer.Add(self.text[P_URL], 0, wx.EXPAND) - self.SetSizer(sizer) - self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) - self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL) - - def on_text(self,evt): - id = evt.GetId() - txt = self.text[id].GetValue() - if not len(txt): return - if id == P_TITLE: - self.handler.xml.set('name',txt) - self.handler.rename(txt) - elif id == P_URL: - self.handler.link.set('href',txt) - -########################## -## webimg node handler -########################## -class webimg_handler(node_handler): - """ A nodehandler for URLs. Will open URL in a wxHTMLFrame - - - - """ - def __init__(self,xml,tree_node): - node_handler.__init__(self,xml,tree_node) - self.link = self.xml[0] - - def get_design_panel(self,parent): - return link_edit_panel(parent,self) - - def get_use_panel(self,parent): - img = img_helper().load_url(self.link.get("href")) - if not img is None: - return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight())) - return wx.EmptyBitmap(1, 1) - - def tohtml(self): - href = self.link.get("href") - title = self.xml.get("name") - return "+title+" - - - -####################### -## resource handler -####################### - -class resource_handler(node_handler): - """ - - Multi-line macro - - """ - def __init__(self,xml,tree_node): - node_handler.__init__(self,xml,tree_node) - self.resource = self.xml.find('resource') - if self.resource.get("checks") == "": - self.resource.set("checks","1") - if self.resource.get("base") == "": - self.resource.set("base","1") - if self.resource.get("current") == "": - self.resource.set("current", self.resource.get("base")) - - def get_design_panel(self,parent): - return resource_edit_panel(parent,self) - - def get_use_panel(self,parent): - return resource_panel(parent,self) - - def tohtml(self): - # decrement the current value or post a "nothing left" message - # print the multi-line macro - return "resource" - - def use_checks(self): - if self.resource.get("checks") == "1": - return True - return False - - def get_base(self): - return int(self.resource.get("base",0)) - - def get_current(self): - return int(self.resource.get("current",0)) - - def get_macro(self): - return getText(self.resource) - - def get_value(self): - return self.resource.get("current") - - def set_value(self, new_value): - self.resource.set("current", new_value) - - -RESOURCE_RESET = wx.NewId() -RESOURCE_CHECKS = wx.NewId() -RESOURCE_NUMBER = wx.NewId() -RESOURCE_DONE = wx.NewId() - - -class resource_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - self.chat = handler.chat - - sizer = wx.BoxSizer(wx.HORIZONTAL) - # sizer.Add(wx.Button(self, RESOURCE_RESET, "Reset")) - sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 1, wx.ALIGN_RIGHT) - if self.handler.use_checks(): - grid = wx.GridSizer(1, 11, 0, 0) - sizer.Add(grid, 0, wx.ALIGN_RIGHT) - self.checks = [] - used = self.handler.get_base() - self.handler.get_current() - for i in range(self.handler.get_base()): - self.checks.append(wx.CheckBox(self, RESOURCE_CHECKS, "")) - checked = False - if i < used: - checked = True - self.checks[i].SetValue(checked) - grid.Add(self.checks[i]) - if i-int(i/10)*10==4: - grid.Add(wx.Size(1,1)) - else: - self.number = wx.TextCtrl(self, RESOURCE_NUMBER, self.handler.resource.get("current")) - sizer.Add(self.number, 0, wx.ALIGN_RIGHT) - sizer.Add(wx.Size(10,10), 0, wx.ALIGN_RIGHT) - sizer.Add(wx.Button(self, RESOURCE_DONE, "Apply"), 0, wx.ALIGN_RIGHT) - # self.chat.InfoPost("res 10") - sizer.SetMinSize(wx.Size(380,10)) - self.sizer = sizer - self.SetSizer(sizer) - self.SetAutoLayout(True) - self.Fit() - # self.chat.InfoPost("res 20") - self.Bind(wx.EVT_BUTTON, self.on_reset, id=RESOURCE_RESET) - self.Bind(wx.EVT_BUTTON, self.on_done, id=RESOURCE_DONE) - - - def on_reset(self,evt): - # uncheck all the check boxes or set the text to max - if self.handler.use_checks(): - for c in self.checks: - c.SetValue(False) - else: - self.number.SetValue(self.handler.resource.get("base")) - self.handler.resource.set("current", self.handler.resource.get("base")) - - def on_done(self,evt): - # save the changes back to the handler - current = 0 - if self.handler.use_checks(): - for c in self.checks: - if not c.GetValue(): - current += 1 - else: - # validate text - current = int(self.number.GetValue()) - change = self.handler.get_current()-current - if change > 0: - macro_text = self.handler.get_macro() - macro_text = macro_text.replace("_NAME_",self.handler.xml.get("name")) - macro_text = macro_text.replace("_CHANGE_", str(change)) - macro_text = macro_text.replace("_CURRENT_", str(current)) - self.handler.chat.ParsePost(macro_text, True, True) - self.handler.resource.set("current",str(current)) - - -RES_EDIT_TITLE = wx.NewId() -RES_EDIT_BASE = wx.NewId() -RES_EDIT_CURRENT = wx.NewId() -RES_EDIT_CHECKS = wx.NewId() -RES_EDIT_MACRO = wx.NewId() - - -class resource_edit_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - - sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Resource Properties"), wx.VERTICAL) - sizer.Add(wx.StaticText(self, -1, "Name of resource:"), 0, wx.EXPAND) - self.title = wx.TextCtrl(self, RES_EDIT_TITLE, self.handler.xml.get('name')) - sizer.Add(self.title, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - - sizer.Add(wx.StaticText(self, -1, "Base amount of resource:"), 0, wx.EXPAND) - self.base = wx.TextCtrl(self, RES_EDIT_BASE, self.handler.resource.get("base")) - sizer.Add(self.base, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - - sizer.Add(wx.StaticText(self, -1, "Current amount of resource:"), 0, wx.EXPAND) - self.current = wx.TextCtrl(self, RES_EDIT_CURRENT, self.handler.resource.get("current")) - sizer.Add(self.current, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - - opts = ['Text Number', 'Check Boxes'] - self.radio = wx.RadioBox(self, RES_EDIT_CHECKS, "Amount of resource is represented by:", choices=opts) - if self.handler.use_checks(): - self.radio.SetSelection(1) - else: - self.radio.SetSelection(0) - sizer.Add(self.radio, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - - sizer.Add(wx.StaticText(self, -1, "Send the following macro:"), 0, wx.EXPAND) - self.macro = wx.TextCtrl(self, RES_EDIT_MACRO, self.handler.get_macro(), style=wx.TE_MULTILINE) - sizer.Add(self.macro, 1, wx.EXPAND) - - self.SetSizer(sizer) - self.SetAutoLayout(True) - self.Fit() - parent.SetSize(self.GetBestSize()) - - self.Bind(wx.EVT_TEXT, self.on_title, id=RES_EDIT_TITLE) - self.Bind(wx.EVT_TEXT, self.on_base, id=RES_EDIT_BASE) - self.Bind(wx.EVT_TEXT, self.on_current, id=RES_EDIT_CURRENT) - self.Bind(wx.EVT_RADIOBOX, self.on_type, id=RES_EDIT_CHECKS) - self.Bind(wx.EVT_TEXT, self.on_macro, id=RES_EDIT_MACRO) - - - def on_title(self, evt): - if len(self.title.GetValue()): - self.handler.xml.set('name', self.title.GetValue()) - self.handler.rename(self.title.GetValue()) - - def on_base(self, evt): - try: - b = int(self.base.GetValue()) - self.handler.resource.set("base",str(b)) - except: - pass - - def on_current(self, evt): - try: - c = int(self.current.GetValue()) - self.handler.resource.set("current",str(c)) - except: - pass - - def on_type(self,evt): - self.handler.resource.set("checks",str(self.radio.GetSelection())) - - def on_macro(self,evt): - self.handler.resource.text = self.macro.GetValue() - - -####################### -## bonus handler -####################### - -class bonus_handler(node_handler): - """ - - Multi-line list of node references - - """ - def __init__(self,xml,tree_node): - node_handler.__init__(self,xml,tree_node) - self.bonus_xml = self.xml.find('bonus') - self.add_to_bonus_map() - - def get_design_panel(self,parent): - return bonus_edit_panel(parent,self) - - def get_use_panel(self,parent):# there is no 'use' for a bonus - return bonus_edit_panel(parent,self) - - def tohtml(self): - return "bonus"# there is no 'send to chat' or 'pretty print' - - def get_value(self): - return self.bonus_xml.get('value', '') - - def delete(self): - self.remove_from_bonus_map() - return node_handler.delete(self) - - def add_to_bonus_map(self): - for target in getText(self.bonus_xml).split('\n'): - self.tree.AddBonus(target, self) - - def remove_from_bonus_map(self): - for target in getText(self.bonus_xml).split('\n'): - self.tree.RemoveBonus(target, self) - - - -BONUS_EDIT_TITLE = wx.NewId() -BONUS_EDIT_VALUE = wx.NewId() -BONUS_EDIT_TYPE = wx.NewId() -BONUS_EDIT_REF = wx.NewId() - - -class bonus_edit_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - - sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Bonus Properties"), wx.VERTICAL) - sizer.Add(wx.StaticText(self, -1, "Name of bonus:"), 0, wx.EXPAND) - self.title = wx.TextCtrl(self, BONUS_EDIT_TITLE, self.handler.xml.get('name')) - sizer.Add(self.title, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - - sizer.Add(wx.StaticText(self, -1, "Size of bonus:"), 0, wx.EXPAND) - self.value = wx.TextCtrl(self, BONUS_EDIT_VALUE, self.handler.bonus_xml.get('value', '')) - sizer.Add(self.value, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - - sizer.Add(wx.StaticText(self, -1, "Type of bonus:"), 0, wx.EXPAND) - self.type = wx.TextCtrl(self, BONUS_EDIT_TYPE, self.handler.bonus_xml.get("type")) - sizer.Add(self.type, 0, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - - sizer.Add(wx.StaticText(self, -1, "Add to the following nodes:"), 0, wx.EXPAND) - self.ref = wx.TextCtrl(self, BONUS_EDIT_REF, getText(self.handler.bonus_xml), style=wx.TE_MULTILINE) - sizer.Add(self.ref, 1, wx.EXPAND) - - self.SetSizer(sizer) - self.SetAutoLayout(True) - self.Fit() - parent.SetSize(self.GetBestSize()) - - self.Bind(wx.EVT_TEXT, self.on_title, id=BONUS_EDIT_TITLE)# too many calls - should call only upon close - self.Bind(wx.EVT_TEXT, self.on_value, id=BONUS_EDIT_VALUE) - self.Bind(wx.EVT_TEXT, self.on_type, id=BONUS_EDIT_TYPE) - self.Bind(wx.EVT_TEXT, self.on_ref, id=BONUS_EDIT_REF) - - - def on_title(self, evt): - if len(self.title.GetValue()): - self.handler.xml.set('name', self.title.GetValue()) - self.handler.rename(self.title.GetValue()) - - def on_value(self, evt): - self.handler.bonus_xml.set('value', self.value.GetValue()) - - def on_type(self, evt): - self.handler.bonus_xml.set('type', self.type.GetValue()) - - def on_ref(self, evt): - self.handler.remove_from_bonus_map() - self.handler.bonus_xml.text = self.ref.GetValue() - self.handler.add_to_bonus_map() +# Copyright (C) 2000-2001 The OpenRPG Project +# +# openrpg-dev@lists.sourceforge.net +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# -- +# +# File: forms.py +# Author: Chris Davis +# Maintainer: +# Version: +# $Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $ +# +# Description: The file contains code for the form based nodehanlers +# + +__version__ = "$Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $" + +from containers import * +import orpg.minidom as minidom +from orpg.orpg_xml import xml +from wx.lib.scrolledpanel import ScrolledPanel + +def bool2int(b): + #in wxPython 2.5+, evt.Checked() returns True or False instead of 1.0 or 0. + #by running the results of that through this function, we convert it. + #if it was an int already, nothing changes. The difference between 1.0 + #and 1, i.e. between ints and floats, is potentially dangerous when we + #use str() on it, but it seems to work fine right now. + if b: return 1 + else: return 0 + +################################# +## form container +################################# + +class form_handler(container_handler): + """ + + + + """ + def __init__(self,xml,tree_node): + container_handler.__init__(self, xml, tree_node) + + def load_children(self): + self.atts = None + for child_xml in self.xml: + if child_xml.tag == "form": self.xml.remove(child_xml) + elif child_xml: self.tree.load_xml(child_xml, self.mytree_node) + if not self.xml.get('width'): self.xml.set('width', '400') + if not self.xml.get('height'): self.xml.set('height', '600') + + def get_design_panel(self,parent): + return form_edit_panel(parent,self) + + def get_use_panel(self,parent): + return form_panel(parent,self) + + def on_drop(self,evt): + # make sure its a contorl node + container_handler.on_drop(self,evt) + +class form_panel(ScrolledPanel): + def __init__(self, parent, handler): + ScrolledPanel.__init__(self, parent, wx.ID_ANY, style=wx.NO_BORDER|wx.VSCROLL|wx.HSCROLL) + self.height = int(handler.xml.get("height")) + self.width = int(handler.xml.get("width")) + self.SetSize((0,0)) + self.handler = handler + self.parent = parent + self.main_sizer = wx.BoxSizer(wx.VERTICAL) + handler.tree.traverse(handler.mytree_node, self.create_child_wnd, None, False) + self.SetSizer(self.main_sizer) + self.SetAutoLayout(True) + self.SetupScrolling() + parent.SetSize(self.GetSize()) + self.Fit() + + def SetSize(self, xy): + (x, y) = self.GetSize() + (nx, ny) = xy + if x < nx: + x = nx+10 + y += ny+11 + ScrolledPanel.SetSize(self, (x, y)) + + def create_child_wnd(self, treenode, evt): + node = self.handler.tree.GetPyData(treenode) + panel = node.get_use_panel(self) + size = node.get_size_constraint() + if panel: + self.main_sizer.Add(panel, size, wx.EXPAND) + self.main_sizer.Add(wx.Size(10,10)) + +F_HEIGHT = wx.NewId() +F_WIDTH = wx.NewId() +class form_edit_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.handler = handler + sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Form Properties"), wx.VERTICAL) + wh_sizer = wx.BoxSizer(wx.HORIZONTAL) + self.text = { P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')), + F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.xml.get('height')), + F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.xml.get('width')) + } + + wh_sizer.Add(wx.StaticText(self, -1, "Width:"), 0, wx.ALIGN_CENTER) + wh_sizer.Add(wx.Size(10,10)) + wh_sizer.Add(self.text[F_WIDTH], 0, wx.EXPAND) + wh_sizer.Add(wx.Size(10,10)) + wh_sizer.Add(wx.StaticText(self, -1, "Height:"), 0, wx.ALIGN_CENTER) + wh_sizer.Add(wx.Size(10,10)) + wh_sizer.Add(self.text[F_HEIGHT], 0, wx.EXPAND) + + sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) + sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(wh_sizer,0,wx.EXPAND) + + self.SetSizer(sizer) + self.SetAutoLayout(True) + self.Fit() + parent.SetSize(self.GetBestSize()) + + self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) + self.Bind(wx.EVT_TEXT, self.on_text, id=F_HEIGHT) + self.Bind(wx.EVT_TEXT, self.on_text, id=F_WIDTH) + + def on_text(self,evt): + id = evt.GetId() + txt = self.text[id].GetValue() + if not len(txt): return + if id == P_TITLE: + self.handler.xml.set('name',txt) + self.handler.rename(txt) + elif id == F_HEIGHT or id == F_WIDTH: + try: int(txt) + except: return 0 + if id == F_HEIGHT: self.handler.xml.set("height",txt) + elif id == F_WIDTH: self.handler.xml.set("width",txt) + +########################## +## control handler +########################## +class control_handler(node_handler): + """ A nodehandler for form controls. + + """ + def __init__(self, xml, tree_node): + node_handler.__init__(self, xml, tree_node) + + def get_size_constraint(self): + return 0 + +########################## +## textctrl handler +########################## + # + # Updated by Snowdog (April 2003) + # Now includes Raw Send Mode (like the chat macro uses) + # and an option to remove the title from text when sent + # to the chat in the normal non-chat macro mode. + # +class textctrl_handler(node_handler): + """ + Text In Node + + """ + def __init__(self,xml,tree_node): + node_handler.__init__(self,xml,tree_node) + self.text_elem = self.xml.find('text') + if self.text_elem.get("send_button") == "": + self.text_elem.set("send_button","0") + if self.text_elem.get("raw_mode") == "": + self.text_elem.set("raw_mode","0") + if self.text_elem.get("hide_title") == "": + self.text_elem.set("hide_title","0") + + def get_design_panel(self,parent): + return textctrl_edit_panel(parent,self) + + def get_use_panel(self,parent): + return text_panel(parent,self) + + def get_size_constraint(self): + return int(self.text_elem.get("multiline",0)) + + def is_multi_line(self): + return int(self.text_elem.get("multiline",0)) + + def is_raw_send(self): + return int(self.text_elem.get("raw_mode",0)) + + def is_hide_title(self): + return int(self.text_elem.get("hide_title",0)) + + def has_send_button(self): + return int(self.text_elem.get("send_button",0)) + + def tohtml(self): + txt = self.get_value() + txt = string.replace(txt,'\n',"
") + if not self.is_hide_title(): + txt = ""+self.xml.get("name")+": "+txt + return txt + + def get_value(self): + return self.text_elem.text + + def set_value(self, new_value): + self.text_elem.text = str(new_value) + +FORM_TEXT_CTRL = wx.NewId() +FORM_SEND_BUTTON = wx.NewId() + +class text_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.chat = handler.chat + self.handler = handler + if handler.is_multi_line(): + text_style = wx.TE_MULTILINE + sizer_style = wx.EXPAND + sizer = wx.BoxSizer(wx.VERTICAL) + else: + sizer_style = wx.ALIGN_CENTER + text_style = 0 + sizer = wx.BoxSizer(wx.HORIZONTAL) + + txt = handler.get_value() + if txt == None: txt = '' + self.text = wx.TextCtrl(self, FORM_TEXT_CTRL, txt, style=text_style) + sizer.Add(wx.StaticText(self, -1, handler.xml.get('name')+": "), 0, sizer_style) + sizer.Add(wx.Size(5,0)) + sizer.Add(self.text, 1, sizer_style) + + if handler.has_send_button(): + sizer.Add(wx.Button(self, FORM_SEND_BUTTON, "Send"), 0, sizer_style) + + self.sizer = sizer + self.SetSizer(sizer) + self.SetAutoLayout(True) + + parent.SetSize(self.GetBestSize()) + self.Bind(wx.EVT_TEXT, self.on_text, id=FORM_TEXT_CTRL) + self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) + + def on_text(self,evt): + txt = self.text.GetValue() + #txt = strip_text(txt) ##Does not seem to exist. + self.handler.text_elem.text = txt + + def on_send(self,evt): + txt = self.text.GetValue() + if not self.handler.is_raw_send(): + #self.chat.ParsePost(self.tohtml(),True,True) + self.chat.ParsePost(self.handler.tohtml(),True,True) + return 1 + actionlist = txt.split("\n") + for line in actionlist: + if(line != ""): + if line[0] != "/": ## it's not a slash command + self.chat.ParsePost(line,True,True) + else: + action = line + self.chat.chat_cmds.docmd(action) + return 1 + +F_MULTI = wx.NewId() +F_SEND_BUTTON = wx.NewId() +F_RAW_SEND = wx.NewId() +F_HIDE_TITLE = wx.NewId() +F_TEXT = wx.NewId() + +class textctrl_edit_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.handler = handler + sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL) + + self.title = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) + self.multi = wx.CheckBox(self, F_MULTI, " Multi-Line") + self.multi.SetValue(handler.is_multi_line()) + self.raw_send = wx.CheckBox(self, F_RAW_SEND, " Send as Macro") + self.raw_send.SetValue(handler.is_raw_send()) + self.hide_title = wx.CheckBox(self, F_HIDE_TITLE, " Hide Title") + self.hide_title.SetValue(handler.is_hide_title()) + self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button") + self.send_button.SetValue(handler.has_send_button()) + + sizer.Add(wx.StaticText(self, P_TITLE, "Title:"), 0, wx.EXPAND) + sizer.Add(self.title, 0, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(self.multi, 0, wx.EXPAND) + sizer.Add(self.raw_send, 0, wx.EXPAND) + sizer.Add(self.hide_title, 0, wx.EXPAND) + sizer.Add(self.send_button, 0 , wx.EXPAND) + sizer.Add(wx.Size(10,10)) + if handler.is_multi_line(): + sizer_style = wx.EXPAND + text_style = wx.TE_MULTILINE + multi = 1 + else: + sizer_style=wx.EXPAND + text_style = 0 + multi = 0 + self.text = wx.TextCtrl(self, F_TEXT, handler.get_value(),style=text_style) + sizer.Add(wx.Size(5,0)) + sizer.Add(self.text, multi, sizer_style) + self.SetSizer(sizer) + self.SetAutoLayout(True) + + self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) + self.Bind(wx.EVT_TEXT, self.on_text, id=F_TEXT) + self.Bind(wx.EVT_CHECKBOX, self.on_button, id=F_MULTI) + self.Bind(wx.EVT_CHECKBOX, self.on_raw_button, id=F_RAW_SEND) + self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_HIDE_TITLE) + self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON) + + def on_text(self,evt): + id = evt.GetId() + if id == P_TITLE: + txt = self.title.GetValue() + if not len(txt): return + self.handler.xml.set('name',txt) + self.handler.rename(txt) + if id == F_TEXT: + txt = self.text.GetValue() + #txt = strip_text(txt) ##Does not seem to exist. + self.handler.text_elem.text = txt + + def on_button(self,evt): + self.handler.text_elem.set("multiline",str(bool2int(evt.Checked()))) + + def on_raw_button(self,evt): + self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked()))) + + def on_hide_button(self,evt): + self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked()))) + + def on_send_button(self,evt): + self.handler.text_elem.set("send_button",str(bool2int(evt.Checked()))) + + +####################### +## listbox handler +####################### + # + # Updated by Snowdog (April 2003) + # Now includesan option to remove the title from + # text when sent to the chat. + # +L_DROP = 0 +L_LIST = 1 +L_RADIO = 2 +L_CHECK = 3 +L_ROLLER = 4 + +class listbox_handler(node_handler): + """ + + + + + + + """ + def __init__(self,xml,tree_node): + node_handler.__init__(self,xml,tree_node) + self.list = self.xml.find('list') + self.options = self.list.findall('option') + if self.list.get("send_button") == "": + self.list.set("send_button","0") + if self.list.get("hide_title") == "": + self.list.set("hide_title","0") + + def get_design_panel(self,parent): + return listbox_edit_panel(parent,self) + + def get_use_panel(self,parent): + return listbox_panel(parent,self) + + def get_type(self): + return int(self.list.get("type")) + + def set_type(self,type): + self.list.set("type",str(type)) + + def is_hide_title(self): + return int(self.list.get("hide_title", 0)) + + # single selection methods + def get_selected_node(self): + for opt in self.options: + if opt.get("selected") == "1": return opt + return None + + def get_selected_index(self): + i = 0 + for opt in self.options: + if opt.get("selected") == "1": + return i + i += 1 + return 0 + + def get_selected_text(self): + node = self.get_selected_node() + if node: + return node.text + else: + return "" + + + # mult selection methods + + def get_selections(self): + opts = [] + for opt in self.options: + if opt.get("selected") == "1": + opts.append(opt) + return opts + + def get_selections_text(self): + opts = [] + for opt in self.options: + if opt.get("selected") == "1": + opts.append(opt.text) + return opts + + def get_selections_index(self): + opts = [] + i = 0 + for opt in self.options: + if opt.get("selected") == "1": + opts.append(i) + i += 1 + return opts + + # setting selection method + + def set_selected_node(self,index,selected=1): + if self.get_type() != L_CHECK: + self.clear_selections() + self.options[index].set("selected", str(bool2int(selected))) + + def clear_selections(self): + for opt in self.options: + opt.set("selected","0") + + # misc methods + + def get_options(self): + opts = [] + for opt in self.options: + opts.append(opt.text) + return opts + + def get_option(self,index): + return self.options[index].text + + def add_option(self,opt): + elem = Element('option') + elem.set("value","0") + elem.set("selected","0") + elem.text = opt + self.list.append(elem) + self.options = self.list.findall('option') + + def remove_option(self,index): + self.list.remove(self.options[index]) + self.options = self.list.findall('option') + + def edit_option(self,index,value): + self.options[index].text = value + + def has_send_button(self): + if self.list.get("send_button") == '0': + return False + else: + return True + + def get_size_constraint(self): + if self.get_type() == L_DROP: + return 0 + else: + return 1 + + def tohtml(self): + opts = self.get_selections_text() + text = "" + if not self.is_hide_title(): + text = ""+self.xml.get("name")+": " + comma = ", " + text += comma.join(opts) + return text + + def get_value(self): + return "\n".join(self.get_selections_text()) + + +F_LIST = wx.NewId() +F_SEND = wx.NewId() + + +class listbox_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.handler = handler + self.chat = handler.chat + opts = handler.get_options() + cur_opt = handler.get_selected_text() + type = handler.get_type() + label = handler.xml.get('name') + + if type == L_DROP: + self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY) + if self.list.GetSize()[0] > 200: + self.list.Destroy() + self.list = wx.ComboBox(self, F_LIST, cur_opt, size=(200, -1), choices=opts, style=wx.CB_READONLY) + elif type == L_LIST: + self.list = wx.ListBox(self,F_LIST,choices=opts) + elif type == L_RADIO: + self.list = wx.RadioBox(self,F_LIST,label,choices=opts,majorDimension=3) + elif type == L_CHECK: + self.list = wx.CheckListBox(self,F_LIST,choices=opts) + self.set_checks() + + for i in handler.get_selections_text(): + if type == L_DROP: + self.list.SetValue( i ) + else: + self.list.SetStringSelection( i ) + + if type == L_DROP: + sizer = wx.BoxSizer(wx.HORIZONTAL) + + else: + sizer = wx.BoxSizer(wx.VERTICAL) + + if type != L_RADIO: + sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND) + sizer.Add(wx.Size(5,0)) + + sizer.Add(self.list, 1, wx.EXPAND) + + if handler.has_send_button(): + sizer.Add(wx.Button(self, F_SEND, "Send"), 0, wx.EXPAND) + self.Bind(wx.EVT_BUTTON, self.handler.on_send_to_chat, id=F_SEND) + + self.sizer = sizer + self.SetSizer(sizer) + self.SetAutoLayout(True) + self.Fit() + + parent.SetSize(self.GetBestSize()) + + if type == L_DROP: + self.Bind(wx.EVT_COMBOBOX, self.on_change, id=F_LIST) + elif type == L_LIST: + self.Bind(wx.EVT_LISTBOX, self.on_change, id=F_LIST) + elif type == L_RADIO: + self.Bind(wx.EVT_RADIOBOX, self.on_change, id=F_LIST) + elif type == L_CHECK: + self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, id=F_LIST) + + + self.type = type + + + def on_change(self,evt): + self.handler.set_selected_node(self.list.GetSelection()) + + def on_check(self,evt): + for i in xrange(self.list.GetCount()): + self.handler.set_selected_node(i, bool2int(self.list.IsChecked(i))) + + def set_checks(self): + for i in self.handler.get_selections_index(): + self.list.Check(i) + + + +BUT_ADD = wx.NewId() +BUT_REM = wx.NewId() +BUT_EDIT = wx.NewId() +F_TYPE = wx.NewId() +F_NO_TITLE = wx.NewId() + +class listbox_edit_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.handler = handler + sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL) + + self.text = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) + + opts = handler.get_options() + self.listbox = wx.ListBox(self, F_LIST, choices=opts, style=wx.LB_HSCROLL|wx.LB_SINGLE|wx.LB_NEEDED_SB) + opts = ['Drop Down', 'List Box', 'Radio Box', 'Check List'] + self.type_radios = wx.RadioBox(self,F_TYPE,"List Type",choices=opts) + self.type_radios.SetSelection(handler.get_type()) + + self.send_button = wx.CheckBox(self, F_SEND_BUTTON, " Send Button") + self.send_button.SetValue(handler.has_send_button()) + + self.hide_title = wx.CheckBox(self, F_NO_TITLE, " Hide Title") + self.hide_title.SetValue(handler.is_hide_title()) + + but_sizer = wx.BoxSizer(wx.HORIZONTAL) + but_sizer.Add(wx.Button(self, BUT_ADD, "Add"), 1, wx.EXPAND) + but_sizer.Add(wx.Size(10,10)) + but_sizer.Add(wx.Button(self, BUT_EDIT, "Edit"), 1, wx.EXPAND) + but_sizer.Add(wx.Size(10,10)) + but_sizer.Add(wx.Button(self, BUT_REM, "Remove"), 1, wx.EXPAND) + + sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) + sizer.Add(self.text, 0, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(self.type_radios, 0, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(self.send_button, 0 , wx.EXPAND) + sizer.Add(self.hide_title, 0, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(wx.StaticText(self, -1, "Options:"), 0, wx.EXPAND) + sizer.Add(self.listbox,1,wx.EXPAND); + sizer.Add(but_sizer,0,wx.EXPAND) + + self.SetSizer(sizer) + self.SetAutoLayout(True) + self.Fit() + parent.SetSize(self.GetBestSize()) + + self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) + self.Bind(wx.EVT_BUTTON, self.on_edit, id=BUT_EDIT) + self.Bind(wx.EVT_BUTTON, self.on_remove, id=BUT_REM) + self.Bind(wx.EVT_BUTTON, self.on_add, id=BUT_ADD) + self.Bind(wx.EVT_RADIOBOX, self.on_type, id=F_TYPE) + self.Bind(wx.EVT_CHECKBOX, self.on_hide_button, id=F_NO_TITLE) + self.Bind(wx.EVT_CHECKBOX, self.on_send_button, id=F_SEND_BUTTON) + + def on_type(self,evt): + self.handler.set_type(evt.GetInt()) + + def on_add(self,evt): + dlg = wx.TextEntryDialog(self, 'Enter option?','Add Option', '') + if dlg.ShowModal() == wx.ID_OK: + self.handler.add_option(dlg.GetValue()) + dlg.Destroy() + self.reload_options() + + def on_remove(self,evt): + index = self.listbox.GetSelection() + if index >= 0: + self.handler.remove_option(index) + self.reload_options() + + def on_edit(self,evt): + index = self.listbox.GetSelection() + if index >= 0: + txt = self.handler.get_option(index) + dlg = wx.TextEntryDialog(self, 'Enter option?','Edit Option', txt) + if dlg.ShowModal() == wx.ID_OK: + self.handler.edit_option(index,dlg.GetValue()) + dlg.Destroy() + self.reload_options() + + def reload_options(self): + self.listbox.Clear() + for opt in self.handler.get_options(): + self.listbox.Append(opt) + + def on_text(self,evt): + id = evt.GetId() + txt = self.text.GetValue() + if not len(txt): return + if id == P_TITLE: + self.handler.xml.set('name',txt) + self.handler.rename(txt) + + def on_send_button(self,evt): + self.handler.list.set("send_button", str( bool2int(evt.Checked()) )) + + def on_hide_button(self,evt): + self.handler.list.set("hide_title", str( bool2int(evt.Checked()) )) + + +############################### +## link image handlers +############################### + +class link_handler(node_handler): + """ A nodehandler for URLs. Will open URL in a wxHTMLFrame + + + + """ + def __init__(self,xml,tree_node): + node_handler.__init__(self,xml,tree_node) + self.link = self.xml[0] + + def on_use(self,evt): + href = self.link.get("href") + wb = webbrowser.get() + wb.open(href) + + def get_design_panel(self,parent): + return link_edit_panel(parent,self) + + def get_use_panel(self,parent): + return link_panel(parent,self) + + def tohtml(self): + href = self.link.get("href") + title = self.xml.get("name") + return ""+title+"" + +class link_panel(wx.StaticText): + def __init__(self,parent,handler): + self.handler = handler + label = handler.xml.get('name') + wx.StaticText.__init__(self,parent,-1,label) + self.SetForegroundColour(wx.BLUE) + self.Bind(wx.EVT_LEFT_DOWN, self.handler.on_use) + + +P_URL = wx.NewId() + +class link_edit_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.handler = handler + sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL) + + self.text = {} + self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.xml.get('name')) + self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.get('href')) + + sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) + sizer.Add(self.text[P_TITLE], 0, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(wx.StaticText(self, -1, "URL:"), 0, wx.EXPAND) + sizer.Add(self.text[P_URL], 0, wx.EXPAND) + self.SetSizer(sizer) + self.Bind(wx.EVT_TEXT, self.on_text, id=P_TITLE) + self.Bind(wx.EVT_TEXT, self.on_text, id=P_URL) + + def on_text(self,evt): + id = evt.GetId() + txt = self.text[id].GetValue() + if not len(txt): return + if id == P_TITLE: + self.handler.xml.set('name',txt) + self.handler.rename(txt) + elif id == P_URL: + self.handler.link.set('href',txt) + +########################## +## webimg node handler +########################## +class webimg_handler(node_handler): + """ A nodehandler for URLs. Will open URL in a wxHTMLFrame + + + + """ + def __init__(self,xml,tree_node): + node_handler.__init__(self,xml,tree_node) + self.link = self.xml[0] + + def get_design_panel(self,parent): + return link_edit_panel(parent,self) + + def get_use_panel(self,parent): + img = img_helper().load_url(self.link.get("href")) + if not img is None: + return wx.StaticBitmap(parent,-1,img,size= wx.Size(img.GetWidth(),img.GetHeight())) + return wx.EmptyBitmap(1, 1) + + def tohtml(self): + href = self.link.get("href") + title = self.xml.get("name") + return "+title+" diff -r d54e1328dbb1 -r 90d19eb43830 orpg/gametree/nodehandlers/rpg_grid.py --- a/orpg/gametree/nodehandlers/rpg_grid.py Tue Nov 03 21:06:03 2009 -0600 +++ b/orpg/gametree/nodehandlers/rpg_grid.py Tue Nov 03 21:30:36 2009 -0600 @@ -1,491 +1,491 @@ -# Copyright (C) 2000-2001 The OpenRPG Project -# -# openrpg-dev@lists.sourceforge.net -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -- -# -# File: rpg_grid.py -# Author: Chris Davis -# Maintainer: -# Version: -# $Id: rpg_grid.py,v 1.20 2006/11/15 12:11:24 digitalxero Exp $ -# -# Description: The file contains code for the grid nodehanlers -# - -__version__ = "$Id: rpg_grid.py,v 1.20 2006/11/15 12:11:24 digitalxero Exp $" - -from core import * -from forms import * - -class rpg_grid_handler(node_handler): - """ Node handler for rpg grid tool - - - - - - - - - - - - - - - - """ - def __init__(self,xml,tree_node): - node_handler.__init__(self,xml,tree_node) - self.grid = self.xml.find('grid') - if self.grid.get("border") == "": - self.grid.set("border","1") - if self.grid.get("autosize") == "": - self.grid.set("autosize","1") - self.macros = self.xml.find('macros') - self.myeditor = None - self.refresh_rows() - - def refresh_die_macros(self): - pass - - def refresh_rows(self): - self.rows = {} - tree = self.tree - icons = self.tree.icons - tree.CollapseAndReset(self.mytree_node) - for row in self.grid.findall('row'): - first_cell = row.find('cell') - name = first_cell.text - if name == None or name == '': - name = "Row" - new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) - handler = grid_row_handler(row,new_tree_node,self) - tree.SetPyData(new_tree_node,handler) - - def tohtml(self): - border = self.grid.get("border") - name = self.xml.get('name') - rows = self.grid.findall('row') - colspan = str(len(rows[0].findall('cell'))) - html_str = "" - for r in rows: - cells = r.findall('cell') - html_str += "" - for c in cells: - #html_str += "" - html_str += "" - html_str += "
"+name+"
" bug here - html_str += "" - text = c.text - if text == None or text == '': - text = '
' - html_str += text + "
" - return html_str - - def get_design_panel(self,parent): - return rpg_grid_edit_panel(parent,self) - - def get_use_panel(self,parent): - return rpg_grid_panel(parent,self) - - def get_size_constraint(self): - return 1 - - def is_autosized(self): - return self.grid.get("autosize") - - def set_autosize(self,autosize=1): - self.grid.set("autosize",str(autosize)) - -class grid_row_handler(node_handler): - """ Node Handler grid row. - """ - def __init__(self,xml,tree_node,parent): - node_handler.__init__(self,xml,tree_node) - self.drag = False - - def on_drop(self,evt): - pass - - def can_clone(self): - return 0; - - def tohtml(self): - cells = self.xml.findall('cell') - html_str = "" - for c in cells: # should loop over rows first, then cells - html_str += "" - html_str += "" - html_str += "
" - text = c.text - if text == '' or text is None: - text = '
' - html_str += text + "
" - return html_str - - def get_value(self): - cells = self.xml.findall('cell') - if len(cells) == 2: - return getText(cells[1]) - else: - return None - - def set_value(self, new_value): - cells = self.xml.findall('cell') - if len(cells) == 2: - cells[1].text = new_value - -class MyCellEditor(wx.grid.PyGridCellEditor): - """ - This is a sample GridCellEditor that shows you how to make your own custom - grid editors. All the methods that can be overridden are show here. The - ones that must be overridden are marked with "*Must Override*" in the - docstring. - - Notice that in order to call the base class version of these special - methods we use the method name preceded by "base_". This is because these - methods are "virtual" in C++ so if we try to call wxGridCellEditor.Create - for example, then when the wxPython extension module tries to call - ptr->Create(...) then it actually calls the derived class version which - looks up the method in this class and calls it, causing a recursion loop. - If you don't understand any of this, don't worry, just call the "base_" - version instead. - - ---------------------------------------------------------------------------- - This class is copied from the wxPython examples directory and was written by - Robin Dunn. - - I have pasted it directly in and removed all references to "log" - - -- Andrew - - """ - def __init__(self): - wx.grid.PyGridCellEditor.__init__(self) - - - def Create(self, parent, id, evtHandler): - """ - Called to create the control, which must derive from wxControl. - *Must Override* - """ - self._tc = wx.TextCtrl(parent, id, "", style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB) - self._tc.SetInsertionPoint(0) - self.SetControl(self._tc) - if evtHandler: - self._tc.PushEventHandler(evtHandler) - - - def SetSize(self, rect): - """ - Called to position/size the edit control within the cell rectangle. - If you don't fill the cell (the rect) then be sure to override - PaintBackground and do something meaningful there. - """ - self._tc.SetDimensions(rect.x+1, rect.y+1, rect.width+2, rect.height+2) - - - def Show(self, show, attr): - """ - Show or hide the edit control. You can use the attr (if not None) - to set colours or fonts for the control. - """ - self.base_Show(show, attr) - - - def BeginEdit(self, row, col, grid): - """ - Fetch the value from the table and prepare the edit control - to begin editing. Set the focus to the edit control. - *Must Override* - """ - self.startValue = grid.GetTable().GetValue(row, col) - self._tc.SetValue(self.startValue) - self._tc.SetInsertionPointEnd() - self._tc.SetFocus() - - # For this example, select the text - self._tc.SetSelection(0, self._tc.GetLastPosition()) - - - def EndEdit(self, row, col, grid): - """ - Complete the editing of the current cell. Returns True if the value - has changed. If necessary, the control may be destroyed. - *Must Override* - """ - changed = False - - val = self._tc.GetValue() - if val != self.startValue: - changed = True - grid.GetTable().SetValue(row, col, val) # update the table - - self.startValue = '' - self._tc.SetValue('') - return changed - - - def Reset(self): - """ - Reset the value in the control back to its starting value. - *Must Override* - """ - self._tc.SetValue(self.startValue) - self._tc.SetInsertionPointEnd() - - - def IsAcceptedKey(self, evt): - """ - Return True to allow the given key to start editing: the base class - version only checks that the event has no modifiers. F2 is special - and will always start the editor. - """ - - ## Oops, there's a bug here, we'll have to do it ourself.. - ##return self.base_IsAcceptedKey(evt) - - return (not (evt.ControlDown() or evt.AltDown()) and - evt.GetKeyCode() != wx.WXK_SHIFT) - - - def StartingKey(self, evt): - """ - If the editor is enabled by pressing keys on the grid, this will be - called to let the editor do something about that first key if desired. - """ - key = evt.GetKeyCode() - ch = None - if key in [wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3, wx.WXK_NUMPAD4, - wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]: - ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0) - - elif key < 256 and key >= 0 and chr(key) in string.printable: - ch = chr(key) - if not evt.ShiftDown(): - ch = string.lower(ch) - - if ch is not None: - # For this example, replace the text. Normally we would append it. - self._tc.AppendText(ch) - else: - evt.Skip() - - - - def Destroy(self): - """final cleanup""" - self.base_Destroy() - - - def Clone(self): - """ - Create a new object which is the copy of this one - *Must Override* - """ - return MyCellEditor() - - - -class rpg_grid(wx.grid.Grid): - """grid for attacks""" - def __init__(self, parent, handler): - wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) - self.parent = parent - self.handler = handler - - # Registers a "custom" cell editor (really the example from Robin Dunn with minor mods - self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor()) - - self.rows = handler.grid.findall('row') - rows = len(self.rows) - cols = len(self.rows[0].findall('cell')) - self.CreateGrid(rows,cols) - self.SetRowLabelSize(0) - self.SetColLabelSize(0) - self.set_col_widths() - - for i in range(0,len(self.rows)): - self.refresh_row(i) - - self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) - self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_col_size) - self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_leftdclick) - - - def on_leftdclick(self,evt): - if self.CanEnableCellControl(): - self.EnableCellEditControl() - - def on_col_size(self, evt): - col = evt.GetRowOrCol() - cells = self.rows[0].findall('cell') - size = self.GetColSize(col) - cells[col].set('size',str(size)) - evt.Skip() - - def on_cell_change(self,evt): - row = evt.GetRow() - col = evt.GetCol() - value = self.GetCellValue(row,col) - cells = self.rows[row].findall('cell') - cells[col].text = value - if col == 0: - self.handler.refresh_rows() - - def set_col_widths(self): - cells = self.rows[0].findall('cell') - for i in range(0,len(cells)): - try: - size = int(cells[i].get('size')) - self.SetColSize(i,size) - except: - continue - - def refresh_row(self,rowi): - cells = self.rows[rowi].findall('cell') - for i in range(0,len(cells)): - text = cells[i].text - if text == None or text == '': - text = '' - cells[i].text = text - self.SetCellValue(rowi,i,text) - - def add_row(self,evt=None): - cols = self.GetNumberCols() - row = ET.Element('row') - for i in range(0,cols): - cell = ET.Element('cell') - cell.text = '' - row.append(cell) - self.handler.grid.append(row) - self.AppendRows(1) - self.rows = self.handler.grid.findall('row') - self.handler.refresh_rows() - - def add_col(self,evt=None): - for r in self.rows: - cell = ET.Element('cell') - cell.text = '' - r.append(cell) - self.AppendCols(1) - self.set_col_widths() - - def del_row(self,evt=None): - num = self.GetNumberRows() - if num == 1: - return - self.handler.grid.remove(self.handler.grid[num-1])#always remove last row -- nasty - self.DeleteRows(num-1,1) - self.rows = self.handler.grid.findall('row') - self.handler.refresh_rows() - - def del_col(self,evt=None): - num = self.GetNumberCols() - if num == 1: - return - for r in self.rows: - cells = r.findall('cell') - r.remove(r[num-1])# always remove the last column -- nasty - self.DeleteCols(num-1,1) - self.set_col_widths() - - -G_TITLE = wx.NewId() -GRID_BOR = wx.NewId() -class rpg_grid_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - self.grid = rpg_grid(self,handler) - label = handler.xml.get('name') - self.main_sizer = wx.BoxSizer(wx.VERTICAL) - self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND) - self.main_sizer.Add(self.grid,1,wx.EXPAND) - self.SetSizer(self.main_sizer) - self.SetAutoLayout(True) - self.Fit() - parent.SetSize(self.GetBestSize()) - - -G_AUTO_SIZE = wx.NewId() -G_ADD_ROW = wx.NewId() -G_ADD_COL = wx.NewId() -G_DEL_ROW = wx.NewId() -G_DEL_COL = wx.NewId() - -class rpg_grid_edit_panel(wx.Panel): - def __init__(self, parent, handler): - wx.Panel.__init__(self, parent, -1) - self.handler = handler - self.grid = rpg_grid(self,handler) - self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name')) - - radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"]) - border = handler.grid.get("border") - radio_b.SetSelection(int(border)) - - self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, " Auto Size") - if handler.is_autosized() == '1': - self.auto_size.SetValue(True) - else: - self.auto_size.SetValue(False) - - sizer = wx.BoxSizer(wx.HORIZONTAL) - sizer.Add(wx.Button(self, G_ADD_ROW, "Add Row"), 1, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(wx.Button(self, G_DEL_ROW, "Remove Row"), 1, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(wx.Button(self, G_ADD_COL, "Add Column"), 1, wx.EXPAND) - sizer.Add(wx.Size(10,10)) - sizer.Add(wx.Button(self, G_DEL_COL, "Remove Column"), 1, wx.EXPAND) - - self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Grid"), wx.VERTICAL) - self.main_sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) - self.main_sizer.Add(self.title, 0, wx.EXPAND) - self.main_sizer.Add(radio_b, 0, 0) - self.main_sizer.Add(self.auto_size, 0, 0) - self.main_sizer.Add(self.grid,1,wx.EXPAND) - self.main_sizer.Add(sizer,0,wx.EXPAND) - - self.SetSizer(self.main_sizer) - self.SetAutoLayout(True) - self.Fit() - - self.Bind(wx.EVT_TEXT, self.on_text, id=G_TITLE) - self.Bind(wx.EVT_BUTTON, self.grid.add_row, id=G_ADD_ROW) - self.Bind(wx.EVT_BUTTON, self.grid.del_row, id=G_DEL_ROW) - self.Bind(wx.EVT_BUTTON, self.grid.add_col, id=G_ADD_COL) - self.Bind(wx.EVT_BUTTON, self.grid.del_col, id=G_DEL_COL) - self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GRID_BOR) - self.Bind(wx.EVT_CHECKBOX, self.on_auto_size, id=G_AUTO_SIZE) - - def on_auto_size(self,evt): - self.handler.set_autosize(bool2int(evt.Checked())) - - def on_radio_box(self,evt): - id = evt.GetId() - index = evt.GetInt() - if id == GRID_BOR: - self.handler.grid.set("border",str(index)) - - def on_text(self,evt): - txt = self.title.GetValue() - if txt != "": - self.handler.xml.set('name',txt) - self.handler.rename(txt) +# Copyright (C) 2000-2001 The OpenRPG Project +# +# openrpg-dev@lists.sourceforge.net +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# -- +# +# File: rpg_grid.py +# Author: Chris Davis +# Maintainer: +# Version: +# $Id: rpg_grid.py,v 1.20 2006/11/15 12:11:24 digitalxero Exp $ +# +# Description: The file contains code for the grid nodehanlers +# + +__version__ = "$Id: rpg_grid.py,v 1.20 2006/11/15 12:11:24 digitalxero Exp $" + +from core import * +from forms import * + +class rpg_grid_handler(node_handler): + """ Node handler for rpg grid tool + + + + + + + + + + + + + + + + """ + def __init__(self,xml,tree_node): + node_handler.__init__(self,xml,tree_node) + self.grid = self.xml.find('grid') + if self.grid.get("border") == "": + self.grid.set("border","1") + if self.grid.get("autosize") == "": + self.grid.set("autosize","1") + self.macros = self.xml.find('macros') + self.myeditor = None + self.refresh_rows() + + def refresh_die_macros(self): + pass + + def refresh_rows(self): + self.rows = {} + tree = self.tree + icons = self.tree.icons + tree.CollapseAndReset(self.mytree_node) + for row in self.grid.findall('row'): + first_cell = row.find('cell') + name = first_cell.text + if name == None or name == '': + name = "Row" + new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) + handler = grid_row_handler(row,new_tree_node,self) + tree.SetPyData(new_tree_node,handler) + + def tohtml(self): + border = self.grid.get("border") + name = self.xml.get('name') + rows = self.grid.findall('row') + colspan = str(len(rows[0].findall('cell'))) + html_str = "" + for r in rows: + cells = r.findall('cell') + html_str += "" + for c in cells: + #html_str += "" + html_str += "" + html_str += "
"+name+"
" bug here + html_str += "" + text = c.text + if text == None or text == '': + text = '
' + html_str += text + "
" + return html_str + + def get_design_panel(self,parent): + return rpg_grid_edit_panel(parent,self) + + def get_use_panel(self,parent): + return rpg_grid_panel(parent,self) + + def get_size_constraint(self): + return 1 + + def is_autosized(self): + return self.grid.get("autosize") + + def set_autosize(self,autosize=1): + self.grid.set("autosize",str(autosize)) + +class grid_row_handler(node_handler): + """ Node Handler grid row. + """ + def __init__(self,xml,tree_node,parent): + node_handler.__init__(self,xml,tree_node) + self.drag = False + + def on_drop(self,evt): + pass + + def can_clone(self): + return 0; + + def tohtml(self): + cells = self.xml.findall('cell') + html_str = "" + for c in cells: # should loop over rows first, then cells + html_str += "" + html_str += "" + html_str += "
" + text = c.text + if text == '' or text is None: + text = '
' + html_str += text + "
" + return html_str + + def get_value(self): + cells = self.xml.findall('cell') + if len(cells) == 2: + return getText(cells[1]) + else: + return None + + def set_value(self, new_value): + cells = self.xml.findall('cell') + if len(cells) == 2: + cells[1].text = new_value + +class MyCellEditor(wx.grid.PyGridCellEditor): + """ + This is a sample GridCellEditor that shows you how to make your own custom + grid editors. All the methods that can be overridden are show here. The + ones that must be overridden are marked with "*Must Override*" in the + docstring. + + Notice that in order to call the base class version of these special + methods we use the method name preceded by "base_". This is because these + methods are "virtual" in C++ so if we try to call wxGridCellEditor.Create + for example, then when the wxPython extension module tries to call + ptr->Create(...) then it actually calls the derived class version which + looks up the method in this class and calls it, causing a recursion loop. + If you don't understand any of this, don't worry, just call the "base_" + version instead. + + ---------------------------------------------------------------------------- + This class is copied from the wxPython examples directory and was written by + Robin Dunn. + + I have pasted it directly in and removed all references to "log" + + -- Andrew + + """ + def __init__(self): + wx.grid.PyGridCellEditor.__init__(self) + + + def Create(self, parent, id, evtHandler): + """ + Called to create the control, which must derive from wxControl. + *Must Override* + """ + self._tc = wx.TextCtrl(parent, id, "", style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB) + self._tc.SetInsertionPoint(0) + self.SetControl(self._tc) + if evtHandler: + self._tc.PushEventHandler(evtHandler) + + + def SetSize(self, rect): + """ + Called to position/size the edit control within the cell rectangle. + If you don't fill the cell (the rect) then be sure to override + PaintBackground and do something meaningful there. + """ + self._tc.SetDimensions(rect.x+1, rect.y+1, rect.width+2, rect.height+2) + + + #def Show(self, show, attr): #deprecated DeprecationWarning: Please use PyGridCellEditor.Show instead. + # """ + # Show or hide the edit control. You can use the attr (if not None) + # to set colours or fonts for the control. + # """ + # self.base_Show(show, attr) # Removed to prevent recursive error type. + + + def BeginEdit(self, row, col, grid): + """ + Fetch the value from the table and prepare the edit control + to begin editing. Set the focus to the edit control. + *Must Override* + """ + self.startValue = grid.GetTable().GetValue(row, col) + self._tc.SetValue(self.startValue) + self._tc.SetInsertionPointEnd() + self._tc.SetFocus() + + # For this example, select the text + self._tc.SetSelection(0, self._tc.GetLastPosition()) + + + def EndEdit(self, row, col, grid): + """ + Complete the editing of the current cell. Returns True if the value + has changed. If necessary, the control may be destroyed. + *Must Override* + """ + changed = False + + val = self._tc.GetValue() + if val != self.startValue: + changed = True + grid.GetTable().SetValue(row, col, val) # update the table + + self.startValue = '' + self._tc.SetValue('') + return changed + + + def Reset(self): + """ + Reset the value in the control back to its starting value. + *Must Override* + """ + self._tc.SetValue(self.startValue) + self._tc.SetInsertionPointEnd() + + + def IsAcceptedKey(self, evt): + """ + Return True to allow the given key to start editing: the base class + version only checks that the event has no modifiers. F2 is special + and will always start the editor. + """ + + ## Oops, there's a bug here, we'll have to do it ourself.. + ##return self.base_IsAcceptedKey(evt) + + return (not (evt.ControlDown() or evt.AltDown()) and + evt.GetKeyCode() != wx.WXK_SHIFT) + + + def StartingKey(self, evt): + """ + If the editor is enabled by pressing keys on the grid, this will be + called to let the editor do something about that first key if desired. + """ + key = evt.GetKeyCode() + ch = None + if key in [wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3, wx.WXK_NUMPAD4, + wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7, wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]: + ch = ch = chr(ord('0') + key - wx.WXK_NUMPAD0) + + elif key < 256 and key >= 0 and chr(key) in string.printable: + ch = chr(key) + if not evt.ShiftDown(): + ch = string.lower(ch) + + if ch is not None: + # For this example, replace the text. Normally we would append it. + self._tc.AppendText(ch) + else: + evt.Skip() + + + + def Destroy(self): + """final cleanup""" + self.base_Destroy() + + + def Clone(self): + """ + Create a new object which is the copy of this one + *Must Override* + """ + return MyCellEditor() + + + +class rpg_grid(wx.grid.Grid): + """grid for attacks""" + def __init__(self, parent, handler): + wx.grid.Grid.__init__(self, parent, -1, style=wx.SUNKEN_BORDER | wx.WANTS_CHARS) + self.parent = parent + self.handler = handler + + # Registers a "custom" cell editor (really the example from Robin Dunn with minor mods + self.RegisterDataType(wx.grid.GRID_VALUE_STRING, wx.grid.GridCellStringRenderer(),MyCellEditor()) + + self.rows = handler.grid.findall('row') + rows = len(self.rows) + cols = len(self.rows[0].findall('cell')) + self.CreateGrid(rows,cols) + self.SetRowLabelSize(0) + self.SetColLabelSize(0) + self.set_col_widths() + + for i in range(0,len(self.rows)): + self.refresh_row(i) + + self.Bind(wx.grid.EVT_GRID_CELL_CHANGE, self.on_cell_change) + self.Bind(wx.grid.EVT_GRID_COL_SIZE, self.on_col_size) + self.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK, self.on_leftdclick) + + + def on_leftdclick(self,evt): + if self.CanEnableCellControl(): + self.EnableCellEditControl() + + def on_col_size(self, evt): + col = evt.GetRowOrCol() + cells = self.rows[0].findall('cell') + size = self.GetColSize(col) + cells[col].set('size',str(size)) + evt.Skip() + + def on_cell_change(self,evt): + row = evt.GetRow() + col = evt.GetCol() + value = self.GetCellValue(row,col) + cells = self.rows[row].findall('cell') + cells[col].text = value + if col == 0: + self.handler.refresh_rows() + + def set_col_widths(self): + cells = self.rows[0].findall('cell') + for i in range(0,len(cells)): + try: + size = int(cells[i].get('size')) + self.SetColSize(i,size) + except: + continue + + def refresh_row(self,rowi): + cells = self.rows[rowi].findall('cell') + for i in range(0,len(cells)): + text = cells[i].text + if text == None or text == '': + text = '' + cells[i].text = text + self.SetCellValue(rowi,i,text) + + def add_row(self,evt=None): + cols = self.GetNumberCols() + row = Element('row') + for i in range(0,cols): + cell = Element('cell') + cell.text = '' + row.append(cell) + self.handler.grid.append(row) + self.AppendRows(1) + self.rows = self.handler.grid.findall('row') + self.handler.refresh_rows() + + def add_col(self,evt=None): + for r in self.rows: + cell = Element('cell') + cell.text = '' + r.append(cell) + self.AppendCols(1) + self.set_col_widths() + + def del_row(self,evt=None): + num = self.GetNumberRows() + if num == 1: + return + self.handler.grid.remove(self.handler.grid[num-1])#always remove last row -- nasty + self.DeleteRows(num-1,1) + self.rows = self.handler.grid.findall('row') + self.handler.refresh_rows() + + def del_col(self,evt=None): + num = self.GetNumberCols() + if num == 1: + return + for r in self.rows: + cells = r.findall('cell') + r.remove(r[num-1])# always remove the last column -- nasty + self.DeleteCols(num-1,1) + self.set_col_widths() + + +G_TITLE = wx.NewId() +GRID_BOR = wx.NewId() +class rpg_grid_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.handler = handler + self.grid = rpg_grid(self,handler) + label = handler.xml.get('name') + self.main_sizer = wx.BoxSizer(wx.VERTICAL) + self.main_sizer.Add(wx.StaticText(self, -1, label+": "), 0, wx.EXPAND) + self.main_sizer.Add(self.grid,1,wx.EXPAND) + self.SetSizer(self.main_sizer) + self.SetAutoLayout(True) + self.Fit() + parent.SetSize(self.GetBestSize()) + + +G_AUTO_SIZE = wx.NewId() +G_ADD_ROW = wx.NewId() +G_ADD_COL = wx.NewId() +G_DEL_ROW = wx.NewId() +G_DEL_COL = wx.NewId() + +class rpg_grid_edit_panel(wx.Panel): + def __init__(self, parent, handler): + wx.Panel.__init__(self, parent, -1) + self.handler = handler + self.grid = rpg_grid(self,handler) + self.title = wx.TextCtrl(self, G_TITLE, handler.xml.get('name')) + + radio_b = wx.RadioBox(self, GRID_BOR, "Border (HTML)", choices=["no","yes"]) + border = handler.grid.get("border") + radio_b.SetSelection(int(border)) + + self.auto_size = wx.CheckBox(self, G_AUTO_SIZE, " Auto Size") + if handler.is_autosized() == '1': + self.auto_size.SetValue(True) + else: + self.auto_size.SetValue(False) + + sizer = wx.BoxSizer(wx.HORIZONTAL) + sizer.Add(wx.Button(self, G_ADD_ROW, "Add Row"), 1, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(wx.Button(self, G_DEL_ROW, "Remove Row"), 1, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(wx.Button(self, G_ADD_COL, "Add Column"), 1, wx.EXPAND) + sizer.Add(wx.Size(10,10)) + sizer.Add(wx.Button(self, G_DEL_COL, "Remove Column"), 1, wx.EXPAND) + + self.main_sizer = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Grid"), wx.VERTICAL) + self.main_sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND) + self.main_sizer.Add(self.title, 0, wx.EXPAND) + self.main_sizer.Add(radio_b, 0, 0) + self.main_sizer.Add(self.auto_size, 0, 0) + self.main_sizer.Add(self.grid,1,wx.EXPAND) + self.main_sizer.Add(sizer,0,wx.EXPAND) + + self.SetSizer(self.main_sizer) + self.SetAutoLayout(True) + self.Fit() + + self.Bind(wx.EVT_TEXT, self.on_text, id=G_TITLE) + self.Bind(wx.EVT_BUTTON, self.grid.add_row, id=G_ADD_ROW) + self.Bind(wx.EVT_BUTTON, self.grid.del_row, id=G_DEL_ROW) + self.Bind(wx.EVT_BUTTON, self.grid.add_col, id=G_ADD_COL) + self.Bind(wx.EVT_BUTTON, self.grid.del_col, id=G_DEL_COL) + self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=GRID_BOR) + self.Bind(wx.EVT_CHECKBOX, self.on_auto_size, id=G_AUTO_SIZE) + + def on_auto_size(self,evt): + self.handler.set_autosize(bool2int(evt.Checked())) + + def on_radio_box(self,evt): + id = evt.GetId() + index = evt.GetInt() + if id == GRID_BOR: + self.handler.grid.set("border",str(index)) + + def on_text(self,evt): + txt = self.title.GetValue() + if txt != "": + self.handler.xml.set('name',txt) + self.handler.rename(txt) diff -r d54e1328dbb1 -r 90d19eb43830 orpg/orpg_version.py --- a/orpg/orpg_version.py Tue Nov 03 21:06:03 2009 -0600 +++ b/orpg/orpg_version.py Tue Nov 03 21:30:36 2009 -0600 @@ -4,7 +4,7 @@ #BUILD NUMBER FORMAT: "YYMMDD-##" where ## is the incremental daily build index (if needed) DISTRO = "Traipse Alpha" DIS_VER = "Ornery Orc" -BUILD = "091003-02" +BUILD = "091003-03" # This version is for network capability. PROTOCOL_VERSION = "1.2"