[q-lang-cvs] qcalc/examples guiexamples.qcalc,1.5,1.6
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-11-15 10:23:47
|
Update of /cvsroot/q-lang/qcalc/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12419/examples Modified Files: guiexamples.qcalc Log Message: added task button example Index: guiexamples.qcalc =================================================================== RCS file: /cvsroot/q-lang/qcalc/examples/guiexamples.qcalc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** guiexamples.qcalc 12 Nov 2007 20:29:35 -0000 1.5 --- guiexamples.qcalc 15 Nov 2007 10:23:43 -0000 1.6 *************** *** 1,5 **** ! // qcalc 1.0, created Mon Nov 12 21:31:39 2007 -*-Q-*- -*- coding: UTF-8 -*- ! // [((0,1),"GUI element"),((0,2),"Value"),((0,3),"Display"),((2,0),"Checkbox"),((2,1),"= checkbox (\"test\",true)"),((2,2),"= B3"),((2,3),"= checkbox (\"test\",B3)"),((4,0),"Combobox"),((4,1),"= combobox ([\"apples\",\"bananas\",\"oranges\"],\"oranges\")"),((4,2),"= B5"),((4,3),"= combobox ([\"apples\",\"bananas\",\"oranges\"],B5)"),((5,0),"Comboedit"),((5,1),"= comboedit ([\"apples\",\"bananas\",\"oranges\"],\"bananas\")"),((5,2),"= B6"),((5,3),"= comboedit ([\"apples\",\"bananas\",\"oranges\"],B6)"),((6,0),"Int Spinbox"),((6,1),"= spinbox (0,100,5,40)"),((6,2),"= B7"),((6,3),"= spinbox (0,100,5,B7)"),((7,0),"Float Spinbox"),((7,1),"= spinbox (0.0,10.0,0.5,4.0)"),((7,2),"= B8"),((7,3),"= spinbox (0.0,10.0,0.5,B8)"),((9,0),"Spinbox with special value"),((9,1),"= spinbox (-1,10,1,0,\"Any\")"),((9,2),"= B10"),((9,3),"= spinbox (-1,10,1,B10,\"Any\")"),((10,0),"Spinbox with prefix"),((10,1),"= spinbox (-0.1,10,0.1,0,\"Any\",\"$ \")"),((10,2),"= B11"),((10,3),"= spinbox (-0.1,10,0.1,B11,\"Any\",\"$ \")"),((11,0),"Spinbox with suffix"),((11,1),"= spinbox (-1,72,1,10,\"Any\",\"\",\"pt\")"),((11,2),"= B12"),((11,3),"= spinbox (-1,72,1,B12,\"Any\",\"\",\"pt\")"),((13,0),"Horizontal slider"),((13,1),"= hslider (0,100,1,50)"),((13,2),"= B14"),((13,3),"= hslider (0,100,1,B14)"),((14,0),"Vertical slider"),((14,1),"= vslider (0,100,1,50)"),((14,2),"= B15"),((14,3),"= vslider (0,100,1,B15)"),((16,0),"Pushbutton"),((16,1),"= pushbutton \"Push me!\""),((16,2),"= B17"),((16,3),"N/A"),((17,0),"Pushbutton with icon"),((17,1),"= pushbutton (\"Push me!\",which \"pixmaps/1rightarrow.png\")"),((17,2),"= B18"),((17,3),"N/A"),((18,0),"Togglebutton with icon"),((18,1),"= togglebutton (\"Toggle me!\",which \"pixmaps/flag.png\")"),((18,2),"= B19"),((18,3),"= togglebutton (\"Toggle me!\",which \"pixmaps/flag.png\",B19)"),((20,0),"\"Buddies\" (linked elements)"),((20,1),"= hslider (0,100,1,D21)"),((20,2),"= B21"),((20,3),"= spinbox (0,100,1,B21)"),((22,0),("Alternative \"remote control\" of GUI elements using setval",1,4)),((24,0),"GUI element A (click here)"),((24,1),"Transfer A -> B"),((24,2),"GUI element B (display)"),((24,3),"Value of B"),((26,0),"= checkbox \"A\""),((26,1),"= setval 'C27 A27"),((26,2),"= checkbox \"B\""),((26,3),"= C27"),((27,0),"= spinbox (-0.1,10,0.1,0,\"Any\")"),((27,1),"= setval 'C28 A28"),((27,2),"= spinbox (-0.1,10,0.1,0,\"Any\")"),((27,3),"= C28"),((28,0),"= spinbox (-5,100,5,40,\"Any\")"),((28,1),"= setval 'C29 A29"),((28,2),"= spinbox (-1,100,1,40,\"Any\")"),((28,3),"= C29"),((29,0),"= combobox ([\"apples\",\"bananas\",\"oranges\"],\"oranges\")"),((29,1),"= setval 'C30 A30"),((29,2),"= combobox ([\"apples\",\"bananas\",\"oranges\"],\"oranges\")"),((29,3),"= C30"),((30,0),"= togglebutton (\"Toggle me!\",which \"pixmaps/flag.png\")"),((30,1),"= setval 'C31 A31"),((30,2),"= togglebutton (\"Toggle me!\",which \"pixmaps/flag.png\")"),((30,3),"= C31")] ! // [(14,55)] ! // [(0,162),(2,139)] // Start of script. Please do not remove this line. --- 1,61 ---- ! // qcalc 1.0, created Thu Nov 15 11:18:06 2007 -*-Q-*- -*- coding: UTF-8 -*- ! // [((0,1),"GUI element"),((0,2),"Value"),((0,3),"Display"),((2,0),"Checkbox"),((2,1),"= checkbox (\"test\",true)"),((2,2),"= B3"),((2,3),"= checkbox (\"test\",B3)"),((4,0),"Combobox"),((4,1),"= combobox ([\"apples\",\"bananas\",\"oranges\"],\"oranges\")"),((4,2),"= B5"),((4,3),"= combobox ([\"apples\",\"bananas\",\"oranges\"],B5)"),((5,0),"Comboedit"),((5,1),"= comboedit ([\"apples\",\"bananas\",\"oranges\"],\"bananas\")"),((5,2),"= B6"),((5,3),"= comboedit ([\"apples\",\"bananas\",\"oranges\"],B6)"),((6,0),"Int Spinbox"),((6,1),"= spinbox (0,100,5,40)"),((6,2),"= B7"),((6,3),"= spinbox (0,100,5,B7)"),((7,0),"Float Spinbox"),((7,1),"= spinbox (0.0,10.0,0.5,4.0)"),((7,2),"= B8"),((7,3),"= spinbox (0.0,10.0,0.5,B8)"),((9,0),"Spinbox with special value"),((9,1),"= spinbox (-1,10,1,0,\"Any\")"),((9,2),"= B10"),((9,3),"= spinbox (-1,10,1,B10,\"Any\")"),((10,0),"Spinbox with prefix"),((10,1),"= spinbox (-0.1,10,0.1,0,\"Any\",\"$ \")"),((10,2),"= B11"),((10,3),"= spinbox (-0.1,10,0.1,B11,\"Any\",\"$ \")"),((11,0),"Spinbox with suffix"),((11,1),"= spinbox (-1,72,1,10,\"Any\",\"\",\"pt\")"),((11,2),"= B12"),((11,3),"= spinbox (-1,72,1,B12,\"Any\",\"\",\"pt\")"),((13,0),"Horizontal slider"),((13,1),"= hslider (0,100,1,50)"),((13,2),"= B14"),((13,3),"= hslider (0,100,1,B14)"),((14,0),"Vertical slider"),((14,1),"= vslider (0,100,1,50)"),((14,2),"= B15"),((14,3),"= vslider (0,100,1,B15)"),((16,0),"Pushbutton"),((16,1),"= pushbutton \"Push me!\""),((16,2),"= B17"),((16,3),"N/A"),((17,0),"Pushbutton with icon"),((17,1),"= pushbutton (\"Push me!\",which \"pixmaps/1rightarrow.png\")"),((17,2),"= B18"),((17,3),"N/A"),((18,0),"Togglebutton with icon"),((18,1),"= togglebutton (\"Toggle me!\",which \"pixmaps/flag.png\")"),((18,2),"= B19"),((18,3),"= togglebutton (\"Toggle me!\",which \"pixmaps/flag.png\",B19)"),((20,0),"\"Buddies\" (linked elements)"),((20,1),"= hslider (0,100,1,D21)"),((20,2),"= B21"),((20,3),"= spinbox (0,100,1,B21)"),((22,0),("Alternative \"remote control\" of GUI elements using setval",1,4)),((24,0),"GUI element A (click here)"),((24,1),"Transfer A -> B"),((24,2),"GUI element B (display)"),((24,3),"Value of B"),((26,0),"= checkbox \"A\""),((26,1),"= setval 'C27 A27"),((26,2),"= checkbox \"B\""),((26,3),"= C27"),((27,0),"= spinbox (-0.1,10,0.1,0,\"Any\")"),((27,1),"= setval 'C28 A28"),((27,2),"= spinbox (-0.1,10,0.1,0,\"Any\")"),((27,3),"= C28"),((28,0),"= spinbox (-5,100,5,40,\"Any\")"),((28,1),"= setval 'C29 A29"),((28,2),"= spinbox (-1,100,1,40,\"Any\")"),((28,3),"= C29"),((29,0),"= combobox ([\"apples\",\"bananas\",\"oranges\"],\"oranges\")"),((29,1),"= setval 'C30 A30"),((29,2),"= combobox ([\"apples\",\"bananas\",\"oranges\"],\"oranges\")"),((29,3),"= C30"),((30,0),"= togglebutton (\"Toggle me!\",which \"pixmaps/flag.png\")"),((30,1),"= setval 'C31 A31"),((30,2),"= togglebutton (\"Toggle me!\",which \"pixmaps/flag.png\")"),((30,3),"= C31"),((32,0),("Task button example (cool stuff!). Shows how to operate a Q thread using a toggle button. See the script tab for the Q code implementing this example.",1,4)),((33,0),""),((33,1),""),((33,2),""),((33,3),""),((34,0),"Seconds for countdown:"),((34,1),"= spinbox (1,60,1,10)"),((34,2),""),((34,3),""),((35,0),"Push here to start counting:"),((35,1),"= taskbutton \"Start me!\" (timer_task B34)"),((35,2),"= spinbox (0,999999)"),((35,3),""),((36,0),""),((36,1),""),((36,2),""),((36,3),""),((37,0),""),((37,1),""),((37,2),""),((37,3),"")] ! // [(14,55),(32,44)] ! // [(0,162),(1,116),(2,139),(3,125)] // Start of script. Please do not remove this line. + + /* Countdown example for the task button (see the bottom of the + spreadsheet). */ + + import calclib; + + /* Main entry point, invoke this with N = number to count from. */ + + timer_task N = waiting N $ get task_input; + + /* Extract the counter data from the quoted thread expression. Note that + this needs to be a special form to prevent premature evaluation of the + timer_task function. */ + + special data X; + data (_,_,'(timer_task N)) + = N where N:Int = N; + + /* Wait for the timer to be started. */ + + waiting N B:Bool = running N N if B; + waiting N X = waiting N $ get task_input where N:Int = data X; + waiting N _ = waiting N $ get task_input otherwise; + + /* Timer is running, count it down. */ + + running N I + /* Check whether there are any messages waiting for us: */ + where X = get task_input if #task_input > 0: + /* Uncomment this to have the task restart itself (in waiting mode) + if a new countdown is set: */ + // = taskbutton (S,INIT) X where (S,INIT,'X) = X; + /* Otherwise we just update our state and restart the countdown at + the new value: */ + = running N N where N:Int = data X; + /* User stopped the countdown: */ + = fini N if not B where B:Bool = X; + /* Check for more messages: */ + = running N I otherwise; + otherwise: + /* Done processing messages from the user, count! */ + = setval task_index $ sprintf "Counting... %d" I || + // update the cell to the right with the current value + setval (task_row,task_column+1) I || + sleep 1 || running N (I-1) if I>0; + /* Reaching zero. Sleep for another second so that the user has a chance to + see our takeoff message on the button. */ + = setval task_index "** Takeoff! **" || + setval (task_row,task_column+1) I || + sleep 1 || running N (I-1) if I=0; + /* Tell qcalc that we're stopped, and prepare for the next run. */ + = setval task_index false || fini N otherwise; + + /* Clean it up after we're done counting. */ + + fini N = setval task_index "Run me again!" || timer_task N; |