#!/usr/bin/wish # # # xbubblejet v0.2 # # by Rob Butera (butera@patriot.net) 12-Sept-1998 # # GUI for setting PS print options for a Canon Bubblejet printer # that uses ghostscript for a PS print filter. Requires the # associated print filter (see WWW page, below) # # for more info, visit http://patriot.net/~butera/xbubblejet.html # # # this routine reads the user's (or system) configuration file # and sets the buttons appropriately # proc ReadConfig {} { global paper qual res cmodel bits global prefix options # # check for local, and if not present, system canon.ps.options file # append fname "/home/" [exec whoami] "/.canon.ps.options" if [catch {open $fname r} fileid] { set fname "/etc/canon.ps.options" if [catch {open $fname r} fileid] { return } } gets $fileid optstring close $fileid # # search for prefix strings in elements of optstring # set len [string length $optstring] # puts "$optstring" foreach aidx [array names prefix] { set sidx [string first $prefix($aidx) $optstring] if { $sidx > -1 } { set substr [string range $optstring $sidx end] set lidx [string first " " $substr] if {$lidx > -1} { set substr [string range $substr 0 $lidx] } # # now aidx is the button (array index, but ALSO variable name) # and substr is the value to set it to # eval "set $aidx $substr" } } } # # this routine writes the configuration data to the user's local file # proc PrintConfig {} { global paper qual res cmodel bits append fname "/home/" [exec whoami] "/.canon.ps.options" set fileid [open $fname w] puts $fileid "$paper $qual $res $cmodel $bits" close $fileid exit } # # put up GUI, configure buttons for appropriate strings for config file # proc ShowChoices { parent varname btitle bprefix bcolor model stringl } { set f [frame $parent.$varname -borderwidth 5] label $f.listtitle -text $btitle -fg $bcolor -pady 5 pack $f.listtitle -side top set l [llength $model] for {set i 0} {$i < $l} {incr i} { radiobutton $f.$i -variable $varname \ -text [lindex $model $i] \ -value [join [list $bprefix [lindex $stringl $i]] "" ] \ -selectcolor $bcolor pack $f.$i -side top -anchor w } pack $f -side top -anchor w } # # init all strings for both file parsing/writing and GUI # # # the GLOBAL variables paper,qual,res,cmodel,bits are used to store # the state (.canon.ps.options string entry) of each radio button. # for conveience, the _names_ of these variables are also the # indices into the associative arrays listed below, which are # lookup tables for all the FUI parameters (colors, button labels, etc) # # # title: strings for titles in GUI # array set title [list \ paper {Paper Type} \ qual {Print Quality} \ res {Resolution} \ cmodel {Color Mode} \ bits {Bits per Pixel} ] # # color: color for each section of GUI # array set color [list \ paper blue \ qual violet \ res forestgreen \ cmodel red \ bits brown ] # # prefix: prefix for ghostscript for each section of buttons in GUI # array set prefix [list \ paper -sMediaType= \ qual -sPrintQuality= \ res -r \ cmodel -sProcessColorModel= \ bits -dBitsPerPixel= ] # # options: list of options (1 per button) for ghostscript # array set options [list \ paper [list PlainPaper TransparencyFilm Card CoatedPaper Envelope Other] \ qual [list High Normal Draft] \ res [list 90x90 180x180 360x360] \ cmodel [list DeviceGray DeviceCMYK] \ bits [list 32 24 16 8 1] ] # # buttons: GUI button labels for each option in options array # array set buttons [list \ paper [list plain transparency card coated envelope other] \ qual [list high normal draft] \ res [list 90x90 180x180 360x360] \ cmodel [list grayscale color] \ bits [list 32 24 16 8 1] ] # # colf: array of column frames for location of each button set # array set colf [list \ paper .col1 \ qual .col2 \ res .col2 \ cmodel .col3 \ bits .col3 ] # # ***************************************************** start of code # ReadConfig frame .col1 frame .col2 frame .col3 pack .col1 .col2 .col3 -side left -anchor n # # loop through indices, setting up each list of buttons # foreach index [ array names options ] { ShowChoices $colf($index) $index $title($index) \ $prefix($index) $color($index) $buttons($index) $options($index) } # # DONE button # button .col1.writeit -text Done -pady 10 -command "PrintConfig" pack .col1.writeit -side top -anchor s