diff orpg/mapper/whiteboard.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 1ed2feab0db9
children 06f10429eedc
line wrap: on
line diff
--- a/orpg/mapper/whiteboard.py	Sat Nov 21 03:19:34 2009 -0600
+++ b/orpg/mapper/whiteboard.py	Mon Nov 23 03:22:50 2009 -0600
@@ -30,10 +30,6 @@
 
 from base import *
 from orpg.mapper.map_utils import *
-from orpg.tools.orpg_log import debug
-from xml.etree.ElementTree import ElementTree, Element, tostring
-
-## I added tr_ to the line and text ID. This should help prevent Traipse's lines from being randomly deleted. ##
 
 def cmp_zorder(first,second):
     f = first.zorder
@@ -103,38 +99,43 @@
         dc.SetTextForeground(wx.Colour(0,0,0))
 
     def toxml(self, action="update"):
-        xml = Element('text')
-        xml.set('action', action)
-        xml.set('id', str(self.id))
-        if action == 'del': return tostring(xml)
-        if self.pointsize != None: xml.set('pointsize', str(self.pointsize))
-        if self.style != None: xml.set('style', str(self.style))
-        if self.weight != None: xml.set('weight', str(self.weight))
-        if self.posx != None: xml.set('posx', str(self.posx))
-        if not (self.posy is None): xml.set('posy', str(self.posy))
-        if self.text_string != None: xml.set('text_string', self.text_string)
-        if self.textcolor != None: xml.set('color', self.textcolor)
+        if action == "del":
+            xml_str = "<text action='del' id='" + str(self.id) + "'/>"
+            return xml_str
+        xml_str = "<text"
+        xml_str += " action='" + action + "'"
+        xml_str += " id='" + str(self.id) + "'"
+        if self.pointsize != None: xml_str += " pointsize='" + str(self.pointsize) + "'"
+        if self.style != None: xml_str += " style='" + str(self.style) + "'"
+        if self.weight != None: xml_str += " weight='" + str(self.weight) + "'"
+        if self.posx != None: xml_str+= " posx='" + str(self.posx) + "'"
+        if not (self.posy is None): xml_str += " posy='" + str(self.posy) + "'"
+        if self.text_string != None: xml_str+= " text_string='" + self.text_string + "'"
+        if self.textcolor != None: xml_str += " color='" + self.textcolor + "'"
+        xml_str += "/>"
         if (action == "update" and self.isUpdated) or action == "new":
             self.isUpdated = False
-            return tostring(xml)
+            return xml_str
         else: return ''
 
     def takedom(self, xml_dom):
-        self.text_string = xml_dom.get("text_string")
-        self.id = xml_dom.get("id")
-        if xml_dom.get("posy"): self.posy = int(xml_dom.get("posy"))
-        if xml_dom.get("posx"): self.posx = int(xml_dom.get("posx"))
-        if xml_dom.get("weight"):
-            self.weight = int(xml_dom.get("weight"))
+        self.text_string = xml_dom.getAttribute("text_string")
+        self.id = xml_dom.getAttribute("id")
+        if xml_dom.hasAttribute("posy"):
+            self.posy = int(xml_dom.getAttribute("posy"))
+        if xml_dom.hasAttribute("posx"):
+            self.posx = int(xml_dom.getAttribute("posx"))
+        if xml_dom.hasAttribute("weight"):
+            self.weight = int(xml_dom.getAttribute("weight"))
             self.font.SetWeight(self.weight)
-        if xml_dom.get("style"):
-            self.style = int(xml_dom.get("style"))
+        if xml_dom.hasAttribute("style"):
+            self.style = int(xml_dom.getAttribute("style"))
             self.font.SetStyle(self.style)
-        if xml_dom.get("pointsize"):
-            self.pointsize = int(xml_dom.get("pointsize"))
+        if xml_dom.hasAttribute("pointsize"):
+            self.pointsize = int(xml_dom.getAttribute("pointsize"))
             self.font.SetPointSize(self.pointsize)
