문제

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

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top