简体   繁体   English

如何将python程序从gtk2移植到gtk3?

[英]How to port Python program from gtk2 to gtk3?

We are trying to port this program from gtk2 to gtk3. 我们正在尝试将该程序从gtk2移植到gtk3。 When I try pygi-convert.sh I got the following error: 当我尝试pygi-convert.sh ,出现以下错误:

Traceback (most recent call last):
  File "scripts/amir", line 53, in <module>
    from gi.repository import GObject
  File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 39, in <module>
    raise ImportError(_static_binding_error)
ImportError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183

Any suggestion or other way to do this port? 有什么建议或其他方式可以进行此移植吗?

First, try to understand what you're doing. 首先,尝试了解您在做什么。 Read the basics of official Python for GTK+ 3 tutorial . 阅读GTK + 3官方Python的基础教程 You'll see that the correct order to do imports is: 您会看到执行导入的正确顺序是:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

The pygi-convert.sh is no silver bullet, you have to understand the changes and review them. pygi-convert.sh不是灵丹妙药,您必须了解更改并进行检查。 For example the imports in this section are most certainly wrong. 例如, 本节中的进口肯定是错误的。 The order is not correct, and you still have an import gtk left on the import gtk,Gtk.glade line. 顺序不正确,并且import gtk,Gtk.glade行上还剩下一个import gtk A git grep -w gtk should help you find all the lowercase gtk occurences in your code, which should be removed or replaced. git grep -w gtk应该可以帮助您找到代码中所有小写的gtk出现,应将其删除或替换。

I also see you have in that same file some code to change the window theme. 我还看到您在同一文件中有一些代码可以更改窗口主题。 Theming changed completely between GTK+ 2 and GTK+ 3. GTK+ 3 uses a CSS engine. 在GTK + 2和GTK + 3之间完全改变了主题。GTK + 3使用CSS引擎。

Check out the Python GTK+ 3 API to know what's available, and check in the C migration guide (not aware of a python resource for that, sorry) what has changed between GTK+ 2 and GTK+ 3 . 查看Python GTK + 3 API以了解可用的内容,并检查C迁移指南(对此尚不了解python资源,对不起) ,GTK + 2和GTK + 3之间发生了什么变化 Most things won't apply to python, but some will. 大多数事情不适用于python,但是有些事情会适用。 For example migrating from the old expose-event to the draw signal when doing custom drawing, or checking which widgets have been killed and replaced. 例如,在进行自定义绘制或检查哪些小部件已被杀死和替换时,从旧的expose-event迁移到draw信号。

Then try to run, fix errors, rinse, repeat. 然后尝试运行,修复错误,冲洗,然后重复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM