Mercurial > traipse_dev
diff orpg/gametree/nodehandlers/forms.py @ 135:dcf4fbe09b70 beta
Traipse Beta 'OpenRPG' {091010-00}
Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on
code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to
offer more advanced features and enhance the productivity of the user.
Update Summary (Beta)
Added Bookmarks
Fix to Remote Admin Commands
Minor fix to text based Server
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
default_manifest.xml renamed to default_upmana.xml
Cleaner clode for saved repositories
New TrueDebug Class in orpg_log (See documentation for usage)
Mercurial's hgweb folder is ported to upmana
**Pretty important update that can help remove thousands of dead children from your gametree.
**Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and
look for dead children!!
**New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author | sirebral |
---|---|
date | Tue, 10 Nov 2009 14:11:28 -0600 |
parents | 68c7bd272f27 |
children | 2345c12d93a7 |
line wrap: on
line diff
--- a/orpg/gametree/nodehandlers/forms.py Fri Sep 25 20:47:16 2009 -0500 +++ b/orpg/gametree/nodehandlers/forms.py Tue Nov 10 14:11:28 2009 -0600 @@ -28,8 +28,8 @@ __version__ = "$Id: forms.py,v 1.53 2007/04/21 23:00:51 digitalxero Exp $" -from containers import * -import orpg.minidom as minidom +from containers import * +import orpg.minidom as minidom from orpg.orpg_xml import xml from wx.lib.scrolledpanel import ScrolledPanel @@ -39,10 +39,8 @@ #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 + if b: return 1 + else: return 0 ################################# ## form container @@ -54,23 +52,16 @@ <form width='100' height='100' /> </nodehandler> """ - - def __init__(self,xml_dom,tree_node): - container_handler.__init__(self,xml_dom,tree_node) + def __init__(self,xml,tree_node): + container_handler.__init__(self, xml, tree_node) def load_children(self): self.atts = None - children = self.master_dom._get_childNodes() - for c in children: - if c._get_tagName() == "form": - self.atts = c - else: - self.tree.load_xml(c,self.mytree_node) - if not self.atts: - elem = minidom.Element('form') - elem.setAttribute("width","400") - elem.setAttribute("height","600") - self.atts = self.master_dom.appendChild(elem) + 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) @@ -82,32 +73,22 @@ # 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.atts.getAttribute("height")) - self.width = int(handler.atts.getAttribute("width")) - - + 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) - tree = self.handler.tree - child = tree.GetFirstChild(handler.mytree_node) - if child[0].IsOk(): - handler.traverse(child[0], self.create_child_wnd, 0, None, False) - + 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 @@ -116,16 +97,14 @@ y += ny+11 ScrolledPanel.SetSize(self, (x, y)) - - def create_child_wnd(self, obj, evt): - panel = obj.get_use_panel(self) - size = obj.get_size_constraint() + 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): @@ -134,9 +113,9 @@ 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.master_dom.getAttribute('name')), - F_HEIGHT : wx.TextCtrl(self, F_HEIGHT, handler.atts.getAttribute('height')), - F_WIDTH : wx.TextCtrl(self, F_WIDTH, handler.atts.getAttribute('width')) + 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) @@ -166,21 +145,13 @@ txt = self.text[id].GetValue() if not len(txt): return if id == P_TITLE: - self.handler.master_dom.setAttribute('name',txt) + 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.setAttribute("height",txt) - elif id == F_WIDTH: - self.handler.atts.setAttribute("width",txt) - - - - + 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 @@ -189,13 +160,12 @@ """ A nodehandler for form controls. <nodehandler name='?' module='forms' class='control_handler' /> """ - def __init__(self,xml_dom,tree_node): - node_handler.__init__(self,xml_dom,tree_node) + def __init__(self, xml, tree_node): + node_handler.__init__(self, xml, tree_node) def get_size_constraint(self): return 0 - ########################## ## textctrl handler ########################## @@ -210,16 +180,12 @@ <text multiline='0' send_button='0' raw_mode='0' hide_title='0'>Text In Node</text> </nodehandler> """ - def __init__(self,xml_dom,tree_node): - node_handler.__init__(self,xml_dom,tree_node) - self.text_elem = self.master_dom.getElementsByTagName('text')[0] - self.text = component.get('xml').safe_get_text_node(self.text_elem) - if self.text_elem.getAttribute("send_button") == "": - self.text_elem.setAttribute("send_button","0") - if self.text_elem.getAttribute("raw_mode") == "": - self.text_elem.setAttribute("raw_mode","0") - if self.text_elem.getAttribute("hide_title") == "": - self.text_elem.setAttribute("hide_title","0") + 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) @@ -228,28 +194,32 @@ return text_panel(parent,self) def get_size_constraint(self): - return int(self.text_elem.getAttribute("multiline")) + return int(self.text_elem.get("multiline",0)) def is_multi_line(self): - return int(self.text_elem.getAttribute("multiline")) + return int(self.text_elem.get("multiline",0)) def is_raw_send(self): - return int(self.text_elem.getAttribute("raw_mode")) + return int(self.text_elem.get("raw_mode",0)) def is_hide_title(self): - return int(self.text_elem.getAttribute("hide_title")) + return int(self.text_elem.get("hide_title",0)) def has_send_button(self): - return int(self.text_elem.getAttribute("send_button")) - + return int(self.text_elem.get("send_button",0)) def tohtml(self): - txt = self.text._get_nodeValue() + txt = self.get_value() txt = string.replace(txt,'\n',"<br />") if not self.is_hide_title(): - txt = "<b>"+self.master_dom.getAttribute("name")+":</b> "+txt + txt = "<b>"+self.xml.get("name")+":</b> "+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() @@ -268,9 +238,10 @@ text_style = 0 sizer = wx.BoxSizer(wx.HORIZONTAL) - txt = handler.text._get_nodeValue() + 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.master_dom.getAttribute('name')+": "), 0, sizer_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) @@ -283,24 +254,25 @@ 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): + self.Bind(wx.EVT_BUTTON, self.on_send, id=FORM_SEND_BUTTON) + + def on_text(self, evt): + debug() txt = self.text.GetValue() - txt = xml.strip_text(txt) - self.handler.text._set_nodeValue(txt) + #txt = strip_text(txt) ##Does not seem to exist. + self.handler.text_elem.text = txt - def on_send(self,evt): - txt = self.text.GetValue() + def on_send(self, evt): + txt = self.text.GetValue() + txt = self.chat.ParseMap(txt, self.handler.xml) if not self.handler.is_raw_send(): - #self.chat.ParsePost(self.tohtml(),True,True) - self.chat.ParsePost(self.handler.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) + self.chat.ParsePost(line, True, True) else: action = line self.chat.chat_cmds.docmd(action) @@ -318,7 +290,7 @@ self.handler = handler sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Text Properties"), wx.VERTICAL) - self.title = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) + 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") @@ -344,7 +316,7 @@ sizer_style=wx.EXPAND text_style = 0 multi = 0 - self.text = wx.TextCtrl(self, F_TEXT, handler.text._get_nodeValue(),style=text_style) + 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) @@ -362,28 +334,24 @@ if id == P_TITLE: txt = self.title.GetValue() if not len(txt): return - self.handler.master_dom.setAttribute('name',txt) + self.handler.xml.set('name',txt) self.handler.rename(txt) if id == F_TEXT: txt = self.text.GetValue() - txt = xml.strip_text(txt) - self.handler.text._set_nodeValue(txt) + #txt = strip_text(txt) ##Does not seem to exist. + self.handler.text_elem.text = txt def on_button(self,evt): - self.handler.text_elem.setAttribute("multiline",str(bool2int(evt.Checked()))) + self.handler.text_elem.set("multiline",str(bool2int(evt.Checked()))) def on_raw_button(self,evt): - self.handler.text_elem.setAttribute("raw_mode",str(bool2int(evt.Checked()))) + self.handler.text_elem.set("raw_mode",str(bool2int(evt.Checked()))) def on_hide_button(self,evt): - self.handler.text_elem.setAttribute("hide_title",str(bool2int(evt.Checked()))) + self.handler.text_elem.set("hide_title",str(bool2int(evt.Checked()))) def on_send_button(self,evt): - self.handler.text_elem.setAttribute("send_button",str(bool2int(evt.Checked()))) - - - - + self.handler.text_elem.set("send_button",str(bool2int(evt.Checked()))) ####################### @@ -409,14 +377,14 @@ </list> </nodehandler> """ - def __init__(self,xml_dom,tree_node): - node_handler.__init__(self,xml_dom,tree_node) - self.list = self.master_dom.getElementsByTagName('list')[0] - self.options = self.list.getElementsByTagName('option') - if self.list.getAttribute("send_button") == "": - self.list.setAttribute("send_button","0") - if self.list.getAttribute("hide_title") == "": - self.list.setAttribute("hide_title","0") + 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) @@ -425,24 +393,24 @@ return listbox_panel(parent,self) def get_type(self): - return int(self.list.getAttribute("type")) + return int(self.list.get("type")) def set_type(self,type): - self.list.setAttribute("type",str(type)) + self.list.set("type",str(type)) def is_hide_title(self): - return int(self.list.getAttribute("hide_title")) + return int(self.list.get("hide_title", 0)) # single selection methods def get_selected_node(self): for opt in self.options: - if opt.getAttribute("selected") == "1": return opt + if opt.get("selected") == "1": return opt return None def get_selected_index(self): i = 0 for opt in self.options: - if opt.getAttribute("selected") == "1": + if opt.get("selected") == "1": return i i += 1 return 0 @@ -450,95 +418,87 @@ def get_selected_text(self): node = self.get_selected_node() if node: - return component.get('xml').safe_get_text_node(node)._get_nodeValue() + return node.text else: return "" # mult selection methods - def get_selections(self): opts = [] for opt in self.options: - if opt.getAttribute("selected") == "1": + if opt.get("selected") == "1": opts.append(opt) return opts def get_selections_text(self): opts = [] for opt in self.options: - if opt.getAttribute("selected") == "1": - opts.append(component.get('xml').safe_get_text_node(opt)._get_nodeValue()) + 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.getAttribute("selected") == "1": + 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].setAttribute("selected", str(bool2int(selected))) + self.options[index].set("selected", str(bool2int(selected))) def clear_selections(self): for opt in self.options: - opt.setAttribute("selected","0") + opt.set("selected","0") # misc methods - def get_options(self): opts = [] - for opt in self.options: - opts.append(component.get('xml').safe_get_text_node(opt)._get_nodeValue()) + for opt in self.options: opts.append(opt.text) return opts def get_option(self,index): - return component.get('xml').safe_get_text_node(self.options[index])._get_nodeValue() + return self.options[index].text def add_option(self,opt): - elem = minidom.Element('option') - elem.setAttribute("value","0") - elem.setAttribute("selected","0") - t_node = minidom.Text(opt) - t_node = elem.appendChild(t_node) - self.list.appendChild(elem) - self.options = self.list.getElementsByTagName('option') + 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.removeChild(self.options[index]) - self.options = self.list.getElementsByTagName('option') + self.list.remove(self.options[index]) + self.options = self.list.findall('option') def edit_option(self,index,value): - component.get('xml').safe_get_text_node(self.options[index])._set_nodeValue(value) + self.options[index].text = value def has_send_button(self): - if self.list.getAttribute("send_button") == '0': - return False - else: - return True + 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 + 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 = "<b>"+self.master_dom.getAttribute("name")+":</b> " + if not self.is_hide_title(): text = "<b>"+self.xml.get("name")+":</b> " comma = ", " text += comma.join(opts) return text + def get_value(self): + return "\n".join(self.get_selections_text()) F_LIST = wx.NewId() @@ -553,7 +513,7 @@ opts = handler.get_options() cur_opt = handler.get_selected_text() type = handler.get_type() - label = handler.master_dom.getAttribute('name') + label = handler.xml.get('name') if type == L_DROP: self.list = wx.ComboBox(self, F_LIST, cur_opt, choices=opts, style=wx.CB_READONLY) @@ -635,7 +595,7 @@ self.handler = handler sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "List Box Properties"), wx.VERTICAL) - self.text = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) + 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) @@ -717,15 +677,14 @@ txt = self.text.GetValue() if not len(txt): return if id == P_TITLE: - self.handler.master_dom.setAttribute('name',txt) + self.handler.xml.set('name',txt) self.handler.rename(txt) def on_send_button(self,evt): - self.handler.list.setAttribute("send_button", str( bool2int(evt.Checked()) )) + self.handler.list.set("send_button", str( bool2int(evt.Checked()) )) def on_hide_button(self,evt): - print "hide_title, " + str(bool2int(evt.Checked())) - self.handler.list.setAttribute("hide_title", str( bool2int(evt.Checked()) )) + self.handler.list.set("hide_title", str( bool2int(evt.Checked()) )) ############################### @@ -738,12 +697,12 @@ <link href='http//??.??' /> </nodehandler > """ - def __init__(self,xml_dom,tree_node): - node_handler.__init__(self,xml_dom,tree_node) - self.link = self.master_dom._get_firstChild() + 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.getAttribute("href") + href = self.link.get("href") wb = webbrowser.get() wb.open(href) @@ -754,14 +713,14 @@ return link_panel(parent,self) def tohtml(self): - href = self.link.getAttribute("href") - title = self.master_dom.getAttribute("name") + href = self.link.get("href") + title = self.xml.get("name") return "<a href=\""+href+"\" >"+title+"</a>" class link_panel(wx.StaticText): def __init__(self,parent,handler): self.handler = handler - label = handler.master_dom.getAttribute('name') + 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) @@ -776,8 +735,8 @@ sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Link Properties"), wx.VERTICAL) self.text = {} - self.text[P_TITLE] = wx.TextCtrl(self, P_TITLE, handler.master_dom.getAttribute('name')) - self.text[P_URL] = wx.TextCtrl(self, P_URL, handler.link.getAttribute('href')) + 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) @@ -793,10 +752,10 @@ txt = self.text[id].GetValue() if not len(txt): return if id == P_TITLE: - self.handler.master_dom.setAttribute('name',txt) + self.handler.xml.set('name',txt) self.handler.rename(txt) elif id == P_URL: - self.handler.link.setAttribute('href',txt) + self.handler.link.set('href',txt) ########################## ## webimg node handler @@ -807,21 +766,20 @@ <link href='http//??.??' /> </nodehandler > """ - def __init__(self,xml_dom,tree_node): - node_handler.__init__(self,xml_dom,tree_node) - self.link = self.master_dom._get_firstChild() + 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.getAttribute("href")) - #print img + 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.getAttribute("href") - title = self.master_dom.getAttribute("name") + href = self.link.get("href") + title = self.xml.get("name") return "<img src=\""+href+"\" alt="+title+" >"