I apologise if this question is answered elsewhere, but I've spent a lot of time searching without hitting the right place, so I'm asking someone's indulgence for "not reading the manual".
Here is a little background.
This is an Acer Aspire netbook with Ubuntu 9.04.
I noticed that Python is a language that is available on a number of platforms. I was also impressed with GTK that came with Gimp when I installed it on a windows machine years ago.
Trying to find a gui interface for Python, there appeared to be two good candidates. Py_QT and Py_GTK. I was able to install the IDE for Py_QT, but ran into problems when trying to run stuff. However Py_GTK seemed to install with no problem, and I have been able to follow the tutorial with no trouble.
When I did the aptitude search for gtk, I found the following:
i python-gtk2 - Python bindings for the GTK+ widget set
p python-gtk2-dbg - Python bindings for the GTK+ widget set (d
p python-gtk2-dev - GTK+ bindings: devel files
i python-gtk2-doc - Python bindings for the GTK+ widget set -
i python-gtk2-tutorial - tutorial for the GTK2 python library
After installing, I have for example the following directory:
file:///usr/share/gtk-doc/html/pygtk/gtk-class-reference.html
I have been following this tutorial:
http://zetcode.com/tutorials/pygtktutorial/
Aside from having to provide a few of my own .jpg images, all the examples seem to work.
All the examples have the following lines:
#!/usr/bin/python
import gtk
If I cd to the /usr/bin directory, I can find python with no problem.
ubuntudevelop@UbuntuNetbook:~$ cd /usr/bin
ubuntudevelop@UbuntuNetbook:/usr/bin$ ls -ld python
lrwxrwxrwx 1 root root 9 2009-08-22 23:04 python -> python2.6
ubuntudevelop@UbuntuNetbook:/usr/bin$
Now, running a small python script in the shell, when you import,
the .py at the end of the import is normally implied. For example I have the following module:
ubuntudevelop@UbuntuNetbook:~/python_work$ cat first_python_module.py
# first python module
def print_hello_world_name(user_name):
hello_world_string = "Hello "
hello_world_string = hello_world_string + user_name + '\n'
print hello_world_string
Then the file:
ubuntudevelop@UbuntuNetbook:~/python_work$ cat hello_world.py
import first_python_module
username = "Ubuntu"
first_python_module.print_hello_world_name(username)
ubuntudevelop@UbuntuNetbook:~/python_work$
Finally the command:
ubuntudevelop@UbuntuNetbook:~/python_work$ python hello_world.py
Hello Ubuntu
ubuntudevelop@UbuntuNetbook:~/python_work$
--------------------------------------------------
So, now to my questions. I know I can read the reference documentation on classes. One of the things GTK has are pre-defined STOCK items. For example there is a STOCK_QUIT.
Now I may be making an erroneous assumption, but if I have a statement:
import gtk, somewhere on my system there should be a gtk.py. I would like to simply look at this file to see what is in it. However when I do a find . -name gtk.py -print, I get no results. (I su to root, so there are no hidden directories.)
If I simply search for gtk, I get lots of hits. Most of them are directories. For example there is a file:
/usr/lib/python-support/python-gtk2/python2.6/gtk-2.0/gtk/_gtk.so
This is not a text file, but a binary shared object file. Is this the file that gets imported?
Some of the examples also use:
import sys
Where is the sys that is imported?
Is there an envrionment variable or a config file that tells python where to find these files? If so, where are these? Or does it simply have a standard location for putting these files?
After I get things working here, undoubtedly I will have similar questions about python and gtk on Macs and Windows XP. It would be awfully nice to be able to write a piece of code and have it work regardless of the machine it runs on.
Thank you in advance for your patience and assistance.
Sam