3

We are trying to port this program from gtk2 to gtk3. When I try pygi-convert.sh I got the following error:

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?

5
  • 2
    Well, why not manually change that import gobject to from gi.repository import GObject? Commented Feb 25, 2018 at 13:18
  • @Aran-Fey Because when I did that, lots of errors occurred, do you have any other idea? Commented Feb 26, 2018 at 5:30
  • GTK4 is in the works, are you sure you want to do port it now? Commented Feb 26, 2018 at 8:16
  • @Aran-Fey I add a new branch github.com/Jooyeshgar/amir/tree/gtk3 and run the pygi-convert.sh and do some fixes but many features not working for now! any idea? Commented Feb 26, 2018 at 9:33
  • @gianmt: It'll be out in 2019 at best, and GTK+ 4 will still use gobject-instrospection, so porting to GTK+ 3 is not useless. Commented Feb 26, 2018 at 9:59

1 Answer 1

5

First, try to understand what you're doing. Read the basics of official Python for GTK+ 3 tutorial. 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. 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. A git grep -w gtk should help you find all the lowercase gtk occurences in your code, which should be removed or replaced.

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.

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. Most things won't apply to python, but some will. 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.

Then try to run, fix errors, rinse, repeat.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.