1

if I declare wxProgressDialog with wxPD_CAN_ABORT, "Cancel" button will be provided in ProgressDialog. Normally, to know if user pressed "Cancel", wxProgressDialog::Update needs to be called.

Is there a way to get an event, if "Cancel" is pressed in wxProgressDialog?

2 Answers 2

2

You could do this by defining a custom Dialog instead of the stock ProgressDialog:

class MyProgressDialog(wx.Dialog):
    def __init__(self, parent, id, title, text=''):
        wx.Dialog.__init__(self, parent, id, title, size=(200,150), style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)

        self.text = wx.StaticText(self, -1, text)
        self.gauge = wx.Gauge(self, -1)
        self.closebutton = wx.Button(self, wx.ID_CLOSE)
        self.closebutton.Bind(wx.EVT_BUTTON, self.OnClose)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.text, 0 , wx.EXPAND)
        sizer.Add(self.gauge, 0, wx.ALIGN_CENTER)
        sizer.Add(self.closebutton, 0, wx.ALIGN_CENTER)

        self.SetSizer(sizer)
        self.Show()

    def OnClose(self, event):
        self.Destroy() 
        #can add stuff here to do in parent.

You can then do updates on the progress bar by calling MyProgressDialog.gauge.Update, and have your event bound to the close button.

1
  • ok, thanks, it works. I was hoping to use ProgressDialog, but I didn't know about gauge before.
    – bitman
    Commented May 6, 2011 at 18:06
2

Since version 2.9.1 of wx you can just use ProgressDialog.WasCancelled()

https://wxpython.org/Phoenix/docs/html/wx.GenericProgressDialog.html#wx-genericprogressdialog

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.