diff orpg/mapper/miniatures.py @ 139:8e07c1a2c69b alpha

Traipse Alpha 'OpenRPG' {091123-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 Mon, 23 Nov 2009 03:22:50 -0600
parents 54446a995007
children 06f10429eedc
line wrap: on
line diff
--- a/orpg/mapper/miniatures.py	Sat Nov 21 03:19:34 2009 -0600
+++ b/orpg/mapper/miniatures.py	Mon Nov 23 03:22:50 2009 -0600
@@ -319,57 +319,67 @@
             dc.DrawText(label,x+1,y+1)
 
     def toxml(self, action="update"):
-        mini = Element('miniature')
-        if action == 'del':
-            mini.set('action', action)
-            mini.set('id', str(self.id))
-            return tostring(mini)
-        mini.set('action', action)
-        mini.set('id', str(self.id))
-        mini.set('label', self.label)
+        if action == "del":
+            xml_str = "<miniature action='del' id='" + self.id + "'/>"
+            return xml_str
+        xml_str = "<miniature"
+        xml_str += " action='" + action + "'"
+        xml_str += " label='" + self.label + "'"
+        xml_str+= " id='" + self.id + "'"
         if self.pos != None:
-            mini.set('posx', str(self.pos.x))
-            mini.set('posy', str(self.pos.y))
-        if self.heading != None: mini.set('heading', str(self.heading))
-        if self.face != None: mini.set('face', str(self.face))
-        if self.path != None: mini.set('path', str(urllib.quote(self.path).replace('%3A', ':')))
-        mini.set('locked', '1') if self.locked else mini.set('locked', '0')
-        mini.set('hide', '1') if self.hide else mini.set('hide', '0')
-        if self.snap_to_align != None: mini.set('align', str(self.snap_to_align))
-        if self.id != None: mini.set('zorder', str(self.zorder))
-        if self.width != None: mini.set('width', str(self.width))
-        if self.height != None: mini.set('height', str(self.height))
+            xml_str += " posx='" + str(self.pos.x) + "'"
+            xml_str += " posy='" + str(self.pos.y) + "'"
+        if self.heading != None: xml_str += " heading='" + str(self.heading) + "'"
+        if self.face != None: xml_str += " face='" + str(self.face) + "'"
+        if self.path != None: xml_str += " path='" + urllib.quote(self.path).replace('%3A', ':') + "'"
+        if self.locked: xml_str += "  locked='1'"
+        else: xml_str += "  locked='0'"
+        if self.hide: xml_str += " hide='1'"
+        else: xml_str += " hide='0'"
+        if self.snap_to_align != None: xml_str += " align='" + str(self.snap_to_align) + "'"
+        if self.id != None: xml_str += " zorder='" + str(self.zorder) + "'"
+        if self.width != None: xml_str += " width='" + str(self.width) + "'"
+        if self.height != None: xml_str += " height='" + str(self.height) + "'"
         if self.local:
-            mini.set('local', str(self.local))
-            mini.set('localPath', str(urllib.quote(self.localPath).replace('%3A', ':')))
-            mini.set('localTime', str(localTime))
+            xml_str += ' local="' + str(self.local) + '"'
+            xml_str += ' localPath="' + str(urllib.quote(self.localPath).replace('%3A', ':')) + '"'
+            xml_str += ' localTime="' + str(self.localTime) + '"'
+        xml_str += " />"
         if (action == "update" and self.isUpdated) or action == "new":
             self.isUpdated = False
-            return mini
+            print xml_str; return xml_str
         else: return ''
 
     def takedom(self, xml_dom):
-        self.id = xml_dom.get("id")
-        if xml_dom.get("posx"): self.pos.x = int(xml_dom.get("posx"))
-        if xml_dom.get("posy"): self.pos.y = int(xml_dom.get("posy"))
-        if xml_dom.get("heading"): self.heading = int(xml_dom.get("heading"))
-        if xml_dom.get("face"): self.face = int(xml_dom.get("face"))
-        if xml_dom.get("path"):
-            self.path = urllib.unquote(xml_dom.get("path"))
+        self.id = xml_dom.getAttribute("id")
+        if xml_dom.hasAttribute("posx"):
+            self.pos.x = int(xml_dom.getAttribute("posx"))
+        if xml_dom.hasAttribute("posy"):
+            self.pos.y = int(xml_dom.getAttribute("posy"))
+        if xml_dom.hasAttribute("heading"):
+            self.heading = int(xml_dom.getAttribute("heading"))
+        if xml_dom.hasAttribute("face"):
+            self.face = int(xml_dom.getAttribute("face"))
+        if xml_dom.hasAttribute("path"):
+            self.path = urllib.unquote(xml_dom.getAttribute("path"))
             self.set_bmp(ImageHandler.load(self.path, 'miniature', self.id))
-        if xml_dom.get("locked"):
-            if xml_dom.get("locked") == '1' or xml_dom.get("locked") == 'True': self.locked = True
+        if xml_dom.hasAttribute("locked"):
+            if xml_dom.getAttribute("locked") == '1' or xml_dom.getAttribute("locked") == 'True': self.locked = True
             else: self.locked = False
-        if xml_dom.get("hide"):
-            if xml_dom.get("hide") == '1' or xml_dom.get("hide") == 'True': self.hide = True
+        if xml_dom.hasAttribute("hide"):
+            if xml_dom.getAttribute("hide") == '1' or xml_dom.getAttribute("hide") == 'True': self.hide = True
             else: self.hide = False
-        if xml_dom.get("label"): self.label = xml_dom.get("label")
-        if xml_dom.get("zorder"): self.zorder = int(xml_dom.get("zorder"))
-        if xml_dom.get("align"):
-            if xml_dom.get("align") == '1' or xml_dom.get("align") == 'True': self.snap_to_align = 1
+        if xml_dom.hasAttribute("label"):
+            self.label = xml_dom.getAttribute("label")
+        if xml_dom.hasAttribute("zorder"):
+            self.zorder = int(xml_dom.getAttribute("zorder"))
+        if xml_dom.hasAttribute("align"):
+            if xml_dom.getAttribute("align") == '1' or xml_dom.getAttribute("align") == 'True': self.snap_to_align = 1
             else: self.snap_to_align = 0
-        if xml_dom.get("width"): self.width = int(xml_dom.get("width"))
-        if xml_dom.get("height"): self.height = int(xml_dom.get("height"))
+        if xml_dom.hasAttribute("width"):
+            self.width = int(xml_dom.getAttribute("width"))
+        if xml_dom.hasAttribute("height"):
+            self.height = int(xml_dom.getAttribute("height"))
 
 ##-----------------------------
 ## miniature layer
@@ -482,49 +492,51 @@
 
     def layerToXML(self, action="update"):
         """ format  """
-        mini_string = ""
+        minis_string = ""
         if self.miniatures:
-            for m in self.miniatures: mini_string = m.toxml(action)
-        if mini_string != '':
-            s = Element('miniatures')
-            s.set('serial', str(self.serial_number))
-            s.append(mini_string)
-            return tostring(s)
+            for m in self.miniatures: minis_string += m.toxml(action)
+        if minis_string != '':
+            s = "<miniatures"
+            s += " serial='" + str(self.serial_number) + "'"
+            s += ">"
+            s += minis_string
+            s += "</miniatures>"
+            return s
         else: return ""
 
     def layerTakeDOM(self, xml_dom):
-        if xml_dom.get('serial'):
-            self.serial_number = int(xml_dom.get('serial'))
-        children = xml_dom.getchildren()
+        if xml_dom.hasAttribute('serial'):
+            self.serial_number = int(xml_dom.getAttribute('serial'))
+        children = xml_dom._get_childNodes()
         for c in children:
-            action = c.get("action")
-            id = c.get('id')
+            action = c.getAttribute("action")
+            id = c.getAttribute('id')
             if action == "del": 
                 mini = self.get_miniature_by_id(id)
                 if mini:
                     self.miniatures.remove(mini)
                     del mini
             elif action == "new":
-                pos = cmpPoint(int(c.get('posx')),int(c.get('posy')))
-                path = urllib.unquote(c.get('path'))
-                label = c.get('label')
+                pos = cmpPoint(int(c.getAttribute('posx')),int(c.getAttribute('posy')))
+                path = urllib.unquote(c.getAttribute('path'))
+                label = c.getAttribute('label')
                 height = width = heading = face = snap_to_align = zorder = 0
                 locked = hide = False
-                if c.get('height'): height = int(c.get('height')) or 0
-                if c.get('width'): width = int(c.get('width'))
-                if c.get('locked') == 'True' or c.get('locked') == '1': locked = True
-                if c.get('hide') == 'True' or c.get('hide') == '1': hide = True
-                if c.get('heading'): heading = int(c.get('heading'))
-                if c.get('face'): face = int(c.get('face'))
-                if c.get('align'): snap_to_align = int(c.get('align'))
-                if c.get('zorder'): zorder = int(c.get('zorder'))
-                image = ImageHandler.load(path, 'miniature', id)
-                mini = BmpMiniature(id, path, image, pos, heading, face, label, locked, hide, snap_to_align, zorder, width, height, func='minis')
-                self.miniatures.append(mini)
-                if c.get('local') and c.get('local') == 'True' and os.path.exists(urllib.unquote(c.get('localPath'))):
-                    localPath = urllib.unquote(c.get('localPath'))
+                if c.hasAttribute('height'): height = int(c.getAttribute('height'))
+                if c.hasAttribute('width'): width = int(c.getAttribute('width'))
+                if c.getAttribute('locked') == 'True' or c.getAttribute('locked') == '1': locked = True
+                if c.getAttribute('hide') == 'True' or c.getAttribute('hide') == '1': hide = True
+                if c.getAttribute('heading'): heading = int(c.getAttribute('heading'))
+                if c.hasAttribute('face'): face = int(c.getAttribute('face'))
+                if c.hasAttribute('align'): snap_to_align = int(c.getAttribute('align'))
+                if c.getAttribute('zorder'): zorder = int(c.getAttribute('zorder'))
+                min = BmpMiniature(id, path, ImageHandler.load(path, 'miniature', id), pos, heading, 
+                    face, label, locked, hide, snap_to_align, zorder, width, height)
+                self.miniatures.append(min)
+                if c.hasAttribute('local') and c.getAttribute('local') == 'True' and os.path.exists(urllib.unquote(c.getAttribute('localPath'))):
+                    localPath = urllib.unquote(c.getAttribute('localPath'))
                     local = True
-                    localTime = float(c.get('localTime'))
+                    localTime = float(c.getAttribute('localTime'))
                     if localTime-time.time() <= 144000:
                         file = open(localPath, "rb")
                         imgdata = file.read()
@@ -534,7 +546,7 @@
                         postdata = urllib.urlencode({'filename':filename[1], 'imgdata':imgdata, 'imgtype':imgtype})
                         thread.start_new_thread(self.upload, (postdata, localPath, True))
                 #  collapse the zorder.  If the client behaved well, then nothing should change.
-                #  Otherwise, this will ensure that there's some kind of z-order
+                #    Otherwise, this will ensure that there's some kind of z-order
                 self.collapse_zorder()
             else:
                 mini = self.get_miniature_by_id(id)