Mike Driscoll escribió:
If you use wx.Sleep(1) or wx.Sleep(2) and you move your mouse quickly enough, you'll see that the cursor on the second frame is set correctly, but then the Yield takes effect and seems to reverse that. I tried pubsub too, but Yield() continues to cause that issue. You'll probably just want to look at threads instead. See the following wiki article:
LongRunningTasks - wxPyWiki
I don't want to launch a thread when the user press a load button to populate a listctrl, etc ....
Making more tests i observed that: Freeze() disable the input !!!
If you try this code, the objects in MyForm are locked while the frame is freezed whitout using Disable() and the cursor is also OK.
This is what i'm looking for.
Thanks.
<code>
import wx
class WorkFrame(wx.Frame):
def Working(self):
self._OldCursor = self.GetCursor()
self.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
self.Freeze()
def EndWork(self):
if hasattr(self, "_OldCursor"):
self.SetCursor(self._OldCursor)
if self.IsFrozen():
self.Thaw()
class MyForm(WorkFrame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Disable Test")
panel = wx.Panel(self, wx.ID_ANY)
btn = wx.Button(panel, wx.ID_ANY, "Start")
btn.Bind(wx.EVT_BUTTON, self.onButton)
btn2 = wx.Button(panel, wx.ID_ANY, "Try me while working!", pos=wx.Point(0,30))
btn2.Bind(wx.EVT_BUTTON, self.onButton2)
txt = wx.TextCtrl(panel, -1, pos=wx.Point(0,60), value="Write here while working")
self.OutFrame = OutForm(self)
self.OutFrame.Show()
def onButton(self, event):
self.Working()
print "Work in progress .."
for x in range(500):
self.OutFrame.text.SetValue(str(x))
wx.GetApp().Yield()
wx.MilliSleep(25)
self.EndWork()
print "Finished"
def onButton2(self, evt):
print "Button2"
class OutForm(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, wx.ID_ANY, "OutFrame")
panel = wx.Panel(self, wx.ID_ANY)
self.text = wx.TextCtrl(panel, -1)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
</code>
···
--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************
PD:
Antes de imprimir este mensaje, asegúrese de que es necesario.
El medio ambiente está en nuestra mano.