I wrote:
I am now porting the PyUnit GUI from TkInter to wxPython, and have
encountered a small problem. The standard behaviour for any xUnit GUI is
for the progress bar that shows the tests being run to start off green,
then change to red as soon as a test fails. I am using a wxGauge for the
progress bar, but I can't find a way of changing the colour of the bar. I
have tried SetForegroundColour and SetBackgroundColour, but the bar stays
resolutely green.Is there any way to change the colour of the progress bar, or is this not
implemented in wxPython?BTW, I am using wxPython 2.4.0.7 on Python 2.2.2 and Windows XP.
I have investigated a little further, and it looks like the wxGauge control has become broken between 2.4.0.6 and 2.4.0.7. I modified the wxGauge demo code to show the desired behaviour (see code below), and it works fine on 2.4.0.6 but not on 2.4.0.7 or 2.4.1.2.
Also, the wxGA_SMOOTH flag doesn't work either, as can be seen from the regular demo - it should have one blocky bar and one smooth bar, but instead it has two blocky bars.
Another possibility has occurred to me - I was running the 2.4.0.6 version on an NT machine and the others on XP, so perhaps the difference is in the native control on the two platforms, rather than between versions of wxPython.
Here is the modified demo code:
#---------------------------------- 8<
···
--------------------------------------------------------
from wxPython.wx import *
class TestPanel(wxPanel):
def __init__(self, parent, log):
wxPanel.__init__(self, parent, -1)
self.log = log
self.count = 0
wxStaticText(self, -1, "This example shows the wxGauge control.",
wxPoint(45, 15))
self.g1 = wxGauge(self, -1, 50, wxPoint(110, 50), wxSize(250, 25))
self.g1.SetBezelFace(3)
self.g1.SetShadowWidth(3)
self.g2 = wxGauge(self, -1, 50, wxPoint(110, 95), wxSize(250, 25),
wxGA_HORIZONTAL|wxGA_SMOOTH)
self.g2.SetBezelFace(5)
self.g2.SetShadowWidth(5)
self.g2.SetForegroundColour(wxGREEN)
EVT_IDLE(self, self.IdleHandler)
def IdleHandler(self, event):
self.count = self.count + 1
if self.count >= 50:
self.count = 0
self.g2.SetForegroundColour(wxGREEN)
self.g1.SetValue(self.count)
self.g2.SetValue(self.count)
if self.count >= 25:
self.g2.SetForegroundColour(wxRED)
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
overview = """\
"""
#----------------------------------------------------------------------
Dave Kirby - The Developers' Coach
Helping software professionals and teams achieve peak performance
email: dave@thedeveloperscoach.com
UK Phone: 020 8376 2274
International Phone: (+44) 20 8376 2274
web: http://www.thedeveloperscoach.com - sign up for my new free eZine, The Agile Life