Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197799
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: PyObjects From Python Via ctypes |
| Date | Thu, 11 Jun 2026 07:44:15 -0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 38 |
| Message-ID | <110dp0f$19tv7$2@dont-email.me> (permalink) |
| References | <110doqv$19tv7$1@dont-email.me> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Thu, 11 Jun 2026 07:44:16 +0000 (UTC) |
| Injection-Info | dont-email.me; logging-data="1374183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19z97ugHzaq0N+VkpBEdbSz"; posting-host="30790e76a89477aca572138a98dab22f" |
| User-Agent | Pan/0.165 (Kostiantynivka) |
| Cancel-Lock | sha1:l9zxzXrdj+hssvAaWRiON4SN6ZI= sha256:4KvdUY+zVQzjLnf81/1LpMpNV6BjnDl7kJU1xP1PCTw= sha1:CxLFjO6d/TVC8yLI3rasMZZbheM= |
| Xref | csiph.com comp.lang.python:197799 |
Show key headers only | View raw
On Thu, 11 Jun 2026 07:41:20 -0000 (UTC), I wrote:
> I see ctypes has a py_object type, but you can’t seem to do much
> with it. The following might be more useful:
Example use: accessing a more powerful Cairo wrapper in a context
where the GUI toolkit wrapper (e.g. PyGObject for GTK) wants to
give you only a pycairo object.
----
import ctypes as ct
import qahirah as qah
from pyobjhack import PyObject
class PyCairo_Context(ct.Structure) :
"extract cairo_t pointer from pycairo.Context object."
_fields_ = \
[
("header", PyObject),
("ctx", ct.c_void_p),
]
@classmethod
def get_ctx(celf, pyctx) :
return \
ct.c_void_p(celf.from_address(id(pyctx)).ctx).value
#end get_ctx
#end PyCairo_Context
def pycairo_to_qah(ctx) :
"returns a qah.Context object wrapping the cairo_t pointer from" \
" a given cairo.Context object."
gx = PyCairo_Context.get_ctx(ctx)
qah.cairo.cairo_reference(gx) # grab one for myself
return \
qah.Context(gx)
#end pycairo_to_qah
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
PyObjects From Python Via ctypes Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-11 07:41 +0000 Re: PyObjects From Python Via ctypes Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-06-11 07:44 +0000
csiph-web