Skip to content Skip to sidebar Skip to footer

How To Set Cancel Button When You Press It In Pyprogress

Hello I use wxpython 4 and windows10.I want to integrate PyProgress (AGW) in my App with the Cancel button and I would like this button Cancel put my App Paused. except that I have

Solution 1:

PyProgress no longer appears to have an operational Cancel button. Use wx.ProgressDialog or wx.Gauge instead.

If you don't want a pause function use something like this:

import wx

classPyProgressDemo(wx.Frame):
    def__init__(self, parent):
        super().__init__(parent)

        self.panel = wx.Panel(self, -1)
        self.startbutton = wx.Button(self.panel, -1, "Start PyProgress!")
        self.startbutton.Bind(wx.EVT_BUTTON, self.onButton)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.startbutton)
        self.panel.SetSizer(vbox)
        self.Show()

    defonButton(self, event):
            self.dlg = wx.ProgressDialog('Search personal Data', 'Analyse en cours..', style= wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT)
            max = 400
            keepGoing = True
            count = 0while keepGoing and count < max:
                count += 1
                wx.MilliSleep(30)

                if count >= max / 2:
                    (keepGoing, skip) = self.dlg.Pulse("Half-time!")
                else:
                    (keepGoing, skip) = self.dlg.Pulse()

            self.dlg.Destroy()

app = wx.App()
prog = PyProgressDemo(None)
app.MainLoop()

If you want a Pause function, I think that you will have to use the Freeze option, something like this:

import wx

classPyProgressDemo(wx.Frame):
    def__init__(self, parent):
        super().__init__(parent)

        self.panel = wx.Panel(self, -1)
        self.startbutton = wx.Button(self.panel, -1, "Start PyProgress!")
        self.stopbutton = wx.Button(self.panel, -1, "Pause/Unpause PyProgress!")
        self.startbutton.Bind(wx.EVT_BUTTON, self.onButton)
        self.stopbutton.Bind(wx.EVT_BUTTON, self.onPause)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self.startbutton)
        vbox.Add(self.stopbutton)
        self.panel.SetSizer(vbox)
        self.Show()

    defonButton(self, event):
            self.dlg = wx.ProgressDialog('Search personal Data', 'Analyse en cours..', style= wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT)
            max = 400
            keepGoing = True
            count = 0try:
                while keepGoing and count < max:
                    if self.dlg.IsFrozen():
                        wx.Yield()
                        wx.MilliSleep(30)
                        continue
                    count += 1
                    wx.MilliSleep(30)

                    if count >= max / 2:
                        (keepGoing, skip) = self.dlg.Pulse("Half-time!")
                    else:
                        (keepGoing, skip) = self.dlg.Pulse()

                self.dlg.Destroy()
            except:
                passdefonPause(self, event):
        try:
            if self.dlg.IsFrozen():
                self.dlg.Thaw()
            else:
                self.dlg.Freeze()
        except:
            pass

app = wx.App()
prog = PyProgressDemo(None)
app.MainLoop()

Post a Comment for "How To Set Cancel Button When You Press It In Pyprogress"