wx.CallAfter()

Thread Solved
Reply

Join Date: Jun 2007
Posts: 1,258
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 118
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

wx.CallAfter()

 
0
  #1
Nov 28th, 2008
Hello All,
can someone tell me exactly what is done by this function?

Thanks alot!
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 838
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 130
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: wx.CallAfter()

 
0
  #2
Nov 28th, 2008
It is used with events in wxPython. If you have a button lets say that when you press it pops up a dialog box. But there is also something else going on and you want the method that makes that dialog box to be called After the event function is done.

So here is the example from http://wiki.wxpython.org/CallAfter
  1. import threading,wx
  2.  
  3. ID_RUN=101
  4. ID_RUN2=102
  5.  
  6. class MyFrame(wx.Frame):
  7. def __init__(self, parent, ID, title):
  8. wx.Frame.__init__(self, parent, ID, title)
  9. panel = wx.Panel(self, -1)
  10. mainSizer=wx.BoxSizer(wx.HORIZONTAL)
  11. mainSizer.Add(wx.Button(panel, ID_RUN, "Click me"))
  12. mainSizer.Add(wx.Button(panel, ID_RUN2, "Click me too"))
  13. panel.SetSizer(mainSizer)
  14. mainSizer.Fit(self)
  15. wx.EVT_BUTTON(self, ID_RUN, self.onRun)
  16. wx.EVT_BUTTON(self, ID_RUN2, self.onRun2)
  17.  
  18. def onRun(self,event):
  19. print "Clicky!"
  20. wx.CallAfter(self.AfterRun, "I don't appear until after OnRun exits")
  21. s=raw_input("Enter something:")
  22. print s
  23.  
  24. def onRun2(self,event):
  25. t=threading.Thread(target=self.__run)
  26. t.start()
  27.  
  28. def __run(self):
  29. wx.CallAfter(self.AfterRun, "I appear immediately (event handler\n"+ \
  30. "exited when OnRun2 finished)")
  31. s=raw_input("Enter something in this thread:")
  32. print s
  33.  
  34. def AfterRun(self,msg):
  35. dlg=wx.MessageDialog(self, msg, "Called after", wx.OK|wx.ICON_INFORMATION)
  36. dlg.ShowModal()
  37. dlg.Destroy()
  38.  
  39.  
  40. class MyApp(wx.App):
  41. def OnInit(self):
  42. frame = MyFrame(None, -1, "CallAfter demo")
  43. frame.Show(True)
  44. frame.Centre()
  45. return True
  46.  
  47. app = MyApp(0)
  48. app.MainLoop()
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,258
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 118
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: wx.CallAfter()

 
0
  #3
Nov 28th, 2008
So If I want let say to execute YouWin() method and when it is done I want to execute another method let me call it MeWin(),
How do I do? What Arguments does it need?

Thanks for reply
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 838
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 130
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: wx.CallAfter()

 
0
  #4
Nov 28th, 2008
you would call wx.CallAfter(self.MeWin,ARGUMENTS) and then that will call the function after the YouWin function is done.
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,258
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 118
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: wx.CallAfter()

 
0
  #5
Nov 28th, 2008
Lastly, what Arguments does it take. Will they be MeWin() method arguments or there are other? I mean wx.CallAfter(self.MeWin(), ARGUMENTS) what exactly ARGUMENTS is?
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 838
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 130
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: wx.CallAfter()

 
1
  #6
Nov 28th, 2008
Woops, should have called them paramaters. If you have any that are needed then you put them as the second paramater but if there are no paramaters needed for the MeWin method then you dont need to have a second paramater.
Note that you dont put parentheses after the self.MeWin the the wx.CallAfter.
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,258
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 118
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: wx.CallAfter()

 
0
  #7
Nov 29th, 2008
Thanks Paul
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC