The gwm widget has a command for printing the contents of the gwm window in a number of formats (JPEG, various flavours of PostScript and HP inkjet). The process of generating the file can be quite time consuming for a large window so the print command returns control as soon as the window contents have been captured and the output file created. Actual generation of the file is then carried out whenever the Tcl interpreter is idle enabling the application to continue to respond to X events while the printing is in progress. Completion of the printing process is signaled by a global Tcl variable (gwm_printvar by default) being set to 1.
The simplest way to detect completion is to wait for the value of the variable to change. e.g.:
global gwm_printvar
set gwm_printvar 0
if [catch {.gwm print plot.ps}] {
...an error
} else {
tkwait variable gwm_printvar
}
An alternative approach is to set a trace on the variable so that a procedure is invoked when the print completes. e.g.:
proc done {name1 name2 opt} {
trace vdelete gwm_printvar w done
}
global gwm_printvar
set gwm_printvar 0
if [catch {.gwm print plot.ps}] {
...an error
} else {
trace variable gwm_printvar w done
}
In this example the trace routine merely deletes itself but any other processing can be done here.
STARTCL --- Starlink Extensions to Tcl & Tk