Reputation: 1661
I am struggling to get a gauge bar to pulse while a subprocess runs so I have gone back to basics and got this basic code which still does not work
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.gauge = wx.Gauge(panel, -1, 50, (20, 50), (250, 25))
self.gauge.Pulse()
app = wx.PySimpleApp()
GaugeFrame().Show()
app.MainLoop()
I have tried the wxpython examples which shows two gauges one uses a wx.Timer and the other is set to pulse. When I remove the timer the gauge which is set to pulse stops working.
Therefore, i can only think that a gauge even set to pulse needs to have a timer.
is this correct?
I have tried adding
self.gauge.Refresh()
and
self.gauge.Refresh(True)
but neither seems to help
Anyone know of a solution
thanks
Upvotes: 1
Views: 1564
Reputation: 7423
From the Gauge document, You are required to call it periodically after making some progress. You have to call it again and again to show progress, Pulse is used for indeterminate mode but you can move a bit to indicate the user that some progress has been made.
But if you just want to fool around the progress then yes you should bind it to timer. Just calling it in init doesn't make any sense.
I have modified example demo code just to fool around, you can bind it to your sub-process and set some checkpoints and increase/decrease the gauge speed if you really want to run it in indeterminate mode.
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.fool = 0
self.gspeed = 200
self.gauge = wx.Gauge(panel, -1, 50, (20, 50), (250, 25))
self.timer = wx.Timer(self)
self.timer.Start(self.gspeed)
self.Bind(wx.EVT_TIMER, self.TimerHandler)
def __del__(self):
self.timer.Stop()
def TimerHandler(self, event):
self.fool = self.fool+1
if self.fool == 20:
self.fool = 0
self.gspeed = self.gspeed - 20
if self.gspeed <= 0:
self.timer.Stop()
self.ShowMessage()
self.Close()
else:
self.timer.Start(self.gspeed)
self.gauge.Pulse()
def ShowMessage(self):
wx.MessageBox('Loading Completed', 'Info', wx.OK | wx.ICON_INFORMATION)
app = wx.PySimpleApp()
GaugeFrame().Show()
app.MainLoop()
Upvotes: 2