[Winopenrpg-developer] openrpg1/orpg/gametree/nodehandlers StarWarsd20.py,NONE,1.1 __init__.py,NONE,
Status: Inactive
Brought to you by:
digitalxero
|
From: Digital X. <dig...@us...> - 2006-01-26 17:33:28
|
Update of /cvsroot/winopenrpg/openrpg1/orpg/gametree/nodehandlers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30930/orpg/gametree/nodehandlers Added Files: StarWarsd20.py __init__.py chatmacro.py containers.py core.py d20.py dnd3e.py forms.py map_miniature_nodehandler.py minilib.py nodehandler_version.py rpg_grid.py voxchat.py Log Message: Initial commit of OpenRPG++ python --- NEW FILE: dnd3e.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # 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. # -- # [...3573 lines suppressed...] elif id == PP_FRE: self.master_dom.setAttribute('free',evt.GetString()) elif id == PP_MFRE: self.master_dom.setAttribute('maxfree',evt.GetString()) def on_size(self,evt): s = self.GetClientSizeTuple() self.sizer.SetDimension(0,0,s[0],s[1]) #a 5.015 this whole function. def on_refresh(self,attr,value): if attr == 'current1': self.dyn1.SetValue(value) else: self.dyn3.SetValue(value) --- NEW FILE: chatmacro.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # 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: chatmacro.py # Author: Chris Davis # Maintainer: # Version: # $Id: chatmacro.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $ # # Description: The file contains code for the form based nodehanlers # __version__ = "$Id: chatmacro.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" from core import * ########################## ## text node handler ########################## class macro_handler(node_handler): """ A nodehandler for text blocks. Will open text in a text frame <nodehandler name='?' module='chatmacro' class='macro_handler'> <text>some text here</text> </nodehandler > """ def __init__(self,xml_dom,tree_node,openrpg): node_handler.__init__(self,xml_dom,tree_node,openrpg) self.text_elem = self.master_dom.getElementsByTagName('text')[0] self.text = safe_get_text_node(self.text_elem) def set_text(self,txt): self.text._set_nodeValue(txt) def on_use(self,evt): txt = self.text._get_nodeValue() actionlist = txt.split("\n") for line in actionlist: if(line != ""): if line[0] != "/": ## it's not a slash command action = self.chat.ParsePost(self.chat.colorize(self.chat.mytextcolor, line),true,true) else: action = line self.chat.chat_cmds.docmd(action) return 1 def get_design_panel(self,parent): return macro_edit_panel(parent,self) def tohtml(self): title = self.master_dom.getAttribute("name") txt = self.text._get_nodeValue() txt = string.replace(txt,'\n',"<br>") return "<P><b>"+title+":</b><br>"+txt P_TITLE = wxNewId() P_BODY = wxNewId() B_CHAT = wxNewId() class macro_edit_panel(wxBoxedSizer): def __init__(self, parent, handler): wxBoxedSizer.__init__(self, parent, "Chat Macro") self.handler = handler self.text = { P_TITLE : orpgTextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')), P_BODY : orpgTextCtrl(self,P_BODY,handler.text._get_nodeValue(),style=wxTE_MULTILINE) } #P_BODY : wxTextCtrl(self, P_BODY,handler.text._get_nodeValue(), style=wxTE_MULTILINE) sizer = wxBoxSizer(wxVERTICAL) sizer.Add(wxStaticText(self, -1, "Title:"), 0, wxEXPAND) sizer.Add(self.text[P_TITLE], 0, wxEXPAND) sizer.Add(wxStaticText(self, -1, "Text Body:"), 0, wxEXPAND) sizer.Add(self.text[P_BODY], 1, wxEXPAND) sizer.Add(wxButton(self, B_CHAT, "Send To Chat"),0,wxEXPAND) EVT_SIZE(self, self.on_size) EVT_TEXT(self, P_TITLE, self.on_text) EVT_TEXT(self, P_BODY, self.on_text) EVT_BUTTON(self, B_CHAT, self.handler.on_use) self.set_sizer(sizer) #EVT_TEXT(self, P_BODY, self.on_text) def on_text(self,evt): id = evt.GetId() txt = self.text[id].GetValue() if txt == "": return if id == P_TITLE: self.handler.master_dom.setAttribute('name',txt) self.handler.rename(txt) elif id == P_BODY: self.handler.set_text(txt) --- NEW FILE: voxchat.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # 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. # -- # [...1198 lines suppressed...] # ## PAGE DOWN # elif event.KeyCode() == WXK_NEXT and event.ControlDown(): # if self.bufferpointer > 0: # self.bufferpointer = self.bufferpointer - self.buffersize # # self.Post() # self.do_chat_action( None ) # else: # event.Skip() # # ## END # elif event.KeyCode() == WXK_END and event.ControlDown(): # self.bufferpointer = 0 # self.do_chat_action( None ) # # self.Post() # event.Skip() ## NOTHING else: event.Skip() # def OnChar - end --- NEW FILE: nodehandler_version.py --- ### this file holds the nodehandler version ### NODEHANDLER_VERSION = "1.0" --- NEW FILE: core.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # 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: core.py # Author: Chris Davis # Maintainer: # Version: # $Id: core.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $ # # Description: The file contains code for the core nodehanlers # __version__ = "$Id: core.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" from nodehandler_version import NODEHANDLER_VERSION from orpg.orpg_windows import * import orpg.dirpath from orpg.orpg_xml import * import webbrowser from orpg.mapper import map import os #html defaults TH_BG = "#E9E9E9" ########################## ## base node handler ########################## class node_handler: """ Base nodehandler with virtual functions and standard implmentations """ def __init__(self,xml_dom,tree_node,openrpg): self.master_dom = xml_dom self.mytree_node = tree_node self.myopenrpg = openrpg self.tree = openrpg.get_component('tree') self.frame = openrpg.get_component('frame') self.chat = openrpg.get_component('chat') self.drag = true self.myeditor = None # designing self.myviewer = None # prett print self.mywindow = None # using # call version hook self.on_version(self.master_dom.getAttribute("version")) # set to current version self.master_dom.setAttribute("version",NODEHANDLER_VERSION) # null events def on_version(self,old_version): ## added version control code here or implement a new on_version in your derived class. ## always call the base class on_version ! pass def on_rclick(self,evt): self.tree.do_std_menu(evt,self) def on_ldclick(self,evt): return 0 def usefulness(self,text): if text=="useful": self.master_dom.setAttribute('status',"useful") elif text=="useless": self.master_dom.setAttribute('status',"useless") elif text=="indifferent": self.master_dom.setAttribute('status',"indifferent") def on_design(self,evt): if self.myeditor == None: del self.myeditor self.create_designframe() try: if self.myeditor.destroyed: del self.myeditor self.create_designframe() except: self.create_designframe() self.myeditor.Show(1) self.myeditor.Raise() def create_designframe(self): title = self.master_dom.getAttribute('name') + " Editor" self.myeditor = wxPFrame(self.frame,title,orpg.dirpath.dir_struct["icon"]+'grid.ico') self.myeditor.panel = self.get_design_panel(self.myeditor) self.myeditor.Show(1) self.myeditor.Raise() def on_use(self,evt): if self.mywindow == None: del self.mywindow self.create_useframe() try: if self.mywindow.destroyed: del self.mywindow self.create_useframe() except: self.create_useframe() self.mywindow.Show(1) self.mywindow.Raise() def create_useframe(self): caption = self.master_dom.getAttribute('name') self.mywindow = wxPFrame(self.frame, caption, orpg.dirpath.dir_struct["icon"] + 'note.ico') self.mywindow.panel = self.get_use_panel(self.mywindow) self.mywindow.Show(1) self.mywindow.Raise() def on_html_view(self,evt): try: self.myviewer.Raise() except: caption = self.master_dom.getAttribute('name') self.myviewer = wxPFrame(self.frame,caption,orpg.dirpath.dir_struct["icon"]+'note.ico') self.myviewer.panel = self.get_html_panel(self.myviewer) self.myviewer.Show(1) def map_aware(self): return 0 def can_clone(self): return 1; def on_del(self,evt): print "on del" def on_new_data(self,xml_dom): pass def get_scaled_bitmap(self,x,y): return None # def is_my_parent(self,parent_node,compare_node): # parent_node = self.tree.GetItemParent(parent_node) # if compare_node == parent_node: # return 1 # elif parent_node == self.tree.root: # return 0 # else: # return self.is_my_parent(compare_node,parent_node) # def is_my_child(self,compare_node,parent_node): # x = self.tree.GetItemParent(compare_node) # while true: # if self.tree.GetItemText(x) == self.tree.GetItemText(parent_node): # return 1 # x = self.tree.GetItemParent(x) # if len(self.tree.GetItemText(x)) < 1: # break # return 0 def on_send_to_map(self,evt): pass def on_send_to_chat(self,evt): self.chat.ParsePost(self.tohtml(),true,true) 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 #if self.is_my_child(self.mytree_node,drag_obj.mytree_node): # return xml_dom = self.tree.drag_obj.delete() parent = self.master_dom._get_parentNode() xml_dom = parent.insertBefore(xml_dom,self.master_dom) parent_node = self.tree.GetItemParent(self.mytree_node) prev_sib = self.tree.GetPrevSibling(self.mytree_node) self.tree.load_xml(xml_dom, parent_node, prev_sib) def toxml(self,pretty=0): return toxml(self.master_dom,pretty) def tohtml(self): return self.master_dom.getAttribute("name") def delete(self): """ removes the tree_node and xml_node, and returns the removed xml_node """ self.tree.Delete(self.mytree_node) parent = self.master_dom._get_parentNode() return parent.removeChild(self.master_dom) def rename(self,name): if len(name): self.tree.SetItemText(self.mytree_node,name) def change_icon(self,icon): self.master_dom.setAttribute("icon",icon) self.tree.SetItemImage(self.mytree_node,self.tree.icons[icon]) self.tree.SetItemSelectedImage(self.mytree_node,self.tree.icons[icon]) def on_save(self,evt): f =wxFileDialog(self.tree,"Select a file", orpg.dirpath.dir_struct["user"],"","XML files (*.xml)|*.xml",wxSAVE) if f.ShowModal() == wxID_OK: type = f.GetFilterIndex() file = open(f.GetPath(),"w") file.write(self.toxml(1)) file.close() f.Destroy() def get_design_panel(self,parent): return None def get_use_panel(self,parent): return None def get_html_panel(self,parent): html_str = "<html><body bgcolor=\"#FFFFFF\" >"+self.tohtml()+"</body></html>" wnd = wxHTMLpanel(parent,-1) html_str = self.chat.ParseDice(html_str) wnd.load_text(html_str) return wnd def get_size_constraint(self): return 0 def about(self): html_str = "<b>"+ self.master_dom.getAttribute('class') html_str += " Applet</b><br>by Chris Davis<br>ch...@rp..." return html_str # All the functions below are foe backward compatiablity ! def old_group_xml(xml_dom,tree_node,openrpg): import containers xml_dom.setAttribute("class","group_handler") xml_dom.setAttribute("module","containers") return containers.group_handler(xml_dom,tree_node,openrpg) static_handler = old_group_xml def old_text_xml(xml_dom,tree_node,openrpg): old_text = safe_get_text_node(xml_dom) elem = minidom.Element('text') elem.setAttribute("multiline","1") t_node = minidom.Text(old_text._get_nodeValue()) t_node = elem.appendChild(t_node) text = safe_get_text_node(elem) xml_dom.appendChild(elem) old_text._set_nodeValue("") xml_dom.setAttribute("class","textctrl_handler") xml_dom.setAttribute("module","forms") import forms return forms.textctrl_handler(xml_dom,tree_node,openrpg) text_handler = old_text_xml dieroll_handler = old_text_xml def old_macro_xml(xml_dom,tree_node,openrpg): old_text = safe_get_text_node(xml_dom) elem = minidom.Element('text') t_node = minidom.Text(old_text._get_nodeValue()) t_node = elem.appendChild(t_node) text = safe_get_text_node(elem) xml_dom.appendChild(elem) old_text._set_nodeValue("") xml_dom.setAttribute("class","macro_handler") xml_dom.setAttribute("module","chatmacro") import chatmacro return chatmacro.macro_handler(xml_dom,tree_node,openrpg) macro_handler = old_macro_xml def old_link_xml(xml_dom,tree_node,openrpg): xml_dom.setAttribute("class","link_handler") xml_dom.setAttribute("module","forms") import forms return forms.link_handler(xml_dom,tree_node,openrpg) link_handler = old_link_xml webbrowser_handler = old_link_xml def old_webimg_xml(xml_dom,tree_node,openrpg): xml_dom.setAttribute("class","webimg_handler") xml_dom.setAttribute("module","forms") import forms return forms.webimg_handler(xml_dom,tree_node,openrpg) webimg_handler = old_webimg_xml # ########################## # ## link node handler # ########################## # class link_handler(node_handler): # """ A nodehandler for URLs. Will open URL in a wxHTMLFrame # <nodehandler name='?' module='core' class='link_handler' > # <link href='http//??.??' /> # </nodehandler > # """ # def __init__(self,xml_dom,tree_node,openrpg): # node_handler.__init__(self,xml_dom,tree_node,openrpg) # self.link = self.master_dom._get_firstChild() # self.wnd = None # self.frame = openrpg.get_component('frame') # def on_use(self,evt): # href = self.link.getAttribute("href") # title = self.master_dom.getAttribute("name") # self.myframe = wxPFrame(self.frame,title,orpg.dirpath.dir_struct["icon"] + 'note.ico') # wnd = wxHTMLpanel(self.myframe,-1) # self.myframe.panel = wnd # wnd.load_url(href) # self.myframe.Show(1) # def on_design(self,evt): # tlist = ['Title','href'] # vlist = [self.master_dom.getAttribute("name"), # self.link.getAttribute("href")] # dlg = wxMultiTextEntry(self.tree.GetParent(),tlist,vlist,"Link Edit") # if dlg.ShowModal() == wxID_OK: # vlist = dlg.get_values() # self.link.setAttribute('href', vlist[1]) # self.master_dom.setAttribute('name', vlist[0]) # self.tree.SetItemText(self.mytree_node,vlist[0]) # dlg.Destroy() # def get_design_panel(self,parent): # return None # def tohtml(self): # href = self.link.getAttribute("href") # title = self.master_dom.getAttribute("name") # return "<a href=\""+href+"\" >"+title+"</a>" # ########################## # ## webimg node handler # ########################## # class webimg_handler(link_handler): # """ A nodehandler for URLs. Will open URL in a wxHTMLFrame # <nodehandler name='?' module='core' class='webimg_handler' > # <link href='http//??.??' /> # </nodehandler > # """ # def __init__(self,xml_dom,tree_node,openrpg): # link_handler.__init__(self,xml_dom,tree_node,openrpg) # def on_use(self,evt): # href = self.link.getAttribute("href") # title = self.master_dom.getAttribute("name") # self.myframe = wxPFrame(self.frame,title,orpg.dirpath.dir_struct["icon"] + 'note.ico') # wnd = scrolled_img_panel(self.myframe,-1) # self.myframe.panel = wnd # wnd.load_url(href) # self.wnd = wnd # self.myframe.Show(1) # def tohtml(self): # href = self.link.getAttribute("href") # title = self.master_dom.getAttribute("name") # return "<img src=\""+href+"\" alt="+title+" >" # ########################## # ## webbrowser node handler # ########################## # class webbrowser_handler(link_handler): # """ A nodehandler for webbroser URLs. Will open URL in the # default webbrowser # <nodehandler name='?' module='core' class='webbrowser_handler' > # <link href='http//??.??' /> # </nodehandler > # """ # def __init__(self,xml_dom,tree_node,openrpg): # link_handler.__init__(self,xml_dom,tree_node,openrpg) # def on_use(self,evt): # href = self.link.getAttribute("href") # wb = webbrowser.get() # wb.open(href) # # def tohtml(self): # href = self.link.getAttribute("href") # title = self.master_dom.getAttribute("name") # return "<a href=\""+href+"\" >"+title+"</a>" # # ########################## # ## text node handler # ########################## # class text_handler2(node_handler): # """ A nodehandler for text blocks. Will open text in a text frame # <nodehandler name='?' module='core' class='text_handler'> # some text here # </nodehandler > # """ # def __init__(self,xml_dom,tree_node,openrpg): # node_handler.__init__(self,xml_dom,tree_node,openrpg) # self.text = safe_get_text_node(self.master_dom) # self.wnd = None # self.frame = openrpg.get_component('frame') # self.myeditor = None # def on_change(self,txt): # self.text._set_nodeValue(txt) # # def on_design(self,evt): # if self.myeditor == None or self.myeditor.destroyed: # title = self.master_dom.getAttribute('name') + " Editor" # self.myeditor = wxPFrame(self.frame,title,orpg.dirpath.dir_struct["icon"]+ 'note.ico') # wnd = text_edit_panel(self.myeditor,self) # self.myeditor.panel = wnd # self.wnd = wnd # self.myeditor.Show(1) # else: # self.myeditor.Raise() # def get_design_panel(self,parent): # return text_edit_panel(parent,self) # # def tohtml(self): # title = self.master_dom.getAttribute("name") # txt = self.text._get_nodeValue() # txt = string.replace(txt,'\n',"<br>") # return "<P><b>"+title+":</b><br>"+txt P_TITLE = 10 P_BODY = 20 class text_edit_panel(wxPanel): def __init__(self, parent, handler): wxPanel.__init__(self, parent, -1) self.handler = handler sizer = wxBoxSizer(wxVERTICAL) self.text = { P_TITLE : orpgTextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')), P_BODY : html_text_edit(self,P_BODY,handler.text._get_nodeValue(),self.on_text) } #P_BODY : wxTextCtrl(self, P_BODY,handler.text._get_nodeValue(), style=wxTE_MULTILINE) sizer.Add(wxStaticText(self, -1, "Title:"), 0, wxEXPAND) sizer.Add(self.text[P_TITLE], 0, wxEXPAND) sizer.Add(wxStaticText(self, -1, "Text Body:"), 0, wxEXPAND) sizer.Add(self.text[P_BODY], 1, wxEXPAND) self.sizer = sizer self.outline = wxStaticBox(self,-1,"Text Block") EVT_SIZE(self, self.on_size) EVT_TEXT(self, P_TITLE, self.on_text) #EVT_TEXT(self, P_BODY, self.on_text) def on_text(self,evt): id = evt.GetId() if id == P_TITLE: txt = self.text[id].GetValue() # The following block strips out 8-bit characters u_txt = "" bad_txt_found = 0 for c in txt: if ord(c) < 128: u_txt += c else: bad_txt_found = 1 if bad_txt_found: wxMessageBox("Some non 7-bit ASCII characters found and stripped","Warning!") txt = u_txt if txt != "": self.handler.master_dom.setAttribute('name',txt) self.handler.rename(txt) elif id == P_BODY: txt = self.text[id].get_text() u_txt = "" bad_txt_found = 0 for c in txt: if ord(c) < 128: u_txt += c else: bad_txt_found = 1 if bad_txt_found: wxMessageBox("Some non 7-bit ASCII characters found and stripped","Warning!") txt = u_txt self.handler.text._set_nodeValue(txt) def on_size(self,evt): s = self.GetClientSizeTuple() self.sizer.SetDimension(20,20,s[0]-40,s[1]-40) self.outline.SetDimensions(5,5,s[0]-10,s[1]-10) # ########################## # ## macro node handler # ########################## # class macro_handler(text_handler2): # """ A nodehandler for text blocks. Will open text in a text frame # <nodehandler name='?' module='core' class='macro_handler'> # a line of text to be macro'ed here # another line of text to be macro'ed # </nodehandler > # """ # # def on_ldclick(self,evt): # txt = self.text._get_nodeValue() # actionlist = txt.split("\n") # for line in actionlist: # if(line != ""): # if line[0] != "/": ## it's not a slash command # action = self.chat.ParsePost(self.chat.colorize(self.chat.mytextcolor, line),true,true) # else: # action = self.chat.ParseDice(line) # self.chat.emote.docmd(line) # return 1 # ########################## # ## dice macro node handler # ########################## # class dieroll_handler(text_handler2): # """ A nodehandler for text blocks. Will open text in a text frame # <nodehandler name='?' module='core' class='dieroll_handler'> # attack roll [1d20+4] # </nodehandler > # """ # def __init__(self,xml_dom,tree_node,openrpg): # text_handler2.__init__(self,xml_dom,tree_node,openrpg) # self.text = safe_get_text_node(self.master_dom) # def tohtml(self): # title = self.master_dom.getAttribute("name") # txt = self.text._get_nodeValue() # txt = string.replace(txt,'\n',"<br>") # return txt ########################## ## node loader ########################## class node_loader(node_handler): """ clones childe node and insert it at top of tree <nodehandler name='?' module='core' class='node_loader' /> """ def __init__(self,xml_dom,tree_node,openrpg): node_handler.__init__(self,xml_dom,tree_node,openrpg) def on_rclick(self,evt): pass def on_ldclick(self,evt): title = self.master_dom.getAttribute('name') new_node = self.master_dom._get_firstChild() new_node = new_node.cloneNode(true) child = self.tree.master_dom._get_firstChild() new_node = self.tree.master_dom.insertBefore(new_node,child) tree_node = self.tree.load_xml(new_node,self.tree.root,self.tree.root) obj = self.tree.GetPyData(tree_node) return 1 #obj.on_design(None) ########################## ## file loader ########################## class file_loader(node_handler): """ loads file and insert into game tree <nodehandler name='?' module='core' class='file_loader' > <file name="file_name.xml" /> </nodehandler> """ def __init__(self,xml_dom,tree_node,openrpg): node_handler.__init__(self,xml_dom,tree_node,openrpg) self.file_node = self.master_dom._get_firstChild() self.frame = openrpg.get_component('frame') def on_ldclick(self,evt): file_name = self.file_node.getAttribute("name") self.tree.insert_xml(open(orpg.dirpath.dir_struct["addon"] + file_name,"r").read()) return 1 def on_design(self,evt): tlist = ['Title','File Name'] vlist = [self.master_dom.getAttribute("name"), self.file_node.getAttribute("name")] dlg = wxMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit") if dlg.ShowModal() == wxID_OK: vlist = dlg.get_values() self.file_node.setAttribute('name', vlist[1]) self.master_dom.setAttribute('name', vlist[0]) self.tree.SetItemText(self.mytree_node,vlist[0]) dlg.Destroy() ########################## ## URL loader ########################## class url_loader(node_handler): """ loads file from url and insert into game tree <nodehandler name='?' module='core' class='url_loader' > <file name="http://file_name.xml" /> </nodehandler> """ def __init__(self,xml_dom,tree_node,openrpg): node_handler.__init__(self,xml_dom,tree_node,openrpg) self.file_node = self.master_dom._get_firstChild() self.frame = openrpg.get_component('frame') def on_ldclick(self,evt): file_name = self.file_node.getAttribute("url") file = urllib.urlopen(file_name) self.tree.insert_xml(file.read()) return 1 def on_design(self,evt): tlist = ['Title','URL'] print "design filename",self.master_dom.getAttribute('name') vlist = [self.master_dom.getAttribute("name"), self.file_node.getAttribute("url")] dlg = wxMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit") if dlg.ShowModal() == wxID_OK: vlist = dlg.get_values() self.file_node.setAttribute('url', vlist[1]) self.master_dom.setAttribute('name', vlist[0]) self.tree.SetItemText(self.mytree_node,vlist[0]) dlg.Destroy() ########################## ## minature map loader ########################## class min_map(node_handler): """ clones childe node and insert it at top of tree <nodehandler name='?' module='core' class='min_map' /> """ def __init__(self,xml_dom,tree_node,openrpg): node_handler.__init__(self,xml_dom,tree_node,openrpg) self.map = openrpg.get_component('map') self.mapdata = self.master_dom._get_firstChild() def on_ldclick(self,evt): self.map.new_data(toxml(self.mapdata)) return 1 --- NEW FILE: minilib.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # 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: minilib.py # Author: Ted Berg # Maintainer: # Version: # $Id: minilib.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $ # # Description: nodehandler for a collection of miniatures. # __version__ = "$Id: minilib.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" """Nodehandler for collections of miniatures. User can add, delete, edit miniatures as sending them to the map singly or in batches. """ from core import * import orpg.dirpath import string import map_miniature_nodehandler import orpg.mapper.map_msg # import scriptkit # GUI Constants # DLG_FRAME = 1 # DLG_DIALOG = 2 # DLG_MYMINIFRAME = 3 # DLG_DEFAULT = 4 LISTBOX_ID = 10 MINICOUNT_ID = 20 OK_BUTTON = 30 CANCEL_BUTTON = 40 LAYER_MINIATURES='miniatures' # Constants TO_MINILIB_MAP = { 'path' : 'url', 'label' : 'name', 'id' : None, 'action':None } FROM_MINILIB_MAP = { 'url' : 'path', 'name' : 'label', 'unique' : None, } CORE_ATTRIBUTES = [ 'name', 'url', 'unique', 'posy', 'posx', 'hide', 'face', 'heading', 'align', 'locked', 'width', 'height', ] ATTRIBUTE_NAME = 'name' ATTRIBUTE_URL = 'url' ATTRIBUTE_UNIQUE = 'unique' ATTRIBUTE_ID = 'id' ATTRIBUTE_POSX = 'posx' ATTRIBUTE_POSY = 'posy' TAG_MINIATURE = 'miniature' COMPONENT_MAP = 'map' COMPONENT_SESSION = 'session' # <nodehandler name='?' module='minilib' class='minilib_handler'> # <miniature name='?' url='?' unique='?'></miniature> # </nodehandler> class minilib_handler( node_handler ): """A nodehandler that manages a collection of miniatures for the map. <pre> <nodehandler name='?' module='minilib' class='minilib_handler'> <miniature name='?' url='?' unique='?'></miniature> </nodehandler> </pre> """ def __init__( self, xml_dom, tree_node, openrpg ): """Instantiates the class, and sets all vars to their default state """ node_handler.__init__( self, xml_dom, tree_node, openrpg ) self.openrpg = openrpg self.myeditor = None self.mywindow = None self.tree_node = tree_node # self.xml_dom = xml_dom self.update_leaves() self.sanity_check_nodes() def get_design_panel( self, parent ): """returns an instance of the miniature library edit control ( see on_design ). This is for use with the the 'edit multiple nodes in a single frame' code. """ return minpedit( parent, self ) def get_use_panel( self, parent ): """returns an instance of the miniature library view control ( see on_use ). This is for use with the the 'view multiple nodes in a single frame' code. """ return minilib_use_panel( parent, self ) def tohtml( self ): """Returns an HTML representation of this node in string format. The table columnwidths are currently being forced, as the wxHTML widgets being used don't handle cells wider than the widgets are expecting for a given column. """ str = '<table border="2" >' list = self.master_dom.getElementsByTagName(TAG_MINIATURE) str += "<tr><th width='20%'>Label</th><th>Image</th><th width='65%'>URL</th><th>Unique</th></t>" for mini in list: url = mini.getAttribute(ATTRIBUTE_URL) label = mini.getAttribute(ATTRIBUTE_NAME) flag = 0 try: flag = eval( mini.getAttribute(ATTRIBUTE_UNIQUE) ) except: pass show = 'yes' if flag: show = 'no' str += """<tr> <td> %s </td> <td><img src="%s"></td> <td> %s </td> <td> %s </td> </tr>""" % ( label, url, url, show ) str += "</table>" print str return str def html_view( self ): """see to_html """ return self.tohtml() 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 if isinstance( drag_obj, minilib_handler ): item = self.tree.GetSelection() name = self.tree.GetItemText( item ) if isinstance( drag_obj, map_miniature_nodehandler.map_miniature_handler ): xml_dom = self.tree.drag_obj.master_dom#.delete() obj = xml_dom.firstChild print obj.getAttributeKeys() dict = {} unique = '' for attrib in obj.getAttributeKeys(): key = TO_MINILIB_MAP.get( attrib, attrib ) if key != None: dict[ key ] = obj.getAttribute( attrib ) # if dict[ ATTRIBUTE_NAME ][-1] in string.digits: # unique = '1' # while dict[ ATTRIBUTE_NAME ][-1] in string.digits: # dict[ ATTRIBUTE_NAME ] = dict[ ATTRIBUTE_NAME ][:-1] dict[ ATTRIBUTE_UNIQUE ] = unique self.new_mini( dict ) def new_mini( self, data={}, add=1 ): mini = minidom.Element( TAG_MINIATURE ) for key in data.keys(): mini.setAttribute( key, data[ key ] ) for key in CORE_ATTRIBUTES: if mini.getAttribute( key ) == '': mini.setAttribute( key, '0' ) if add: self.add_mini( mini ) self.add_leaf( mini ) return mini def add_mini( self, mini ): self.master_dom.appendChild( mini ) def add_leaf( self, mini, icon='gear' ): tree = self.tree icons = tree.icons key = mini.getAttribute( ATTRIBUTE_NAME ) self.mydata.append( mini ) # new_tree_node = tree.AppendItem( self.mytree_node, key, icons[ icon ], icons[ icon ] ) # handler = mini_handler( mini, new_tree_node, self.myopenrpg, self ) # tree.SetPyData( new_tree_node, handler ) def update_leaves( self ): self.mydata = [] nl = self.master_dom.getElementsByTagName( TAG_MINIATURE ) for n in nl: self.add_leaf( n ) def on_drag( self, evt ): print 'drag event caught' def send_mini_to_map( self, mini, count=1 ): if mini == None: return if mini.getAttribute( ATTRIBUTE_URL ) == '' or mini.getAttribute( ATTRIBUTE_URL ) == 'http://': self.chat.ParsePost( self.chat.colorize(self.chat.syscolor, '"%s" is not a valid URL, the mini "%s" will not be added to the map' % ( mini.getAttribute( ATTRIBUTE_URL ), mini.getAttribute( ATTRIBUTE_NAME ) )) ) return session = self.myopenrpg.get_component( COMPONENT_SESSION ) if (session.my_role() <> session.ROLE_GM) and (session.my_role()<>session.ROLE_PLAYER): self.myopenrpg.get_component("chat").InfoPost("You must be either a player or GM to use the miniature Layer") return map = self.myopenrpg.get_component( COMPONENT_MAP ) for loop in range( count ): msg = self.get_miniature_XML( mini ) msg = str("<map action='update'><miniatures>" + msg + "</miniatures></map>") map.new_data( msg ) session.send( msg ) def get_miniature_XML( self, mini ): msg = orpg.mapper.map_msg.mini_msg() map = self.myopenrpg.get_component( COMPONENT_MAP ) session = self.myopenrpg.get_component( COMPONENT_SESSION ) msg.init_prop( ATTRIBUTE_ID, session.get_next_id() ) for k in mini.getAttributeKeys(): # translate our attributes to map attributes key = FROM_MINILIB_MAP.get( k, k ) if key != None: msg.init_prop( key, mini.getAttribute( k ) ) unique = self.is_unique( mini ) label = mini.getAttribute( ATTRIBUTE_NAME ) # use_serial = map.canvas.use_serial # auto_label = map.canvas..auto_label # if auto_label: # if use_serial: # label = '%s %d' % ( label, map.canvas.layers[ LAYER_MINIATURE ].next_serial() ) # msg.set_prop( ATTRIBUTE_NAME, label ) # else: # msg.set_prop( ATTRIBUTE_NAME, '' ) return msg.get_all_xml() def is_unique( self, mini ): unique = mini.getAttribute( ATTRIBUTE_UNIQUE ) val = 0 try: val = eval( unique ) except: val = len( unique ) return val def sanity_check_nodes( self ): nl = self.master_dom.getElementsByTagName( TAG_MINIATURE ) for node in nl: if node.getAttribute( ATTRIBUTE_POSX ) == '': node.setAttribute( ATTRIBUTE_POSX, '0' ) if node.getAttribute( ATTRIBUTE_POSY ) == '': node.setAttribute( ATTRIBUTE_POSY, '0' ) def get_mini( self, index ): try: nl = self.master_dom.getElementsByTagName( TAG_MINIATURE ) return nl[ index ] except: return None class mini_handler( node_handler ): def __init__( self, xml_dom, tree_node, openrpg, handler ): node_handler.__init__( self, xml_dom, tree_node, openrpg ) self.handler = handler def on_ldclick( self, evt ): self.handler.send_mini_to_map( self.master_dom ) def on_drop( self, evt ): pass def on_lclick( self, evt ): print 'hi' evt.Skip() class minilib_use_panel( wxPanel ): """This panel will be displayed when the user double clicks on the miniature library node. It is a sorted listbox of miniature labels, a text field for entering a count ( for batch adds ) and 'add'/'done' buttons. """ def __init__( self, frame, handler ): """Constructor. """ wxPanel.__init__( self, frame, -1 ) self.handler = handler self.frame = frame self.map = self.handler.openrpg.get_component('map') names = self.buildList() # self.keys = self.list.keys() # self.keys.sort() s = self.GetClientSizeTuple() self.sizer = wxBoxSizer( wxVERTICAL ) box = wxBoxSizer( wxHORIZONTAL ) self.listbox = wxListBox( self, LISTBOX_ID, ( 10, 10 ), (s[0] - 10, s[1] - 30 ), names, wxLB_SINGLE ) self.count = wxTextCtrl( self, MINICOUNT_ID, '1' ) box.Add( wxStaticText( self, -1, 'Minis to add' ), 0, wxEXPAND ) box.Add(wxSize(10,10)) box.Add( self.count, 1, wxEXPAND ) self.sizer.Add( self.listbox, 1, wxEXPAND ) self.sizer.Add( box, 0, wxEXPAND ) box = wxBoxSizer( wxHORIZONTAL ) box.Add( wxButton( self, OK_BUTTON, 'Add' ), 0, wxEXPAND ) box.Add( wxButton( self, CANCEL_BUTTON, 'Done' ), 0, wxEXPAND ) self.sizer.Add(wxSize(10,10)) self.sizer.Add( box, 0, wxEXPAND ) EVT_SIZE( self, self.on_size ) EVT_BUTTON( self, OK_BUTTON, self.on_ok ) EVT_BUTTON( self, CANCEL_BUTTON, self.on_cancel ) self.SetSizer(self.sizer) def buildList( self ): """Returns a dictionary of label => game tree miniature DOM node mappings. """ list = self.handler.master_dom.getElementsByTagName(TAG_MINIATURE) self.list = [] for mini in list: self.list.append( mini.getAttribute( ATTRIBUTE_NAME ) ) return self.list # self.list = {} # for mini in list: # name = mini.getAttribute( ATTRIBUTE_NAME ) # if name == '': # name = self.map.canvas.get_label_from_url( mini.getAttribute( ATTRIBUTE_URL ) ) # self.list[ name ] = mini def on_size( self, evt ): """Adjusts the sizer dimensions. Is this really necessary? """ s = self.GetClientSizeTuple() self.sizer.SetDimension( 10, 10, s[0] - 20 , s[1] - 20 ) def on_ok( self, evt ): """Event handler for the 'add' button. """ #key = self.keys[ self.listbox.GetSelection() ] index = self.listbox.GetSelection() # nl = self.handler.master_dom.getElementsByTagName( TAG_MINIATURE ) # name = nl[ index ].getAttribute( ATTRIBUTE_NAME ) # url = nl[ index ].getAttribute( ATTRIBUTE_URL ) # unique = nl[ index ].getAttribute( ATTRIBUTE_UNIQUE ) #url = self.list[ key ].getAttribute( ATTRIBUTE_URL ) #unique = self.list[ key ].getAttribute( ATTRIBUTE_UNIQUE ) try: count = eval( self.count.GetValue() ) except: count = 1 try: if eval( unique ): count = 1 unique = eval( unique ) except: pass self.handler.send_mini_to_map( self.handler.get_mini( index ), count ) # for loop in range( 0, count ): # self.handler.send_mini_to_map( nl[ index ] ) # #self.map.canvas.add_miniature( url, name, unique ) def on_cancel( self, evt ): """Event handler for 'done' button. Calls wxPFrame.OnCloseWindow so that all proper frame closing details are taken care of. """ wxPFrame.OnCloseWindow( self.frame, None ) ADD_MINI = 10 DEL_MINI = 20 SEND_TO_MAP = 30 SEND_GROUP_TO_MAP = 40 class minpedit( wxPanel ): """Panel for editing game tree miniature nodes. Node information is displayed in a grid, and buttons are provided for adding, deleting nodes, and for sending minis to the map ( singly and in batches ). """ def __init__( self, frame, handler ): """Constructor. """ wxPanel.__init__( self, frame, -1 ) self.handler = handler self.frame = frame self.sizer = wxBoxSizer( wxVERTICAL ) self.grid = minilib_grid( self, handler ) bbox = wxBoxSizer( wxHORIZONTAL ) bbox.Add( wxButton( self, ADD_MINI, "New mini" ), 0, wxEXPAND ) bbox.Add( wxButton( self, DEL_MINI, "Del mini" ), 0, wxEXPAND ) bbox.Add(wxSize(10,10)) bbox.Add( wxButton( self, SEND_TO_MAP, "Add 1" ), 0, wxEXPAND ) bbox.Add( wxButton( self, SEND_GROUP_TO_MAP, "Add Batch" ), 0, wxEXPAND ) self.sizer.Add( self.grid, 1, wxEXPAND) self.sizer.Add( bbox, 0) self.SetSizer(self.sizer) EVT_SIZE( self, self.on_size ) EVT_BUTTON( self, ADD_MINI, self.add_mini ) EVT_BUTTON( self, DEL_MINI, self.del_mini ) EVT_BUTTON( self, SEND_TO_MAP, self.send_to_map ) EVT_BUTTON( self, SEND_GROUP_TO_MAP, self.send_group_to_map ) def add_mini( self, evt=None ): """Event handler for the 'New mini' button. It calls minilib_grid.add_row """ self.grid.add_row() def del_mini( self, evt=None ): """Event handler for the 'Del mini' button. It calls minilib_grid.del_row """ self.grid.del_row( ) def send_to_map( self, evt=None ): """Event handler for the 'Add 1' button. Sends the miniature defined by the currently selected row to the map, once. """ # map = self.handler.openrpg.get_component('map') # min_label = self.grid.getSelectedLabel() # min_url = self.grid.getSelectedURL() # flag = self.grid.getSelectedSerial() # try: # flag = eval( flag ) # except: # pass # map.canvas.add_miniature( min_url, min_label, flag ) index = self.grid.GetGridCursorRow() self.handler.send_mini_to_map( self.handler.get_mini( index ) ) def send_group_to_map( self, evt=None ): """Event handler for the 'Add batch' button. Querys the user for a mini count and sends the miniature defined by the currently selected row to the map, the specified number of times. """ if self.grid.GetNumberRows() > 0: dlg = wxTextEntryDialog( self.frame, 'How many %s\'s do you want to add?' % ( self.grid.getSelectedLabel() ), 'Batch mini add', '2' ) if dlg.ShowModal() == wxID_OK: try: value = eval( dlg.GetValue() ) except: value = 0 # for loop in range( 0, value ): # self.send_to_map() print 'getting selected index for batch send' index = self.grid.GetGridCursorRow() print 'sending batch to map' self.handler.send_mini_to_map( self.handler.get_mini( index ), value ) def on_size( self, evt ): """Event handler for panel resizing events. """ s = self.GetClientSizeTuple() self.sizer.SetDimension( 10, 10, s[0] - 20 , s[1] - 20 ) class minilib_grid( wxGrid ): """A wxGrid subclass designed for editing game tree miniature library nodes. """ def __init__( self, parent, handler ): """Constructor. """ wxGrid.__init__(self, parent, -1, style=wxSUNKEN_BORDER | wxWANTS_CHARS ) self.parent = parent self.handler = handler #self.keys = [ ATTRIBUTE_NAME, ATTRIBUTE_URL, ATTRIBUTE_UNIQUE ] self.keys = CORE_ATTRIBUTES self.CreateGrid( 1, len( self.keys ) ) # self.SetColLabelValue( 0, 'Name' ) # self.SetColLabelValue( 1, 'URL' ) # self.SetColSize( 1, 250 ) # self.SetColLabelValue( 2, 'Unique' ) for key in self.keys: self.SetColLabelValue( self.keys.index( key ), key ) self.update_all() self.selectedRow = 0 self.AutoSizeColumns() EVT_GRID_CELL_CHANGE( self, self.on_cell_change ) EVT_GRID_SELECT_CELL( self, self.select_cell ) def update_cols( self ): nl = self.handler.master_dom.getElementsByTagName( TAG_MINIATURE ) for n in nl: for k in n.getAttributeKeys(): if k not in self.keys: self.keys.append( k ) def select_cell( self, evt ): """Event handler for grid cell selection changes. It stores the last selected row in a variable for use by the add[*] and del_row operations. """ self.BeginBatch() self.selectedRow = evt.GetRow() self.SelectRow( self.selectedRow ) self.EndBatch() evt.Skip() def getList( self ): """Returns the list of 'miniature' DOM elements associated with this miniature library. """ return self.handler.master_dom.getElementsByTagName( TAG_MINIATURE ) def add_row( self, count = 1 ): """creates a new miniature node, and then adds it to the current miniature library, and to the grid. """ self.AppendRows( count ) node = self.handler.new_mini( { ATTRIBUTE_NAME :' ', ATTRIBUTE_URL :'http://'} )# minidom.Element( TAG_MINIATURE ) self.update_all() #self.handler.master_dom.appendChild( node ) def del_row( self ): """deletes the miniature associated with the currently selected row. BUG BUG BUG this method should drop a child from the DOM but does not. """ if self.selectedRow > -1: pos = self.selectedRow list = self.handler.master_dom.getElementsByTagName(TAG_MINIATURE) self.handler.master_dom.removeChild( list[pos] ) self.DeleteRows( pos, 1 ) list = self.getList() del list[ pos ] def on_cell_change( self, evt ): """Event handler for cell selection changes. selected row is used to update data for that row. """ row = evt.GetRow() self.update_data_row( row ) def update_all( self ): """ensures that the grid is displaying the correct number of rows, and then updates all data displayed by the grid """ list = self.getList() count = 0 for n in list: for k in n.getAttributeKeys(): if k not in self.keys: self.keys.append( k ) count = len( self.keys ) if self.GetNumberCols() < count: self.AppendCols( count - self.GetNumberCols() ) for k in self.keys: self.SetColLabelValue( self.keys.index( k ), k ) count = len( list ) rowcount = self.GetNumberRows() if ( count > rowcount ): total = count - rowcount self.AppendRows( total ) elif ( count < rowcount ): total = rowcount - count self.DeleteRows( 0, total ); for index in range( 0, count ): self.update_grid_row( index ) def getSelectedLabel( self ): """Returns the label for the selected row """ return self.GetTable().GetValue( self.selectedRow, 0 ) def getSelectedURL( self ): """Returns the URL for the selected row """ return self.GetTable().GetValue( self.selectedRow, 1 ) def getSelectedSerial( self ): """Returns the ATTRIBUTE_UNIQUE value for the selected row """ return self.GetTable().GetValue( self.selectedRow, 2 ) def update_grid_row( self, row ): """Updates the specified grid row with data from the DOM node specified by 'row' """ list = self.getList() item = list[ row ] # self.GetTable().SetValue( row, 0, item.getAttribute(ATTRIBUTE_NAME) ) # self.GetTable().SetValue( row, 1, item.getAttribute(ATTRIBUTE_URL) ) # self.GetTable().SetValue( row, 2, item.getAttribute(ATTRIBUTE_UNIQUE) ) for key in self.keys: self.GetTable().SetValue( row, self.keys.index( key ), item.getAttribute( key ) ) def update_data_row( self, row ): """Updates the DOM nodw 'row' with grid data from 'row' """ list = self.getList() item = list[ row ] for key in self.keys: item.setAttribute( key, string.strip( self.GetTable().GetValue( row, self.keys.index( key ) ) ) ) # item.setAttribute( ATTRIBUTE_NAME, string.strip( self.GetTable().GetValue( row, 0 ) ) ) # item.setAttribute( ATTRIBUTE_URL, string.strip( self.GetTable().GetValue( row, 1 ) ) ) # item.setAttribute( ATTRIBUTE_UNIQUE, string.strip( self.GetTable().GetValue( row, 2 ) ) ) # self.GetTable().SetValue( row, 0, item.getAttribute(ATTRIBUTE_NAME) ) # self.GetTable().SetValue( row, 1, item.getAttribute(ATTRIBUTE_URL) ) # self.GetTable().SetValue( row, 2, item.getAttribute(ATTRIBUTE_UNIQUE) ) --- NEW FILE: rpg_grid.py --- # Copyright (C) 2000-2001 The OpenRPG Project # # ope...@li... # # 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.1 2006/01/26 17:33:16 digitalxero Exp $ # # Description: The file contains code for the grid nodehanlers # __version__ = "$Id: rpg_grid.py,v 1.1 2006/01/26 17:33:16 digitalxero Exp $" from core import * from forms import * class rpg_grid_handler(node_handler): """ Node handler for rpg grid tool <nodehandler module='rpg_grid' class='rpg_grid_handler' name='sample'> <grid border='' autosize='1' > <row> <cell size='?'></cell> <cell></cell> </row> <row> <cell></cell> <cell></cell> </row> </grid> <macros> <macro name=''/> </macros> </nodehandler> """ def __init__(self,xml_dom,tree_node,openrpg): node_handler.__init__(self,xml_dom,tree_node,openrpg) self.grid = self.master_dom.getElementsByTagName('grid')[0] if self.grid.getAttribute("border") == "": self.grid.setAttribute("border","1") if self.grid.getAttribute("autosize") == "": self.grid.setAttribute("autosize","1") self.macros = self.master_dom.getElementsByTagName('macros')[0] self.frame = openrpg.get_component('frame') 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) node_list = self.master_dom.getElementsByTagName('row') for n in node_list: cells = n.getElementsByTagName('cell') t_node = cells[0]._get_firstChild() if t_node == None: name = "Row" else: name = t_node._get_nodeValue() if name == "": name = "Row" new_tree_node = tree.AppendItem(self.mytree_node,name,icons['gear'],icons['gear']) handler = grid_row_handler(n,new_tree_node,self.myopenrpg,self) tree.SetPyData(new_tree_node,handler) def tohtml(self): border = self.grid.getAttribute("border") name = self.master_dom.getAttribute('name') rows = self.grid.getElementsByTagName('row') colspan = str(len(rows[0].getElementsByTagName('cell'))) html_str = "<table border=\""+border+"\" align=center><tr bgcolor=\""+TH_BG+"\" ><th colspan="+colspan+">"+name+"</th></tr>" for r in rows: cells = r.getElementsByTagName('cell') html_str += "<tr>" for c in cells: #html_str += "<td width='"+c.getAttribute('size')+"' >" bug here html_str += "<td >" t_node = c._get_firstChild() if t_node == None: html_str += "<br></td>" else: html_str += t_node._get_nodeValue() + "</td>" html_str += "</tr>" html_str += "</table>" 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 int(self.grid.getAttribute("autosize")) def set_autosize(self,autosize=1): self.grid.setAttribute("autosize",str(autosize)) class grid_row_handler(node_handler): """ Node Handler grid row. """ def __init__(self,xml_dom,tree_node,openrpg,parent): node_handler.__init__(self,xml_dom,tree_node,openrpg) self.drag = false self.frame = self.myopenrpg.get_component('frame') def on_drop(self,evt): pass def can_clone(self): return 0; def tohtml(self): cells = self.master_dom.getElementsByTagName('cell') html_str = "<table border=1 align=center><tr >" for c in cells: html_str += "<td >" t_node = c._get_firstChild() if t_node == None: html_str += "<br></td>" else: html_str += t_node._get_nodeValue() + "</td>" html_str += "</tr>" html_str += "</table>" return html_str class MyCellEditor(wxPyGridCellEditor): """ 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, log): def __init__(self): # self.log = log # self.log.write("MyCellEditor ctor\n") wxPyGridCellEditor.__init__(self) def Create(self, parent, id, evtHandler): """ Called to create the control, which must derive from wxControl. *Must Override* """ # self.log.write("MyCellEditor: Create\n") self._tc = orpgTextCtrl(parent, id, "", style=wxTE_PROCESS_ENTER|wxTE_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 somethi... [truncated message content] |