在pyProgress中按下取消按钮时如何设置
how to set Cancel button when you press it in pyProgress
您好,我使用 wxpython 4
和 windows10
。我想将 PyProgress (AGW)
与 Cancel button
集成到我的应用程序中,我想要这个按钮 Cancel
把我的应用程序 Paused
。除了我添加了取消按钮但它不可点击并且我无法与该按钮绑定暂停功能。
import wx.lib.agw.pyprogress as PP
def onButton(self, event):
"""
Based on the wxPython demo by the same name
"""
event.Skip()
dlg = PP.PyProgress(None, -1, "Demo", "Demo in progress", agwStyle=wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT)
dlg.SetGaugeProportion(0.2)
dlg.SetGaugeSteps(50)
dlg.SetGaugeBackground(wx.WHITE)
dlg.SetFirstGradientColour(wx.WHITE)
dlg.SetSecondGradientColour(wx.BLUE)
max = 400
keepGoing = True
count = 0
while keepGoing and count < max:
count += 1
wx.MilliSleep(30)
if count >= max / 2:
keepGoing = dlg.UpdatePulse("Half-time!")
else:
keepGoing = dlg.UpdatePulse()
dlg.Destroy()
#if(wx.PD_CAN_ABORT):
#execute onPause(event)
def onPause(self, event):
???
PyProgress
似乎不再有可操作的 Cancel
按钮。
请改用 wx.ProgressDialog
或 wx.Gauge
。
如果您不想使用暂停功能,请使用如下方式:
import wx
class PyProgressDemo(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()
def onButton(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 = 0
while 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()
如果你想要一个 Pause
函数,我认为你必须使用 Freeze
选项,像这样:
import wx
class PyProgressDemo(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()
def onButton(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 = 0
try:
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:
pass
def onPause(self, event):
try:
if self.dlg.IsFrozen():
self.dlg.Thaw()
else:
self.dlg.Freeze()
except:
pass
app = wx.App()
prog = PyProgressDemo(None)
app.MainLoop()
您好,我使用 wxpython 4
和 windows10
。我想将 PyProgress (AGW)
与 Cancel button
集成到我的应用程序中,我想要这个按钮 Cancel
把我的应用程序 Paused
。除了我添加了取消按钮但它不可点击并且我无法与该按钮绑定暂停功能。
import wx.lib.agw.pyprogress as PP
def onButton(self, event):
"""
Based on the wxPython demo by the same name
"""
event.Skip()
dlg = PP.PyProgress(None, -1, "Demo", "Demo in progress", agwStyle=wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT)
dlg.SetGaugeProportion(0.2)
dlg.SetGaugeSteps(50)
dlg.SetGaugeBackground(wx.WHITE)
dlg.SetFirstGradientColour(wx.WHITE)
dlg.SetSecondGradientColour(wx.BLUE)
max = 400
keepGoing = True
count = 0
while keepGoing and count < max:
count += 1
wx.MilliSleep(30)
if count >= max / 2:
keepGoing = dlg.UpdatePulse("Half-time!")
else:
keepGoing = dlg.UpdatePulse()
dlg.Destroy()
#if(wx.PD_CAN_ABORT):
#execute onPause(event)
def onPause(self, event):
???
PyProgress
似乎不再有可操作的 Cancel
按钮。
请改用 wx.ProgressDialog
或 wx.Gauge
。
如果您不想使用暂停功能,请使用如下方式:
import wx
class PyProgressDemo(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()
def onButton(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 = 0
while 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()
如果你想要一个 Pause
函数,我认为你必须使用 Freeze
选项,像这样:
import wx
class PyProgressDemo(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()
def onButton(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 = 0
try:
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:
pass
def onPause(self, event):
try:
if self.dlg.IsFrozen():
self.dlg.Thaw()
else:
self.dlg.Freeze()
except:
pass
app = wx.App()
prog = PyProgressDemo(None)
app.MainLoop()