File: fvPreferences.tcl

package info (click to toggle)
ftools-fv 5.3%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,908 kB
  • ctags: 2,922
  • sloc: tcl: 48,319; ansic: 16,926; cpp: 169; makefile: 157; sh: 121; csh: 10; exp: 2
file content (1006 lines) | stat: -rw-r--r-- 34,381 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
# When this class is initialized in fvApp, the constructor will create a
# ::fvPref namespace with various variable names

itcl::class fvPreferences {

   # Create and initialize fvPref namespace
   constructor { args } {}
   destructor { }

   public {
      method save  { }
      method edit  { {page "fv"} }
      method close { }
      method raisePage { page }
      method _setGraphSize { menu {val ""} }
      method _askDirectorySetup {}
      method getCurrentGraphSize {} { return $fvPref::graphDispSize }
      method setNewGraphSize { size } { set ::fvPref::graphDispSize $size ; fvPref save }
   }

   private {
      method _read {}
      method _browseDirectory { win }
      method _selectDirectory { dir }

      method _buildPage_App      { w }
      method _buildPage_Keywords { w }
      method _buildPage_Tables   { w }
      method _buildPage_Graphs   { w }
      method _buildPage_Colors   { w }

      method _getGraphSize { }
      method _correctPath { path }
      method _changeColor  { type }
      method _changeWindowColors { win type }
      method _toggleChoice {}

      variable note
      variable _FVRC
      variable _padXAmnt 10
      variable _padYAmnt 3
      variable _tabLabels [list App Keywords Tables Graphs Colors]
      variable _selectedDirectoryName
      variable _currentBrowseDirectoryEntry
      variable _previousDirectory ""
      variable viewerWindow ""
      variable previousImgDisplayer ""
   }
}

itcl::body fvPreferences::constructor { args } {
   global tcl_platform env FITSVIEWER_LIBRARY
   global g_titleFont

   switch $tcl_platform(platform) {
      "macintosh" {
         set _FVRC [file join $env(PREF_FOLDER) "fv Preferences"]
      }
      "windows" {
         set  FITSVIEWER_LIBRARY $env(FITSVIEWER_LIBRARY)
         set _FVRC [file join $FITSVIEWER_LIBRARY "fv.ini"]
         # Pan Chai: uncomment when XPA is available in Windows
         # lappend _tabLabels Library
      }
      default {
         set _FVRC "~/.fvrc"
      }
   }

   option add *fvPreference.font g_titleFont
   # Create and initialize fvPref namespace

   namespace eval ::fvPref { 
      variable globalBgColor        #cccccc
      variable globalFgColor        black  
      variable activeBgColor        #eeeeee
      variable activeFgColor        black  
      variable checkBBgColor        red
      variable imgDisplayer         POW
      variable ifWriteHisKey        1
      variable ifDispFitsOnly       1
      variable ifWCSInfo            1
      variable ifProtectedKeys      1
      variable ifAutoReformatKeys   1
      variable ifLeftJustifyString  1
      variable ifAutoUpdateChecksum 0
      variable ifUseManager         1
      variable ifAutoPlotPrimary    0
      variable keepFileDialogVisible 0
      variable xpaLibPath           
      variable ds9LibPath           
      variable winManagement        Keep
      variable graphDispSize        [list 300 300]
      variable webModulesURLsHead   "http://heasarc.gsfc.nasa.gov/hera/"
      variable BrowserSetting       "None Defined"
   }

   # Override some defaults based on enviroment

   if { [winfo screenheight .]>850 } {
      set fvPref::graphDispSize [list 500 500]
   }

   set tmpBg [option get . background Background]
   if { $tmpBg != ""} {
      set fvPref::globalBgColor $tmpBg
   }
   set tmpFg [option get . foreground Foreground]
   if { $tmpFg != ""} {
      set fvPref::globalFgColor $tmpFg
   }

   if { $tcl_platform(platform)=="macintosh" } {
      set fvPref::ifUseManager 0
      set fvPref::globalBgColor "#eeeeee"
      set fvPref::activeBgColor "#cccccc"
   }

   if { $tcl_platform(platform)!="windows" } {
      set fvPref::BrowserSetting "None Defined"
   }

   if [info exists env(HERA_SERVER) ] {
      set fvPref::webModulesURLsHead "http://$env(HERA_SERVER)/hera/"
   } 
      
   #  Read in the preferences file
   _read
}

itcl::body fvPreferences::destructor { } {
   if { [winfo exists .fvpref] } {
      destroy .fvpref
   }
}


