[q-lang-cvs] qcalc calclib.q,1.47,1.48 qcalc.q,1.202,1.203
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-11-30 13:04:47
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv31126 Modified Files: calclib.q qcalc.q Log Message: add task window element (experimental) Index: qcalc.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/qcalc.q,v retrieving revision 1.202 retrieving revision 1.203 diff -C2 -d -r1.202 -r1.203 *** qcalc.q 29 Nov 2007 02:13:38 -0000 1.202 --- qcalc.q 30 Nov 2007 13:04:35 -0000 1.203 *************** *** 909,912 **** --- 909,918 ---- IT:QtObject = make_gui taskbutton_gui (I,J) (TEXT,INIT); + = process_sel2 [(I,J,IT)] + where [K] = regex "" + "^\\+\\+\\+ Taskwindow: (\\([0-9]+,[0-9]+\\))$" S + (reg 1), + (I,J) = val K, + IT:QtObject = make_gui taskwindow_gui (I,J) (); = qt X "setIconSet" ICONSET || procmsg (I,J) (Y<>0) where [(K,S)] = regex "" *************** *** 2784,2787 **** --- 2790,2808 ---- qt X "setPageStep" STEP || qt X "setValue" INIT; + private yywin KEY MSG; + taskwindow_gui (I,J) () () + = qt X "setBackgroundMode" (qt_val "Qt" "PaletteBase") || + send_expr '(yywin (I,J) ID) || + qt TABLE "setCellWidget" (I,J,X) || IT + where ID = qt X "winId" () + if not is_nil IT and then not is_nil X + where X:QtObject = qt_object "QWidget" TABLE + "MyTaskWindow" (I,J) [("resizeEvent",gui_update)] [] [], + IT:QtObject = make_table_item (I,J,X,ref "") + (qt_val "QTableItem" "Never"); + + taskwindow_gui (I,J) X:QtObject () + = (); + label_gui (I,J) () (S,A) = qt X "setBackgroundMode" (qt_val "Qt" "PaletteBase") || *************** *** 2918,2921 **** --- 2939,2945 ---- gui_get_togglebutton,gui_getc_togglebutton, gui_set_taskbutton); + "MyTaskWindow", (taskwindow_gui, + gui_get_nop,gui_getc_taskwindow, + gui_set_taskwindow); "MyActionButton", (actionbutton_gui, gui_get_nop,gui_getc_actionbutton, *************** *** 3002,3005 **** --- 3026,3035 ---- = "" otherwise; + gui_getc_taskwindow X + = fformat S + where (I,J) = qt_data X, (R:Ref|_) = gui_data (I,J), + S:String = get R; + = "" otherwise; + gui_getc_spinbox X = qt X "cleanText" (); *************** *** 3053,3056 **** --- 3083,3090 ---- where (I,J) = qt_data X, (R:Ref|_) = gui_data (I,J); + gui_set_taskwindow X S + = R := S + where (I,J) = qt_data X, (R:Ref|_) = gui_data (I,J); + gui_set_taskbutton X S = if checkstr 'Y then *************** *** 3130,3139 **** private yyeval KEY X, yyset KEY X, yyclear X, yyval KEY, yytask KEY MSG, ! yyaction KEY, yyclearaction KEY; gui_action X (I,J) where C:String = gui_class X: ! = send_expr '(yytask (I,J) ~(qt X "isOn" ())) if C = "MyTaskButton"; = send_expr '(yyaction (I,J)) if C = "MyActionButton"; --- 3164,3177 ---- private yyeval KEY X, yyset KEY X, yyclear X, yyval KEY, yytask KEY MSG, ! yywin KEY MSG, yyaction KEY, yyclearaction KEY; gui_action X (I,J) where C:String = gui_class X: ! = send_expr '(yytask (I,J) B) ! where B = qt X "isOn" () if C = "MyTaskButton"; + = send_expr '(yywin (I,J) (W,H)) + where (W,H) = (qt X "width" (),qt X "height" ()) + if C = "MyTaskWindow"; = send_expr '(yyaction (I,J)) if C = "MyActionButton"; *************** *** 3141,3147 **** // process (also check that the value is transferable) submit_val (I,J) Y ! if checkval Y ! where Y = gui_getval X ! if gui_hasval X; gui_clear X (I,J) --- 3179,3183 ---- // process (also check that the value is transferable) submit_val (I,J) Y ! if checkval Y where Y = gui_getval X if gui_hasval X; gui_clear X (I,J) *************** *** 3149,3152 **** --- 3185,3190 ---- = send_expr '(yytask (I,J) ()) if C = "MyTaskButton"; + = send_expr '(yywin (I,J) ()) || cell_setval (I,J) () + if C = "MyTaskWindow"; = send_expr '(yyclearaction (I,J)) || cell_setval (I,J) () if C = "MyActionButton"; *************** *** 3833,3836 **** --- 3871,3880 ---- (I1,J1) = val K1, (S1,A1,B1) = val S1, IT:QtObject = make_gui pixmap_gui (I1,J1) (S1,A1,B1); + = results_loop T0 (insert U ((I1,J1),IT)) [(I,J)|V] + where [K1] = regex "" + "^\\+\\+\\+ Taskwindow: (\\([0-9]+,[0-9]+\\))$" S + (reg 1), + (I1,J1) = val K1, + IT:QtObject = make_gui taskwindow_gui (I1,J1) (); // anything else just gets passed to the digest function, and we try again = local (digest S) || results_loop T0 U [(I,J)|V]; Index: calclib.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/calclib.q,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** calclib.q 28 Nov 2007 08:18:37 -0000 1.47 --- calclib.q 30 Nov 2007 13:04:35 -0000 1.48 *************** *** 60,68 **** actions on the button inside QCalc, and the task_params function can be used to extract arguments from a quoted taskbutton call (which is sent to ! the task when the button gets updated). */ public special taskbutton ~ARGS X, task_params X; public task_input; /* Implementation. *********************************************************/ --- 60,81 ---- actions on the button inside QCalc, and the task_params function can be used to extract arguments from a quoted taskbutton call (which is sent to ! the task when the task button cell is recomputed). */ public special taskbutton ~ARGS X, task_params X; public task_input; + /* The task window works pretty much like a task button, minus the toggle + button functionality. Instead, it provides an empty parent window inside + the task's cell which can be operated directly by the task in the inferior + Q process. The id of the parent window is available inside the task with + the task_winid function. In addition, messages of the form (W:Int,H:Int) + are delivered via the task_input semaphore (see above) whenever the size of + the parent window changes, and the task_params function (see above) can be + used to extract arguments from a quoted taskwindow call (which is sent to + the task when the task window cell is recomputed). */ + + public special taskwindow X; + public task_winid; + /* Implementation. *********************************************************/ *************** *** 75,79 **** public yymain, yyval KEY, yyset KEY VAL, yyclear KEY, yytask KEY MSG, ! yyaction KEY, yyclearaction KEY; public special yyeval ~KEY VAL; private yyloop, yyout X, yyerror X; --- 88,92 ---- public yymain, yyval KEY, yyset KEY VAL, yyclear KEY, yytask KEY MSG, ! yywin KEY MSG, yyaction KEY, yyclearaction KEY; public special yyeval ~KEY VAL; private yyloop, yyout X, yyerror X; *************** *** 353,357 **** /* The task button. */ ! var YYTASKS = ref emptyhdict, YYSEM = ref emptyhdict; special task_expr_params ~Xs X; --- 366,370 ---- /* The task button. */ ! var YYTASKS = ref emptyhdict, YYTLD = ref emptyhdict; special task_expr_params ~Xs X; *************** *** 367,374 **** = Xs otherwise; ! task_input = SEM ! where (I,J,SEM) = get YYSEM!thread_no this_thread; ! task_index = (I,J) ! where (I,J,SEM) = get YYSEM!thread_no this_thread; private begin_task ARGS, end_task ARGS, fini_task X ARGS; --- 380,386 ---- = Xs otherwise; ! task_input = SEM where (I,J,SEM:Semaphore|_) = ! get YYTLD!thread_no this_thread; ! task_index = (I,J) where (I,J|_) = get YYTLD!thread_no this_thread; private begin_task ARGS, end_task ARGS, fini_task X ARGS; *************** *** 391,395 **** thread (begin_task (I,J,SEM) || do_task X (I,J,SEM) || end_task (I,J,SEM)); ! if active H where (I,J,_) = get YYSEM!thread_no this_thread, (H:Thread,SEM,'_) = get YYTASKS!(I,J): // request by a task to replace itself with a new task --- 403,407 ---- thread (begin_task (I,J,SEM) || do_task X (I,J,SEM) || end_task (I,J,SEM)); ! if active H where (I,J|_) = get YYTLD!thread_no this_thread, (H:Thread,SEM,'_) = get YYTASKS!(I,J): // request by a task to replace itself with a new task *************** *** 404,408 **** begin_task (I,J,SEM) ! = YYSEM := insert (get YYSEM) (thread_no this_thread,(I,J,SEM)) || printf "\f+++ Taskstate: %s 1\n" (str (I,J)) || flush; --- 416,420 ---- begin_task (I,J,SEM) ! = YYTLD := insert (get YYTLD) (thread_no this_thread,(I,J,SEM)) || printf "\f+++ Taskstate: %s 1\n" (str (I,J)) || flush; *************** *** 426,429 **** --- 438,476 ---- = () otherwise; + /* The task window. */ + + task_winid = ID where (I,J,SEM,ID:Int) = get YYTLD!thread_no this_thread; + + task_params '(taskwindow X) + = tuple ARGS + where ARGS:List = catch () (task_expr_params [] 'X); + + private init_task ARGS; + + taskwindow X + where (I,J) = get YYKEY: + // update existing task + = yywin (I,J) 'X if member (get YYTASKS) (I,J); + // start up a new task + = YYTASKS := insert (get YYTASKS) (I,J;H,SEM) || + yyset (I,J) () || () + where SEM:Semaphore = semaphore, + H:Thread = + printf "\f+++ Taskwindow: %s\n" $ str (I,J) || + thread (init_task (I,J,SEM) || do_task X (I,J,SEM)); + if active H where (I,J|_) = get YYTLD!thread_no this_thread, + (H:Thread,SEM) = get YYTASKS!(I,J): + // request by a task to replace itself with a new task + = yyset (I,J) () || X; + + /* Our actual window id is sent by the parent process via the SEM semaphore + using a yywin call (see below) when it processes the "Taskwindow" + message. We store this value in the thread-local data so that the task can + access it using task_winid. */ + + init_task (I,J,SEM) + = YYTLD := insert (get YYTLD) + (thread_no this_thread,(I,J,SEM,get SEM)); + /* Internals. */ *************** *** 496,500 **** // thread has terminated and is deactivated, put it in limbo = YYTASKS := insert (get YYTASKS) (I,J;(),(),'X) || ! YYSEM := delete (get YYSEM) (thread_no H) if isthread H; --- 543,547 ---- // thread has terminated and is deactivated, put it in limbo = YYTASKS := insert (get YYTASKS) (I,J;(),(),'X) || ! YYTLD := delete (get YYTLD) (thread_no H) if isthread H; *************** *** 515,519 **** where (H,SEM,'X) = get YYTASKS!(I,J): = cancel H || YYTASKS := delete (get YYTASKS) (I,J) || ! YYSEM := delete (get YYSEM) (thread_no H) || yyclear (I,J) if isthread H; = YYTASKS := delete (get YYTASKS) (I,J) || yyclear (I,J); --- 562,597 ---- where (H,SEM,'X) = get YYTASKS!(I,J): = cancel H || YYTASKS := delete (get YYTASKS) (I,J) || ! YYTLD := delete (get YYTLD) (thread_no H) || yyclear (I,J) if isthread H; = YYTASKS := delete (get YYTASKS) (I,J) || yyclear (I,J); + + /* Initialize a window task (set up the window id). */ + + yywin (I:Int,J:Int) ID:Int + = post SEM ID + where (H,SEM:Semaphore) = get YYTASKS!(I,J); + + /* Process task window resize messages. */ + + yywin (I:Int,J:Int) (W:Int,H:Int) + where (H,SEM) = get YYTASKS!(I,J): + // thread is still alive and kicking; pass the message + = post SEM (W,H) if isthread H and then active H; + + /* Update a task window with new data. */ + + yywin (I:Int,J:Int) 'X + where (H,SEM) = get YYTASKS!(I,J): + // task is alive and kicking, update it with the new data + = post SEM '(taskwindow X) || () + where 'X = subst 'X + if isthread H and then active H; + // zombie: kill it, then restart + = yywin (I,J) () || taskwindow X; + + /* Kill a task window. */ + + yywin (I:Int,J:Int) () + = cancel H || YYTASKS := delete (get YYTASKS) (I,J) || + YYTLD := delete (get YYTLD) (thread_no H) || yyclear (I,J) + where (H:Thread,ID) = get YYTASKS!(I,J); |