[goocanvas/introspection] Remove some overrides to keep api similar to pygoocanvas



commit df20d9ad1b1f50012f309ec2874a2cb38a95ea73
Author: John Stowers <john stowers gmail com>
Date:   Sun May 22 14:38:52 2011 +1200

    Remove some overrides to keep api similar to pygoocanvas

 src/GooCanvas.py |   67 +++------------------------
 src/demo.py      |  132 ++++++++++++++++++++++++++++++++----------------------
 2 files changed, 85 insertions(+), 114 deletions(-)
---
diff --git a/src/GooCanvas.py b/src/GooCanvas.py
index 26249fb..c1b42fa 100644
--- a/src/GooCanvas.py
+++ b/src/GooCanvas.py
@@ -5,39 +5,11 @@ GooCanvas = modules['GooCanvas']._introspection_module
 
 __all__ = []
 
-class _GooCanvasItem:
-    def __init__(self, parent, **props):
-        if parent:
-            parent.add_child(self, -1)
-        for k,v in props.iteritems():
-            self.set_property(k,v)
-
-class CanvasPath(GooCanvas.CanvasPath, _GooCanvasItem):
-
-    def __init__(self, parent, path_data, **props):
-        GooCanvas.CanvasPath.__init__(self)
-        _GooCanvasItem.__init__(self, parent, **props)
-        if path_data:
-            self.props.data = path_data
-
-CanvasPath = override(CanvasPath)
-__all__.append('CanvasPath')
-
-class CanvasRect(GooCanvas.CanvasRect, _GooCanvasItem):
-
-    def __init__(self, parent, x, y, width, height, **props):
-        GooCanvas.CanvasPath.__init__(self)
-        props.update(x=x,y=y,width=width,height=height)
-        _GooCanvasItem.__init__(self, parent, **props)
-
-CanvasRect = override(CanvasRect)
-__all__.append('CanvasRect')
-
 #We cant change the numner of points once constructed, and boxed types do not allow
 #arguments to constructors, so override __new__
 class CanvasPoints(GooCanvas.CanvasPoints):
 
-    def __new__(cls, *points):
+    def __new__(cls, points):
 
         assert len(points)
         assert len(points[0])
@@ -52,41 +24,16 @@ class CanvasPoints(GooCanvas.CanvasPoints):
 CanvasPoints = override(CanvasPoints)
 __all__.append('CanvasPoints')
 
-class CanvasPolyline(GooCanvas.CanvasPolyline, _GooCanvasItem):
-
-    def __init__(self, parent, close_path, *points, **props):
-        GooCanvas.CanvasPolyline.__init__(self)
-        props.update(close_path=close_path)
-        if points:
-            props.update(points=CanvasPoints(*points))
-        _GooCanvasItem.__init__(self, parent, **props)
+class CanvasPolyline(GooCanvas.CanvasPolyline):
 
     @classmethod
     def new_line(cls, parent, x1, y1, x2, y2, **props):
-        return cls(parent, False, *((x1,y1),(x2,y2)), **props)
+        props.update(
+                parent=parent,
+                points=CanvasPoints(((x1,y1),(x2,y2))),
+                close_path=False)
+        return cls(**props)
 
 CanvasPolyline = override(CanvasPolyline)
 __all__.append('CanvasPolyline')
 
-class CanvasImage(GooCanvas.CanvasImage, _GooCanvasItem):
-
-    def __init__(self, parent, pixbuf, x, y, **props):
-        GooCanvas.CanvasImage.__init__(self)
-        props.update(pixbuf=pixbuf,x=x,y=y)
-        _GooCanvasItem.__init__(self, parent, **props)
-
-CanvasImage = override(CanvasImage)
-__all__.append('CanvasImage')
-
-class CanvasWidget(GooCanvas.CanvasWidget, _GooCanvasItem):
-
-    def __init__(self, parent, widget, x, y, width, height, **props):
-        GooCanvas.CanvasWidget.__init__(self)
-        #taken from the C constructor
-        #g_object_set_data (G_OBJECT (witem->widget), "goo-canvas-item", witem);
-        widget.show()
-        props.update(widget=widget,x=x,y=y,width=width,height=height)
-        _GooCanvasItem.__init__(self, parent, **props)
-
-CanvasWidget = override(CanvasWidget)
-__all__.append('CanvasWidget')
diff --git a/src/demo.py b/src/demo.py
index 3e37d12..6d6310f 100644
--- a/src/demo.py
+++ b/src/demo.py
@@ -3,7 +3,7 @@ from gi.repository import Gtk, GdkPixbuf, GooCanvas
 def setup_polyline(c):
     group = c.get_root_item()
 
