Last edition : 2009-10-05 21:57:54.532129
Grun stands for "GUI run'ner".
Grun is a python module helper to help you to build out some simple gtk app, by providing nice things to improve your scripts with GUI "bling bling".
It's clearly the easiest way to put some GUI things in your scripts/commands. It's a kind of gui framework. It provides :
All these things are available in a simple module, thru one magic method : grun() ! And better : it works on all platforms (windows, linux/bsd, mac) with its Tk backend. It uses pygtk if it's available.
Here we start ...
User forms (main feature)
grun is a magic method, and can act as a decorator too, to turn your methods into GUI forms.
A window, named "Ask Login" will appear. The login will be pre-filled with "marc". When the user hit "ok" button, you'll get back these datas.
Note that if you don't want to use decorators: you can do
Many things are done under the hood :
widgets are created according param's name or default value. Here's the rules :
the text "hello world" will be sended to notification system. Note that if pynotify is available, grun will use desktop notifications, else it will show a simple window during 2 seconds.
Just ends your string with "!".
A message box (of
Add a "?" at the end of the string, and it will turn it into a prompt box :
which will display a prompt box, letting you answer by ok or cancel. The grun method return a boolean.
By providing a generator to grun, it will display a 'progress window'. The generator should yield a float value between 0 and 1.
But the generator can provide a textual message too, like that :
This thing works only with pygtk. With Tk, it simulates a window application (see below) with given actions.
For setting your icon, see below.
A window application is a window with a button per action.
Just launch a popup menu providing actions :
But you can show up a popup of selectable values, like that :
the selected value will be returned by
And better, you can create submenu, by providing a tuple of 2 items : the first will be the label, the seconds a list.
It's a quick way to make a winform (useful for dynamic forms).
It's the simplest form ... But you can give more too (by providing default values) :
You can have access to your clipboar manager (text only). If you want to put some text in the clipboard :
If you want to retrieve the content text of the clipboard
You can delete it too :
It provides a simple way to store a config dict, for config or persistant datas. Grun called with nothing returns a dict-like, which can be saved with its
Some little things :
Providing a name for window's title
All windows use the name of the main script in their title. But you can override that by providing a global variable named
Providing an icon for windows/IconApp
You can provide an ICON too (to be displayed in window title or IconApp)
When you use pygtk, ICON can refer a gtk icon stock, or an image file.
When you use tk backend (when pygtk is not available), you can give an ICO file under windows, or a xpm file under linux (should be prefixed with '@' !). But, currently, it will not work under tk, and will be corrected soon.
Use pango markups
When using pygtk backend, you can you use Pango Markup Language.
Not available with Tk backend.
Get Help !
At anytime you can ask help ;-)
This call will print in
This call will print in a messagebox, the short help :
Grun is available on pypy, install it from a terminal with