Frage

My code looks like

from gi.repository import PangoCairo
from gi.repository import Gtk

class Column(Gtk.DrawingArea):
    getContext = lambda self: PangoCairo.create_context(self.get_window().cairo_create())

    ...

        cr = self.getContext()        
        cr.rectangle(0, 0, w, h)

And I get this error:

AttributeError: 'Context' object has no attribute 'rectangle'

The method was called rectangle in PyGTK (both cairo.Context and pango.Context)
But I searched in gtk3 C documentations and it seems It should be draw_rectangle
And none of them exist in Python

War es hilfreich?

Lösung

I was wrong
rectangle is present in cairo.Context but not in pango.Context

I used pango.Context because I couldn't find show_layout in cairo.Context
Now I see the method is not in pango.Context object either
We have to use unbounded method PangoCairo.show_layout

Summary:

cr = self.get_window().cairo_create()
cr.rectangle(0, 0, w, h)
PangoCairo.show_layout(cr, layout)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top