Is Wxpython Progressdialog Cancel Event Possible?
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
Solution 1:
You could do this by defining a custom Dialog instead of the stock ProgressDialog:
classMyProgressDialog(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()
defOnClose(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.
Solution 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
Post a Comment for "Is Wxpython Progressdialog Cancel Event Possible?"