How to close ProgressDialog.Pulse() modal after clicking cancel?

What are the recommended ways to close a ProgressDialog.Pulse() modal after clicking “cancel”?
http://www.wxpython.org/docs/api/wx.ProgressDialog-class.html

http://docs.wxwidgets.org/trunk/classwx_generic_progress_dialog.html#ab5ecf227eebaa1aadb5f5c553e4a4ee5

I tried adding the following code to the end of my onButton method but my gauge did not animate.

while True:

wx.MilliSleep(200)

if (self.dlg.Update() == False):

break

self.dlg.Destroy

import wx

class MyFrame(wx.Frame):

def init(self, parent):

wx.Frame.init(self, parent)

class MyPanel(wx.Panel):

def init(self, parent):

wx.Panel.init(self, parent)

btn = wx.Button(self, -1, label=‘Click me’)

btn.Bind(wx.EVT_BUTTON, self.onButton)

box = wx.BoxSizer(wx.VERTICAL)

box.Add(btn)

self.SetSizer(box)

box.Fit(parent)

def onButton(self, evt):

self.dlg = wx.ProgressDialog(“Progress dialog example”,

“Processing request”,

parent=self,

style = wx.PD_CAN_ABORT | wx.PD_APP_MODAL

)

self.dlg.Pulse()

class MyApp(wx.App):

def init(self, redir):

wx.App.init(self, redir)

frame = MyFrame(None)

panel = MyPanel(frame)

frame.Show()

self.MainLoop()

app = MyApp(0)

I just wanted to comment in my below example code, when you click “cancel” the modal is not destroyed, the button is merely disabled. Is this the intended functionality?

How would I close the modal when someone clicks the “cancel” button?

···

On Saturday, November 23, 2013 6:32:51 AM UTC-5, RedHotChiliPepper wrote:

What are the recommended ways to close a ProgressDialog.Pulse() modal after clicking “cancel”?
http://www.wxpython.org/docs/api/wx.ProgressDialog-class.html

http://docs.wxwidgets.org/trunk/classwx_generic_progress_dialog.html#ab5ecf227eebaa1aadb5f5c553e4a4ee5

I tried adding the following code to the end of my onButton method but my gauge did not animate.

while True:

wx.MilliSleep(200)

if (self.dlg.Update() == False):

break

self.dlg.Destroy

import wx

class MyFrame(wx.Frame):

def init(self, parent):

wx.Frame.init(self, parent)

class MyPanel(wx.Panel):

def init(self, parent):

wx.Panel.init(self, parent)

btn = wx.Button(self, -1, label=‘Click me’)

btn.Bind(wx.EVT_BUTTON, self.onButton)

box = wx.BoxSizer(wx.VERTICAL)

box.Add(btn)

self.SetSizer(box)

box.Fit(parent)

def onButton(self, evt):

self.dlg = wx.ProgressDialog(“Progress dialog example”,

“Processing request”,

parent=self,

style = wx.PD_CAN_ABORT | wx.PD_APP_MODAL

)

self.dlg.Pulse()

class MyApp(wx.App):

def init(self, redir):

wx.App.init(self, redir)

frame = MyFrame(None)

panel = MyPanel(frame)

frame.Show()

self.MainLoop()

app = MyApp(0)

After looking at the wxpython demo i think the solution is:

def onButton(self, evt):

    self.dlg = wx.ProgressDialog("Progress dialog example",

                           "Processing request",

                           parent=self,

                           style = wx.PD_CAN_ABORT | wx.PD_APP_MODAL

                            )

    pulse = True

    while pulse:

        (pulse, skip) = self.dlg.Pulse()

    self.dlg.Destroy()

I’ve tested it with

  • Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32

  • wxPython 2.9.5.0 msw (classic)

Test_ProgressDialogPulse.py (1.02 KB)

Are you sure this is the correct answer? When I click the button that frame freezes and the button remains depressed down while the ProgressDialog animates.

···

On Saturday, November 23, 2013 12:27:17 PM UTC-5, Torsten wrote:

After looking at the wxpython demo i think the solution is:

def onButton(self, evt):
    self.dlg = wx.ProgressDialog("Progress dialog example",
                           "Processing request",
                           parent=self,
                           style = wx.PD_CAN_ABORT | wx.PD_APP_MODAL
                            )
    pulse = True
    while pulse:
        (pulse, skip) = self.dlg.Pulse()
    self.dlg.Destroy()

I’ve tested it with

  • Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
  • wxPython 2.9.5.0 msw (classic)

Maybe there’s another way, but on my system it works. In my previous post i attached the script that is working on my system (win7 64Bit, Python 32Bit, wxPython 2.9.5.0). I’ve attached a small recording of the running app.

Untitled.flv (467 KB)

Hi Torsten -

Thanks for all your help and especially the video. The code runs the same on my machine as well (win 7 64bit.) My only comment was that the “Click me” button is depressed while the modal is displayed. After you close the modal it is clickable again.

Just out of curiosity, isn’t it bad to have this infinite loop running from a system resource utilization perspective? I added a sleep function so that it loops every 1/5 of a second instead of tens of thousands of times per second.

wx.MilliSleep(200)

But I just wanted your take if that was even necessary.

···

On Saturday, November 23, 2013 5:25:29 PM UTC-5, Torsten wrote:

Maybe there’s another way, but on my system it works. In my previous post i attached the script that is working on my system (win7 64Bit, Python 32Bit, wxPython 2.9.5.0). I’ve attached a small recording of the running app.