gauge (or a progress bar) for a long running process

Hi, I'm following the example below to get a gauge (or it can be a
progress bar in the future) that will develop while a third party
python program runs. However, I do not get how to call my third party
program in that example and how to stop the gauge one the process
stop.

This is my program so far:
http://code.google.com/p/ccc-gistemp/source/browse/branches/2011-05-18/gsoc/gui/run_gui.py

And this is the example I'm following:

# gauge.py
# Updated to follow style guidelines

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title)

        self.timer = wx.Timer(self, 1)
        self.count = 0

        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)

        panel = wx.Panel(self, -1)
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        hbox3 = wx.BoxSizer(wx.HORIZONTAL)

        self.gauge = wx.Gauge(panel, -1, 50, size=(250, 25))
        self.btn1 = wx.Button(panel, wx.ID_OK)
        self.btn2 = wx.Button(panel, wx.ID_STOP)
        self.text = wx.StaticText(panel, -1, "Task to be done")

        self.Bind(wx.EVT_BUTTON, self.OnOk, self.btn1)
        self.Bind(wx.EVT_BUTTON, self.OnStop, self.btn2)

        hbox1.Add(self.gauge, 1, wx.ALIGN_CENTRE)
        hbox2.Add(self.btn1, 1, wx.RIGHT, 10)
        hbox2.Add(self.btn2, 1)
        hbox3.Add(self.text, 1)
        vbox.Add((0, 50), 0)
        vbox.Add(hbox1, 0, wx.ALIGN_CENTRE)
        vbox.Add((0, 30), 0)
        vbox.Add(hbox2, 1, wx.ALIGN_CENTRE)
        vbox.Add(hbox3, 1, wx.ALIGN_CENTRE)

        panel.SetSizer(vbox)
        self.Centre()

    def OnOk(self, event):
        if self.count >= 50:
            return
        self.timer.Start(100)
        self.text.SetLabel("Task in Progress")

    def OnStop(self, event):
        if self.count == 0 or self.count >= 50 or not self.timer.IsRunning():
            return
        self.timer.Stop()
        self.text.SetLabel("Task Interrupted")
        wx.Bell()

    def OnTimer(self, event):
        self.count = self.count +1
        self.gauge.SetValue(self.count)
        if self.count == 50:
            self.timer.Stop()
            self.text.SetLabel("Task Completed")

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "gauge.py")
        frame.Show(True)
        return True

app = MyApp(0)
app.MainLoop()

Thanks for the attention, Filipe

If you use wx.Execute and wx.Process then you can get an event when the child process terminates, and you can clean up the gauge and whatever else you need to do at that point. If you use some other way to launch the child process (such as with the subprocess module in the Python library) then you can use a timer to periodically check if the process has terminated and then do your end of process code there if it has terminated.

···

On 7/7/11 2:42 PM, Filipe Pires Alvarenga Fernandes wrote:

Hi, I'm following the example below to get a gauge (or it can be a
progress bar in the future) that will develop while a third party
python program runs. However, I do not get how to call my third party
program in that example and how to stop the gauge one the process
stop.

--
Robin Dunn
Software Craftsman