【问题标题】:Using Cairo Regions in python with gi.repository在带有 gi.repository 的 python 中使用开罗地区
【发布时间】:2011-09-02 06:44:40
【问题描述】:

我似乎无法让开罗地区在其中工作 使用 gintrospection。

例如

from gi.repository import cairo

 reg = cairo.Region()

会给我

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError

并尝试从 Gdk.get_clip_region() 获取一个区域会给我

    return info.invoke(*args)
TypeError: Couldn't find conversion for foreign struct 'cairo.Region'

我错过了什么明显的东西?我找不到初始化库的方法,也无法想象您需要对看起来像简单结构的区域进行初始化。我不知道为什么 gdk 找不到 cairo 类型,也不知道我是否应该以某种方式显示它。

【问题讨论】:

  • 你不是唯一一个为我做这件事的人。我认为这是一个错误,有人在编写 gir xml 定义文件时忽略了一些事情。如果还没有,它可能会在以后的版本中得到修复。

标签: python-3.x introspection cairo gobject pycairo


【解决方案1】:

显然您需要使用常规的 cairo 绑定,即使您对其他所有内容都使用自省。

所以只需import cairo

(我不确定为什么存在gi.repository.cairo...)

当您拥有所有必要的库时,“找不到转换”错误将消失(例如,在 Ubuntu 上,除了 python-cairo(或等效的 python3 软件包)之外,您还需要 python-gi-cairo 软件包)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多