itcl::body fvPreferences::edit { {page "fv"} } {
   global tcl_platform
   global g_titleFont
   
   if { [winfo exists .fvpref] } {
      if {$tcl_platform(platform)!= "windows"} { 
        .fvpref activate
        Notebook:raise [.fvpref childsite].notebook $page
        # since the notebook does not actual destroy, we need this line to update graph size
        _setGraphSize [.fvpref childsite].notebook.f3.graphsize $fvPref::graphDispSize
      } else {
        focus .fvpref
        raise .fvpref        
        Notebook:raise .fvpref.notebook $page
      }        
      return
   }

   ###########
   # Setup Dialog Box
   ###########
   if { $tcl_platform(platform) != "windows" } {  
    ::iwidgets::dialogshell .fvpref -title "fv: Preferences" -modality "none"
    .fvpref add Save -text "Save" -command [itcl::code $this save] -font g_titleFont
    .fvpref add Help -text "Help" -command "hhelp preferences" -font g_titleFont
    .fvpref add Exit -text "Exit" -command [itcl::code $this close] -font g_titleFont
    .fvpref default Exit
   } else {
     toplevel .fvpref -class Dialog
     wm  title .fvpref "fv: Preferences"
     frame .fvpref.buts
     button .fvpref.buts.save -text Save -command [itcl::code $this save] -font g_titleFont
     button .fvpref.buts.help -text Help -command "hhelp preferences" -font g_titleFont
     button .fvpref.buts.exit -text Exit -command [itcl::code $this close] -font g_titleFont
     pack .fvpref.buts.save -side left -padx 30 -pady 4          
     pack .fvpref.buts.help -side left -padx 30  -pady 4        
     pack .fvpref.buts.exit -side right -padx 30 -pady 4
                
   }

   bind .fvpref <<CloseWindow>> [itcl::code $this close]

   ###########
   # Setup Tabbed Notebook Widget
   ###########

   if {$tcl_platform(platform) != "windows" } {   
      set note "[.fvpref childsite].notebook"
   } else {
      set note .fvpref.notebook
   } 

   Notebook:create $note -pages $_tabLabels -pad 8

   foreach p $_tabLabels {
      eval _buildPage_$p [Notebook:frame $note $p]
   }

   pack $note -fill both -expand 1   
    
   ###########
   # Display dialog
   ###########

   Notebook:raise $note $page
   Notebook:raise.page $note [lsearch $_tabLabels "Graphs"]
   Notebook:resize $note
   if {$tcl_platform(platform) != "windows" } {    
      .fvpref activate
   } else {
      pack .fvpref.buts 
   }
}

itcl::body fvPreferences::raisePage { page } {

   Notebook:raise.page $note [lsearch $_tabLabels $page]
   Notebook:resize $note
     
}

itcl::body fvPreferences::close { } {
   global tcl_platform
   if { [winfo exists .fvpref] } {
      if {$tcl_platform(platform) == "windows" } { 
        destroy .fvpref
      } else {
        .fvpref deactivate
      }
   }
   checkForExit
}


itcl::body fvPreferences::_read { } {
   global tcl_platform

   if { ![catch { set rcFile [open $_FVRC r] } ] } {
      while { [gets $rcFile line] != -1} {
         set entry [lindex $line 0]
         set value [lindex $line 1]
         if { [string length [string trim $entry]] <= 0 } continue
         switch -glob -- $entry {
            "Background" {	
               set fvPref::globalBgColor $value
            }
            "Foreground" {
               set fvPref::globalFgColor $value
            }
            "ActiveBackground" {
               set fvPref::activeBgColor $value
            }
            "ActiveForeground" {
               set fvPref::activeFgColor $value
            }
            "CheckButtonColor" {
               set fvPref::checkBBgColor $value
            }
            "ImageDisplayer" {
               set fvPref::imgDisplayer $value
            }
            "IfWriteHisKey" {
               set fvPref::ifWriteHisKey $value
            } 
            "IfDispFitsOnly" {
               set fvPref::ifDispFitsOnly $value
            } 	
            "IfWCSInfo" {
               set fvPref::ifWCSInfo $value
            }
            "IfProtectedKeys" {
               set fvPref::ifProtectedKeys $value
            }
            "IfAutoReformatKeys" {
               set fvPref::ifAutoReformatKeys $value
            }
            "WinManagement" {
               set fvPref::winManagement $value	
            }		
            "IfAutoUpdateChecksum" {
               set fvPref::ifAutoUpdateChecksum $value
            }	
            "IfLeftJustifyString" {
               set fvPref::ifLeftJustifyString $value
            }
            "IfUseDesktopManager" {
               if { $tcl_platform(platform) != "macintosh" } {
                  set fvPref::ifUseManager $value
               }
            }
            "IfAutoPlotPrimary" {
               set fvPref::ifAutoPlotPrimary $value
            }
            "GraphDisplaySize" {
               set fvPref::graphDispSize $value
            }
            "xpaLibPath" {
               set fvPref::xpaLibPath "$value"
            }
            "ds9LibPath" {
               set fvPref::ds9LibPath "$value"
            }
            "BrowserSetting" {
               set fvPref::BrowserSetting "$value"
            }
            "#*" {
            }
            default {
               set fvPref::$entry $value
            }
         }
      }			 
      ::close $rcFile
   }

   option add *Background          $fvPref::globalBgColor
   option add *Foreground          $fvPref::globalFgColor
   option add *HighlightBackground $fvPref::globalBgColor
   option add *activeForeground    $fvPref::activeFgColor
   option add *activeBackground    $fvPref::activeBgColor
   option add *selectForeground    $fvPref::activeFgColor
   option add *selectBackground    $fvPref::activeBgColor
   option add *selectColor         $fvPref::checkBBgColor

}

