[q-lang-cvs] qcalc calclib.q,1.55,1.56 qcalc.q,1.212,1.213
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-12-04 00:52:22
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv4304 Modified Files: calclib.q qcalc.q Log Message: add gnuplot support Index: qcalc.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/qcalc.q,v retrieving revision 1.212 retrieving revision 1.213 diff -C2 -d -r1.212 -r1.213 *** qcalc.q 2 Dec 2007 20:33:47 -0000 1.212 --- qcalc.q 4 Dec 2007 00:52:18 -0000 1.213 *************** *** 20,24 **** - Improve the print output (configurable margins, alignment and html markup ! for headers and footers). - Maybe add a second interpreter running interactively in the log pane. --- 20,24 ---- - Improve the print output (configurable margins, alignment and html markup ! for headers and footers, prettier gnuplot graphics). - Maybe add a second interpreter running interactively in the log pane. *************** *** 2351,2354 **** --- 2351,2368 ---- chksel _ = false otherwise; + /* Temporary files for image data (gnuplot interface). */ + + def TMPNAM = ref (), TMPCTR = ref 0; + + mktmpname EXT = TMPCTR := N+1 || sprintf "%s-%d.%s" (get TMPNAM,N,EXT) + where S:String = init_tmpfiles || get TMPNAM, + N:Int = get TMPCTR; + + init_tmpfiles = clear_tmpfiles || TMPNAM := tmpnam || TMPCTR := 0; + + clear_tmpfiles = do unlink (glob (S++"-[0-9]*.*")) || + TMPNAM := () || TMPCTR := 0 + where S:String = get TMPNAM; + /* Print. This is based on the "application walkthrough" from the Qt3 docs. */ *************** *** 2363,2366 **** --- 2377,2381 ---- CONTENTS (FROM,TO) 1 (1,1) || qt P "end" () || + clear_tmpfiles || statusmsg "Done" where M = qt_new "QPaintDeviceMetrics" $ qt P "device" (), *************** *** 2555,2560 **** sel_cval (I,J) else "", ! B = is_gui_elem (I,J) and then gui_hasrichtext (gui_elem (I,J)), ! T = if B then S else htmlquote S, (N,M) = cell_span (I,J), SP = if (N>1) or else (M>1) then --- 2570,2574 ---- sel_cval (I,J) else "", ! (T,B) = format_text (I,J) S, (N,M) = cell_span (I,J), SP = if (N>1) or else (M>1) then *************** *** 2584,2587 **** --- 2598,2622 ---- where L = filter (neg null) [T,htmlquote F]; + format_text (I,J) S + if not is_nil X where X:QtObject = gui_elem (I,J): + = (S,true) if gui_hasrichtext (); + = (make_gnuplot (W,H) S,true) + where S:String = drop (P+1) S, + (W,H) = (qt X "width" (),qt X "height" ()) + if P>=0 where S:String = val S, P:Int = pos "\n" S + if take (#MAGIC) S = MAGIC + where MAGIC = "\"-*- gnuplot -*-\\n"; + otherwise: + = (htmlquote S,false); + + make_gnuplot (W,H) CMD + = fprintf PLOT "set terminal png size %d, %d; \ + set output '%s'\n" (W,H,TMP) || + fprintf PLOT "%s\n" CMD || + sprintf "<img src=\"%s\">" (htmlquote TMP) + where PLOT:File = popen "gnuplot" "w", + TMP:String = mktmpname "png"; + = "" otherwise; + /* Exit the application. */ *************** *** 3049,3053 **** gui_getc_pixmap X ! = sprintf "<img src=\"%s\"/>" (htmlquote S) where (I,J) = qt_data X, (R:Ref|_) = gui_data (I,J), S:String = get R; --- 3084,3088 ---- gui_getc_pixmap X ! = sprintf "<img src=\"%s\">" (htmlquote S) where (I,J) = qt_data X, (R:Ref|_) = gui_data (I,J), S:String = get R; Index: calclib.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/calclib.q,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** calclib.q 2 Dec 2007 01:52:18 -0000 1.55 --- calclib.q 4 Dec 2007 00:52:17 -0000 1.56 *************** *** 51,55 **** /* Advanced GUI elements. Currently supported are action buttons, task buttons ! and task windows. */ /* The action button is a special push button which has an associated Q --- 51,56 ---- /* Advanced GUI elements. Currently supported are action buttons, task buttons ! and task windows. We also provide a convenience function to embed gnuplot ! in a table cell. */ /* The action button is a special push button which has an associated Q *************** *** 81,84 **** --- 82,97 ---- public task_winid; + /* Convenience function to set up a task window running gnuplot. CMD is a + string containing the gnuplot command used to produce the plot, and DATA is + the data to be plotted, usually a range (list) of cell values. Use '-' to + specify the dataset inside the gnuplot command. DATA can also be () if no + additional data is required, or a tuple of lists if multiple datasets are + to be plotted. NOTE: Currently this only works under X11 and requires a + gnuplot version which supports the 'x11-external' option. If necessary, you + can set the GNUPLOT variable to the name of your gnuplot executable. */ + + public var GNUPLOT = "gnuplot"; + public gnuplot CMD DATA; + /* Implementation. *********************************************************/ *************** *** 473,476 **** --- 486,535 ---- where ID = get SEM; + /* Gnuplot support (experimental). */ + + private gnuplot_task KEY ID PLOT CMD, gnuplot_loop PLOT MSG, + gnuplot_data DATA, gnuplot_dataset DATA, gnuplot_datapoint DATA, + gnuplot_dataval X; + + gnuplot CMD:String DATA + = taskwindow (gnuplot_task CMD DATA); + + gnuplot_task CMD DATA + = fprintf PLOT "set terminal x11 window '%x'\n" task_winid || + fputs PLOT CMD || + setval index ("-*- gnuplot -*-\n"++CMD) || + gnuplot_loop PLOT (get task_input) + where DATA:String = gnuplot_data DATA, + PLOT:File = popen GNUPLOT "w", CMD = CMD++"\n"++DATA; + + gnuplot_loop PLOT 'X + = fprintf PLOT "\nset term x11; reset\n" || + fputs PLOT CMD || + setval index ("-*- gnuplot -*-\n"++CMD) || + gnuplot_loop PLOT (get task_input) + where (CMD,DATA) = task_params 'X, + DATA:String = gnuplot_data DATA, CMD = CMD++"\n"++DATA; + gnuplot_loop PLOT _ + = gnuplot_loop PLOT (get task_input); + + gnuplot_data () = ""; + gnuplot_data DATA:Tuple + = strcat $ map gnuplot_dataset $ list DATA; + gnuplot_data DATA:List + = gnuplot_dataset DATA; + + gnuplot_dataset DATA:List + = strcat (map gnuplot_datapoint DATA) ++ "e\n"; + + gnuplot_datapoint DATA:List + = join " " (map gnuplot_dataval DATA) ++ "\n"; + gnuplot_datapoint DATA + = gnuplot_dataval DATA ++ "\n" otherwise; + + gnuplot_dataval X + = str X if isint X or else isfloat X or else isstr X; + = str X where X:Float = float X if isreal X; + = str "" otherwise; + /* Internals. */ |