-    GooCanvas.CanvasRect (group, 0, 0, 600, 450, line_width=4.0)
+    GooCanvas.CanvasRect (parent=group, x=0,y=0,width=600,height=450, line_width=4.0)
 
     GooCanvas.CanvasPolyline.new_line(group, 0, 150, 600, 150, line_width=4.0)
 
@@ -13,11 +13,13 @@ def setup_polyline(c):
 
     GooCanvas.CanvasPolyline.new_line(group, 400, 0, 400, 450, line_width=4.0)
 
-    GooCanvas.CanvasPolyline (group, False,
-                       (340.0, 170.0),
-                       (340.0, 230.0),
-                       (390.0, 230.0),
-                       (390.0, 170.0),
+    p_points = GooCanvas.CanvasPoints((
+                            (340.0, 170.0),
+                            (340.0, 230.0),
+                            (390.0, 230.0),
+                            (390.0, 170.0)))
+    GooCanvas.CanvasPolyline (parent=group, close_path=False,
+                       points=p_points,
                        stroke_color="midnightblue",
                        line_width=3.0,
                        start_arrow=True,
@@ -26,9 +28,11 @@ def setup_polyline(c):
                        arrow_length=4.0,
                        arrow_width=3.5)
 
-    GooCanvas.CanvasPolyline (group, False,
-                       (356.0, 180.0),
-                       (374.0, 220.0),
+    p_points = GooCanvas.CanvasPoints((
+                            (356.0, 180.0),
+                            (374.0, 220.0)))
+    GooCanvas.CanvasPolyline (parent=group, close_path=False,
+                       points=p_points,
                        stroke_color="blue",
                        line_width=1.0,
                        start_arrow=True,
@@ -37,8 +41,8 @@ def setup_polyline(c):
                        arrow_length=6.0,
                        arrow_width=6.0)
 
-    GooCanvas.CanvasPolyline (group, False,
-                       (356.0, 220.0),
+    GooCanvas.CanvasPolyline (parent=group, close_path=False,
+                       points=GooCanvas.CanvasPoints(((356.0, 220.0),)),
                        start_arrow=True,
                        end_arrow=True)
 
@@ -46,59 +50,63 @@ def setup_canvas(c):
     root = c.get_root_item()
 
     #Test the simple commands like moveto and lineto: MmZzLlHhVv. */
-    GooCanvas.CanvasPath (root, "M 20 20 L 40 40")
-    GooCanvas.CanvasPath (root, "M30 20 l20, 20")
-    GooCanvas.CanvasPath (root, "M 60 20 H 80")
-    GooCanvas.CanvasPath (root, "M60 40 h20")
-    GooCanvas.CanvasPath (root, "M 100,20 V 40")
-    GooCanvas.CanvasPath (root, "M 120 20 v 20")
-
-    GooCanvas.CanvasPath (root,
-                  "M 180 20 h20 v20 h-20 z m 5,5 h10 v10 h-10 z",
+    GooCanvas.CanvasPath (parent=root, data="M 20 20 L 40 40")
+    GooCanvas.CanvasPath (parent=root, data="M30 20 l20, 20")
+    GooCanvas.CanvasPath (parent=root, data="M 60 20 H 80")
+    GooCanvas.CanvasPath (parent=root, data="M60 40 h20")
+    GooCanvas.CanvasPath (parent=root, data="M 100,20 V 40")
+
+    #test empty    
+    p = GooCanvas.CanvasPath (parent=root, data="")
+    p.props.data = "M 120 20 v 20"
+
+    GooCanvas.CanvasPath (parent=root,
+                  data="M 180 20 h20 v20 h-20 z m 5,5 h10 v10 h-10 z",
                   fill_color="red",
     #              "fill_rule", CAIRO_FILL_RULE_EVEN_ODD,
                   )
 
-    GooCanvas.CanvasPath (root, "M 220 20 L 260 20 L 240 40 z",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M 220 20 L 260 20 L 240 40 z",
                   fill_color="red",
                   stroke_color="blue",
                   line_width=3.0,
                   )
 
     #Test the bezier curve commands: CcSsQqTt. */
-    GooCanvas.CanvasPath (root,
-                  "M20,100 C20,50 100,50 100,100 S180,150 180,100",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M20,100 C20,50 100,50 100,100 S180,150 180,100",
                   )
 
-    GooCanvas.CanvasPath (root,
-                  "M220,100 c0,-50 80,-50 80,0 s80,50 80,0",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M220,100 c0,-50 80,-50 80,0 s80,50 80,0",
                   )
 
-    GooCanvas.CanvasPath (root,
-                  "M20,200 Q60,130 100,200 T180,200",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M20,200 Q60,130 100,200 T180,200",
                   )
 
-    GooCanvas.CanvasPath (root,
-                  "M220,200 q40,-70 80,0 t80,0",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M220,200 q40,-70 80,0 t80,0",
                   )
 
     # Test the elliptical arc commands: Aa. */
-    GooCanvas.CanvasPath (root,
-                  "M200,500 h-150 a150,150 0 1,0 150,-150 z",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M200,500 h-150 a150,150 0 1,0 150,-150 z",
                   fill_color="red",
                   stroke_color="blue",
                   line_width=5.0,
                   )
 
-    GooCanvas.CanvasPath (root,
-                  "M175,475 v-150 a150,150 0 0,0 -150,150 z",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M175,475 v-150 a150,150 0 0,0 -150,150 z",
                   fill_color="yellow",
                   stroke_color="blue",
                   line_width=5.0,
                   )
 
-    GooCanvas.CanvasPath (root,
-                  """M400,600 l 50,-25
+    GooCanvas.CanvasPath (parent=root,
+                  data="""M400,600 l 50,-25
                   a25,25 -30 0,1 50,-25 l 50,-25
                   a25,50 -30 0,1 50,-25 l 50,-25
                   a25,75 -30 0,1 50,-25 l 50,-25
@@ -107,23 +115,23 @@ def setup_canvas(c):
                   line_width=5.0,
                   )
 
-    GooCanvas.CanvasPath (root,
-                  "M 525,75 a100,50 0 0,0 100,50",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M 525,75 a100,50 0 0,0 100,50",
                   stroke_color="red",
                   line_width=5.0,
                   )
-    GooCanvas.CanvasPath (root,
-                  "M 725,75 a100,50 0 0,1 100,50",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M 725,75 a100,50 0 0,1 100,50",
                   stroke_color="red",
                   line_width=5.0,
                   )
-    GooCanvas.CanvasPath (root,
-                  "M 525,200 a100,50 0 1,0 100,50",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M 525,200 a100,50 0 1,0 100,50",
                   stroke_color="red",
                   line_width=5.0,
                   )
-    GooCanvas.CanvasPath (root,
-                  "M 725,200 a100,50 0 1,1 100,50",
+    GooCanvas.CanvasPath (parent=root,
+                  data="M 725,200 a100,50 0 1,1 100,50",
                   stroke_color="red",
                   line_width=5.0,
                   )
@@ -176,14 +184,18 @@ def setup_scalability(c):
     for i in range(N_COLS):
         for j in range(N_ROWS):
             if pb:
-                GooCanvas.CanvasImage (root, pb,
-                           i * (width + PADDING),
-                           j * (height + PADDING))
+                GooCanvas.CanvasImage (
+                            parent=root,
+                            pixbuf=pb,
+                            x=i * (width + PADDING),
+                            y=j * (height + PADDING))
             else:
-                item = GooCanvas.CanvasRect (root,
-                          i * (width + PADDING),
-                          j * (height + PADDING),
-                          width, height)
+                item = GooCanvas.CanvasRect (
+                            parent=root,
+                            x=i * (width + PADDING),
+                            y=j * (height + PADDING),
+                            width=width,
+                            height=height)
                 item.props.fill_color = {True:"mediumseagreen",False:"steelblue"}[j % 2 == 0]
 
     return vbox
@@ -192,16 +204,28 @@ def setup_widget(c):
     root = c.get_root_item()
 
     #Add a few simple items. */
-    GooCanvas.CanvasWidget (root, Gtk.Label("Hello World"), 50, 50, 200, 100)
-    GooCanvas.CanvasWidget (root, Gtk.Entry(), 50, 250, 200, 50)
+    GooCanvas.CanvasWidget (
+                parent=root,
+                widget=Gtk.Label("Hello World"),
+                x=50, y=50, width=200, height=100)
+    GooCanvas.CanvasWidget (
+                parent=root,
+                widget=Gtk.Entry(),
+                x=50, y=250, width=200, height=50)
 
     entry = Gtk.Entry ()
     entry.set_text ("Size: -1 x -1")
-    GooCanvas.CanvasWidget (root, entry, 50, 300, -1, -1)
+    GooCanvas.CanvasWidget (
+                parent=root,
+                widget=entry,
+                x=50, y=300, width=-1, height=-1)
 
     entry = Gtk.Entry ()
     entry.set_text ("Size: 100 x -1")
-    GooCanvas.CanvasWidget (root, entry, 50, 350, 100, -1)
+    GooCanvas.CanvasWidget (
+                parent=root,
+                widget=entry,
+                x=50, y=350, width=100, height=-1)
 
 def demo_window(setup_func):
     c = GooCanvas.Canvas()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]