Python3:如何找出我使用的GTK +版本? [英] Python3: How can I find out what version of GTK+ I am using?

查看:102
本文介绍了Python3:如何找出我使用的GTK +版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找出我正在使用的GTK +版本.问题在于似乎涉及了许多不同的版本号,我不确定哪个版本号最相关.

I need to find out what version of GTK+ I am using. The problem is there seem to be so many different version numbers involved I am not sure which ones are most relevant.

我的系统是Ubuntu 12.04,并且是libgtk2.0-0的标准配置,但是当我安装Python 3.2开发环境时,我还安装了许多其他软件包以绑定到GTK3.

My system is Ubuntu 12.04 and comes as standard with libgtk2.0-0, but when I installed my Python 3.2 development environment I also installed a number of other packages to bind to GTK3.

在大多数情况下,这一切都可行",但是我想实现一些东西(在devhelp中)仅在GTK 3.2版中可用.不用说,我问的原因是Python无法在API中找到该方法.

Most of the time this all 'just works', but I want to implement something that (in devhelp) is only available in Version 3.2 of GTK. Needless to say, my reason for asking is that Python cannot find the method in the API.

所以,现在我想知道我能做些什么(如果有的话),但是首先我需要确切地了解系统上的功能.

So, now I am wondering what (if anything) I can do about it, but first I need to find out exactly what I have got on my system.

这个问题似乎指向正确的方向,但已经过时了四年.有没有人有任何最新的信息可以帮助您?

This question seems to point in the right direction, but it is four years out of date. Does anyone have any more recent information that could help?

感谢@ptomato和@Pablo的有用答案.我现在的问题是如何理解出现的不同象形文字. dpkg输出(除其他外)提供以下内容

Thanks to @ptomato and @Pablo for their helpful answers. My problem now is how to make sense of the different hieroglyphics that come out. The dpkg output gives (among other things) the following

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中,我得到了以下内容

while in the Python3 shell I get the following

>>> 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中标记为可用的方法?

If I read this correctly (I am not sure I am) this means I am using GTK+ version 3.4.2, but there is some doubt because of the number on the libraries, viz, libgtk-3-0. Also, if I am using 3.4.2, why is a method labelled as being available in 3.2 not present?

有人可以解释不同数字的含义吗?

Can someone explain what the different numbers mean?

更具体地说,我正在研究的方法是Gtk.Grid().get_child_at().在DevHelp GTK +手册中,

To be more specific, the method I am investigating is Gtk.Grid().get_child_at(). From the DevHelp GTK+ manual,

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

我在当前项目中尝试使用此方法,并且在堆栈跟踪中收到以下消息;

I tried using this method in my current project and I get the following message in the stack trace;

    neighbour = self.parent.grid.get_child_at(x, y)
AttributeError: 'Grid' object has no attribute 'get_child_at'

但是,如果我使用的是Gtk 3.4.2,并且该方法自"3.2起"可用,那似乎没有多大意义.也许我在其他地方犯了错误?

But if I am using Gtk 3.4.2, and the method was available 'since 3.2' that does not seem to make much sense. Maybe I made a mistake elsewhere?

这是一个简短的测试程序,用于说明错误(请参见标记为< --------的行)

Here is a short test program that illustrates the error (see the line marked <--------)

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提示符下键入以下内容或在脚本中执行以下操作:

Type the following at your Python prompt or do the equivalent in a script:

>>> from gi.repository import Gtk
>>> Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION
(3, 4, 3)

此数字是您正在使用的GTK的实际版本号. libgtk-3-0软件包表示该软件包适用于3.0系列,每个后续版本的主要版本号为3都兼容.如果他们将软件包重命名为3.2等,那么您将无法升级它,所有其他软件包都将损坏.

This number is the actual version number of GTK that you are using. The libgtk-3-0 package indicates that that package is for the 3.0 series, which every subsequent version with a major version number of 3 is compatible with. If they renamed the package for 3.2, etc., then you wouldn't be able to upgrade it and all your other packages would break.

至于Gtk.Grid.get_child_at(),在我的Gtk 3.4.2的Python设置中也不可用.这很奇怪,因为Python API是从C API自动生成的.如果您遇到这样的问题,那么要做的第一件事就是仔细检查程序中是否存在其他错误:

As for Gtk.Grid.get_child_at(), it's not available in my Python setup with Gtk 3.4.2 either. This is odd, since the Python API is automatically generated from the C API. If you are facing a problem like this, then the first thing to do is double-check that there's not a different error in your program:

>>> from gi.repository import Gtk
>>> grid = Gtk.Grid()
>>> 'get_child_at' in dir(grid)
False

所以真的没有方法.有时,方法注释在文档注释中标记为(skip),这意味着它们仅用于C语言,不应出现在其他语言的绑定中.所以也检查一下. GTK源代码在线上此处;搜索get_child_at,您会看到没有(skip)批注.所以那也不是问题.

So there really is no method. Sometimes methods are marked as (skip) in the documentation comments, meaning they are C-only and shouldn't show up in bindings in other languages; so check that too. The GTK source code is online here; search for get_child_at and you'll see there is no (skip) annotation. So that's not the problem either.

下一步是检查PyGObject源代码是否有替代.有时候,某些方法会被更Python化的东西所取代;例如,grid[0, 0]将比grid.get_child_at(0, 0)具有更多的Python风格,如果PyGObject团队想到了这一点,那就太好了.

The next thing to do is to check the PyGObject source code for an override. Sometimes certain methods are superseded by something that's more Pythonic; for example, grid[0, 0] would be much more Pythonic than grid.get_child_at(0, 0) and it would be awesome if the PyGObject team had thought of that.

>>> grid[0, 0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Grid' object has no attribute '__getitem__'

没有这种运气.因此,请在此处中查看PyGObject的GTK,然后搜索get_child_atGrid等.

No such luck. So look at PyGObject's GTK overrides here and search for get_child_at, Grid, etc. No mention.

所以我能想到的唯一的可能性就是一个错误.转到 http://bugzilla.gnome.org 并报告Python绑定中缺少此方法.如果您有雄心壮志,为什么还不建议他们使用grid[0, 0]表示法呢?

So the only possibility remaining that I can think of, is a bug. Go to http://bugzilla.gnome.org and report the lack of this method in the Python bindings. If you're feeling ambitious, why not suggest the grid[0, 0] notation to them as well?

这篇关于Python3:如何找出我使用的GTK +版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