python timers and COM/directshow

Sayanan Sivaraman sayananbig at gmail.com
Thu Sep 25 21:06:51 CEST 2008


Ok, so I actually found a solution to this out there, and decided I'd
post back here and share it.

import pygtk
pygtk.require('2.0')
import gtk
import ctypes
from ctypes import *
from comtypes import client
from ctypes.wintypes import *
import gobject

def delete_event(widget,event,data=None):
    global filter_builder, filter_graph, media_control, vseek
    media_control.Stop
    vseek.Release
    filter_builder.Release
    GUIDATA.win1.Release
    media_control.Release
    filter_graph.Release
    del GUIDATA.win1
    del filter_graph
    del vseek
    del filter_builder
    del media_control
    del all
    sys.exit([status])
    os._exit(status)
    gtk.main_quit()
    exit()
    return False

def pauser(widget,data=None):
    global media_control,playing, scrollbar, vseek
    if GUIDATA.data_loaded==0:
        return 0
    scrollbar.set_value(vseek.CurrentPosition*30)
    media_control.Pause()
    playing=0
    return 0

def player(widget,data=None):
    global media_control, vseek, scrollbar,playing
    if GUIDATA.data_loaded==0:
        return 0
    media_control.Run()
    playing=1
    gobject.timeout_add(1,on_timer,scrollbar)

def scrollbar_callback(widget,scroll, data=None):
    global media_control, vseek
    vseek.CurrentPosition= scrollbar.get_value()/30
    return 0
def on_timer(data=None):
    global scrollbar, vseek, playing, media_control
    if (playing==1)and
(vseek.CurrentPosition*30)<int(frame2.get_text()) :
        g= vseek.CurrentPosition
        scrollbar.set_value(g*30)
        f= "%d" %(vseek.CurrentPosition*30)
        curframe.set_text(f)
        print "update"
        return True




win = gtk.Window()
win.connect("destroy", lambda x: gtk.main_quit())
win.set_default_size(500,800)
win.set_title("LISA GUI")

filename= LPCWSTR("mymovie.avi")
#importing quartz.dll and qedit.dll for filtergraph construction
qedit = client.GetModule('qedit.dll') # DexterLib
quartz= client.GetModule('quartz.dll')

CLSID_FilterGraph = '{e436ebb3-524f-11ce-9f53-0020af0ba770}'
filter_graph =
client.CreateObject(CLSID_FilterGraph,interface=qedit.IFilterGraph)
filter_builder = filter_graph.QueryInterface(qedit.IGraphBuilder)
media_control = filter_builder.QueryInterface(quartz.IMediaControl)
GUIDATA.win1= filter_builder.QueryInterface(quartz.IVideoWindow)
filter_builder.RenderFile(GUIDATA.video, None)
GUIDATA.win1.SetWindowPosition(512, 0, 512, 400)
vseek=filter_graph.QueryInterface(interface=quartz.IMediaPosition)



adj= gtk.Adjustment(1,1,30*vseek.Duration+1,1,1.0,1.0)
scrollbar = gtk.HScale(adj)
scrollbar.set_update_policy(gtk.UPDATE_CONTINUOUS)
scrollbar.connect("change_value",scrollbar_callback)
scrollbar.show()
hbox6=gtk.HBox(False,0)
hbox6.pack_start(scrollbar,True,True)
hbox6.show()
vbox.pack_end(hbox6,False,True)



play_video= gtk.Button("Play")
play_video.connect("clicked",player)
play_video.show()

pause_video= gtk.Button("Pause")
pause_video.connect("clicked",pauser)
pause_video.show()

hbox4= gtk.HBox(False,0)
hbox4.pack_start(play_video,True,True)
hbox4.pack_start(pause_video,True,True)
hbox4.show()
vbox.pack_end(hbox4,False,True)
vbox.show()
win.add(vbox)
win.show_all()
gtk.main()




More information about the Python-list mailing list