itcl::body fvPreferences::save {} {
   global tcl_platform

# check if _FVRC file is there
   catch { [file delete -force $_FVRC]} 

   if { [catch {set rcFile [open $_FVRC w]} err] == 1} {
      error "Unable to open $_FVRC to write"
      return 
   }

   puts $rcFile "\# Please don't change this file. It's auto generated by fv"
   puts $rcFile "Background           $fvPref::globalBgColor"
   puts $rcFile "Foreground           $fvPref::globalFgColor"
   puts $rcFile "ActiveBackground     $fvPref::activeBgColor"
   puts $rcFile "ActiveForeground     $fvPref::activeFgColor"
   puts $rcFile "CheckButtonColor     $fvPref::checkBBgColor"
   puts $rcFile "ImageDisplayer       $fvPref::imgDisplayer"
   puts $rcFile "IfWriteHisKey        $fvPref::ifWriteHisKey"
   puts $rcFile "IfDispFitsOnly       $fvPref::ifDispFitsOnly"
   puts $rcFile "WinManagement        $fvPref::winManagement"
   puts $rcFile "IfWCSInfo            $fvPref::ifWCSInfo"
   puts $rcFile "IfProtectedKeys      $fvPref::ifProtectedKeys"
   puts $rcFile "IfAutoReformatKeys   $fvPref::ifAutoReformatKeys"
   puts $rcFile "IfAutoUpdateChecksum $fvPref::ifAutoUpdateChecksum"
   puts $rcFile "IfLeftJustifyString  $fvPref::ifLeftJustifyString"
   puts $rcFile "IfUseDesktopManager  $fvPref::ifUseManager"
   puts $rcFile "IfAutoPlotPrimary    $fvPref::ifAutoPlotPrimary"
   puts $rcFile "GraphDisplaySize     {$fvPref::graphDispSize}"

   if { [info exists ::fvPref::BrowserSetting] && [string trim $fvPref::BrowserSetting] != "None Defined" } {
      puts $rcFile "BrowserSetting       $fvPref::BrowserSetting"
   }

   if {$tcl_platform(platform) != "windows" } { 
      if { [winfo exists .fvpref] && [winfo ismapped [.fvpref childsite].notebook.f3.graphsize] } {
         _setGraphSize [.fvpref childsite].notebook.f3.graphsize $fvPref::graphDispSize
      }
   } else {
      if { [winfo exists .fvpref] && [winfo ismapped .fvpref.notebook.f3.graphsize] } {
         _setGraphSize .fvpref.notebook.f3.graphsize $fvPref::graphDispSize
      }
   }

   if { [winfo exists .browseDirectorySetup] && [winfo ismapped .browseDirectorySetup] } {
      set browseDirectorySetupHList [.browseDirectorySetup.directory.directoryTree subwidget hlist]

      set _selectedDirectoryName [$browseDirectorySetupHList selection get]
      $_currentBrowseDirectoryEntry delete 0 end
      $_currentBrowseDirectoryEntry insert end $_selectedDirectoryName
   }

#  Pan Chai: uncomment these line when XPA available in Windows
   if {$tcl_platform(platform) == "windows" } { 
      if { [info exists ::fvPref::xpaLibPath] && [string length [string trim $fvPref::xpaLibPath]] > 0 } {
         puts $rcFile "xpaLibPath           \"$fvPref::xpaLibPath\""
      } elseif { $::fvPref::imgDisplayer == "DS9" } {
         _askDirectorySetup
         puts $rcFile "xpaLibPath           \"$fvPref::xpaLibPath\""
         puts $rcFile "ds9LibPath           \"$fvPref::ds9LibPath\""
      }

      if { [info exists ::fvPref::ds9LibPath] && [string length [string trim $fvPref::ds9LibPath]] > 0 } {
         puts $rcFile "ds9LibPath           \"$fvPref::ds9LibPath\""
      } elseif { $::fvPref::imgDisplayer == "DS9" } {
         _askDirectorySetup
         puts $rcFile "ds9LibPath           \"$fvPref::ds9LibPath\""
         puts $rcFile "xpaLibPath           \"$fvPref::xpaLibPath\""
      }

      if [winfo exists .fvwinkeeper] {
         .fvwinkeeper updateDisplayDeviceStatus
      }
   }

   ::close $rcFile

   set _previousDirectory ""
   catch { wm deiconify .browseDirectorySetup }
   catch { wm withdraw .browseDirectorySetup }

# puts "Options saved in $_FVRC"
}

