Re: [wxpython-users] wxMediaCtrl
by Josiah Carlson other posts by this author
Jun 4 2009 10:21PM messages near this date
Re: [wxpython-users] wxMediaCtrl
|
Re: [wxpython-users] wxMediaCtrl
On Thu, Jun 4, 2009 at 5:10 PM, Timothy W. Grove <tim_grove@[...].org> wrote:
> Dear Josiah,
>
> This is quite an old posting, but I'm facing a similar problem to Stuart. In
> your response below you mentioned specifically:
>
> "Alternatively (what I would suggest) is to create a secondary thread
> that uses wx.CallAfter() to call the wx.Timer event handler that you
> would have written every 10 ms or so..."
>
> Could you expand any further on how you would use wxCallAfter, perhaps an
> example line of code? I think at some point today I was trying to use
> wxCallLater() in a new thread, but it kept telling me that I needed to call
> the timer from the main thread instead. I'm using wxPython 2.8 under Windows
> Vista, if that makes any difference!
You are in luck, I only randomly check threads here. :)
import threading
import wx
_stop = {}
def call_every(function, msdelay, token=None):
if token is None:
token = object()
threading.Thread(target=call_repeatedly, args=(function,
msdelay, token).start()
_stop[token] = 0
return token
time.sleep(msdelay/1000.0)
while not _stop[token]:
wx.CallAfter(function, token)
time.sleep(msdelay/1000.0)
_stop.pop(token)
def stop(token):
_stop[token] = 1
Used like:
self.stopper = call_every(self.OnTimer, 10)
Then in OnTimer:
if <condition for stop> :
stop(self.stopper)
It's a bit of boilerplate, but it might be more convenient for
non-timer-based polls.
For some of my own stuff, I'm actually using a secondary thread to
handle all of my wx.FutureCall() and wx.Timer() replacements. One
thread for maybe a dozen delayed things.
Though...maybe a wx.FutureCall() is really what you are looking for
(check status, if it's not what you want, wx.FutureCall()).
- Josiah
> Josiah Carlson wrote:
> >
> > On Thu, Aug 21, 2008 at 1:43 PM, Stuart Thiessen
> > <thiessenstuart@[...].com> wrote:
> >
> >>
> >> I am working on a program where I want to be able to let a user select a
> >> start and end point in a video using MediaCtrl.Tell() to find the actual
> >> points. Then I want them to be able to click a button and just play that
> >> clip. Finding those points is simple enough, but I am apparently not
> >> doing
> >> it right to start it playing at the start point and tell it to pause or
> >> stop
> >> at the end point.
> >>
> >> Any suggestions?
> >>
> >> Thanks,
> >>
> >> Stuart
> >>
> >> My code is as follows: (where self.startclip is the ms to start playing
> >> and
> >> self.endclip is the ms to end playing. I am assuming as I look at my
> >> code,
> >> that I need to do something with an Event handler somehow instead of what
> >> I'm doing, but I'm not sure how I would do that.
> >>
> >> def OnPlayClip(self, evt):
> >> Â Â Â Â Â Â Â self.mc.Seek(self.startclip)
> >> Â Â Â Â Â Â Â self.mc.Play()
> >> Â Â Â Â Â Â Â while self.mc.Tell() < self.endclip:
> >> Â Â Â Â Â Â Â Â Â Â Â pass
> >> Â Â Â Â Â Â Â self.mc.Stop()
> >>
> >
> > That while loop is going to kill you, which is why things aren't
> > working. Â Create a wx.Timer instance and have it signal an event every
> > 100ms or so where you do your check to see if you should stop the
> > video.
> >
> > Alternatively (what I would suggest) is to create a secondary thread
> > that uses wx.CallAfter() to call the wx.Timer event handler that you
> > would have written every 10 ms or so. Â Why? Â Because wx.Timer()
> > instances are limited depending on the platform, have very limited
> > precision, etc. Â I've found that just running a single thread in the
> > background to handle scheduled events to be generally faster (a future
> > release of PyPE uses this method to improve performance on OS X
> > significantly).
> >
> > Â - Josiah
> > _______________________________________________
> > wxpython-users mailing list
> > wxpython-users@[...].org
> > http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
> >
> >
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@[...].org
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>
_______________________________________________
wxpython-users mailing list
wxpython-users@[...].org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Thread:
Stuart Thiessen
Josiah Carlson
Timothy W. Grove
Josiah Carlson
Stuart Thiessen
|