python timers and COM/directshow

Sayanan Sivaraman sayananbig at gmail.com
Tue Sep 23 14:32:20 EDT 2008


On Sep 23, 4:24 am, Tim Golden <m... at timgolden.me.uk> wrote:
> Sayanan Sivaraman wrote:
> > So I've written a simple video player using directshow/COM in VC++,
> > and I'm in the process of translating it to python.  For example, when
> > the avi starts playing, I have a call media_control.Run() , etc.
>
> > I'm wondering how I should go about updating my gtk.Hscale widget as a
> > trackbar for the avi player.
>
> > In C++, I have the following callbacks that update the scrollbar and
> > video position with a timer.
>
> [... snip callbacks ...]
>
>
>
> > I'm wondering how I would implement similar callbacks in Python for a
> > gtk.Hscale, and some sort of time [I'm not familiar with Pythons
> > timers/threading at all].
>
> You'd help your cause a lot here if you posted *Python*
> code to indicate what's calling what back where. Also if
> you stated whether you were using, eg, the GTK toolkit which
> your description suggests, or some other GUI toolkit. Because
> they tend to vary as to how they arrange their callbacks.
>
> In geeneral, Python callbacks are trivial: you create the
> function to do whatever and then pass the function as an
> object into the calling-back function call. Something
> like this (invented GUI toolkit):
>
> <code>
> def handle_lbutton_click (event):
>   #
>   # do stuff with lbutton click
>   #
>
> def handle_widget_slide (event):
>   #
>   # do stuff with widget slide
>   #
>
> handle_event ("lbutton_click", handle_lbutton_click)
> widget.attach_event ("slide", handle_widget_slide)
>
> </code>
>
> But the details will obviously depend on the toolkit you
> use.
>
> TJG
> TJG

Sorry, you make a very good point.  I am using gtk.  I don't have a
problem with callbacks for the gtk widgets.  My question is about
timers and their callbacks.  The reason I used c++ code is that
Microsoft's COM interface is natively in C++, and Python uses "import
comtypes" to access this functionality and the dll's.[ie
GetModule('quartz.dll')]

Essentially what I would like to have [as evidenced by the c++ code]
is something like the following:

def timer_callback(args):
     while timer is active
     update scrollbar position based on video progress

     #here I am using microsoft's COM interface, so the function would
be something like
      scrollbar.set_value(media_control.CurrentPosition)

def scrollbar_callback :
      when the scrollbar is moved, update this video position
      #this I understand.  It would be something like
      media_control.CurrentPosition= scrollbar.get_value()

def pauser :
    media_control.Pause()
    *somehow kill timer*

def player:
    media_control.Run()
    timer.run() #timer.run() would call timer_callback


So I would like to know how to construct and implement a timer that
would do the above, a la the first callback.  In addition, the timer
has to be able to be paused/killed if I pause the video, and
implemented again if I play the video ie:


Thanks,
sayanan



More information about the Python-list mailing list