itcl::body fvPreferences::_askDirectorySetup {} {
    option add *textBackground white

    if [winfo exists .askDirectorySetup] {
       destroy .askDirectorySetup
    }
    toplevel .askDirectorySetup 
    wm title .askDirectorySetup "Input DS9 and XPA Directory"
    set top .askDirectorySetup

    frame $top.selection
    set selectionFrame $top.selection

    ::iwidgets::entryfield $selectionFrame.ds9Path -labeltext "DS9 Path" -labelfont g_titleFont -width 30 \
                                             -textvariable fvPref::ds9LibPath
    ::iwidgets::entryfield $selectionFrame.xpaPath -labeltext "XPA Path" -labelfont g_titleFont -width 30 \
                                          -textvariable fvPref::xpaLibPath
    button $selectionFrame.ds9PathBrowse -text "Browse" -font g_titleFont
    button $selectionFrame.xpaPathBrowse -text "Browse" -font g_titleFont

    bind $selectionFrame.ds9PathBrowse <ButtonRelease-1> [itcl::code $this _browseDirectory %W]
    bind $selectionFrame.xpaPathBrowse <ButtonRelease-1> [itcl::code $this _browseDirectory %W]

    grid $selectionFrame.ds9Path -row 0  -column 0  -columnspan 4 -sticky news
    grid $selectionFrame.xpaPath -row 1  -column 0  -columnspan 4 -sticky news

    grid $selectionFrame.ds9PathBrowse -row 0  -column 6  -sticky news
    grid $selectionFrame.xpaPathBrowse -row 1  -column 6  -sticky news
    grid $selectionFrame -row 0  -column 0 -columnspan 6 -rowspan 2 -sticky news
    
    #grid columnconfigure $top.selection 1 -weight 1
    #grid rowconfigure $top.selection 0 -weight 1

    frame $top.action 
    button $top.action.ok     -text "OK" -font g_titleFont -command { destroy .askDirectorySetup }
    
    grid $top.action.ok     -row 0 -column 1 -sticky w
    grid $top.action -row 2 -column 0 -columnspan 6 -sticky news
}

##########################################################
#############      Private Functions      ################
##########################################################


##################
#
# Setup Page: fv
#
##################

itcl::body fvPreferences::_buildPage_App { w } {
   global tcl_platform
   global g_titleFont

   checkbutton $w.fits  -text "List FITS files only"  \
         -font g_titleFont \
         -variable fvPref::ifDispFitsOnly

   if { $tcl_platform(platform)!="macintosh" } {
      checkbutton $w.mngr  -text "Show desktop manager"  \
            -variable fvPref::ifUseManager \
            -font g_titleFont \
            -command ".fvwinkeeper updateVisibility"
   }

   checkbutton $w.filedpv  -text "Kepp File Dialog Panel visible"  \
         -font g_titleFont \
         -variable fvPref::keepFileDialogVisible

   ::iwidgets::radiobox $w.windows -labeltext "Window Management" -labelfont g_titleFont

   $w.windows add NONE \
         -text "Leave existing windows open when opening new one"
   $w.windows buttonconfigure 0 -variable fvPref::winManagement -value "Keep"
   $w.windows add HIDE \
         -text "Hide existing windows when opening new one"
   $w.windows buttonconfigure 1 -variable fvPref::winManagement -value "Hide"
   $w.windows add CLOSE \
         -text "Close existing windows when opening new one"
   $w.windows buttonconfigure 2 -variable fvPref::winManagement -value "Close"

   option add *textBackground white
   ::iwidgets::entryfield $w.browser -labeltext "Html Browser:" -labelfont g_titleFont -width 15 \
                                     -textvariable fvPref::BrowserSetting

   grid $w.fits     -row 1  -column 1  -sticky w   -pady $_padYAmnt \
         -padx $_padXAmnt
   if { $tcl_platform(platform)!="macintosh" } {
      grid $w.mngr  -row 2  -column 1  -sticky w   -pady $_padYAmnt \
            -padx $_padXAmnt
   }
   grid $w.filedpv -row 3  -column 1  -sticky w   -pady $_padYAmnt \
         -padx $_padXAmnt

   grid $w.windows  -row 4  -column 1  -sticky we  -pady $_padYAmnt

   if { !$::isWin } {
      grid $w.browser -row 5  -column 1  -sticky w -pady $_padYAmnt
   }

   grid columnconfig $w 1 -weight 1
}