-        if xml_dom.get("color") and xml_dom.get("color") != '':
-            self.textcolor = xml_dom.get("color")
+        if xml_dom.hasAttribute("color") and xml_dom.getAttribute("color") != '':
+            self.textcolor = xml_dom.getAttribute("color")
             if self.textcolor == '#0000000': self.textcolor = '#000000'
 
 class WhiteboardLine:
@@ -211,42 +212,45 @@
         #selected outline
 
     def toxml(self, action="update"):
-        xml = Element('line')
-        xml.set('action', action)
-        xml.set('id', str(self.id))
-        if action == "del": return tostring(xml)
+        if action == "del":
+            xml_str = "<line action='del' id='" + str(self.id) + "'/>"
+            return xml_str
         #  if there are any changes, make sure id is one of them
-        xml.set('line_string', self.line_string)
+        xml_str = "<line"
+        xml_str += " action='" + action + "'"
+        xml_str += " id='" + str(self.id) + "'"
+        xml_str+= " line_string='" + self.line_string + "'"
         if self.upperleft != None:
-            xml.set('upperleftx', str(self.upperleft.x))
-            xml.set('upperlefty', str(self.upperleft.y))
+            xml_str += " upperleftx='" + str(self.upperleft.x) + "'"
+            xml_str += " upperlefty='" + str(self.upperleft.y) + "'"
         if self.lowerright != None:
-            xml.set('lowerrightx', str(self.lowerright.x))
-            xml.set('lowerrighty', str(self.lowerright.y))
+            xml_str+= " lowerrightx='" + str(self.lowerright.x) + "'"
+            xml_str+= " lowerrighty='" + str(self.lowerright.y) + "'"
         if self.linecolor != None:
-            xml.set('color', str(self.linecolor))
+            xml_str += " color='" + str(self.linecolor) + "'"
         if self.linewidth != None:
-            xml.set('width', str(self.linewidth))
-        if action == "new": return tostring(xml)
+            xml_str += " width='" + str(self.linewidth) + "'"
+        xml_str += "/>"
+        if action == "new": return xml_str
         return ''
 
     def takedom(self, xml_dom):
-        self.line_string = xml_dom.get("line_string")
-        self.id = xml_dom.get("id")
-        if xml_dom.get("upperleftx"):
-            self.upperleft.x = int(xml_dom.get("upperleftx"))
-        if xml_dom.get("upperlefty"):
-            self.upperleft.y = int(xml_dom.get("upperlefty"))
-        if xml_dom.get("lowerrightx"):
-            self.lowerright.x = int(xml_dom.get("lowerrightx"))
-        if xml_dom.get("lowerrighty"):
-            self.lowerright.y = int(xml_dom.get("lowerrighty"))
-        if xml_dom.get("color") and xml_dom.get("color") != '':
-            self.linecolor = xml_dom.get("color")
+        self.line_string = xml_dom.getAttribute("line_string")
+        self.id = xml_dom.getAttribute("id")
+        if xml_dom.hasAttribute("upperleftx"):
+            self.upperleft.x = int(xml_dom.getAttribute("upperleftx"))
+        if xml_dom.hasAttribute("upperlefty"):
+            self.upperleft.y = int(xml_dom.getAttribute("upperlefty"))
+        if xml_dom.hasAttribute("lowerrightx"):
+            self.lowerright.x = int(xml_dom.getAttribute("lowerrightx"))
+        if xml_dom.hasAttribute("lowerrighty"):
+            self.lowerright.y = int(xml_dom.getAttribute("lowerrighty"))
+        if xml_dom.hasAttribute("color") and xml_dom.getAttribute("color") != '':
+            self.linecolor = xml_dom.getAttribute("color")
             if self.linecolor == '#0000000':
                 self.linecolor = '#000000'
-        if xml_dom.get("width"):
-            self.linewidth = int(xml_dom.get("width"))
+        if xml_dom.hasAttribute("width"):
+            self.linewidth = int(xml_dom.getAttribute("width"))
 
 ##-----------------------------
 ## whiteboard layer
