【发布时间】:2012-09-14 12:19:41
【问题描述】:
我需要找出我正在使用的 GTK+ 版本。问题是涉及的版本号似乎太多了,我不确定哪些是最相关的。
我的系统是 Ubuntu 12.04,标配有 libgtk2.0-0,但是当我安装 Python 3.2 开发环境时,我还安装了许多其他包来绑定到 GTK3。
大多数情况下,这一切都“正常工作”,但我想实现一些(在 devhelp 中)仅在 GTK 3.2 版中可用的东西。不用说,我问的原因是Python在API中找不到方法。
所以,现在我想知道我能做些什么(如果有的话),但首先我需要弄清楚我的系统到底有什么。
This question 似乎指向了正确的方向,但它已经过时了四年。有没有人有任何可以提供帮助的最新信息?
编辑:感谢@ptomato 和@Pablo 提供的有用答案。我现在的问题是如何理解出现的不同象形文字。 dpkg 输出给出(除其他外)以下内容
bob@bobStudio:~$ dpkg -l libgtk* | grep ^i
ii libgtk-3-0 3.4.2-0ubuntu0.4 GTK+ graphical user interface library
ii libgtk-3-bin 3.4.2-0ubuntu0.4 programs for the GTK+ graphical user interface library
ii libgtk-3-common 3.4.2-0ubuntu0.4 common files for the GTK+ graphical user interface library
ii libgtk-3-dev 3.4.2-0ubuntu0.4 development files for the GTK+ library
ii libgtk-3-doc 3.4.2-0ubuntu0.4 documentation for the GTK+ graphical user interface library
[etc....]
在 Python3 shell 中我得到以下内容
>>> from gi.repository import Gtk
>>> Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION
(3, 4, 2)
如果我没看错(我不确定我是否正确),这意味着我使用的是 GTK+ 版本 3.4.2,但由于库中的编号,即libgtk-3-0,因此存在一些疑问。另外,如果我使用的是 3.4.2,为什么在 3.2 中标记为可用的方法不存在?
谁能解释一下不同数字的含义?
EDIT2:更具体地说,我正在调查的方法是Gtk.Grid().get_child_at()。来自 DevHelp GTK+ 手册,
gtk_grid_get_child_at ()
GtkWidget * gtk_grid_get_child_at (GtkGrid *grid,
gint left,
gint top);
Gets the child of grid whose area covers the grid cell whose upper left corner is at left, top.
grid : a GtkGrid
left : the left edge of the cell
top : the top edge of the cell
Returns : the child at the given position, or NULL
Since 3.2
我尝试在当前项目中使用此方法,并在堆栈跟踪中收到以下消息;
neighbour = self.parent.grid.get_child_at(x, y)
AttributeError: 'Grid' object has no attribute 'get_child_at'
但是,如果我使用的是 Gtk 3.4.2,并且该方法“自 3.2 以来”可用,那似乎没有多大意义。也许我在其他地方犯了错误?
这是一个说明错误的简短测试程序(参见标记为
from gi.repository import Gtk
window = Gtk.Window()
grid = Gtk.Grid()
window.add(grid)
# the callout method
def on_button_clicked(widget):
origin = grid.get_child_at(0, 0) #<-------------
if widget == origin:
print('You clicked (0,0)')
else:
print('You clicked (1,0)')
# add a couple of widgets
button00 = Gtk.Button()
button10 = Gtk.Button()
button00.set_label('(0,0)')
button10.set_label('(1,0)')
grid.attach(button00, 0, 0, 1, 1)
grid.attach(button10, 1, 0, 1, 1)
# attach the callouts
button00.connect("clicked", on_button_clicked)
button10.connect("clicked", on_button_clicked)
# display the window
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
【问题讨论】:
标签: python-3.x ubuntu-12.04 gtk3