The diary of a dedicated Ubuntu user that lucked into his dream job working on the Ubuntu team.

Friday, December 18, 2009

quidgets.prompts ... gtk.Dialogs now one-liners!

As I mentioned in a previous post, I became a tad enraged at PyGtk when I was providing some simple "get a value from a user code" to one of my bughugger collaborators. My response was to write a bit of code to provide a fun and easy way to get values from users, meet the quidgets.prompts namespace.

The essential patter is quite simple. All of the prompts showed above follow the same pattern. To use a prompt, simply:

Call the right function, such as quidgets.prompts.string()

Check the response from the function call to see if the user said "Ok" or not.

Note that the default value needs to be a type expected by the prompt. quidgets.prompts.date() expects the default value to be a three tuple in the form of year, month (zero indexed!), and day. So it might look like this:

Speaking of numeric prompts, as you can see, they use spinners to collect input from users. By default the spinners allow negative numbers. If you don't want to allow negative numbers, the numeric prompts have extended the arguments a bit so that you can set the minimum value to zero:

These guys seem ready to go. Next up, I'll be adding prompts to manage asynchronous activity. So that you can create a prompt to display while a long running computation is occurring without freezing the UI. Stay tuned.