views:

257

answers:

3

Pastebin link: http://pastebin.com/f40ae1bcf

The problem: I made a wx.Gauge, with the range of 50. Then a function that updates Gauge's value when the program is idle. When the gauge is filled by around 50% it empties and doesn't show anything for a while. The value is actually 50 when it does this, and I think that when the value is 50 it should be full.

Why does it do this? I also tried with a wx.Timer instead of binding to wx.EVT_IDLE but I didn't have luck.

A: 

Are you sure that the code you posted is the code that is giving you the problems? This code looks very similar to the demo code for wxPython, and works on my machine without problems.

If you did actually set your gauge's value to 50, that could be your issue. You have to be sure not to exceed that range of a wx.Gauge. If the range is 50, the highest value you can set in it will be 49.

Ryan Ginstrom
He loops back to 0 if it's >= 50, before setting the value. It tops out at 49...
FogleBird
I asked whether the posted code is the code terabytest is having problems with, because the posted code works, and terabytest mentions trying to plug "50" into the gauge value (which does cause problems).
Ryan Ginstrom
+1  A: 

A few things.

  • I can't reproduce this on my iMac, it goes all the way to full. Python 2.5.4, wxPython 2.8.9.2
  • Idle events can come at strange times. Try adding print event to your idle handler to see exactly when those events are coming. A timer would be best. Is the gauge moving really fast or flickering?
  • You can try calling gauge.Update() to force a complete redraw too.
  • I always just use 100 as my gauge limit, maybe just try that.

An easier way than a timer could be:

import wx

class GaugeFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Gauge example",
                          size=(350, 150))
        panel = wx.Panel(self, -1)
        self.count = 0
        self.gauge = wx.Gauge(panel, -1, 50, (20, 50), (250, 25))
        self.update_gauge()

    def update_gauge(self):
        self.count = self.count + 1
        if self.count >= 50:
            self.count = 0
        self.gauge.SetValue(self.count)
        wx.CallLater(100, self.update_gauge)

app = wx.PySimpleApp()
GaugeFrame().Show()
app.MainLoop()
FogleBird
A: 

After more tests I discovered that I must override the range of 2 units to display the gauge when completely full. On windows vista it seems not to cause problems. Does it cause problems on linux or mac?

Gabriele Cirulli