@@ -283,7 +287,7 @@
         self.serial_number -= 1
 
     def add_line(self, line_string="", upperleft=cmpPoint(0,0), lowerright=cmpPoint(0,0), color="#000000", width=1):
-        id = 'tr_line-' + str(self.next_serial())
+        id = 'line ' + str(self.next_serial())
         line = WhiteboardLine(id, line_string, upperleft, lowerright, color=self.color, width=self.width)
         self.lines.append(line)
         xml_str = "<map><whiteboard>"
@@ -325,6 +329,7 @@
     def del_all_lines(self):
         for i in xrange(len(self.lines)):
             self.del_line(self.lines[0])
+        print self.lines
 
     def del_text(self, text):
         xml_str = "<map><whiteboard>"
@@ -382,7 +387,7 @@
         self.font = font
 
     def add_text(self, text_string, pos, style, pointsize, weight, color="#000000"):
-        id = 'tr_text-' + str(self.next_serial())
+        id = 'text ' + str(self.next_serial())
         text = WhiteboardText(id,text_string, pos, style, pointsize, weight, color)
         self.texts.append(text)
         xml_str = "<map><whiteboard>"
@@ -432,13 +437,13 @@
             return ""
 
     def layerTakeDOM(self, xml_dom):
-        serial_number = xml_dom.get('serial')
+        serial_number = xml_dom.getAttribute('serial')
         if serial_number != "": self.serial_number = int(serial_number)
-        children = xml_dom.getchildren()
+        children = xml_dom._get_childNodes()
         for l in children:
-            nodename = l.tag
-            action = l.get("action")
-            id = l.get('id')
+            nodename = l._get_nodeName()
+            action = l.getAttribute("action")
+            id = l.getAttribute('id')
             if self.serial_number < int(id[5:]): self.serial_number = int(id[5:])
             if action == "del":
                 if nodename == 'line':
@@ -450,17 +455,17 @@
             elif action == "new":
                 if nodename == "line":
                     try:
-                        line_string = l.get('line_string')
-                        upperleftx = l.get('upperleftx')
-                        upperlefty = l.get('upperlefty')
-                        lowerrightx = l.get('lowerrightx')
-                        lowerrighty = l.get('lowerrighty')
+                        line_string = l.getAttribute('line_string')
+                        upperleftx = l.getAttribute('upperleftx')
+                        upperlefty = l.getAttribute('upperlefty')
+                        lowerrightx = l.getAttribute('lowerrightx')
+                        lowerrighty = l.getAttribute('lowerrighty')
                         upperleft = wx.Point(int(upperleftx),int(upperlefty))
                         lowerright = wx.Point(int(lowerrightx),int(lowerrighty))
-                        color = l.get('color')
+                        color = l.getAttribute('color')
                         if color == '#0000000': color = '#000000'
-                        id = l.get('id')
-                        width = int(l.get('width'))
+                        id = l.getAttribute('id')
+                        width = int(l.getAttribute('width'))
                     except:
                         line_string = upperleftx = upperlefty = lowerrightx = lowerrighty = color = 0
                         continue
@@ -468,15 +473,15 @@
                     self.lines.append(line)
                 elif nodename == "text":
                     try:
-                        text_string = l.get('text_string')
-                        style = l.get('style')
-                        pointsize = l.get('pointsize')
-                        weight = l.get('weight')
-                        color = l.get('color')
+                        text_string = l.getAttribute('text_string')
+                        style = l.getAttribute('style')
+                        pointsize = l.getAttribute('pointsize')
+                        weight = l.getAttribute('weight')
+                        color = l.getAttribute('color')
                         if color == '#0000000': color = '#000000'
-                        id = l.get('id')
-                        posx = l.get('posx')
-                        posy = l.get('posy')
+                        id = l.getAttribute('id')
+                        posx = l.getAttribute('posx')
+                        posy = l.getAttribute('posy')
                         pos = wx.Point(0,0)
                         pos.x = int(posx)
                         pos.y = int(posy)