diff orpg/gametree/nodehandlers/core.py~ @ 151:06f10429eedc alpha

Traipse Alpha 'OpenRPG' {091125-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 (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, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! New Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Wed, 25 Nov 2009 06:15:49 -0600
parents 4385a7d0efd1
children bf799efe7a8a
line wrap: on
line diff
--- a/orpg/gametree/nodehandlers/core.py~	Tue Nov 24 17:17:42 2009 -0600
+++ b/orpg/gametree/nodehandlers/core.py~	Wed Nov 25 06:15:49 2009 -0600
@@ -29,19 +29,19 @@
 __version__ = "$Id: core.py,v 1.49 2007/12/07 20:39:48 digitalxero Exp $"
 
 from nodehandler_version import NODEHANDLER_VERSION
+
 try:
     from orpg.orpg_windows import *
-    import orpg.dirpath
-    from orpg.orpg_xml import *
-    from orpg.orpgCore import open_rpg
-    import webbrowser
+    from orpg.dirpath import dir_struct
+    from orpg.orpgCore import component
+    import webbrowser, os
     from orpg.mapper import map
-    import os
+    from wx import DisplaySize
 except:
     import wx
 
-
-
+from xml.etree.ElementTree import ElementTree, Element, tostring, XML
+from orpg.tools.orpg_log import debug
 
 #html defaults
 TH_BG = "#E9E9E9"
@@ -50,22 +50,31 @@
 ##########################
 class node_handler:
     """ Base nodehandler with virtual functions and standard implmentations """
-    def __init__(self,xml_dom,tree_node):
-        self.master_dom = xml_dom
+    def __init__(self,xml,tree_node):
+        self.xml = xml
         self.mytree_node = tree_node
         self.tree = open_rpg.get_component('tree')
         self.frame = open_rpg.get_component('frame')
         self.chat = open_rpg.get_component('chat')
-        self.xml = open_rpg.get_component('xml')
         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"))
+        self.on_version(self.xml.get("version"))
         # set to current version
-        self.master_dom.setAttribute("version",NODEHANDLER_VERSION)
+        self.xml.set("version",NODEHANDLER_VERSION)
         # null events
+        self.frame_size = None
+        self.frame_pos  = None
+        try:
+            frame = self.xml.get("frame")
+            if len(frame):
+                (sx,sy,px,py) = [int(value) for value in frame.split(',')]
+                self.frame_size = (sx, sy)
+                (maxx, maxy) = DisplaySize()
+                if px < maxx-80 and py < maxy-50: self.frame_pos  = (px, py) #if it's off screen ignore the saved pos
+        except: pass
 
     def on_version(self,old_version):
         ## added version control code here or implement a new on_version in your derived class.
@@ -78,32 +87,10 @@
     def on_ldclick(self,evt):
         return 0
 
-    def traverse(self, traverseroot, function, cookie=0, event=None, recursive=True):
-        """ walk tree control """
-        if traverseroot.IsOk():
-            # step in subtree if there are items or ...
-            if self.tree.ItemHasChildren(traverseroot) and recursive:
-                firstchild, cookie = self.tree.GetFirstChild(traverseroot)
-                obj = self.tree.GetPyData(firstchild)
-                function(obj, event)
-                self.traverse(firstchild, function, cookie, event, recursive)
-
-            # ... loop siblings
-            obj = self.tree.GetPyData(traverseroot)
-            function(obj, event)
-
-            child = self.tree.GetNextSibling(traverseroot)
-            if child.IsOk():
-                self.traverse(child, function, cookie, event, recursive)
-
-
     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")
+        if text=="useful": self.xml.set('status',"useful")
+        elif text=="useless": self.xml.set('status',"useless")
+        elif text=="indifferent": self.xml.set('status',"indifferent")
 
     def on_design(self,evt):
         try:
@@ -114,13 +101,11 @@
             if self.create_designframe():
                 self.myeditor.Show()
                 self.myeditor.Raise()
-            else:
-                return
+            else: return
         wx.CallAfter(self.myeditor.Layout)
 
-
     def create_designframe(self):
-        title = self.master_dom.getAttribute('name') + " Editor"
+        title = self.xml.get('name') + " Editor"
         self.myeditor = wx.Frame(None, -1, title)
         self.myeditor.Freeze()
         if wx.Platform == '__WXMSW__':
@@ -139,15 +124,12 @@
         self.myeditor.SetAutoLayout(True)
 
         (x, y) = self.myeditor.GetSize()
-        if x < 400:
-            x = 400
-        if y < 400:
-            y = 400
+        if x < 400: x = 400
+        if y < 400: y = 400
 
         self.myeditor.SetSize((x, y))
         self.myeditor.Layout()
         self.myeditor.Thaw()
-
         return True
 
     def on_use(self,evt):
@@ -157,18 +139,17 @@
         except:
             del self.mywindow
             if self.create_useframe():
+                self.mywindow.SetSize(self.frame_size)
+                if self.frame_pos: self.mywindow.SetPosition(self.frame_pos)
                 self.mywindow.Show()
                 self.mywindow.Raise()
-            else:
-                return
+            else: return
         wx.CallAfter(self.mywindow.Layout)
 
-
     def create_useframe(self):
-        caption = self.master_dom.getAttribute('name')
+        caption = self.xml.get('name', '')
         self.mywindow = wx.Frame(None, -1, caption)
         self.mywindow.Freeze()
-
         if wx.Platform == '__WXMSW__':
             icon = wx.Icon(orpg.dirpath.dir_struct["icon"] + 'note.ico', wx.BITMAP_TYPE_ICO)
             self.mywindow.SetIcon(icon)
@@ -183,24 +164,28 @@
         self.mywindow.SetSizer(sizer)
         self.mywindow.SetAutoLayout(True)
 
-        (x, y) = self.mywindow.GetSize()
-        if x < 400:
-            x = 400
-        if y < 400:
-            y = 400
+        if self.frame_size is None:
+            self.frame_size = self.mywindow.GetSize()
+            if self.frame_size.x < 400: self.frame_size.x = 400
+            if self.frame_size.y < 400: self.frame_size.y = 400
 
-        self.mywindow.SetSize((x, y))
         self.mywindow.Layout()
         self.mywindow.Thaw()
+        self.mywindow.Bind(wx.EVT_CLOSE, self.close_useframe)
+        return True
 
-        return True
+    def close_useframe(self, evt):
+        self.frame_size = self.mywindow.GetSize()
+        self.frame_pos  = self.mywindow.GetPosition()
+        frame_values = str(self.frame_size.x)+','+str(self.frame_size.y)+','+str(self.frame_pos.x)+','+str(self.frame_pos.y)
+        self.xml.set("frame", frame_values)
+        self.mywindow.Destroy()
 
 
     def on_html_view(self,evt):
-        try:
-            self.myviewer.Raise()
+        try: self.myviewer.Raise()
         except:
-            caption = self.master_dom.getAttribute('name')
+            caption = self.xml.get('name')
             self.myviewer = wx.Frame(None, -1, caption)
             if wx.Platform == '__WXMSW__':
                 icon = wx.Icon(orpg.dirpath.dir_struct["icon"] + 'grid.ico', wx.BITMAP_TYPE_ICO)
@@ -218,7 +203,7 @@
     def on_del(self,evt):
         print "on del"
 
-    def on_new_data(self,xml_dom):
+    def on_new_data(self,xml):
         pass
 
     def get_scaled_bitmap(self,x,y):
@@ -230,52 +215,61 @@
     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):
+    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)
+        drop_xml = self.tree.drag_obj.delete()
         parent_node = self.tree.GetItemParent(self.mytree_node)
         prev_sib = self.tree.GetPrevSibling(self.mytree_node)