##################
#
# Setup Page: Keywords
#
##################

itcl::body fvPreferences::_buildPage_Keywords { w } {
   global g_titleFont
   checkbutton $w.hist  -text "Write history keyword after modification" \
         -font g_titleFont \
         -variable fvPref::ifWriteHisKey
   checkbutton $w.format  -text "Auto-reformat keywords"  \
         -font g_titleFont \
         -variable fvPref::ifAutoReformatKeys
   checkbutton $w.protect  -text "Protect required keywords"  \
         -font g_titleFont \
         -variable fvPref::ifProtectedKeys

   ::iwidgets::radiobox $w.chksm -labeltext "Checksum Updates" -labelfont g_titleFont

   $w.chksm add ALWAYS -text "Always update"
   $w.chksm buttonconfigure 0 -variable fvPref::ifAutoUpdateChecksum -value 2
   $w.chksm add EXIST  -text "Update only if they exist"
   $w.chksm buttonconfigure 1 -variable fvPref::ifAutoUpdateChecksum -value 1
   $w.chksm add NEVER  -text "Do not update"
   $w.chksm buttonconfigure 2 -variable fvPref::ifAutoUpdateChecksum -value 0

   grid $w.hist     -row 1  -column 1  -sticky w  -pady $_padYAmnt \
         -padx $_padXAmnt
   grid $w.format   -row 2  -column 1  -sticky w  -pady $_padYAmnt \
         -padx $_padXAmnt
   grid $w.protect  -row 3  -column 1  -sticky w  -pady $_padYAmnt \
         -padx $_padXAmnt
   grid $w.chksm    -row 4  -column 1  -sticky we -pady $_padYAmnt
   grid columnconfig $w 1 -weight 1
}

##################
#
# Setup Page: Table
#
##################

itcl::body fvPreferences::_buildPage_Tables { w } {
   global g_titleFont

   ::iwidgets::radiobox $w.justify -labeltext "ASCII Column Justification" -labelfont g_titleFont

   $w.justify add LFT -text Left
   $w.justify buttonconfigure 0 -variable fvPref::ifLeftJustifyString -value 1
   $w.justify add RGT -text Right
   $w.justify buttonconfigure 1 -variable fvPref::ifLeftJustifyString -value 0

   grid $w.justify  -row 2  -column 1 -sticky ew  -pady $_padYAmnt
   grid columnconfig $w 1 -weight 1
}

##################
#
# Setup Page: Graph
#
##################

itcl::body fvPreferences::_buildPage_Graphs { w } {
   global g_hasSAOtng g_hasDS9
   global g_titleFont
   global tcl_platform

   # Auto Plot Primary
   
   set viewerWindow $w.viewer

   checkbutton $w.auto  -text "Auto-Plot Primary Image" \
         -font g_titleFont \
         -variable fvPref::ifAutoPlotPrimary

   # WCS info
   
   # checkbutton $w.wcs  -text "Use WCS Info" -variable fvPref::ifWCSInfo -font g_titleFont

   # Image Viewer

   ::iwidgets::radiobox $w.viewer -labeltext "Image Viewer" -labelfont g_titleFont

   $w.viewer add DS9 -text DS9
   $w.viewer buttonconfigure 0 -variable fvPref::imgDisplayer -value DS9 -command [itcl::code $this _toggleChoice]
   $w.viewer add POW -text POW 
   $w.viewer buttonconfigure 1 -variable fvPref::imgDisplayer -value POW -command [itcl::code $this _toggleChoice]
   #$w.viewer add SAO -text SAOtng
   #$w.viewer buttonconfigure 2 -variable fvPref::imgDisplayer -value SAOTNG -command [itcl::code $this _toggleChoice]

   if {$tcl_platform(platform) == "windows"} { 
      # DS9 entry

      option add *textBackground white

      ::iwidgets::entryfield $w.viewer.ds9Path -labeltext "DS9 Path" -labelfont g_titleFont -width 30 \
                                               -textvariable fvPref::ds9LibPath
      ::iwidgets::entryfield $w.viewer.xpaPath -labeltext "XPA Path" -labelfont g_titleFont -width 30 \
                                               -textvariable fvPref::xpaLibPath
      button $w.viewer.ds9PathBrowse -text "Browse" -font g_titleFont
      button $w.viewer.xpaPathBrowse -text "Browse" -font g_titleFont

      bind $w.viewer.ds9PathBrowse <ButtonRelease-1> [itcl::code $this _browseDirectory %W]
      bind $w.viewer.xpaPathBrowse <ButtonRelease-1> [itcl::code $this _browseDirectory %W]
   
      if { $fvPref::imgDisplayer == "DS9" } {
         grid $w.viewer.ds9Path -row 1  -column 2  -columnspan 4 -sticky swe
         grid $w.viewer.xpaPath -row 1  -column 2  -columnspan 4 -sticky nwe
   
         grid $w.viewer.ds9PathBrowse -row 1  -column 6  -sticky se
         grid $w.viewer.xpaPathBrowse -row 1  -column 6  -sticky ne
      }

      update idletasks
   }

   if { ! $g_hasDS9 } {
       $w.viewer buttonconfigure 0 -state disabled
   }

   if { ! $g_hasSAOtng } {
      # $w.viewer buttonconfigure 2 -state disabled
   }

   # Default graph display size
   
   ::iwidgets::optionmenu $w.graphsize -labeltext "Graph Size:" -labelpos w \
         -command [itcl::code $this _setGraphSize $w.graphsize] -labelfont g_titleFont -font g_titleFont
   $w.graphsize insert 0 \
         100x100 120x120 160x160 200x200 256x256 300x300 400x400 500x500 600x600 700x700 300x400 400x300 \
         "-----" Other...
   $w.graphsize disable "-----"
   _setGraphSize $w.graphsize $fvPref::graphDispSize

   grid $w.auto       -row 1  -column 1  -sticky w  -pady $_padYAmnt \
         -padx $_padXAmnt
   #grid $w.wcs        -row 2  -column 1  -sticky w  -pady $_padYAmnt \
   #      -padx $_padXAmnt
   grid $w.viewer     -row 3  -column 1  -sticky we -pady $_padYAmnt
   grid $w.graphsize  -row 4  -column 1  -sticky w  -pady $_padYAmnt \
         -padx $_padXAmnt

   grid columnconfig $w 1 -weight 1
}

