Bsoft  2.1.0
Bernard's software package
bshow_misc.tcl
Go to the documentation of this file.
1 ##
2 # @file bshow_misc.tcl
3 #
4 # @brief Miscellaneous procedures for Bshow and other scripts.
5 #
6 # @author Bernard Heymann
7 # @date Created: 20010516
8 # @date Modified: 20200625
9 
10 
11 set PI 3.141592654
12 set HPI [expr $PI/2]
13 
14 set px 1
15 set py 1
16 set mx 0
17 set my 0
18 set m0x 0
19 set m0y 0
20 set sx1 0
21 set sx2 0
22 set sy1 0
23 set sy2 0
24 set sz1 0
25 set sz2 0
26 
27 set textfile ""
28 set cursorName "crosshair"
29 set trace_line 0
30 
31 set rem_scale 1
32 set ori_color "blue"
33 set box_color "yellow"
34 set box_select_color "green"
35 set bad_color "red"
36 set bad_select_color "purple"
37 set filament_color "yellow"
38 set filament_first_color "blue"
39 set filament_select_color "green"
40 set spot_color "yellow"
41 set spot_select_color "green"
42 set ll_color "yellow"
43 set ll_select_color "green"
44 set marker_color "yellow"
45 set marker2_color "red"
46 set marker_select_color "green"
47 set error_color "orange"
48 set error_select_color "blue"
49 
50 proc getControlWindow { theimg } {
51  set wc ".wcontrol"
52  if [string equal "theimg" $theimg] {
53  set wc ""
54  }
55  return $wc
56 }
57 
58 proc getImageCanvas { theimg } {
59  set c ""
60  if { [string length $theimg] < 1 } {
61  puts "Error: image not selected!"
62  return $c
63  }
64  set c ".w$theimg"
65  if [string equal "theimg" $theimg] {
66  set c ""
67  }
68  append c ".frame.c"
69  return $c
70 }
71 
72 ## @brief Creates the right-side controls for image display
73 #
74 # @param w Control window.
75 
76 proc setupControls { w } {
77  global theimg helv12
78 
79  frame $w.img
80  label $w.img.tag -text "Image type"
81  tk_optionMenu $w.img.menu imgtype "" "mg" "frame" "part" "fil" "rec" "ft" "ps" "mod"
82  $w.img.menu configure -width 10
83 # trace add variable imgbigtype write imageType
84 
85  frame $w.mode
86  checkbutton $w.mode.avg -text "Averaging mode" -variable mode \
87  -command { Update 1 }
88  button $w.mode.invert -text "Invert" -command { invertContrast }
89 
90  frame $w.pixel
91  label $w.pixel.xtag -font $helv12 -text "x"
92  label $w.pixel.x -text "0" -relief sunken -bd 1 -width 6 \
93  -font $helv12 -anchor w
94  label $w.pixel.ytag -font $helv12 -text "y"
95  label $w.pixel.y -text "0" -relief sunken -bd 1 -width 6 \
96  -font $helv12 -anchor w
97  label $w.pixel.vtag -font $helv12 -text "value"
98  label $w.pixel.value -text "0" -relief sunken -bd 1 -width 20 \
99  -font $helv12 -anchor w
100 
101  set pixel_size "1 1 1"
102  setupVectorEntry $w.pixel_size "Pixel size" double $pixel_size "Image pixel size in Å/pixel"
103  bind $w.pixel_size.x <Return> { setPixelsize $theimg }
104  bind $w.pixel_size.y <Return> { setPixelsize $theimg }
105  bind $w.pixel_size.z <Return> { setPixelsize $theimg }
106 
107  frame $w.origin
108  label $w.origin.tag -font $helv12 -text "Origin"
109  label $w.origin.x -text "0" -relief sunken -bd 1 -width 6 \
110  -font $helv12 -anchor w
111  label $w.origin.y -text "0" -relief sunken -bd 1 -width 6 \
112  -font $helv12 -anchor w
113  label $w.origin.z -text "0" -relief sunken -bd 1 -width 6 \
114  -font $helv12 -anchor w
115  checkbutton $w.origin.show -text "Show" -variable show_origin -command { drawOrigin }
116  $w.origin.show toggle
117 
118  frame $w.distance
119  label $w.distance.tag -font $helv12 -text "Distance" -width 10
120  label $w.distance.value -text "" -relief sunken -bd 1 -width 16 \
121  -font $helv12 -anchor w
122  label $w.distance.unit -text "Å" -width 3 -font $helv12 -anchor w
123 
124  setupScales $w
125 
126  pack $w.img $w.mode -side top -pady 2
127  pack $w.img.tag $w.img.menu -side left -pady 2 -anchor w
128  pack $w.mode.avg $w.mode.invert -side left -pady 2 -anchor w
129 
130  pack $w.pixel.xtag $w.pixel.x $w.pixel.ytag $w.pixel.y $w.pixel.vtag \
131  $w.pixel.value -side left -pady 10 -padx 2
132 
133  pack $w.origin.tag $w.origin.x $w.origin.y $w.origin.z $w.origin.show -side left -pady 10 -padx 2
134  pack $w.distance.tag $w.distance.value $w.distance.unit -side left -pady 10
135 
136  pack $w.pixel $w.pixel_size $w.origin $w.distance $w.image $w.slice $w.scale \
137  $w.min $w.max $w.step $w.as $w.ani -side top -fill x -pady 2
138 }
139 
140 ## @brief Flips the display y axis.
141 #
142 # @param y Canvas y value.
143 
144 proc yFlip { y } {
145  global theimg
146  set h [Bimage get $theimg height]
147  return [expr $h - $y - 1]
148 }
149 
150 ## @brief Returns the image coordinates given canvas coordinates.
151 #
152 # @param x
153 # @param y Canvas coordinates.
154 
155 proc imageCoordinatesFromCanvas { x y } {
156  global theimg
157  global px py
158  set c [getImageCanvas $theimg]
159  set wc [getControlWindow $theimg]
160  set scale [$wc.scale.scale get]
161  set z [$wc.slice.scale get]
162  set px [expr floor( [$c canvasx $x] / $scale ) ]
163  set py [expr floor( [$c canvasy $y] / $scale ) ]
164  set pyi [yFlip $py]
165  return "$px $pyi $z"
166 }
167 
168 ## @brief Selects a color.
169 #
170 # @param w parent window
171 
172 proc selectColor { w } {
173  global selected_color
174  set initialColor $selected_color
175  set color [tk_chooseColor -title "Choose a color" -parent $w \
176  -initialcolor $selected_color]
177  if { [string compare $color ""] } {
178  set selected_color $color
179  $w configure -background $color
180  }
181  Update 0
182  return $selected_color
183 }
184 
185 if {[tk windowingsystem] eq "aqua"} {
186  proc ::tk::mac::ShowPreferences { } { setPreferences }
187 }
188 
189 proc setPreferences { } {
190  global helv12 rem_scale avg_check kernel
191  global ori_color
192  global box_color box_select_color bad_color bad_select_color
193  global filament_color filament_first_color filament_select_color
194  global ll_color ll_select_color
195  global spot_color spot_select_color
196  global marker_color marker_select_color error_color error_select_color
197 
198  set w .wprf
199 
200  if ![winfo exists .wprf] {
201  toplevel $w
202 
203  checkbutton $w.rem_scale -text "Remember scale" -variable rem_scale
204 
205  setupCheckEntry $w.avg "Kernel" list kernel avg_check "The size of the filter kernel"
206 
207  labelframe $w.col -text "Colors"
208  label $w.col.lbl -text "Draw Select First" -anchor e
209 
210  frame $w.col.origins
211  label $w.col.origins.label -text "Origins" -width 15 -anchor e
212  canvas $w.col.origins.well -width 30 -height 30 -relief sunken \
213  -borderwidth 2 -background $ori_color
214 
215  frame $w.col.box
216  label $w.col.box.label -text "Boxes" -width 15 -anchor e
217  canvas $w.col.box.well -width 30 -height 30 -relief sunken \
218  -borderwidth 2 -background $box_color
219  canvas $w.col.box.well2 -width 30 -height 30 -relief sunken \
220  -borderwidth 2 -background $box_select_color
221 
222  frame $w.col.bad
223  label $w.col.bad.label -text "Bad areas" -width 15 -anchor e
224  canvas $w.col.bad.well -width 30 -height 30 -relief sunken \
225  -borderwidth 2 -background $bad_color
226  canvas $w.col.bad.well2 -width 30 -height 30 -relief sunken \
227  -borderwidth 2 -background $bad_select_color
228 
229  frame $w.col.filament
230  label $w.col.filament.label -text "Filaments" -width 15 -anchor e
231  canvas $w.col.filament.well -width 30 -height 30 -relief sunken \
232  -borderwidth 2 -background $filament_color
233  canvas $w.col.filament.well2 -width 30 -height 30 -relief sunken \
234  -borderwidth 2 -background $filament_select_color
235  canvas $w.col.filament.well3 -width 30 -height 30 -relief sunken \
236  -borderwidth 2 -background $filament_first_color
237 
238  frame $w.col.spot
239  label $w.col.spot.label -text "Diffraction spots" -width 15 -anchor e
240  canvas $w.col.spot.well -width 30 -height 30 -relief sunken \
241  -borderwidth 2 -background $spot_color
242  canvas $w.col.spot.well2 -width 30 -height 30 -relief sunken \
243  -borderwidth 2 -background $spot_select_color
244 
245  frame $w.col.ll
246  label $w.col.ll.label -text "Layer lines" -width 15 -anchor e
247  canvas $w.col.ll.well -width 30 -height 30 -relief sunken \
248  -borderwidth 2 -background $ll_color
249  canvas $w.col.ll.well2 -width 30 -height 30 -relief sunken \
250  -borderwidth 2 -background $ll_select_color
251 
252  frame $w.col.marker
253  label $w.col.marker.label -text "Markers" -width 15 -anchor e
254  canvas $w.col.marker.well -width 30 -height 30 -relief sunken \
255  -borderwidth 2 -background $marker_color
256  canvas $w.col.marker.well2 -width 30 -height 30 -relief sunken \
257  -borderwidth 2 -background $marker_select_color
258 
259  frame $w.col.error
260  label $w.col.error.label -text "Marker errors" -width 15 -anchor e
261  canvas $w.col.error.well -width 30 -height 30 -relief sunken \
262  -borderwidth 2 -background $error_color
263  canvas $w.col.error.well2 -width 30 -height 30 -relief sunken \
264  -borderwidth 2 -background $error_select_color
265 
266  button $w.update -text "Update" -relief raised -command { Update 0 }
267 
268  pack $w.col.origins.label $w.col.origins.well -side left
269  pack $w.col.box.label $w.col.box.well $w.col.box.well2 -side left
270  pack $w.col.bad.label $w.col.bad.well $w.col.bad.well2 -side left
271  pack $w.col.filament.label $w.col.filament.well $w.col.filament.well2 \
272  $w.col.filament.well3 -side left
273  pack $w.col.spot.label $w.col.spot.well $w.col.spot.well2 -side left
274  pack $w.col.ll.label $w.col.ll.well $w.col.ll.well2 -side left
275  pack $w.col.marker.label $w.col.marker.well $w.col.marker.well2 -side left
276  pack $w.col.error.label $w.col.error.well $w.col.error.well2 -side left
277  pack $w.col.lbl $w.col.origins $w.col.box $w.col.bad $w.col.filament \
278  $w.col.spot $w.col.ll $w.col.marker $w.col.error -side top -fill x -padx 5
279  pack $w.rem_scale $w.avg $w.col $w.update -side top -pady 5 -padx 5
280  } else {
281  wm deiconify $w
282  raise $w
283  }
284  wm title $w "Preferences"
285  wm iconname $w "Preferences"
286  bind $w.col.origins.well <1> { set ori_color [selectColor .wprf.col.origins.well] }
287  bind $w.col.box.well <1> { set box_color [selectColor .wprf.col.box.well] }
288  bind $w.col.box.well2 <1> { set box_select_color [selectColor .wprf.col.box.well2] }
289  bind $w.col.bad.well <1> { set bad_color [selectColor .wprf.col.bad.well] }
290  bind $w.col.bad.well2 <1> { set bad_select_color [selectColor .wprf.col.bad.well2] }
291  bind $w.col.filament.well <1> { set filament_color [selectColor .wprf.col.filament.well] }
292  bind $w.col.filament.well2 <1> { set filament_select_color \
293  [selectColor .wprf.col.filament.well2] }
294  bind $w.col.filament.well3 <1> { set filament_first_color \
295  [selectColor .wprf.col.filament.well3] }
296  bind $w.col.spot.well <1> { set spot_color [selectColor .wprf.col.spot.well] }
297  bind $w.col.spot.well2 <1> { set spot_select_color [selectColor .wprf.col.spot.well2] }
298  bind $w.col.ll.well <1> { set ll_color [selectColor .wprf.col.ll.well] }
299  bind $w.col.ll.well2 <1> { set ll_select_color [selectColor .wprf.col.ll.well2] }
300  bind $w.col.marker.well <1> { set marker_color [selectColor .wprf.col.marker.well] }
301  bind $w.col.marker.well2 <1> { set marker_select_color [selectColor .wprf.col.marker.well2] }
302  bind $w.col.error.well <1> { set error_color [selectColor .wprf.col.error.well] }
303  bind $w.col.error.well2 <1> { set error_select_color [selectColor .wprf.col.error.well2] }
304 }
305 
306 ## @brief Saves the settings file .bshow
307 #
308 
309 proc writeSettingsFile { } {
310  global theimg project_root
311  global window_width window_height window_scale
312  global autoscale std_scale imageonly
313  global rem_scale img_filter
314  global lg avgtileps avgframeps tiled
315  global tilex tiley tilez defocus
316  global tilt_axis tilt_angle tilt_offset show_tilt_axis
317  global direct_beam
318  global volt Cs amp_fac
319  global focal_length obj_apert slit
320  global ctf_win_x ctf_win_y
321  global ctf_scale_x ctf_scale_y
322  global ctf_hires ctf_lores
323  global cont_update show_rings base_type env_type sub_base
324  global box_size bad_radius
325  global filament_width filament_node_radius boxing_interval helix_rise helix_angle
326  global marker_radius
327  global shift_limit thickness
328  global spot_radius spot_resolution
329  global ll_length ll_width ll_resolution
330  global comp_radius link_radius selected_color line_width
331  global width height orix oriy color
332  global magnification magsize
333  global ori_color
334  global box_color box_select_color bad_color bad_select_color
335  global filament_color filament_first_color filament_select_color
336  global ll_color ll_select_color
337  global spot_color spot_select_color
338  global marker_color marker_select_color error_color error_select_color
339 
340  set c [getImageCanvas $theimg]
341  set window_width [expr [winfo width $c] - 10]
342  set window_height [expr [winfo height $c] - 10]
343 # puts "Settings: $window_width $window_height $window_scale $autoscale"
344 
345  if { [catch {open .bshow w} fset] } { return }
346 
347  puts $fset "# .bshow: Bshow parameter file"
348  puts $fset "# ----------------------------"
349  puts $fset "# [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S}]"
350  puts $fset "# This must be valid Tcl/Tk code."
351  puts $fset ""
352  puts $fset "# File access:"
353  puts $fset "set img_filter $img_filter"
354  puts $fset ""
355  puts $fset "# Image window parameters:"
356  puts $fset "set window_width $window_width"
357  puts $fset "set window_height $window_height"
358  puts $fset "set window_scale $window_scale"
359  puts $fset "set rem_scale $rem_scale"
360  puts $fset "set autoscale $autoscale"
361  puts $fset "set std_scale $std_scale"
362  puts $fset "set imageonly $imageonly"
363  puts $fset "set ori_color $ori_color"
364  puts $fset ""
365  puts $fset "# Micrograph parameters:"
366  puts $fset "set project_root $project_root"
367  puts $fset "set tilt_axis $tilt_axis"
368  puts $fset "set tilt_angle $tilt_angle"
369  puts $fset "set tilt_offset $tilt_offset"
370  puts $fset "set show_tilt_axis $show_tilt_axis"
371  puts $fset "set direct_beam $direct_beam"
372  puts $fset ""
373  puts $fset "# Powerspectrum parameters:"
374  puts $fset "set lg $lg"
375  puts $fset "set avgtileps $avgtileps"
376  puts $fset "set avgframeps $avgframeps"
377  puts $fset "set tiled $tiled"
378  puts $fset "set tilex $tilex"
379  puts $fset "set tiley $tiley"
380  puts $fset "set tilez $tilez"
381  puts $fset "set defocus $defocus"
382  puts $fset ""
383  puts $fset "# CTF parameters:"
384  puts $fset "set volt $volt"
385  puts $fset "set Cs $Cs"
386  puts $fset "set amp_fac $amp_fac"
387  puts $fset "set focal_length $focal_length"
388  puts $fset "set obj_apert $obj_apert"
389  puts $fset "set slit $slit"
390  puts $fset "set ctf_hires $ctf_hires"
391  puts $fset "set ctf_lores $ctf_lores"
392  puts $fset "set ctf_win_x $ctf_win_x"
393  puts $fset "set ctf_win_y $ctf_win_y"
394  puts $fset "set ctf_scale_x $ctf_scale_x"
395  puts $fset "set ctf_scale_y $ctf_scale_y"
396  puts $fset "set cont_update $cont_update"
397  puts $fset "set show_rings $show_rings"
398  puts $fset "set base_type $base_type"
399  puts $fset "set env_type $env_type"
400  puts $fset "set sub_base $sub_base"
401  puts $fset ""
402  puts $fset "# Boxing parameters:"
403  puts $fset "set box_size \"$box_size\""
404  puts $fset "set bad_radius $bad_radius"
405  puts $fset "set box_color $box_color"
406  puts $fset "set box_select_color $box_select_color"
407  puts $fset "set bad_color $bad_color"
408  puts $fset "set bad_select_color $bad_select_color"
409  puts $fset ""
410  puts $fset "# Filament parameters:"
411  puts $fset "set filament_width $filament_width"
412  puts $fset "set filament_node_radius $filament_node_radius"
413  puts $fset "set boxing_interval $boxing_interval"
414  puts $fset "set helix_rise $helix_rise"
415  puts $fset "set helix_angle $helix_angle"
416  puts $fset "set filament_color $filament_color"
417  puts $fset "set filament_first_color $filament_first_color"
418  puts $fset "set filament_select_color $filament_select_color"
419  puts $fset ""
420  puts $fset "# Tomography parameters:"
421  puts $fset "set marker_radius $marker_radius"
422  puts $fset "set marker_color $marker_color"
423  puts $fset "set marker_select_color $marker_select_color"
424  puts $fset "set error_color $error_color"
425  puts $fset "set error_select_color $error_select_color"
426  puts $fset "set shift_limit $shift_limit"
427  puts $fset "set thickness $thickness"
428  puts $fset ""
429  puts $fset "# Crystallography parameters:"
430  puts $fset "set spot_radius $spot_radius"
431  puts $fset "set spot_resolution $spot_resolution"
432  puts $fset "set spot_color $spot_color"
433  puts $fset "set spot_select_color $spot_select_color"
434  puts $fset ""
435  puts $fset "# Helix parameters:"
436  puts $fset "set ll_length $ll_length"
437  puts $fset "set ll_width $ll_width"
438  puts $fset "set ll_resolution $ll_resolution"
439  puts $fset "set ll_color $ll_color"
440  puts $fset "set ll_select_color $ll_select_color"
441  puts $fset ""
442  puts $fset "# Model parameters:"
443  puts $fset "set comp_radius $comp_radius"
444  puts $fset "set link_radius $link_radius"
445  puts $fset "set selected_color $selected_color"
446  puts $fset "set line_width $line_width"
447  puts $fset ""
448  puts $fset "# Graph parameters:"
449  puts $fset "set width $width"
450  puts $fset "set height $height"
451  puts $fset "set orix $orix"
452  puts $fset "set oriy $oriy"
453  puts $fset "set color { blue green red yellow black SkyBlue2 }"
454  puts $fset ""
455  puts $fset "# Magnification parameters:"
456  puts $fset "set magnification $magnification"
457  puts $fset "set magsize $magsize"
458  puts $fset ""
459  close $fset
460 }
461 
462 ## @brief getFileName
463 # Edits a file name entry
464 #
465 # @param w the entry window
466 
467 proc getFileName { w } {
468  global imgdir
469  set name [tk_getOpenFile -initialdir $imgdir]
470  if { $name > " " } {
471  $w.e delete 0 end
472  $w.e insert 0 $name
473  }
474 }
475 
476 proc checkType {type val} {
477  if { [expr {[string match {[.-+]} $val] || [string is $type $val]}] } {
478  return true
479  } else {
480  return false
481  }
482 }
483 
484 proc setupEntry { w name type var desc } {
485  frame $w
486  label $w.l -text $name -width 20 -anchor w
487  entry $w.e -validate key -invcmd bell -width 10 \
488  -vcmd [list checkType $type %P]
489  $w.e insert 0 $var
490  button $w.b -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
491  pack $w.l $w.e $w.b -side left -padx 1m
492 }
493 
494 proc setupResolutionEntry { w } {
495  global hires lores
496  labelframe $w.res -text "Resolution limits"
497  setupEntry $w.res.hi "High" double $hires "High resolution limit in angstrom"
498  setupEntry $w.res.lo "Low" double $lores "Low resolution limit in angstrom"
499  pack $w.res.hi $w.res.lo -side top -fill x
500 }
501 
502 proc setupCheckEntry { w name type var cvar desc } {
503  frame $w
504  checkbutton $w.c -text $name -variable $cvar
505  entry $w.e -validate key -invcmd bell -width 10 \
506  -vcmd [list checkType $type %P] -textvariable $var
507 # $w.e insert 0 $var
508  button $w.b -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
509  pack $w.c $w.e $w.b -side left -padx 1m
510 }
511 
512 proc setupScrollEntry { w name var desc } {
513  frame $w
514  label $w.l -text $name -anchor w
515  entry $w.e -validate key -invcmd bell -width 40 \
516  -xscrollcommand "$w.s set"
517  $w.e insert 0 $var
518  scrollbar $w.s -relief sunken -orient horiz -command "$w.e xview"
519  button $w.b -text "Browse ..." -command "getFileName $w" -width 10
520  button $w.i -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
521  pack $w.s $w.e -side bottom -fill x -expand 1 -padx 1m
522  pack $w.l $w.b $w.i -side left -fill x -padx 1m
523 }
524 
525 proc setupVectorEntry { w name type var desc } {
526  frame $w
527  label $w.l -text $name -anchor w
528  entry $w.x -width 6 -validate key -vcmd [list checkType $type %P]
529  entry $w.y -width 6 -validate key -vcmd [list checkType $type %P]
530  entry $w.z -width 6 -validate key -vcmd [list checkType $type %P]
531  $w.x insert 0 [lindex $var 0]
532  $w.y insert 0 [lindex $var 1]
533  $w.z insert 0 [lindex $var 2]
534  button $w.b -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
535  pack $w.l $w.x $w.y $w.z $w.b -side left -padx 1m
536 }
537 
538 proc setupCheckSizeEntry { w name type var cvar desc } {
539  frame $w
540  checkbutton $w.c -text $name -variable $cvar -command [list updateCheckSizeEntry $w $var]
541  entry $w.x -width 6 -validate key -vcmd [list checkType $type %P]
542  entry $w.y -width 6 -validate key -vcmd [list checkType $type %P]
543  entry $w.z -width 6 -validate key -vcmd [list checkType $type %P]
544  $w.x insert 0 [lindex $var 0]
545  $w.y insert 0 [lindex $var 1]
546  $w.z insert 0 [lindex $var 2]
547  button $w.b -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
548  pack $w.c $w.x $w.y $w.z $w.b -side left -padx 1m
549 }
550 
551 proc updateCheckSizeEntry { w var } {
552  set ax [$w.x get]
553  set ay [$w.y get]
554  set az [$w.z get]
555  set kernel [list $ax $ay $az]
556  return $kernel
557 }
558 
559 proc setupFileEntry { w name file desc } {
560  frame $w
561  label $w.l -text $name -anchor w
562  entry $w.e -width 40
563  $w.e insert 0 $file
564  button $w.i -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
565  pack $w.l $w.e $w.i -side left -pady 5
566 }
567 
568 proc setupNewFileEntry { w name newfile desc } {
569  frame $w
570  label $w.l -text $name -anchor w
571  entry $w.e -width 40
572  $w.e insert 0 $newfile
573  button $w.b -text "Load" \
574  -relief raised -command " loadParam \[$w.e get] "
575  button $w.i -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
576  pack $w.l $w.e $w.b $w.i -side left -pady 5
577 }
578 
579 proc setupPostscriptEntry { w name psfile desc } {
580  frame $w
581  label $w.l -text $name -anchor w
582  entry $w.e -width 40
583  $w.e insert 0 $psfile
584  button $w.b -text "Open" \
585  -relief raised -command "openPostscript \[$w.e get] "
586  button $w.i -text "?" -command "tk_messageBox -message \"$desc\" -type ok"
587  pack $w.l $w.e $w.b $w.i -side left -pady 5
588 }
589 
590 proc openPostscript { file } {
591  global tcl_platform
592  if { $tcl_platform(os) == "Darwin" } {
593  exec open $file
594  } elseif { $tcl_platform(os) == "Linux" } {
595  exec evince $file
596  }
597 }
598 
599 ## @brief Opens a text documentation file
600 #
601 # @param helpfile File name.
602 
603 proc showHelp { helpfile } {
604  global bshow_script
605  if ![winfo exists .help] {
606  toplevel .help
607  frame .help.frame
608  pack .help.frame -expand yes -fill both -padx 1 -pady 1
609  text .help.text -height 40 -wrap word -background white\
610  -xscrollcommand ".help.xscroll set" \
611  -yscrollcommand ".help.yscroll set" \
612  -setgrid 1 -highlightthickness 0 -pady 2 -padx 3
613  scrollbar .help.xscroll -command ".help.text xview" \
614  -highlightthickness 0 -orient horizontal
615  scrollbar .help.yscroll -command ".help.text yview" \
616  -highlightthickness 0 -orient vertical
617 
618  grid .help.text -in .help.frame -padx 1 -pady 1 \
619  -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
620  grid .help.yscroll -in .help.frame -padx 1 -pady 1 \
621  -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
622  grid rowconfig .help.frame 0 -weight 1 -minsize 0
623  grid columnconfig .help.frame 0 -weight 1 -minsize 0
624  } else {
625  wm deiconify .help
626  raise .help
627  }
628  wm title .help $helpfile
629  wm iconname .help $helpfile
630  readTextFile .help "$bshow_script/$helpfile"
631 }
632 
633 ## @brief Opens a URL in a web browser.
634 #
635 # @param url URL.
636 
637 proc showURL { url } {
638  global tcl_platform
639  if [catch {
640  switch $tcl_platform(os) {
641  Darwin {
642  exec open $url
643  }
644  Linux -
645  FreeBSD -
646  OpenBSD -
647  HP-UX -
648  IRIX -
649  AIX -
650  SunOS {
651  foreach pot_exe {firefox mozilla netscape iexplorer opera lynx
652  w3m links epiphany galeon konqueror mosaic amaya
653  browsex elinks} {
654  set executable [auto_execok $pot_exe]
655  break
656  }
657  if [string length $executable] {
658  exec $executable $url &
659  }
660  }
661  {Windows 95} -
662  {Windows 98} -
663  {Windows NT} {
664  exec [auto_execok start] $url
665  }
666  }
667  } err ] {
668  tk_messageBox -icon error -message "Error: '$err' displaying '$url'"
669  }
670 }
671 
672 proc toolTip { w t } {
673 # bind $w <Any-Enter> "after 1000 showTip %X %Y $t; after 3000 hideTip"
674 # bind $w <Any-Leave> "hideTip"
675 # bind $w <ButtonPress-3> "set btn3 1; showTip %X %Y $t"
676 # bind $w <ButtonRelease-3> "set btn3 0; hideTip"
677  bind $w <ButtonPress-3> "showTip %X %Y $t"
678  bind $w <ButtonRelease-3> "hideTip"
679 }
680 
681 proc showTip { x y args } {
682  wm geometry .tooltip +$x+$y
683  .tooltip.message configure -text $args
684  raise .tooltip
685 }
686 
687 proc hideTip { } {
688  lower .tooltip
689  wm geometry .tooltip +0+0
690  .tooltip.message configure -text ""
691 }
692 
693 toplevel .tooltip
694 wm geometry .tooltip 1x1+0+0
695 wm overrideredirect .tooltip 1
696 label .tooltip.message -bd 1 -fg black -bg lightyellow -font fixed -text ""
697 pack .tooltip.message
698 hideTip
699 
700 ## @brief Updates the pixel size from parameter information
701 #
702 
703 proc updatePixelsize { } {
704  global filename project_item theimg imgtype
705 
706  if [Bmg exists] {
707  set n 1
708 # puts "in updatePixelsize: Item: $project_item"
709  if [regexp "Field" $project_item] {
710  set n [Bmg get $project_item number_of_mg]
711  if { $imgtype == "mg" || $imgtype == "frame" } {
712  set ps [Bmg get $project_item pixel_size]
713  } else {
714  set ps [Bimage get $theimg pixel_size]
715  }
716  } elseif [regexp "Micrograph" $project_item] {
717  if { $imgtype == "mg" || $imgtype == "frame" } {
718  set ps [Bmg get $project_item pixel_size]
719  } elseif { $imgtype == "part" } {
720 # set n [Bmg get $project_item number_of_part]
721  set ps [Bmg get $project_item part_pixel_size]
722  } else {
723  set ps [Bimage get $theimg pixel_size]
724  }
725  } elseif [regexp "Reconstruction" $project_item] {
726  if { $imgtype == "rec" } {
727  set ps [Bmg get $project_item pixel_size]
728  } elseif { $imgtype == "part" } {
729 # set n [Bmg get $project_item number_of_part]
730  set ps [Bmg get $project_item part_pixel_size $filename]
731  } else {
732  set ps [Bimage get $theimg pixel_size]
733  }
734  } elseif [regexp "Class" $project_item] {
735  if { $imgtype == "part" } {
736  set ps [Bmg get $project_item part_pixel_size $filename]
737  }
738  }
739 # puts "updatePixelsize: $ps"
740  set i 0
741  foreach {x y z} $ps {
742  Bimage set $theimg pixel_size $i $x $y $z
743  incr i
744  }
745  }
746  updatePixelSizeEntry
747 }
748 
749 ## @brief Updates the current pixel size entry displayed
750 #
751 
752 proc updatePixelSizeEntry { } {
753  global theimg
754  set wc [getControlWindow $theimg]
755  set img_num [$wc.image.scale get]
756  set ps [Bimage get $theimg pixel_size $img_num]
757 # puts "updatePixelSizeEntry: $ps"
758  if [llength $ps] {
759  $wc.pixel_size.x delete 0 end
760  $wc.pixel_size.x insert 0 [lindex $ps 0]
761  $wc.pixel_size.y delete 0 end
762  $wc.pixel_size.y insert 0 [lindex $ps 1]
763  $wc.pixel_size.z delete 0 end
764  $wc.pixel_size.z insert 0 [lindex $ps 2]
765  }
766 }
767 
768 ## @brief Returns the current pixel size entry
769 #
770 
771 proc getPixelSizeEntry { } {
772  global project_item theimg
773  set wc [getControlWindow $theimg]
774  set psx [$wc.pixel_size.x get]
775  set psy [$wc.pixel_size.y get]
776  set psz [$wc.pixel_size.z get]
777  set ps "$psx $psy $psz"
778 # puts "getPixelSizeEntry: $ps"
779  return $ps
780 }
781 
782 ## @brief Sets the pixel size of the image and micrograph
783 #
784 # theimg Image identifier.
785 
786 proc setPixelsize { theimg } {
787  global project_item
788  set wc [getControlWindow $theimg]
789  set img_num [$wc.image.scale get]
790  set ps [getPixelSizeEntry]
791 # puts "setPixelsize: $ps"
792  Bimage set $theimg pixel_size $img_num [lindex $ps 0] [lindex $ps 1] [lindex $ps 2]
793  if [Bmg exists] {
794  Bmg set $project_item pixel_size [lindex $ps 0] [lindex $ps 1] [lindex $ps 2]
795  if [winfo exists .wctf] { updateCTF }
796  }
797  set ps [Bimage get $theimg pixel_size $img_num]
798  puts "setPixelsize: $ps"
799 }
800 
801 ## @brief Sets the pixel size of the image and micrograph
802 #
803 # theimg Image identifier.
804 
805 proc setAllPixelsizes { theimg } {
806  global project_item
807  set wc [getControlWindow $theimg]
808  set ps [getPixelSizeEntry]
809 # puts "setPixelsize: $ps"
810  Bimage set $theimg pixel_size -1 [lindex $ps 0] [lindex $ps 1] [lindex $ps 2]
811  if [Bmg exists] {
812  Bmg set all pixel_size [lindex $ps 0] [lindex $ps 1] [lindex $ps 2]
813  if [winfo exists .wctf] { updateCTF }
814  }
815  set ps [Bimage get $theimg pixel_size $img_num]
816  puts "setPixelsize: $ps"
817 }
818 
819 ## @brief Updates the image origins from parameters
820 #
821 
822 proc updateOrigins { } {
823  global theimg filename
824  global imgtype project_item
825  if [Bmg exists] {
826  set n 1
827 # puts "in updateOrigins: Item: $project_item"
828  if [regexp "Field" $project_item] {
829  set n [Bmg get $project_item number_of_mg]
830  if { $imgtype == "mg" || $imgtype == "frame" } {
831  set origin [Bmg get $project_item origin]
832  } else {
833  set origin [Bimage get $theimg origin]
834  }
835  } elseif [regexp "Micrograph" $project_item] {
836  if { $imgtype == "mg" || $imgtype == "frame" } {
837  set origin [Bmg get $project_item origin]
838  } elseif { $imgtype == "part" } {
839 # set n [Bmg get $project_item number_of_part]
840  set origin [Bmg get $project_item part_origin $filename]
841  } else {
842  set origin [Bimage get $theimg origin]
843  }
844  } elseif [regexp "Reconstruction" $project_item] {
845  if { $imgtype == "rec" } {
846  set origin [Bmg get $project_item origin]
847  } elseif { $imgtype == "part" } {
848 # set n [Bmg get $project_item number_of_part]
849  set origin [Bmg get $project_item part_origin $filename]
850  } else {
851  set origin [Bimage get $theimg origin]
852  }
853  } elseif [regexp "Class" $project_item] {
854  if { $imgtype == "part" } {
855  set origin [Bmg get $project_item part_origin $filename]
856  }
857  }
858 # puts "Origin: $origin"
859  set i 0
860  foreach {x y z} $origin {
861  Bimage set $theimg origin $x $y $z $i
862  incr i
863  }
864  }
865  drawOrigin
866 }
867 
868 ## @brief Draws the current image origin
869 #
870 
871 proc drawOrigin { } {
872  global theimg
873  global show_origin ori_color
874  set c [getImageCanvas $theimg]
875  set wc [getControlWindow $theimg]
876  $c delete origin
877  set img_num [$wc.image.scale get]
878  set slice_num [$wc.slice.scale get]
879  set scale [$wc.scale.scale get]
880  set origin [Bimage get $theimg origin $img_num]
881  set ox [lindex $origin 0]
882  set oy [lindex $origin 1]
883  set oz [lindex $origin 2]
884  if { $show_origin } {
885  if { [expr abs($oz - $slice_num)] < 1 } {
886  set h [lindex [$c cget -scrollregion] 3]
887  $c create oval [expr int(($ox - 4.5)*$scale)] \
888  [expr int($h - ($oy - 4.5)*$scale)] \
889  [expr int(($ox + 5.5)*$scale)] \
890  [expr int($h - ($oy + 5.5)*$scale)] \
891  -tags origin -outline $ori_color
892  }
893  }
894  $wc.origin.x config -text $ox
895  $wc.origin.y config -text $oy
896  $wc.origin.z config -text $oz
897 }
898 
899 proc getPixelCoordinates { c x y } {
900  global theimg
901  set wc [getControlWindow $theimg]
902  set scale [$wc.scale.scale get]
903  set h [lindex [$c cget -scrollregion] 3]
904  set cx [$c canvasx $x]
905  set cy [$c canvasy $y]
906  set px [expr int($cx / $scale) ]
907  set py [expr int(($h - $cy) / $scale) ]
908  set p [list $px $py]
909  return $p
910 }
911 
912 ## @brief Update or grabs items closeby whenever the mouse is pressed
913 #
914 # @param c Canvas object.
915 # @param x
916 # @param y Coordinates on the canvas.
917 
918 proc mousePressed { c x y } {
919  global tool theimg
920  global px py m0x m0y mx my
921  set m0x $mx
922  set m0y $my
923  set mx $x
924  set my $y
925  set p [getPixelCoordinates $c $x $y ]
926  set px [lindex $p 0]
927  set py [lindex $p 1]
928  showCoords
929  updateMagnify $px $py default mouse
930 }
931 
932 ## @brief Updates or moves grabbed items whenever the mouse is moved.
933 #
934 # @param c Canvas object.
935 # @param x
936 # @param y Coordinates on the canvas.
937 # @param b button pressed.
938 
939 proc mouseMoved { c x y b } {
940  global filename theimg
941  global tool
942  global px py
943  global mx my
944  global selectiontype trace_line
945  if { [string length $filename] < 1 } { return }
946  set wc [getControlWindow $theimg]
947  set scale [$wc.scale.scale get]
948  set cx [$c canvasx $x]
949  set cy [$c canvasy $y]
950  set cmx [$c canvasx $mx]
951  set cmy [$c canvasy $my]
952  set p1 [getPixelCoordinates $c $mx $my ]
953  set p1x [lindex $p1 0]
954  set p1y [lindex $p1 1]
955  set p [getPixelCoordinates $c $x $y ]
956  set px [lindex $p 0]
957  set py [lindex $p 1]
958  $c delete measure
959  set w .wsel
960  if { [winfo exists $w] && $b == 1 && $tool == "select" } {
961  $c delete selection
962  set xsize [expr abs($px - $p1x) + 1]
963  set ysize [expr abs($py - $p1y) + 1]
964  set zsize 1
965  if { $selectiontype == "Square" || $selectiontype == "Cube" \
966  || $selectiontype == "Circle" || $selectiontype == "Sphere" } {
967  if { $cy > $cmy } {
968  set cy [expr $cmy + abs($cx - $cmx) ]
969  } else {
970  set cy [expr $cmy - abs($cx - $cmx) ]
971  }
972  set ysize $xsize
973  if { $selectiontype == "Cube" || $selectiontype == "Sphere" } {
974  set zsize $xsize
975  }
976  }
977  if { $selectiontype == "Square" || $selectiontype == "Rectangle" || $selectiontype == "Cube" } {
978  $c create rectangle $cmx $cmy $cx $cy -tags selection -outline red
979  }
980  if { $selectiontype == "Circle" || $selectiontype == "Ellipse" || $selectiontype == "Sphere" } {
981  $c create oval $cmx $cmy $cx $cy -tags selection -outline red
982  }
983  $w.size.x config -text $xsize
984  $w.size.y config -text $ysize
985  $w.size.z config -text $zsize
986  }
987  if { $tool == "measure" || $trace_line } {
988  $c create line $cmx $cmy $cx $cy -fill yellow -width 1 -tags measure
989  }
990  showCoords
991  updateMagnify $px $py default mouse
992 }
993 
994 ## @brief Updates grabbed or nearby items whenever the mouse is released.
995 #
996 # @param c Canvas object.
997 
998 proc mouseReleased { c } {
999  global tool theimg
1000  global px py
1001  global mx my
1002  global m0x m0y
1003  global selectiontype calc_stats trace_line line_width
1004  global sx1 sx2 sy1 sy2 sz1 sz2
1005  set wc [getControlWindow $theimg]
1006  set slice_num [$wc.slice.scale get]
1007  set n [$wc.image.scale get]
1008  set scale [$wc.scale.scale get]
1009 # puts "m=$mx,$my p=$px,$py"
1010  set p0 [getPixelCoordinates $c $m0x $m0y ]
1011  set p1 [getPixelCoordinates $c $mx $my ]
1012  set sx0 [lindex $p0 0]
1013  set sx1 [lindex $p1 0]
1014  set sx2 $px
1015  set sy0 [lindex $p0 1]
1016  set sy1 [lindex $p1 1]
1017  set sy2 $py
1018  set sz0 $slice_num
1019  set sz1 $slice_num
1020  set sz2 $slice_num
1021  if { [winfo exists .wsel] && $tool == "select" } {
1022 # puts "Statistics for $mx $my $px $py"
1023  if { $selectiontype == "Square" || $selectiontype == "Cube" \
1024  || $selectiontype == "Circle" || $selectiontype == "Sphere" } {
1025  if { $sy2 > $sy1 } {
1026  set sy2 [expr $sy1 + abs($sx2 - $sx1) ]
1027  } else {
1028  set sy2 [expr $sy1 - abs($sx2 - $sx1) ]
1029  }
1030  if { $selectiontype == "Cube" || $selectiontype == "Sphere" } {
1031  set dz [expr abs($sx1 - $sx2)]
1032  set zrad [expr $dz/2]
1033  set sz1 [expr $slice_num - $zrad]
1034  set sz2 [expr $slice_num + $zrad]
1035  if { [expr 2*$zrad] != $dz } { set sz1 [expr $sz1 - 1] }
1036 # puts "$sx1 $sx2 $zrad $sz1 $sz2"
1037  }
1038  }
1039  if { $calc_stats } { updateSelectionStats }
1040  } elseif { $tool == "measure" } {
1041  set ps [getPixelSizeEntry]
1042  set dx [expr ($sx2 - $sx0) * [lindex $ps 0]]
1043  set dy [expr ($sy2 - $sy0) * [lindex $ps 1]]
1044  set d [expr sqrt($dx*$dx + $dy*$dy)]
1045 # puts "Distance = $d angstrom"
1046 # puts [expr 57.296 * atan2($dy, $dx)]
1047  $wc.distance.value config -text "$d"
1048  } elseif { $tool == "voxels" } {
1049  set w .wvox
1050  if ![winfo exists $w] { Voxels }
1051  if { $trace_line } {
1052  set line_width [$w.type.width.e get]
1053  set line [Bimage get $theimg line $sx0 $sy0 $sz0 $sx2 $sy2 $sz2 $n $line_width]
1054  foreach {n x y z v} $line {
1055  $w.text insert end "$n $x $y $z $v\n"
1056  }
1057  set trace_line 0
1058  } else {
1059  set value [Bimage get $theimg pixel $sx2 $sy2 $sz2 $n]
1060 # puts "$sx2 $sy2 $value"
1061  $w.text insert end "$n $sx2 $sy2 $sz2 $value\n"
1062  }
1063  $w.text see end
1064  }
1065 }
1066 
1067 ## @brief Displays updated coordinates whenever the mouse is moved.
1068 #
1069 
1070 proc showCoords { } {
1071  global filename
1072  global theimg imgtype
1073  global tool
1074  global px py
1075  if { [string length $filename] < 1 } { return }
1076  if ![Bimage exists $theimg] { return }
1077 # puts "px = $px py = $py"
1078  set wc [getControlWindow $theimg]
1079  set img_num [$wc.image.scale get]
1080  set slice_num [$wc.slice.scale get]
1081  set value [Bimage get $theimg pixel $px $py $slice_num $img_num]
1082  if { $value eq " " } { return }
1083  $wc.pixel.x config -text "$px"
1084  $wc.pixel.y config -text "$py"
1085  $wc.pixel.value config -text "$value"
1086  if { $tool != "measure" } {
1087  set ps [getPixelSizeEntry]
1088 # puts "pixel size = $ps"
1089  if { $imgtype == "ft" || $imgtype == "ps" } {
1090  set width [Bimage get $theimg width]
1091  set height [Bimage get $theimg height]
1092  set depth [Bimage get $theimg nslices]
1093  set dx [expr ($px*1.0/$width - 0.5) / [lindex $ps 0]]
1094  set dy [expr ($py*1.0/$height - 0.5) / [lindex $ps 1]]
1095  if { $slice_num > 1 } {
1096  set dz [expr ($slice_num*1.0/$depth - 0.5) / [lindex $ps 2]]
1097  } else {
1098  set dz 0
1099  }
1100 # puts "$dx $dy $dz"
1101  set d [expr sqrt($dx*$dx + $dy*$dy + $dz*$dz)]
1102  if { $d < 0.0001 } { set d 0.0001 }
1103  set d [expr 1/$d]
1104  set u "1/A"
1105  } else {
1106  set origin [Bimage get $theimg origin]
1107  set dx [expr [lindex $ps 0]*($px - [lindex $origin 0])]
1108  set dy [expr [lindex $ps 1]*($py - [lindex $origin 1])]
1109  set dz [expr [lindex $ps 2]*($slice_num - [lindex $origin 2])]
1110  set d [expr sqrt($dx*$dx + $dy*$dy + $dz*$dz)]
1111  set u "A"
1112  }
1113  $wc.distance.value config -text "$d"
1114  $wc.distance.unit config -text "$u"
1115  }
1116 }
1117 
1118 ## @brief Sets and updates the cutoff FOM.
1119 #
1120 # @param cutoff FOM cutoff value.
1121 
1122 proc setFOMcutoff { cutoff } {
1123  global fom_cutoff
1124  set fom_cutoff $cutoff
1125  Update 0
1126 }
1127 
1128 
1129 ## @brief Selects a cursor for the canvas window.
1130 #
1131 
1132 proc selectCursor { } {
1133  global theimg
1134  global tcl_platform
1135  global cursorName
1136 
1137  set c [getImageCanvas $theimg]
1138 
1139  set pad 4; # extra space around buttons
1140  set cols 6; # number of button columns
1141 
1142  set cursor_list {
1143  X_cursor arrow based_arrow_down based_arrow_up bottom_left_corner
1144  bottom_right_corner bottom_side bottom_tee box_spiral center_ptr circle
1145  cross cross_reverse crosshair diamond_cross dot dotbox double_arrow
1146  draft_large draft_small draped_box exchange fleur hand1 hand2
1147  icon iron_cross left_ptr left_side left_tee ll_angle lr_angle
1148  plus right_ptr right_side
1149  right_tee sb_down_arrow sb_h_double_arrow sb_left_arrow
1150  sb_right_arrow sb_up_arrow sb_v_double_arrow sizing
1151  target tcross top_left_arrow top_left_corner top_right_corner top_side
1152  top_tee ul_angle ur_angle
1153  }
1154 
1155  if { $tcl_platform(platform) == "windows" } {
1156  lappend cursor_list no starting size_ne_sw size_ns size_nw_se size_we uparrow wait
1157  }
1158 
1159  if { $tcl_platform(os) == "Darwin" } {
1160  lappend cursor_list text cross-hair
1161  }
1162 
1163  set w .wcurs
1164  toplevel $w
1165  wm title $w "Select a cursor"
1166  wm iconname $w "Cursors"
1167 
1168  foreach cursor $cursor_list {
1169  set cb [button $w.b_$cursor -text $cursor -cursor $cursor -command "configCursor_destroyWindow $c $w $cursor"]
1170  lappend cblist $cb
1171  if { [llength $cblist] >= $cols } {
1172  # place whole row of buttons
1173  eval grid $cblist -ipadx $pad -ipady $pad -sticky nswe
1174  set cblist {}
1175  }
1176  }
1177  if { [llength $cblist] > 0 } {
1178  # place rest of buttons
1179  eval grid $cblist -ipadx $pad -ipady $pad -sticky nswe
1180  }
1181 
1182  eval grid [button $w.cancel -text Cancel -relief flat -overrelief raised -command "destroy $w"] \
1183  -ipadx $pad -ipady $pad -sticky nswe
1184 
1185 }
1186 
1187 proc configCursor_destroyWindow { c w name } {
1188  configCursor $c $name
1189  destroy $w
1190 }
1191 
1192 proc configCursor { c name } {
1193  global cursorName tcl_platform
1194  set cursorName $name
1195 # $c config -cursor $cursorName
1196  switch -- $tcl_platform(platform) {
1197  unix {
1198 # $c config -cursor "$cursorName #ffffff #ffff00"
1199  $c config -cursor $cursorName
1200  }
1201  windows {
1202  $c config -cursor $cursorName
1203  }
1204  }
1205 }
1206 
1207 if {[tk windowingsystem] eq "aqua"} {
1208  proc ::tk::mac::ShowHelp { } {
1209  global Bsoft
1210  showURL "file://$Bsoft/doc/bshow/bshow.html"
1211  }
1212 }
1213 
1214 proc canvas2Photo { canvId } {
1215  # The following line grabs the contents of the canvas canvId into photo image ph.
1216  set retVal [catch {image create photo -format window -data $canvId} ph]
1217  if { $retVal != 0 } {
1218  puts "\n\tFATAL ERROR: Cannot create photo from canvas window"
1219  exit 1
1220  }
1221  return $ph
1222 }
1223 
1224 proc capture {W format file} {
1225  if {[catch {package require Img}]} {
1226  # Error thrown - package not found.
1227  # Set up a dummy interface to work around the absence
1228  puts "package Img not found!"
1229  return
1230  }
1231 # raise $W
1232 # update idletasks
1233  set image [image create photo -format window -data $W]
1234  $image write -format $format $file
1235  puts "capture -> '$file' ([file size $file] bytes)"
1236  image delete $image
1237  }
1238