+        if parent_node == self.tree.root: parent_xml = self.tree.GetPyData(parent_node)
+        else: parent_xml = self.tree.GetPyData(parent_node).xml
+        for i in range(len(parent_xml)):
+            if parent_xml[i] is self.xml:
+                parent_xml.insert(i, drop_xml)
+                break
         if not prev_sib.IsOk():
             prev_sib = parent_node
-        self.tree.load_xml(xml_dom, parent_node, prev_sib)
+        self.tree.load_xml(drop_xml, parent_node, prev_sib)
+
+    def get_tree(self):
+        family = []
+        test = treenode
+        while test != self.tree.root:
+            test = self.tree.GetItemParent(test)
+            parent = self.tree.GetItemText(test)
+            family.append(parent)
+        return family
 
     def toxml(self,pretty=0):
-        return toxml(self.master_dom,pretty)
+        return tostring(self.xml) #toxml(self.master_dom,pretty)
 
     def tohtml(self):
-        return self.master_dom.getAttribute("name")
+        return self.xml.get("name")
 
     def delete(self):
         """ removes the tree_node and xml_node, and returns the removed xml_node """
-
+        parent_node = self.tree.GetItemParent(self.mytree_node)
+        if parent_node == self.tree.root: parent_xml = self.tree.GetPyData(parent_node)
+        else: parent_xml = self.tree.GetPyData(parent_node).xml
+        parent_xml.remove(self.xml)
         self.tree.Delete(self.mytree_node)
