Py_GTK and Python
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:
I have been following this tutorial:
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:
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
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
hello_world_string = "Hello "
hello_world_string = hello_world_string + user_name + '\n'
Then the file:
ubuntudevelop@UbuntuNetbook:~/python_work$ cat hello_world.py
username = "Ubuntu"
Finally the command:
ubuntudevelop@UbuntuNetbook:~/python_work$ python hello_world.py
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:
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:
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.
You're right on the money- some python extensions are not written in python. When you import them, you're importing a dynamically loaded module, essentially a C library, that implements an interface that the interpreter knows how to use.
I think that the core modules like sys are linked into the interpreter, I've never actually looked for them, but I suspect that even if you find where the symbols live, it'd be a little difficult to read. Since the module docs are pretty good, everything you'll need would be at:
one thing you can do if you're curious is to run the interpreter (just run python with no arguments or scripts)
calling dir() on a module name will give you a directory of the things that are exported by the module. Theres no documentation per se, but often times just seeing the names of the functions is helpful to give you some distinct terms to google for.
Using Python import whatever, dir(whatever)
Thank you for your response. Running the python dir(gtk) gave me an eyeful. I noticed you have been thanked 18 times. I wanted to add to the count, but didn't see the field to do this. I did flag your response as helpful.
When I do a cd to
/usr/lib/python-support/python-gtk2/python2.6/gtk-2.0, then ls -ld, I see a file gtkunixprint.so.
Following your directions, replacing whatever with gtkunixprint I get the following.
['PRINT_CAPABILITY_COLLATE', 'PRINT_CAPABILITY_COPIES', 'PRINT_CAPABILITY_GENERATE_PDF', 'PRINT_CAPABILITY_GENERATE_PS', 'PRINT_CAPABILITY_NUMBER_UP', 'PRINT_CAPABILITY_NUMBER_UP_LAYOUT', 'PRINT_CAPABILITY_PAGE_SET', 'PRINT_CAPABILITY_PREVIEW', 'PRINT_CAPABILITY_REVERSE', 'PRINT_CAPABILITY_SCALE', 'PageSetupUnixDialog', 'PrintCapabilities', 'PrintJob', 'PrintUnixDialog', 'Printer', '__doc__', '__file__', '__name__', '__package__', '__version__', 'enumerate_printers']
I can see that this will be very helpful.
|All times are GMT -5. The time now is 11:48 AM.|