Main index > Python programming > Is it possible to use PyGTK within a desklet program?

By darkliquid (Desklet Author), on Mon Mar 21 13:08:55 2005: Is it possible to use PyGTK within a desklet program?.

For my Calendar desklet, i've been deveoping the ability to add todos, reminders, etc to dates on the calendar by clicking on the coressponding cells. However, to actually add the data, I need some kind of input dialogue box, which is what I've been trying to do in PyGTK.

I've been trying for a while now to be able to create a GTK text entry box, a little panel that has a save and cancel button and a text edit widget that contains the current text for that date. When either button is pressed, the box should close, returning the new text for saving. However, I must be doing something wrong.

While I can get a dialogue box up and running, using the buttons locks up the program. Closing the window does not. Also, I tried using the self.block self.unblock around the event section that triggers the dialogues popping up but it seems to work a little strange. Instead of throwing away the clicks, it seems to queue them, opening multiple dialogues once the initial one closes. This locks up the desklet as well.

Essentially, the desklet grabs an event and the relevent data, ie:
Gets date from click position
Checks todo/reminder file for an entry for that date
Blocks events
Passes date and entry text to PyGTK dialogue
Dialogue processes data, returns it if changed
Saves data back into todo/reminder file
Unblocks events

So, is it really possible to use PyGTK within a desklet without breaking things badly, or is it just me? :P

By syfou (Core Developer & Desklet Author), on Mon Mar 21 13:55:50 2005.

I never tried using PyGTK myself. Theorically, it shouldn't have any counter indication using along adesklets, the dependency bug aside, but the behavior you report certainly seems abnormal, so I wouldn't bet on it - but maybe someone will know better. Talking of dependencies, here is what PyGTK needs to be installed on the test system described here:

Code:


# emerge -ptv pygtk

These are the packages that I would merge, in reverse order:

Calculating dependencies ...done!
[ebuild  N    ] dev-python/pygtk-2.4.1  -debug -doc -gnome +opengl 697 kB 
[ebuild  N    ]  x11-libs/gtkglarea-1.99.0  -debug 205 kB 
[ebuild  N    ]  dev-python/pyopengl-2.0.0.44  1,251 kB 
[ebuild  N    ]   media-libs/glut-3.7.1  2,479 kB 
[ebuild  N    ]  x11-libs/gtk+-2.6.2  -debug -doc -jpeg -static -tiff 10,969 kB 
[ebuild  N    ]   x11-misc/shared-mime-info-0.14-r2  347 kB 
[ebuild  N    ]    dev-libs/libxml2-2.6.16  -debug -ipv6 +python +readline 3,027 kB 
[ebuild  N    ]    dev-util/intltool-0.31.2  121 kB 
[ebuild  N    ]     dev-perl/XML-Parser-2.34  224 kB 
[ebuild  N    ]   x11-libs/pango-1.8.1  -debug -doc -static 973 kB 
[ebuild  N    ]   dev-libs/atk-1.8.0  -debug -doc 488 kB 
[ebuild  N    ]   dev-libs/glib-2.6.2-r1  -debug -doc 2,288 kB 
[ebuild  N    ]    dev-util/pkgconfig-0.15.0  596 kB 

Total size of downloads: 23,670 kB



Have you considered Tkinter?

Code:


# USE="tcltk" emerge -ptv python

These are the packages that I would merge, in reverse order:

Calculating dependencies ...done!
[ebuild   R   ] dev-lang/python-2.4-r2  +X -berkdb -bootstrap -build -debug -doc -gdbm -ipv6 +ncurses +readline +ssl +tcltk* -ucs2 7,656 kB 
[ebuild  N    ]  dev-lang/tk-8.4.6-r1  -threads 3,155 kB 
[ebuild  N    ]   dev-lang/tcl-8.4.6  -threads 3,367 kB 

Total size of downloads: 14,179 kB



It is not more complicated to use, and it's lighter dependency-wise. I tested it successsfully with adesklets python package; I will probaly include a demo in the test directory of adesklets package on next update.But personally, I would just go with dialog on a xterm, but I certainly do have a strange sense of aesthetic:

Code:


dialog --inputbox 'This is the label' 10 60 'This is the initial value'



dialog is about 200KB, and doesn't use anything not already needed by adesklets to compile.

By darkliquid (Desklet Author), on Mon Mar 21 14:57:22 2005.

I've been having a go at Tkinter, but then I discovered when I tested that I don't have Tkinter support in my python installation, so I'll rebuild sooner or later and give it a go.

I'd like to use PyGTK though because I want to learn it for use in other things, plus GTK widgets generally looks nicer than Tk widgets. I might do it in both so that people without PyGTK can use it. For now though, I'll have a go at hacking at Tkinter and I'll make a GTK version later if I can.

By syfou (Core Developer & Desklet Author), on Mon Mar 21 15:27:46 2005.

darkliquid wrote:


I'd like to use PyGTK though because I want to learn it for use in other things, plus GTK widgets generally looks nicer than Tk widgets. I might do it in both so that people without PyGTK can use it. For now though, I'll have a go at hacking at Tkinter and I'll make a GTK version later if I can.


That's a good point: I also like GTK look (although newer TK also look fairly native to me)... Of course, using it would mean that your desklet will likely not be as usable for users, due to the dependency burden. So, in the best of world, you should probably consider providing multiple interfaces: GTK+, TK, ncurses maybe., making everything optional. But I fully understand your need for this.


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.