-        parent = self.master_dom._get_parentNode()
-        return parent.removeChild(self.master_dom)
+        return self.xml
 
     def rename(self,name):
         if len(name):
             self.tree.SetItemText(self.mytree_node,name)
-            self.master_dom.setAttribute('name', name)
+            self.xml.set('name', name)
 
     def change_icon(self,icon):
-        self.master_dom.setAttribute("icon",icon)
+        self.xml.set("icon",icon)
         self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon])
         self.tree.SetItemImage(self.mytree_node, self.tree.icons[icon], wx.TreeItemIcon_Selected)
         self.tree.Refresh()
 
     def on_save(self,evt):
         f = wx.FileDialog(self.tree,"Select a file", orpg.dirpath.dir_struct["user"],"","XML files (*.xml)|*.xml",wx.SAVE)
-        if f.ShowModal() == wx.ID_OK:
-            type = f.GetFilterIndex()
-            file = open(f.GetPath(),"w")
-            file.write(self.toxml(1))
-            file.close()
+        if f.ShowModal() == wx.ID_OK: ElementTree(self.xml).write(f.GetPath())
         f.Destroy()
 
     def get_design_panel(self,parent):
@@ -286,31 +280,36 @@
 
     def get_html_panel(self,parent):
         html_str = "<html><body bgcolor=\"#FFFFFF\" >"+self.tohtml()+"</body></html>"
-        wnd = wx.HTMLpanel(parent,-1)
+        wnd = wx.html.HtmlWindow(parent,-1)
         html_str = self.chat.ParseDice(html_str)
-        wnd.load_text(html_str)
+        wnd.SetPage(html_str)
         return wnd
 
     def get_size_constraint(self):
         return 0
 
     def about(self):
-        html_str = "<b>"+ self.master_dom.getAttribute('class')
+        """html_str = "<b>"+ self.xml.get('class')
         html_str += " Applet</b><br />by Chris Davis<br />chris@rpgarchive.com"
-        return html_str
+        return html_str"""
+        text = self.xml.get('class') + 'Applet\n'
+        text += 'by Chris Davis chris@rpgarchive.com'
+        return text
+
+    def get_value(self):
+        return None
 
 P_TITLE = 10
-P_BODY = 20
+P_BODY = 20
+
 class text_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.master_dom.getAttribute('name')),
-                        P_BODY : html_text_edit(self,P_BODY,handler.text._get_nodeValue(),self.on_text)
+        self.text = {   P_TITLE : wx.TextCtrl(self, P_TITLE, handler.xml.get('name')),
+                        P_BODY : html_text_edit(self,P_BODY,handler.text,self.on_text)
                       }
-        #P_BODY : wx.TextCtrl(self, P_BODY,handler.text._get_nodeValue(), style=wx.TE_MULTILINE)
-
         sizer.Add(wx.StaticText(self, -1, "Title:"), 0, wx.EXPAND)
         sizer.Add(self.text[P_TITLE], 0, wx.EXPAND)
         sizer.Add(wx.StaticText(self, -1, "Text Body:"), 0, wx.EXPAND)
@@ -327,26 +326,21 @@
             u_txt = ""
             bad_txt_found = 0
             for c in txt:
-                if ord(c) < 128:
-                    u_txt += c
-                else:
-                    bad_txt_found = 1
+                if ord(c) < 128: u_txt += c
+                else: bad_txt_found = 1
             if bad_txt_found:
                 wx.MessageBox("Some non 7-bit ASCII characters found and stripped","Warning!")
             txt = u_txt
             if txt != "":
-                self.handler.master_dom.setAttribute('name',txt)
+                self.handler.xml.set('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 ord(c) < 128: u_txt += c
+                else: bad_txt_found = 1
             if bad_txt_found:
                 wx.MessageBox("Some non 7-bit ASCII characters found and stripped","Warning!")
             txt = u_txt
@@ -361,22 +355,18 @@
     """ clones childe node and insert it at top of tree
         <nodehandler name='?'  module='core' class='node_loader'  />
     """
-    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 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)
+        title = self.xml.get('name')
+        new_xml = XML(tostring(self.xml[0]))
+        self.tree.root_xml.insert(0, new_xml)
+        tree_node = self.tree.load_xml(new_xml,self.tree.root,self.tree.root)
         return 1
-        #obj.on_design(None)
 
 ##########################
 ## file loader
@@ -388,25 +378,25 @@
         <file name="file_name.xml" />
         </nodehandler>
     """
-    def __init__(self,xml_dom,tree_node):
-        node_handler.__init__(self,xml_dom,tree_node)
-        self.file_node = self.master_dom._get_firstChild()
+    def __init__(self,xml,tree_node):
+        node_handler.__init__(self,xml,tree_node)
+        self.file_node = self.xml[0]
         self.frame = open_rpg.get_component('frame')
 
     def on_ldclick(self,evt):
-        file_name = self.file_node.getAttribute("name")
+        file_name = self.file_node.get("name")
         self.tree.insert_xml(open(orpg.dirpath.dir_struct["nodes"] + 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")]
+        vlist = [self.xml.get("name"),
+                  self.file_node.get("name")]
         dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit")
         if dlg.ShowModal() == wx.ID_OK:
             vlist = dlg.get_values()
-            self.file_node.setAttribute('name', vlist[1])
-            self.master_dom.setAttribute('name', vlist[0])
+            self.file_node.set('name', vlist[1])
+            self.xml.set('name', vlist[0])
             self.tree.SetItemText(self.mytree_node,vlist[0])
         dlg.Destroy()
 
@@ -420,27 +410,27 @@
         <file name="http://file_name.xml" />
         </nodehandler>
     """
-    def __init__(self,xml_dom,tree_node):
-        node_handler.__init__(self,xml_dom,tree_node)
-        self.file_node = self.master_dom._get_firstChild()
+    def __init__(self,xml,tree_node):
+        node_handler.__init__(self,xml,tree_node)
+        self.file_node = self.xml[0]
         self.frame = open_rpg.get_component('frame')
 
     def on_ldclick(self,evt):
-        file_name = self.file_node.getAttribute("url")
+        file_name = self.file_node.get("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")]
+        print "design filename",self.xml.get('name')
+        vlist = [self.xml.get("name"),
+                 self.file_node.get("url")]
         dlg = orpgMultiTextEntry(self.tree.GetParent(),tlist,vlist,"File Loader Edit")
         if dlg.ShowModal() == wx.ID_OK:
             vlist = dlg.get_values()
-            self.file_node.setAttribute('url', vlist[1])
-            self.master_dom.setAttribute('name', vlist[0])
+            self.file_node.set('url', vlist[1])
+            self.xml.set('name', vlist[0])
             self.tree.SetItemText(self.mytree_node,vlist[0])
         dlg.Destroy()
 
@@ -452,11 +442,11 @@
     """ clones childe node and insert it at top of tree
         <nodehandler name='?'  module='core' class='min_map'  />
     """
-    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)
         self.map = open_rpg.get_component('map')
-        self.mapdata = self.master_dom._get_firstChild()
+        self.mapdata = self.xml[0]
 
     def on_ldclick(self,evt):
-        self.map.new_data(toxml(self.mapdata))
+        self.map.new_data(tostring(self.mapdata))
         return 1