changeset c0b161144da5 in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=c0b161144da5
description: Changed minidom to simplexml

diffstat:

 src/chat_control.py     |    8 ++-
 src/whiteboardwidget.py |  102 
++++++++++++++++++++++++++++++++-------------------
 2 files changed, 69 insertions(+), 41 deletions(-)

diffs (206 lines):

diff -r a91c0ade3d9b -r c0b161144da5 src/chat_control.py
--- a/src/chat_control.py       Sun Jun 28 15:27:08 2009 -0700
+++ b/src/chat_control.py       Fri Jul 03 01:25:38 2009 -0700
@@ -2747,15 +2747,17 @@
                        self.print_conversation(' (', 'status', simple=True)
                        self.print_conversation('%s' % (status), 'status', 
simple=True)
                        self.print_conversation(')', 'status', simple=True)
-                       
+       
        def _on_whiteboard_button_clicked(self, widget):
                hbox = self.xml.get_widget('chat_child_hbox')
                if len(hbox.get_children()) == 1:
-                       whiteboard = Whiteboard(gajim.connections[self.account])
+                       whiteboard = Whiteboard(gajim.connections[self.account],
+                                               self.account,
+                                               self.contact)
                        try:
                                hbox.pack_start(whiteboard)
                                whiteboard.show()
                        except:
                                pass # TODO: Fix problem with groupchat?
-               
+
 # vim: se ts=3:
diff -r a91c0ade3d9b -r c0b161144da5 src/whiteboardwidget.py
--- a/src/whiteboardwidget.py   Sun Jun 28 15:27:08 2009 -0700
+++ b/src/whiteboardwidget.py   Fri Jul 03 01:25:38 2009 -0700
@@ -1,6 +1,11 @@
 import gtk
 import goocanvas
-from xml.dom.minidom import Document
+from common.xmpp import Node
+
+#for sxe session
+from random import choice
+import string
+import urllib
 
 """ 
 A whiteboard widget made for Gajim. Only has basic line tool that draws
@@ -9,38 +14,38 @@
 """
 
 class Whiteboard(goocanvas.Canvas):
-    def __init__(self, connection):
+    def __init__(self, connection, account, contact):
         goocanvas.Canvas.__init__(self)
         self.set_flags(gtk.CAN_FOCUS)
         self.root = self.get_root_item()
-        
+        self.session = SXESession()
+
         # Events
         self.connect("button-press-event", self.button_press_event)
         self.connect("button-release-event", self.button_release_event)
         self.connect("motion-notify-event", self.motion_notify_event)
         self.connect("key-press-event", self.key_press_event)
-        
+
         # Config
         self.draw_tool = 'brush'
         self.line_width = 10
-        
+
         # SVG Storage
-        #TODO: get height width info
+        # TODO: get height width info
         self.image = SVGObject(self.root)
-        
+
         # Temporary Variables for items
         self.item_temp = None
         self.item_temp_coords = (0,0)
         self.item_data = None
-        
 
-        
+ 
     def button_press_event(self, widget, event):
         x = event.x
         y = event.y
         state = event.state
         self.item_temp_coords = (x,y)
-        
+
         if self.draw_tool == 'brush':
             self.item_data = 'M %s,%s ' % (x, y)
             self.item_temp = goocanvas.Ellipse(parent = self.root,
@@ -52,7 +57,7 @@
                                                 fill_color = "black",
                                                 line_width = self.line_width)
             self.item_data = self.item_data + 'L '
-        
+
     def motion_notify_event(self, widget, event):
         x = event.x
         y = event.y
@@ -84,7 +89,7 @@
                                                 fill_color = "black",
                                                 line_width = self.line_width)
             self.image.add_path(self.item_data, self.line_width)
-            
+
         self.item_data = None
         if self.item_temp is not None:
             self.item_temp.remove()
@@ -95,52 +100,73 @@
         print 'test'
         if event.keyval == 'p':
             self.image.print_xml()
-            
+  
 class SVGObject():
     ''' A class to store the svg document and make changes to it.
     Stores items in a tuple that's (minidom node, goocanvas object).'''
     
-    def __init__(self, root, height = 500, width = 500):
-        self.items = []
+    def __init__(self, root, height = 300, width = 300):
+        self.items = [] # Will be [{ID: (Node, GooCanvas )}] instance
         self.root = root
-        
+
         # initialize svg document
-        self.doc = Document()
-        self.svg = self.doc.createElement('svg')
-        self.svg.setAttribute('version', '1.1')
-        self.svg.setAttribute('height', str(height))
-        self.svg.setAttribute('width', str(width))
-        self.svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg')
-        self.doc.appendChild(self.svg)
+        self.svg = Node(node = '<svg/>')
+        self.svg.setAttr('version', '1.1')
+        self.svg.setAttr('height', str(height))
+        self.svg.setAttr('width', str(width))
+        self.svg.setAttr('xmlns', 'http://www.w3.org/2000/svg')
+
         #TODO: make this settable        
-        self.g = self.doc.createElement('g')
-        self.g.setAttribute('fill', 'none')
-        self.g.setAttribute('stroke-linecap', 'round')
-        self.svg.appendChild(self.g)
-        
+        self.g = Node(node = '<g/>')
+        self.g.setAttr('fill', 'none')
+        self.g.setAttr('stroke-linecap', 'round')
+        self.svg.addChild(node = self.g)
+
     def add_path(self, data, line_width):
         ''' adds the path to the items listing, both minidom node and goocanvas
         object in a tuple '''
-        
+
         goocanvas_obj = self.items.append(goocanvas.Path(parent = self.root,
                                     data = data,
                                     line_width = line_width))
+
+        node = Node(node = '<path />')
+        node.setAttr('d', data)
+        node.setAttr('stroke-width', str(line_width))
+        node.setAttr('stroke', 'black')
+        self.g.addChild(node = node)
         
-        minidom_obj = self.doc.createElement('path')
-        minidom_obj.setAttribute('d', data)
-        minidom_obj.setAttribute('stroke-width', str(line_width))
-        minidom_obj.setAttribute('stroke', 'black')
-        self.g.appendChild(minidom_obj)
-        
-        self.items.append((minidom_obj, goocanvas_obj))
-        self.print_xml()
+        self.items.append((goocanvas_obj))
+
         
     def print_xml(self):
         file = open('whiteboardtest.svg','w')
-        file.writelines(self.doc.toprettyxml('  '))
+        file.writelines(str(self.svg, True))
         file.close()
 
+def SXESession():
+    ''' stores all the sxe session methods and info'''
+    def __init__(self, connection, account, contact, sid = None):
+        self.connection = connection
+        self.account = account
+        self.contact = contact
         
+        #generate unique session ID
+        if sid is None:
+            chars = string.letters + string.digits
+            self.sid = ''.join([choice(chars) for i in range(7)])
+        else:
+            self.sid = sid
+    
+    def connect(self):
+        pass
+    
+    def encode(self, xml):
+        #encodes it sendable string
+        return 'data:text/xml' + urllib.quote(xml)
+    
+
+
 def main():
     window = gtk.Window()
     window.set_events(gtk.gdk.EXPOSURE_MASK
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to