[pygtk] Formatting a spinbutton's display
Tim Evans
t.evans at aranz.com
Wed Jul 30 14:51:04 WST 2008
Jeremy S wrote:
> I would like to use a spinbutton but instead of just displaying a
> float or integer, I want the display to be formatted. In my case I
> want it to be formatted as currency ($ in front and commas separating
> thousands, millions, etc.), but I can't even find any information on
> how to tackle this problem generally.
>
> I know for treeviews this type of thing can be accomplished with
> set_cell_data_func. Is there anything similar for spinbuttons?
The "input" and "output" signals on the spinbutton solve this problem.
Using the "input" signal is rather complex however because the second
argument is a C pointer to a double and not a python type. To make it
worse, it's passed as an opaque "gpointer" type. I found (by looking at
the pygtk source code) that I could access the real address from it
using the "hash" function, and once I had that I could use ctypes to set
the double it points to.
Attached an ugly hack that solves your problem. Thanks for posting btw,
this was fun ;)
--
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: spin_input_output.py
Url: http://www.daa.com.au/pipermail/pygtk/attachments/20080730/a5822192/attachment.txt
More information about the pygtk
mailing list