itcl::body fvPreferences::_toggleChoice { } {
     global isWin

     if { $isWin } {
        set wndw $viewerWindow

        if { $fvPref::imgDisplayer == "DS9" } {
           grid $wndw.ds9Path -row 1  -column 2  -columnspan 4 -sticky swe
           grid $wndw.xpaPath -row 1  -column 2  -columnspan 4 -sticky nwe
   
           grid $wndw.ds9PathBrowse -row 1  -column 6  -sticky se
           grid $wndw.xpaPathBrowse -row 1  -column 6  -sticky ne
           update idletasks
           
           scan [winfo geometry $wndw] "%dx%d+%d+%d" Pw Ph Px Py
           set width [expr [winfo reqwidth $wndw.ds9Path] + [winfo reqwidth $wndw.ds9PathBrowse]]
           scan [winfo geometry .fvpref] "%dx%d+%d+%d" Rw Rh Rx Ry
           if { $previousImgDisplayer != "DS9" } {
              catch { wm geometry .fvpref [expr ${width} + $Rw - $Pw * 5 / 7 ]x$Rh+$Rx+$Ry } err
           }
           update idletasks

        } else {
           
           scan [winfo geometry $wndw] "%dx%d+%d+%d" Pw Ph Px Py
           set width [expr ([winfo reqwidth $wndw.ds9Path] + [winfo reqwidth $wndw.ds9PathBrowse]) * 7 / 5]

           grid forget $wndw.ds9Path
           grid forget $wndw.xpaPath
   
           grid forget $wndw.ds9PathBrowse
           grid forget $wndw.xpaPathBrowse

           update idletasks
           scan [winfo geometry .fvpref] "%dx%d+%d+%d" Rw Rh Rx Ry

           if { $previousImgDisplayer == "DS9" } {
              catch { wm geometry .fvpref [expr $Rw - $width * 2 / 7 + 20]x$Rh+$Rx+$Ry } err
           }
           update idletasks
        }
        set previousImgDisplayer $fvPref::imgDisplayer
     }
}

##################
#
# Setup Page: Colors   grid columnconfig $w 1 -weight 1
#
##################

itcl::body fvPreferences::_buildPage_Colors { w } {
   global g_titleFont

   set row 1
   foreach lbl [list \
         Background: \
         Foreground: \
         "Active Background:" \
         "Active Foreground:" \
         "Check Button:"] \
         var [list \
         globalBg \
         globalFg \
         activeBg \
         activeFg \
         checkBBg] {
      label $w.clab$row -text $lbl -font g_titleFont
      button $w.cbtn$row -textvariable fvPref::${var}Color -width 7 \
            -command [itcl::code $this _changeColor $var] -font g_titleFont
      grid $w.clab$row -row $row -column 1 -sticky w  -pady 0 \
            -padx $_padXAmnt
      grid $w.cbtn$row -row $row -column 2 -sticky w  -pady 0 \
            -padx 0
      incr row
   }
   grid columnconfigure $w 2 -weight 1
}

