Re: PyGObject and Cairo



Hi!

I am far from being a GTK/Cairo expert, but I just ported a small
project to PyGI/GTK3/Cairo myself.

>From what I understand, the logic of Gtk.DrawingArea itself changed
quite a lot. Instead of using the expose event, you connect to the
"draw" event. All in all, the new semantics seem clearer and easier, but
it differs from the old expose based stuff.

For full details, see
http://developer.gnome.org/gtk3/stable/GtkDrawingArea.html

By the way, great to see Labyrinth alive. I liked it quite a lot,
although it was rather minimalistic.

Regards
Frederik

Am Sonntag, den 18.03.2012, 10:53 -0400 schrieb Brent:
> Hello,
> 
> I am currently attempting to port labyrinth, a mindmap application
> written in PyGTK and cairo, to PyGObject and cairo. Labyrinth uses a
> custom widget subclassed from Gtk.DrawingArea() drawn with cairo. I am
> having difficulty discovering how to hook things up properly in the
> brave new world of gobject-introspection!
> 
> The relevant PyGTK functions looked like this
> 
>     def expose (self, widget, event):
>         '''Expose event.  Calls the draw function'''
>         context = self.window.cairo_create ()
>         self.draw (event, context)
>         return False
> 
>     def draw (self, event, context):
>         '''Draw the map and all the associated thoughts'''
>         area = event.area
>         context.rectangle (area.x, area.y, area.width, area.height)
>         context.clip ()
>         context.set_source_rgb (1.0,1.0,1.0)
>         context.move_to (area.x, area.y)
>         context.paint ()
>         context.set_source_rgb (0.0,0.0,0.0)
> 	...
> 
> I changed the expose function to
> 
>     def expose (self, widget, event):
>         '''Expose event.  Calls the draw function'''
>         context = self.get_property('window').cairo_create()
>         self.draw(event, context)
>         return False
> 
> but when I run this code I get
> 
>   File "/home/blang/code/absinthe/ABSINTHE/gtkui/editor/mmaparea.py",
> line 770, in expose
>     self.draw(event, context)
>   File "../mmaparea.py", line 775, in draw
>     area = event.area
> AttributeError: 'cairo.Context' object has no attribute 'area'
> 
> Any assistance appreciated!
> 
> Brent
> 
> _______________________________________________
> python-hackers-list mailing list
> python-hackers-list gnome org
> http://mail.gnome.org/mailman/listinfo/python-hackers-list




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