[pygtk] use of modify_bg locking up program
Saftoiu, Claudiu
Claudiu_Saftoiu at brown.edu
Fri Mar 28 08:13:18 WST 2008
Hello everyone,
So, I created a widget for the purpose of having another widget inside with a background color. The code looks
like this:
class ColorBin(gtk.EventBox):
def __init__(self, widget, color):
gtk.EventBox.__init__(self)
self.widget = widget
self.add(widget)
self.modify_bg(gtk.STATE_NORMAL, color)
def changecol(self, color):
self.modify_bg(gtk.STATE_NORMAL, color)
I use it in various places in my code. Up till now, all I was doing was creating a window and adding some
ColorBins with Labels in them to the window. This displayed fine, and the program worked normally.
Recently however, I started needing to change the color of a ColorBin once it had already been created.
Something like this happens:
...
def __init__(self):
#...
self.cbin = ColorBin(gtk.Label("Hiya"), gtk.gdk.Color(30000, 30000, 30000))
somecontainer.pack_start(self.cbin)
def update(self):
#called 5 seconds later
self.cbin.changecol(gtk.gdk.Color(65535, 0, 0))
When update is called, the program freezes. I'm sure it's modify_bg, because I ran the code with the
ColorBin class looking like this:
def changecol(self, color):
pass #self.modify_bg(gtk.STATE_NORMAL, color)
And it worked, but when I ran the same code only changing that one line back to normal, it froze.
Am I supposed to do something like gtk.gdk.window_process_all_events() before modifying the bg some
way like this? Note also that my example is a bit more complicated than as above:
- I have another widget, a LabelGridWidget, which is a Table of ColorBins. I'm modifying the
color of one of these cells. Should I do something hide_all() / show_all() before changing a color?
(I tried it and it had no effect, but I was just trying things randomly at this point)
Note also that changing the text without the color of a colorbin with a label in it works just fine.
Thanks in advance for any help,
- Claudiu
More information about the pygtk
mailing list