Re: [pygtk] style question again
On Thu, Mar 02, 2000 at 10:47:06AM +0100, Javi Roman wrote: > I have: > > ... > style = self.window.get_style ().copy () > style.bg[STATE_NORMAL] = style.black > self.window.set_style (style) > ... > > This works correctly, but i want a red background color, and i try: > > ... > style.bg[STATE_NORMAL] = style.red > ... > > This fail. I think that i don't understand very well. Can anybody help > me? > > Side issue: Suggestion to James: make the GDK colormap allocation function accept floating point values from 0 to 1 as well as 16-bit integers. Or does it do this already? The "bg" element is an "array" of five GDKcolors, which have to be allocated. (style.black is a provided constant, but there is no style.red.) GDKcolors, in turn, are created per X-window (blargh) from three 16-bit RGB values. # set the background style red = (1,0,0) for i in range(5): style.bg[i] = _alloc_color (o.window, red) # Allocate a GDKcolor from RGB values expressed as numbers # from 0 to 1.0 def _alloc_color (widget, RGB): RGB48 = map (lambda f: f * ((1<<16) - 1), RGB) return apply (widget.get_colormap().alloc, RGB48) Suggestion to James: provide a variant of alloc() which will accept floating point values in the interval [0, 1.0] directly. -- Randolph To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
Re: [pygtk] style question again
There isn't a style.red attribute. To create the colour red in the colormap used by the widget, use one of the following: red = widget.get_colormap().alloc('red') red = widget.get_colormap().alloc('#ff') red = widget.get_colormap().alloc(0x, 0, 0) All these forms are equivalent (the last is a little bit faster, but the first allows the system administrator to redefine red to something else in /usr/lib/X11/rgb.txt :) James. -- Email: [EMAIL PROTECTED] WWW: http://www.daa.com.au/~james/ On Thu, 2 Mar 2000, Javi Roman wrote: > I have: > > ... > style = self.window.get_style ().copy () > style.bg[STATE_NORMAL] = style.black > self.window.set_style (style) > ... > > This works correctly, but i want a red background color, and i try: > > ... > style.bg[STATE_NORMAL] = style.red > ... > > This fail. I think that i don't understand very well. Can anybody help > me? > > > Regards. > To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED] > To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
[pygtk] style question again
I have: ... style = self.window.get_style ().copy () style.bg[STATE_NORMAL] = style.black self.window.set_style (style) ... This works correctly, but i want a red background color, and i try: ... style.bg[STATE_NORMAL] = style.red ... This fail. I think that i don't understand very well. Can anybody help me? Regards. To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]