wxGauge while processing data

Hello,

My program allow user to open file, but this opening contains lot of processing and it takes some time. I would like to create and show small frame with gauge while program process data from file.

I wrote small class for gauge (using wxPython demo, it's great btw .)):

class FileOpenGauge(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, title="Analyzing..", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE)
               panel = wx.Panel(self, wx.ID_ANY)
               self.g1 = wx.Gauge(panel, wx.ID_ANY, 50, (110, 50), (250, 25))
        self.Bind(wx.EVT_TIMER, self.TimeHandler)
               self.timer = wx.Timer(self)
        self.timer.Start(100)
               self.Show(True)
           def __del__(self):
        self.timer.Stop()
           def TimeHandler(self, event):
        self.g1.Pulse()

and then i tried to create this gauge before calling method which process data. But nothing appears. Then i realized that i need threads maybe and tried something like this:
http://wiki.wxpython.org/LongRunningTasks (thread example) but i can't make it works.

So, is there some easy way to do this? Do i need threads? I will appreciate any help, because i'm in hurry.
Thank you in advice.

···

--
Gabriel

Gabriel wrote:

Hello,

My program allow user to open file, but this opening contains lot of processing and it takes some time. I would like to create and show small frame with gauge while program process data from file.

I wrote small class for gauge (using wxPython demo, it's great btw .)):

class FileOpenGauge(wx.Frame):
   def __init__(self, parent):
       wx.Frame.__init__(self, parent, title="Analyzing..", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE)
             panel = wx.Panel(self, wx.ID_ANY)
             self.g1 = wx.Gauge(panel, wx.ID_ANY, 50, (110, 50), (250, 25))
       self.Bind(wx.EVT_TIMER, self.TimeHandler)
             self.timer = wx.Timer(self)
       self.timer.Start(100)
             self.Show(True)
         def __del__(self):
       self.timer.Stop()
         def TimeHandler(self, event):
       self.g1.Pulse()

and then i tried to create this gauge before calling method which process data. But nothing appears. Then i realized that i need threads maybe and tried something like this:
LongRunningTasks - wxPyWiki (thread example) but i can't make it works.

So, is there some easy way to do this? Do i need threads? I will appreciate any help, because i'm in hurry.
Thank you in advice.

I answered a similar question before, hopefully my answer should be relevant here:
http://www.nabble.com/Showing-a-Gauge-for-a-system-call-of-unknown-time-td21926900.html#a21926900

It makes use of wx.Process to first create and show the gauge, and execute the command, then the notify event it sends when the command is completed is handled to destroy the gauge...quite simple overall!

Gabriel wrote:

Hello,

My program allow user to open file, but this opening contains lot of processing and it takes some time. I would like to create and show small frame with gauge while program process data from file.

I wrote small class for gauge (using wxPython demo, it's great btw .)):

class FileOpenGauge(wx.Frame):
   def __init__(self, parent):
       wx.Frame.__init__(self, parent, title="Analyzing..", pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE)
             panel = wx.Panel(self, wx.ID_ANY)
             self.g1 = wx.Gauge(panel, wx.ID_ANY, 50, (110, 50), (250, 25))
       self.Bind(wx.EVT_TIMER, self.TimeHandler)
             self.timer = wx.Timer(self)
       self.timer.Start(100)
             self.Show(True)
         def __del__(self):
       self.timer.Stop()
         def TimeHandler(self, event):
       self.g1.Pulse()

Have you looked at wx.ProgressDialog?

and then i tried to create this gauge before calling method which process data. But nothing appears.

Because the event loop is blocked so there are no paint events, no timer events, etc.

Then i realized that i need threads maybe and tried something like this:
LongRunningTasks - wxPyWiki (thread example) but i can't make it works.

You should also read Non-Blocking Gui - wxPyWiki

So, is there some easy way to do this? Do i need threads?

Maybe. It depends on what your long running task is doing and whether it can be reorganized to be performed in small chunks of if it must be one contiguous process.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!