diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2019-06-05 17:04:41 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2019-06-05 17:04:41 (GMT) |
commit | 5bbbfdad35e9ae65ced0f29eb88b1600e8ead687 (patch) | |
tree | 08f8cea324f240a0a540395e565d65a81c0fa738 | |
parent | 66cab23c3c5e896c429702901481517079b925e5 (diff) | |
download | blt-5bbbfdad35e9ae65ced0f29eb88b1600e8ead687.zip blt-5bbbfdad35e9ae65ced0f29eb88b1600e8ead687.tar.gz blt-5bbbfdad35e9ae65ced0f29eb88b1600e8ead687.tar.bz2 |
GUI: colobar cmds load/save errors now report via Error proc
-rw-r--r-- | ds9/doc/release/r8.1.html | 1 | ||||
-rw-r--r-- | ds9/library/colorbar.tcl | 97 | ||||
-rw-r--r-- | tksao/colorbar/colorbar.C | 119 |
3 files changed, 125 insertions, 92 deletions
diff --git a/ds9/doc/release/r8.1.html b/ds9/doc/release/r8.1.html index b58b6b8..8548a4c 100644 --- a/ds9/doc/release/r8.1.html +++ b/ds9/doc/release/r8.1.html @@ -81,6 +81,7 @@ <li><tt><b>05.15.2019 RELEASE version 8.1b1</b></tt></li> <li><tt>05.28.2019 URL: more tolerant of mime types when downloading via http.</tt></li> <li><tt>06.04.2019 COLORBAR: fixed a number of issues with updating the screen with color tags active.</tt></li> +<li><tt>06.05.2019 GUI: colobar load/save errors now report via Error proc.</tt></li> <li><tt><b>xx.xx.2019 RELEASE version 8.1b2</b></tt></li> </ol> </div> diff --git a/ds9/library/colorbar.tcl b/ds9/library/colorbar.tcl index f3a657f..c3fa35f 100644 --- a/ds9/library/colorbar.tcl +++ b/ds9/library/colorbar.tcl @@ -133,33 +133,39 @@ proc LoadColormap {} { } # used by backup -proc LoadColormapFile {filename} { +proc LoadColormapFile {fn} { global colorbar global icolorbar global current global ds9 - if {$filename != {}} { - colorbar load "\{$filename\}" - set id [colorbar get id] - set colorbar(map) [colorbar get name] + if {$fn == {}} { + return + } + + if {[catch {colorbar load "\{$fn\}"} rr]} { + Error $rr + return + } + + set id [colorbar get id] + set colorbar(map) [colorbar get name] + + $ds9(mb).color.user add radiobutton \ + -label "$colorbar(map)" \ + -variable colorbar(map) \ + -command [list ChangeColormapID $id] - $ds9(mb).color.user add radiobutton \ + if {[winfo exists $icolorbar(top)]} { + $icolorbar(mb).colormap.user add radiobutton \ -label "$colorbar(map)" \ -variable colorbar(map) \ -command [list ChangeColormapID $id] - - if {[winfo exists $icolorbar(top)]} { - $icolorbar(mb).colormap.user add radiobutton \ - -label "$colorbar(map)" \ - -variable colorbar(map) \ - -command [list ChangeColormapID $id] - } - incr icolorbar(count) - - ChangeColormapID $id } + incr icolorbar(count) + + ChangeColormapID $id } proc SaveColormap {} { @@ -167,36 +173,45 @@ proc SaveColormap {} { SaveColormapFile [SaveFileDialog colorbarfbox] } -proc SaveColormapFile {filename} { - if {$filename != {}} { - colorbar save "\{$filename\}" +proc SaveColormapFile {fn} { + if {$fn == {}} { + return + } + + if {[catch {colorbar save "\{$fn\}"} rr]} { + Error $rr + return } } proc LoadContrastBias {} { global dcolorbar - set filename [OpenFileDialog contrastbiasfbox] - if {$filename != {}} { - if {![catch {set ch [open $filename r]}]} { - set ll [gets $ch] - close $ch - set dcolorbar(contrast) [lindex $ll 0] - set dcolorbar(bias) [lindex $ll 1] - ApplyColormap - } + set fn [OpenFileDialog contrastbiasfbox] + if {$fn == {}} { + return + } + + if {![catch {set ch [open $fn r]}]} { + set ll [gets $ch] + close $ch + set dcolorbar(contrast) [lindex $ll 0] + set dcolorbar(bias) [lindex $ll 1] + ApplyColormap } } proc SaveContrastBias {} { global dcolorbar - set filename [SaveFileDialog contrastbiasfbox] - if {$filename != {}} { - if {![catch {set ch [open $filename w]}]} { - puts $ch "$dcolorbar(contrast) $dcolorbar(bias)" - close $ch - } + set fn [SaveFileDialog contrastbiasfbox] + if {$fn == {}} { + return + } + + if {![catch {set ch [open $fn w]}]} { + puts $ch "$dcolorbar(contrast) $dcolorbar(bias)" + close $ch } } @@ -676,7 +691,10 @@ proc LoadColorTag {fn} { if {$fn != {}} { # yes, we need this UpdateColormapLevel - $current(colorbar) tag load "\{$fn\}" + if {[catch {$current(colorbar) tag load "\{$fn\}"} rr]} { + Error $rr + return + } if {$current(frame) != {}} { $current(frame) colormap [$current(colorbar) get colormap] $current(frame) colorbar tag "\{[$current(colorbar) get tag]\}" @@ -688,8 +706,13 @@ proc SaveColorTag {} { global current set fn [SaveFileDialog colortagfbox] - if {$fn != {}} { - $current(colorbar) tag save "\{$fn\}" + if {$fn == {}} { + return + } + + if {[catch {colorbar tag save "\{$fn\}"} rr]} { + Error $rr + return } } diff --git a/tksao/colorbar/colorbar.C b/tksao/colorbar/colorbar.C index a35610d..49229cd 100644 --- a/tksao/colorbar/colorbar.C +++ b/tksao/colorbar/colorbar.C @@ -723,69 +723,78 @@ void Colorbar::tagLoadCmd(const char* fn) { ifstream str(fn); - if (str) { - ctags.deleteAll(); - - while (!str.eof()) { - int mm=0; - int nn=0; - double aa =0; - double bb =0; - char color[32]; - *color ='\0'; - - str >> aa >> bb >> color; - - if (aa && bb && *color) { - // special case - if (aa>lut[cnt-1] && bb>lut[cnt-1]) - continue; - else if (aa<lut[0] && bb<lut[0]) - continue; - - mm =0; - for (int ii=0; ii<cnt; ii++) - if (aa<lut[ii]) { - mm=ii; - break; - } - nn =cnt-1; - for (int ii=cnt-1; ii>=0; ii--) - if (bb>lut[ii]) { - nn=ii; - break; - } - - Vector rr = Vector(mm,nn)/cnt*colorCount; - ctags.append(new ColorTag(this,rr[0],rr[1],color)); - } - } + if (!str) { + Tcl_AppendResult(interp, " unable to load color tags: ", fn, NULL); + result = TCL_ERROR; + return; + } - updateColors(); + ctags.deleteAll(); + + while (!str.eof()) { + int mm=0; + int nn=0; + double aa =0; + double bb =0; + char color[32]; + *color ='\0'; + + str >> aa >> bb >> color; + + if (aa && bb && *color) { + // special case + if (aa>lut[cnt-1] && bb>lut[cnt-1]) + continue; + else if (aa<lut[0] && bb<lut[0]) + continue; + + mm =0; + for (int ii=0; ii<cnt; ii++) + if (aa<lut[ii]) { + mm=ii; + break; + } + nn =cnt-1; + for (int ii=cnt-1; ii>=0; ii--) + if (bb>lut[ii]) { + nn=ii; + break; + } + + Vector rr = Vector(mm,nn)/cnt*colorCount; + ctags.append(new ColorTag(this,rr[0],rr[1],color)); + } } + + updateColors(); } void Colorbar::tagSaveCmd(const char* fn) { ofstream str(fn); - if (str) { - ctags.head(); - while (ctags.current()) { - int startid = float(ctags.current()->start())/colorCount * cnt; - int stopid = float(ctags.current()->stop())/colorCount * cnt; - if (startid<0) - startid = 0; - if (startid>=cnt) - startid = cnt-1; - if (stopid<0) - stopid = 0; - if (stopid>=cnt) - stopid = cnt-1; - str << lut[startid] << ' ' << lut[stopid] << ' ' - << ctags.current()->colorname() << endl; - ctags.next(); - } + if (!str) { + Tcl_AppendResult(interp, " unable to save color tags: ", fn, NULL); + result = TCL_ERROR; + return; + } + + ctags.head(); + while (ctags.current()) { + int startid = float(ctags.current()->start())/colorCount * cnt; + int stopid = float(ctags.current()->stop())/colorCount * cnt; + if (startid<0) + startid = 0; + if (startid>=cnt) + startid = cnt-1; + if (stopid<0) + stopid = 0; + if (stopid>=cnt) + stopid = cnt-1; + + str << lut[startid] << ' ' << lut[stopid] << ' ' + << ctags.current()->colorname() << endl; + ctags.next(); } } |