GObject Inspection 编程经验分享
Tofloor
poster avatar
186******98
deepin
2011-12-18 18:24
Author
给大家一个编程经验哈, 如果 Python 没有绑定某个库, 比如 soup, 不要用 ctypes 的方法, ctypes 的方法会得到无法捕获的异常, 非常危险。

我建议用 gobject inspection 的方法, 比如我用 emacs 扫描 gir1.2 库会得到:

gir1.2-accountsservice-1.0
gir1.2-anjuta-3.0
gir1.2-appindicator-0.1
gir1.2-appindicator3-0.1
gir1.2-atk-1.0
gir1.2-atspi-2.0
gir1.2-caribou-1.0
gir1.2-champlain-0.10
gir1.2-champlain-0.8
gir1.2-cheese-3.0
gir1.2-clutter-1.0
gir1.2-clutter-gst-1.0
gir1.2-clutter-gtk-0.10
gir1.2-cogl-1.0
gir1.2-colord-1.0
gir1.2-couchdb-1.0
gir1.2-cryptui-0.0
gir1.2-dbusmenu-glib-0.4
gir1.2-dbusmenu-gtk-0.4
gir1.2-dbusmenu-gtk3-0.4
gir1.2-dee-0.5
gir1.2-desktopcouch-1.0
gir1.2-ebook-1.2
gir1.2-ecalendar-1.2
gir1.2-edataserver-1.2
gir1.2-emerillon-0.1
gir1.2-epiphany-2.31
gir1.2-evince-3.0
gir1.2-folks-0.6
gir1.2-freedesktop
gir1.2-gconf-2.0
gir1.2-gda-4.0
gir1.2-gdata-0.0
gir1.2-gdkpixbuf-2.0
gir1.2-gdl-3
gir1.2-gee-1.0
gir1.2-geocodeglib-1.0
gir1.2-ges-0.10
gir1.2-gkbd-3.0
gir1.2-gladeui-2.0
gir1.2-glib-2.0
gir1.2-gmenu-3.0
gir1.2-gnomebluetooth-1.0
gir1.2-gnomedesktop-3.0
gir1.2-gnomegamessupport-1.0
gir1.2-goa-1.0
gir1.2-grip
gir1.2-gssdp-1.0
gir1.2-gst-plugins-base-0.10
gir1.2-gst-rtsp-server-0.10
gir1.2-gstreamer-0.10
gir1.2-gtk-2.0
gir1.2-gtk-3.0
gir1.2-gtkchamplain-0.10
gir1.2-gtkchamplain-0.8
gir1.2-gtkclutter-1.0
gir1.2-gtksource-3.0
gir1.2-gtop-2.0
gir1.2-gucharmap-2.90
gir1.2-gudev-1.0
gir1.2-gupnp-1.0
gir1.2-gupnp-av-1.0
gir1.2-gupnpigd-1.0
gir1.2-gweather-3.0
gir1.2-gwibber-0.2
gir1.2-gwibber-gtk-0.2
gir1.2-indicate-0.6
gir1.2-json-1.0
gir1.2-launchpad-integration-3.0
gir1.2-lightdm-1
gir1.2-memphis-0.2
gir1.2-midgard2
gir1.2-mutter-3.0
gir1.2-mx-1.0
gir1.2-nautilus-3.0
gir1.2-networkmanager-1.0
gir1.2-notify-0.7
gir1.2-packagekitglib-1.0
gir1.2-panelapplet-4.0
gir1.2-pango-1.0
gir1.2-peas-1.0
gir1.2-polkit-1.0
gir1.2-rb-3.0
gir1.2-rest-0.7
gir1.2-rest-extras-0.7
gir1.2-socialweb-client
gir1.2-soup-2.4
gir1.2-sushi-1.0
gir1.2-syncdaemon-1.0
gir1.2-telepathyglib-0.12
gir1.2-telepathylogger-0.2
gir1.2-timezonemap-1.0
gir1.2-totem-1.0
gir1.2-totem-plparser-1.0
gir1.2-tracker-0.10
gir1.2-ubuntuone-1.0
gir1.2-unique-3.0
gir1.2-unity-4.0
gir1.2-upowerglib-1.0
gir1.2-urfkill-glib0
gir1.2-v-sim-1.0
gir1.2-vte-2.90
gir1.2-webkit-1.0
gir1.2-webkit-3.0
gir1.2-wnck-1.0
gir1.2-wnck-3.0

所以这些库都是可以通过 python 来直接调用的, 而且非常的安全,

我讲一下怎么使用 gi 的语法:

>>> import gi
>>> gi.require_version('WebKit', '3.0')
>>> from gi.repository import WebKit

这样就可了

所以我建议以后大家用 python 编程的时候都用 gi 的方法, 能调用最多的库、 安全、而且API的更新不用修改代码

如果 gi 都没有绑定的库 (一般这些库都不是基于 gobject 实现的) 可以用 ctypes, 但是一定要用多进程的方案隔离 ctypes 的代码, gtk 里面多进程隔离的方法就是 GtkSocket/GtkPlug
Reply Favorite View the author
All Replies

No replies yet