##################
# Setup Page: Library Path
##################

itcl::body fvPreferences::_setGraphSize { menu {val ""} } {
   if { $val=="" } {
      # Update parameter for menu selection

      set value [$menu get]
      if { $value=="Other..." } {
         set val [_getGraphSize]
         _setGraphSize $menu $val
      } else {
         set fvPref::graphDispSize [split $value x]
      }

   } else {

      # Set menu selection to supplied value
      set value [join $val x]
      if { [catch {$menu index $value}] } {
         $menu insert 0 $value
      }
      $menu select $value
      set fvPref::graphDispSize $val

   }
}


itcl::body fvPreferences::_getGraphSize { } {
   global g_titleFont

   ::iwidgets::dialogshell .gSize -title "fv: Graph Size" -modality "application" 

   .gSize add OK     -text Ok      -command {.gSize deactivate 1} -font g_titleFont
   .gSize add CANCEL -text Cancel  -command {.gSize deactivate 0} -font g_titleFont
   .gSize default OK

   set w [.gSize childsite]

   label $w.wid -text "Width:" -font g_titleFont
   label $w.hgt -text "Height:" -font g_titleFont
   entry $w.wide -font g_titleFont
   entry $w.hgte -font g_titleFont

   $w.wide insert 0 [lindex $fvPref::graphDispSize 0]
   $w.hgte insert 0 [lindex $fvPref::graphDispSize 1]

   grid $w.wid   -row 1  -column 1  -padx 3 -pady 3 -sticky e
   grid $w.hgt   -row 2  -column 1  -padx 3 -pady 3 -sticky e
   grid $w.wide  -row 1  -column 2  -padx 3 -pady 3 -sticky w
   grid $w.hgte  -row 2  -column 2  -padx 3 -pady 3 -sticky w

   set result [.gSize activate]
   set width  [$w.wide get]
   set height [$w.hgte get]
   destroy .gSize

   if { $result!="" && $result } {
      if { $width > 19 && $height > 19 && $width < 2001 && $height < 2001 } {
         return [list $width $height]
      }
      tk_messageBox -type ok -icon error -parent .fvpref -title "Bad Size" \
            -message "The graph size entered does not fall into the range\
            20-2000.  Reverting to previous value."
   }
   return $fvPref::graphDispSize
}



itcl::body fvPreferences::_changeColor {type} {
   
   switch $type {
      "globalBg" { set currColor $fvPref::globalBgColor }
      "globalFg" { set currColor $fvPref::globalFgColor }
      "activeBg" { set currColor $fvPref::activeBgColor }
      "activeFg" { set currColor $fvPref::activeFgColor }
      "checkBBg" { set currColor $fvPref::checkBBgColor }
      default    { set currColor "black" }
   }

   set tmpColor [tk_chooseColor -initialcolor $currColor]
   if { $tmpColor == "" } return 
   
   switch $type {
      "globalBg" {
         option add *Background          $tmpColor
         option add *HighlightBackground $tmpColor
         set fvPref::globalBgColor       $tmpColor
      }
      "globalFg" {
         option add *Foreground          $tmpColor
         set fvPref::globalFgColor       $tmpColor
      }
      "activeFg" {
         option add *activeForeground    $tmpColor
         set fvPref::activeFgColor       $tmpColor
      }
      "activeBg" {
         option add *activeBackground    $tmpColor
         set fvPref::activeBgColor       $tmpColor
      }
      "checkBBg" {
         option add *selectColor         $tmpColor
         set fvPref::checkBBgColor       $tmpColor
      }
      default {error "Unknown color type"}
   }

   # find all the windows and change their color
   set tmpWins [winfo children .]
   foreach i $tmpWins {
      _changeWindowColors $i $type
   }
}


itcl::body fvPreferences::_changeWindowColors {win type} {

   switch $type {
      "globalBg" {
         catch {$win configure -background $fvPref::globalBgColor}
         catch {$win configure -highlightbackground $fvPref::globalBgColor}
         if { [winfo class $win] == "Checkbutton" } {
            catch {$win configure -activebackground $fvPref::globalBgColor}
         }
      }
      "globalFg" {
         Notebook:config $note -textFg $fvPref::globalFgColor
         catch {$win configure -foreground $fvPref::globalFgColor}	    
      }
      "activeFg" {
         catch {$win configure -activeforeground $fvPref::activeFgColor}
      }
      "activeBg" {
         catch {$win configure -activebackground $fvPref::activeBgColor}
      }
      "checkBBg" {
         catch {$win configure -selectcolor $fvPref::checkBBgColor}
      }
      default {error "Unknown bg type"}
   }
   
   set tmpChildren [winfo children $win]
   if { $tmpChildren == "" } {
      return
   } else {
      foreach i $tmpChildren {
         _changeWindowColors $i $type 
      }
   }
}

