0

I just upgraded from Fedora 30 to Fedora 32. All my python stuff stopped working. The first problem was with

import gtk

I read that I should switch it to

from gi.repository import Gtk as gtk
from gi.repository import Gdk

But many many modules are not present. For example:

AttributeError: 'gi.repository.Gtk' object has no attribute 'combo_box_new_text'
AttributeError: 'gi.repository.Gtk' object has no attribute 'WINDOW_TOPLEVEL'
AttributeError: 'gi.repository.Gtk' object has no attribute 'settings_get_for_screen'

A huge mess.

How do I fix this?

Luis A. Florit
  • 2,169
  • 1
  • 33
  • 58

1 Answers1

0

Using Gtk 3:

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

in gtk use:

self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)

in Gtk 3 use:

self.set_position(Gtk.WindowPosition.CENTER)

So must convert your code to version 3 .

Alchimie
  • 426
  • 4
  • 12
  • No difference, same errors. `AttributeError: 'gi.repository.Gtk' object has no attribute 'combo_box_new_text'` – Luis A. Florit May 25 '20 at 17:37
  • This is helpful example for ComboBox , try to understand and use it:https://python-gtk-3-tutorial.readthedocs.io/en/latest/combobox.html – Alchimie May 25 '20 at 17:46
  • The problem is that `gi.repository` `Gtk` is not a replacement for the old `gtk` module. The above was just an example, there are many errors like this, and I have several programs in python. Never had such a problem with a mature python. Maybe I should downgrade to python 2.7...? – Luis A. Florit May 25 '20 at 17:51
  • Example: `settings = gtk.settings_get_for_screen(gdk.screen_get_default())` gives error: `AttributeError: 'gi.repository.Gtk' object has no attribute 'settings_get_for_screen'`, and I have no idea which is the `gi` couterpart. The problem is that I don't have a "dictionary" from the old `gtk` module to the `gi` one. – Luis A. Florit May 25 '20 at 19:46
  • I get exactly the same errors with `self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)` ( no attribute 'WIN_POS_CENTER_ALWAYS'), `self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)` (no attribute 'WINDOW_TOPLEVEL'), etc, etc. – Luis A. Florit May 25 '20 at 20:06
  • As I wrote, I had many, MANY errors like those. I am trying to clean them (in particular the one you edited), but more keep appearing. Is there a "dictionary"? I think it is the double problem python2-->3 + gtk2-->3. Huge mess. – Luis A. Florit May 25 '20 at 21:09
  • I don't know, maybe you have to do that manual( convert all your code manual ) and search one by one for the new instruction. ..... https://www.tutorialspoint.com/pygtk/pygtk_quick_guide.htm – Alchimie May 25 '20 at 21:14
  • 1
    @LuisA.Florit [GTK2 to GTK3 migration guide](http://developer.gnome.org/gtk3/stable/gtk-migrating-2-to-3.html) – stovfl May 25 '20 at 21:23
  • why should convert to python3:"The final version of Python 2.0 was released on October 16, 2000. ", good luck. https://www.python.org/doc/sunset-python-2/ – Alchimie May 25 '20 at 21:23
  • No language should break backward compatibility. – Luis A. Florit May 25 '20 at 21:42
  • @stovfl: That should be useful. Thanks! – Luis A. Florit May 25 '20 at 21:43
  • @LuisA.Florit: This isn't the language, or the library, breaking backward compatibility. What's happened is that the library you were using (the Python GTK2 library, `import gtk`) has been removed from Fedora. There is an equivalent Python GTK3 library (`gi.repository`) but it's not the _same_ library. If you can install the old library somehow (separate Python distribution, Docker container, Flatpak, ...) you can continue to use your old code. – ptomato May 26 '20 at 01:18
  • @ptomato: Yes, indeed you're right regarding GTK. But it seems to me that I am also getting strange Python3 errors too. For example with str/unicode, tons of errors byte/str, iters, etc. Please see as an example https://stackoverflow.com/questions/62011325/python3-assertion-iter-is-valid-iter-list-store-failed – Luis A. Florit May 26 '20 at 02:23