[q-lang-cvs] qcalc/examples mplayer.qcalc,NONE,1.1
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-12-02 01:13:24
|
Update of /cvsroot/q-lang/qcalc/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv14121/examples Added Files: mplayer.qcalc Log Message: add taskwindow example --- NEW FILE: mplayer.qcalc --- // qcalc 1.0, created Sun Dec 2 02:12:57 2007 -*-Q-*- -*- coding: UTF-8 -*- // [((0,0),("= label \"<h2>MPlayer \\\"in a bottle\\\"</h2><p>This program demonstrates the new taskwindow element which enables you to render graphics, animations, etc. directly into a table cell. To see this in action, please enter a video filename into cell A2 below or use the \\\"Browse\\\" button to select a video file. Then push the \\\"Play\\\" button to start playback. <b>NOTE:</b> You need the mplayer program to make this work.</p>\"",1,2)),((1,1),"= file_browser"),((2,0),("= taskwindow win_task",1,2)),((3,0),("= taskbutton \"Play\" (player_task A2 A3)",1,2))] // [(0,135),(2,283)] // [(0,319),(1,98)] // Start of script. Please do not remove this line. /* mplayer.qcalc: render a movie into a table cell using mplayer */ /* This program demonstrates the use of the taskwindow element which lets you draw cell contents directly from a spreadsheet script. We use this here to play back a movie in a table cell using mplayer, but in the same fashion you could also draw any kind of graphics or animation, using either an external program or Q's own graphics capabilities. NOTE: To make this program work, you need to have mplayer installed, see http://www.mplayerhq.hu. */ import calclib, smokeqt, system; /* Browse for a video filename (standard Qt file selection dialog). */ def (APP,ARGV) = qt_app ARGS; file_browser = actionbutton ("Browse...","","") $ setval (row,column-1) $ qt "QFileDialog" "getOpenFileName" (getcwd, "All files (*.*)", nil, "Choose a video file"); /* The window task only sets the cell value to the window id, the actual playback is done by the player_task below. */ win_task = setval index task_winid; /* The player task. To be used with the taskbutton element. */ player_task NAME ID = player NAME ID 0 (get task_input); player NAME ID PID (try _) = // no GUI messages yet, check whether we're still playing sleep 0.1 || player NAME ID PID (try task_input) where () = waitpid PID WNOHANG; = () otherwise; player NAME ID PID 'X = // play a new file player NAME ID PID true where (_,_,NAME,ID) = task_params 'X; player NAME ID PID true = // start playing player NAME ID PID (try task_input) where PID = stop PID || start NAME ID; player NAME ID PID _ = // stop playing stop PID otherwise; /* MPlayer command. Adapt the options as needed. */ start NAME ID = spawn "mplayer" ["mplayer","-really-quiet","-wid",str ID,NAME]; stop PID = kill SIGTERM PID || waitpid PID 0 if PID>0; |