itcl::body fvPreferences::_browseDirectory { win } {

     if { [string first "ds9" $win] >= 0 } {
       set win [winfo parent $win].ds9Path
     } else {
       set win [winfo parent $win].xpaPath
     }

     set _currentBrowseDirectoryEntry $win

     if [winfo exist .browseDirectorySetup] {
        wm deiconify .browseDirectorySetup
        .browseDirectorySetup.directory.saveInEntry delete 0 end
        if { [$win get] != "" } {
           .browseDirectorySetup.directory.saveInEntry insert end [$win get]
           set directoryValue [$win get]
        } else {
           .browseDirectorySetup.directory.saveInEntry insert end [pwd]
           set directoryValue [pwd]
        }
        .browseDirectorySetup.directory.directoryTree configure -value $directoryValue

     } else {

        toplevel .browseDirectorySetup 
        wm title .browseDirectorySetup "Select Directory"

        grid rowconfigure .browseDirectorySetup 2 -weight 1
        grid columnconfigure .browseDirectorySetup 0 -weight 1
        grid columnconfigure .browseDirectorySetup 1 -weight 1

        frame .browseDirectorySetup.directory             -bd 2 -relief ridge
        label .browseDirectorySetup.directory.dirLabel    -text "Directory: " -font g_titleFont
        entry .browseDirectorySetup.directory.saveInEntry -width 35 -bg white -font g_titleFont

        .browseDirectorySetup.directory.saveInEntry delete 0 end
        if { [$win get] != "" } {
           .browseDirectorySetup.directory.saveInEntry insert end [$win get]
           set directoryValue [$win get]
        } else {
           .browseDirectorySetup.directory.saveInEntry insert end [pwd]
           set directoryValue [pwd]
        }

        tixDirTree .browseDirectorySetup.directory.directoryTree -value $directoryValue \
                   -browsecmd [itcl::code $this _selectDirectory] \
                   -options { \
                        hlist.foreground black \
                        hlist.background white \
                        hlist.font g_titleFont \
                        hlist.width 40 \
                   }

        set _selectedDirectoryName $directoryValue

        grid .browseDirectorySetup.directory               -row 2 -column 0 -sticky news -columnspan 5 -rowspan 10
        grid .browseDirectorySetup.directory.dirLabel      -row 2 -column 0 -sticky nw
        grid .browseDirectorySetup.directory.saveInEntry   -row 2 -column 1 -sticky new
        grid .browseDirectorySetup.directory.directoryTree -row 3 -column 0 -columnspan 5 -rowspan 10 -sticky news

        grid columnconfigure .browseDirectorySetup.directory 1 -weight 1
        grid rowconfigure .browseDirectorySetup.directory 3 -weight 1

        frame .browseDirectorySetup.action 
        button .browseDirectorySetup.action.ok     -text "OK" -font g_titleFont \
                                                   -command [itcl::code $this save]
        label .browseDirectorySetup.action.blanklabel -text " " -font g_titleFont
        button .browseDirectorySetup.action.cancel -text "Cancel" -font g_titleFont \
                                                   -command [itcl::code $this _selectDirectory true]
        
        grid .browseDirectorySetup.action -row 18 -column 0 -columnspan 6 -sticky news
        grid .browseDirectorySetup.action.ok     -row 0 -column 1 -sticky w
        grid .browseDirectorySetup.action.blanklabel -row 0 -column 2 -columnspan 2 -sticky news
        grid .browseDirectorySetup.action.cancel -row 0 -column 4 -sticky e
     }

}

itcl::body fvPreferences::_selectDirectory { dir } {
     set _selectedDirectoryName [_correctPath $dir]

     if { $_previousDirectory == "" } {
        set _previousDirectory $dir
     }

     if { $dir == "true" } {
        wm deiconify .browseDirectorySetup
        wm withdraw .browseDirectorySetup
        set _selectedDirectoryName $_previousDirectory
     }

     if { $_selectedDirectoryName != "true" } {
        $_currentBrowseDirectoryEntry delete 0 end
        $_currentBrowseDirectoryEntry insert end $_selectedDirectoryName

        .browseDirectorySetup.directory.saveInEntry delete 0 end 
        .browseDirectorySetup.directory.saveInEntry insert end $_selectedDirectoryName
     }
}

itcl::body fvPreferences::_correctPath { path } {
     set newStr ""
     set path [string trim $path "{}"]

     for {set i 0} {$i < [string length $path]} {incr i} {
         if { [string range $path $i $i] == "\\" } {
            set newStr [format "%s/" $newStr]
         } else {
            set newStr [format "%s%s" $newStr [string range $path $i $i]]
         }
     }
     set newStr [string trimleft $newStr "/"]
     return $newStr
}