pygobject / pgi

[Unmaintained: Use PyGObject instead] GTK+ / GObject Introspection Bindings for PyPy.
GNU Lesser General Public License v2.1
74 stars 16 forks source link

How does one use the Context object? #47

Closed P403n1x87 closed 6 years ago

P403n1x87 commented 6 years ago

I have some code that used to work with the gi installed from the Ubuntu repository. I was trying to run the same code with pgi from PyPI, but I get the following error

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

The code in question comes from the callback registered with the draw signal. I have a subclass of Gtk.Window that on __init__() does self.connect("draw", self._on_draw). The registered callback has the following code

    def _on_draw(self, widget, cr):
        cr.set_source_rgba(.2, .2, .2, self.opacity)
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.paint()
        cr.set_operator(cairo.OPERATOR_OVER)
        self.on_draw(widget, cr)

but the Context instance cr doesn't seem to have any of the methods one would expect from the pycairo package.

P403n1x87 commented 6 years ago

Nevermind, I think I have found the answer in the README (!) and in one of the tests. It seems that support is incomplete. I leave it to you to confirm and close as appropriate, if that is OK.

lazka commented 6 years ago

Yeah, this project isn't maintained any more.

For your problem, it might work if you install the cairocffi package.

If you tested pgi because it can be installed through pip, the latest pygobject can be installed with pip as well: https://pypi.org/project/PyGObject/

P403n1x87 commented 6 years ago

Yes, I gave pgi a try because it was available on PyPI and PyGObject was only available from the distro repositories. I didn't realise that it is on PyPI now. Thanks for the feedback!