After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 604790 - Unable to set a GC's foreground colour
Unable to set a GC's foreground colour
Status: RESOLVED NOTABUG
Product: pygtk
Classification: Bindings
Component: gdk
2.16.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2009-12-17 01:48 UTC by Chris Le Sueur
Modified: 2009-12-27 09:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Testcase for setting the foreground colour of a GC (821 bytes, text/x-python)
2009-12-26 14:21 UTC, Chris Le Sueur
Details

Description Chris Le Sueur 2009-12-17 01:48:13 UTC
I cannot set the foreground colour of a graphics context, nor modify any of its RGB values. This is corroborated in this Stack Overflow post: http://stackoverflow.com/questions/938921/pygtk-graphics-contexts-and-allocating-colors

My code snippet to reproduce:

grey = gtk.gdk.Color('gray')

drawable.get_colormap().alloc_color(grey)
gc = drawable.new_gc()

print "Before", repr(gc.foreground)
gc.foreground = grey
print "Assignment", repr(grey)
print "After", repr(gc.foreground)

print "Blue value before", gc.foreground.blue
gc.foreground.blue = 65535
print "Blue value after", gc.foreground.blue


## Produces:

Before gtk.gdk.Color('#dff400a4dff4')
Assignment gtk.gdk.Color('#bebebe')
After gtk.gdk.Color('#04c000250001')
Blue value before 1
Blue value after 1

Note that the colour changes, but not in such a way as to be useful.
The properties are listed as read-write, and so I would expect them to by updated when I try to set them. The corresponding method set_foreground() has the same effect.
Attempting to allocate the colour (as shown above) has no influence on the result.
Comment 1 Gian Mario Tagliaretti 2009-12-25 20:05:10 UTC
Can you post a complete (minimal) working example showing the problem? thanks
Comment 2 Chris Le Sueur 2009-12-26 14:21:43 UTC
Created attachment 150406 [details]
Testcase for setting the foreground colour of a GC
Comment 3 John Finlay 2009-12-27 09:19:16 UTC
This is not a bug.

The basic problem with the test case is that it doesn't capture the allocated color from the call to self.window.get_colormap().alloc_color(grey) so when the unallocated color grey is used it of course doesn't fill the drawing area with the right color.

The important attribute of an allocated color is the pixel value. If you assign a new value to any of the red, green or blue attributes of an allocated gtk.gdk.Color the color is not changed because the pixel value is unchanged.

When a gtk.gdk.GC retrieves one of its color attributes (e.g. foreground) only the pixel attribute is set; the red, green and blue attributes are not set.

To fix the test case assign the return value from self.window.get_colormap().alloc_color(grey) to 'grey'.