Is there a way to get code-hints for gtk3 and python working on aptana? - python

My situation is Aptana eclipse plug-in installed and working properly.
If I from gi.repository import Gtk the code completion I'm used to from import gtk is gone. Any solutions or is it just a bug?
My interim solution is keeping an import gtk\ngtk. in a clipboard manager and dropping it in when I need hints.

Yes, there is!
You should add gi to the forced builtins and you'll get a code completion:
Go to the Window->Preferences, PyDev->Interpreter python section and add gi to the "Forced builtin" tab for each interpreter you would like to use Gtk3.
More about this:
http://pydev.org/manual_101_interpreter.html

from gi.repository import Gtk
is not same like
import gtk
With the statement "
from gi.repository import Gtk
your are importing Gtk 3. With
import gtk
your are importing Gtk 2.
I would say that you code completion doesn't know Gtk 3.
maybe useful:
Tutorial for Gtk 3 http://readthedocs.org/docs/python-gtk-3-tutorial/en/latest/index.html
http://live.gnome.org/PyGObject

Related

GTK module not found in Python (PyCharm)

How can I avoid the following error:
GTK module not found in Python (PyCharm), please see the snippet below.
This answer hasn't helped.
(Still cannot find gtk in pip.)
if you are using pyhon 3.0+ then import this library like this: from gi.repository import Gtk

Error: no module named gtk.glade

I researched and tried this for two days now and I cannot get gtk to work on Windows 7 with Python 3.4! Whenever I launch my .py file on Python 3.4 with import gtk, I get No module named gtk! I installed pygobject but it did not help. Even gtk3-demo command works in the windows cmd prompt.
I finally got gtk to import (I think) by copying the GTK directory right to C:\Python34\Lib. But now I have a problem with gtk.glade.
Where is this? Where do I copy it from and to where?
You are possibly using an outdated tutorial, see the current Python GTK 3 tutorial for a more up-to-date reference.
In particular, the way to import GTK has changed in GTK3 to:
from gi.repository import Gtk
And instead of libglade, you would use the newer Gtk.Builder class like so:
ui = Gtk.Builder()
ui.add_from_file("my_glade_file.glade")
(you still develop the UI using Glade, it is only how you access it from your program that has changed).

Gtk object has no attribute 'ICON_SIZE_BUTTON'

I'm nearly new to python and new to gtk.
I just can't figure out, why I get this error message:
self.builder.get_object("checkstatus").set_from_stock("gtk-yes", Gtk.ICON_SIZE_BUTTON)
.......
AttributeError: 'gi.repository.Gtk' object has no attribute 'ICON_SIZE_BUTTON'
At the beginning I'm importing:
import pygtk
pygtk.require('2.0')
from gi.repository import Gtk
So the problem is that gtk has no no attribute called 'ICON_SIZE_BUTTON'?
But when I look at the documentation it says so...
http://developer.gnome.org/pygtk/2.22/class-gtkimage.html#method-gtkimage--set-from-stock
I would appreciate any help. Thanks!
Well, there's a few things going on.
For GTK+ 3 which uses PyGObject, you use from gi.repository import Gtk and then use Gtk.IconSize.BUTTON.
For GTK+ 2 which uses PyGTK you use import pygtk and import gtk and then use gtk.ICON_SIZE_BUTTON.
In other words, you're mixing up versions. PyGTK (GTK 2) was replaced by PyGObject and something called "gobject introspection" in GTK 3. Check out this tutorial: http://python-gtk-3-tutorial.readthedocs.org/en/latest/index.html

Understanding gi.repository

I have troubles understanding gi.repository
I use this contruction in my code
from gi.repository import Gtk
But if I want to use some component I get import error
I searched and I got it worked for some components, like GtkSource, Vte, GLib, ...
So my code is like
from gi.repository import Gtk, GtkSource, Vte, GLib
Everything worked fine, but if I want to add matplotlib to draw on my canvas I get and error
enter code/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: specified class size for type `PyGtkGenericCellRenderer' is smaller than the parent type's `GtkCellRenderer' class size
from gtk import _gtk
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: assertion `node != NULL' failed
from gtk import _gtk
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_ascii_strncasecmp: assertion `s2 != NULL' failed
from gtk import _gtk
Segmentation fault (core dumped) here
How can I get matplotlib working with gi.repository?
Thank you
It seems that the support for Gtk3 it's been added recently. I guess it will take some time till it's available in the main distributions.
The best solution would be to download and install the latest version.
As a workaround to avoid installing stuff in my Ubuntu 11.10 I have dowloaded backend_gtk3.py and backend_gtk3agg.py files and imported directly like:
from gi.repository import Gtk
from matplotlib.figure import Figure
from backend_gtk3agg import FigureCanvasGTK3Agg as FigCanvas
I had to change backend_gtk3agg.py line 6 where it says:
import backend_agg
with
from matplotlib.backends import backend_agg
, so it can import the module from my installation.
So far it works for me, but I understand this solution can't work with different versions of matplotlib.
That's a very good question. I'm afraid the answer might be "you can't." Matplotlib's GTK backend is written for PyGTK, the old-style Python bindings for GTK. The gi.repository package is the new-style Python bindings. I don't know one way or the other whether they can mix or not, but your results seem to indicate they can't.

Problems importing GDK

I am trying to import GDK to my program however I continue to get an error
No module named GDK
Do you know how I can fix this? Since it was working before I already tried import gtk.GDK
and import GDK.
I have installed PyGTK and PyGDK is part of of it pyGTK.
Try:
import gtk.gdk
(note: small letters)

Categories