Commits

Amirouche Boubekki committed f365a51

it's alive

Comments (0)

Files changed (3)

kkes/renderer/render_block_container.py

         RenderBlock.__init__(self, render_styles, parent, name)
 
     def __unicode__(self):
-        return '\n'
+        str = ''
+        for child in self.childs:
+            str += unicode(child)
+            str += '\n'
+        return str

kkes/renderer/render_object.py

-from PySide.QtGui import QGraphicsItem
-from PySide.QtCore import Qt
-from PySide.QtCore import QRectF, QRect
-
 class RenderObject:
     def __init__(self, render_styles=None, parent=None, name=None):
-        QGraphicsItem.__init__(self)
-
-        if parent:
-            self.set_parent(parent)
-
+        self._parent = None
+        self.set_parent(parent)
         self.render_styles = render_styles
         self.name = name
 
     def parent(self):
         return self._parent
 
-    def set_parent(self, parent):
+    def set_parent(self, value):
         if self.parent is not None:
             self.parent.childs.remove(self)
-        self._parent = parent
-        self._parent.childs.append(self)
+        if value is not None:
+            value.childs.append(self)
+        self._parent = value
 
-    def child_nodes(self):
-        return self.childs
+
+    def __iter__(self):
+        return self.childs.__iter__()
 
     def next_sibling(self):
-        siblings = self.parent().child_nodes()
-        index = siblings.index(self)
-        sibling_index = index + 1
-        if len(siblings) > sibling_index + 1:
-            return siblings[sibling_index]
+        if self.parent is not None:
+            siblings = self.parent.child_nodes()
+            index = siblings.index(self)
+            sibling_index = index + 1
+            if len(siblings) > sibling_index + 1:
+                return siblings[sibling_index]
+            return None
         return None
 
     def previous_sibling(self):
-        siblings = self.parent().child_nodes()
+        siblings = self.parent.childs
         index = siblings.index(self)
         sibling_index = index - 1
         if len(siblings) > 0:
         return None
 
     def pprint(self, tab=''):
-        print '%s%s (%s) [top:%s, left:%s, w:%s, h:%s]' % (tab,
-                                                           self.__class__.__name__,
-                                                           self.name)
-        for child in self.child_nodes():
+        print '%s%s (%s)' % (tab,
+                             self.__class__.__name__,
+                             self.name)
+        for child in self.childs:
             child.pprint(tab + '    ')
 
     def get_root(self):

kkes/renderer/render_text.py

 class RenderText(RenderInline):
     def __init__(self, render_styles, parent, data, name):
         RenderInline.__init__(self, render_styles, parent, name)
-        self.data = data
-        if self.next_sibling() is not None:
-            self.data += ' '
+        self.data = data + ' '
 
     def pprint(self, tab=''):
         RenderInline.pprint(self, tab)
         print '%s : %s' % (tab, self.data)
 
     def __unicode__(self):
-        return self.data
+        return unicode(self.data)