Changeset 6323 for branches/1.7
- Timestamp:
- May 11, 2016 10:05:24 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.7/gui/scripts/analyzer.tcl
r6272 r6323 120 120 private method SelectSimsetForLoading {} 121 121 private method SelectSimsetNameAndSave {} 122 private method SelectSimsetTo Publish{}123 private method WriteSimsetFile { appName fileName publish}122 private method SelectSimsetToShare {} 123 private method WriteSimsetFile { appName fileName share } 124 124 private method OverwriteSaveFile {} 125 125 private method BuildQuestionDialog { popup } 126 126 private method Save {} 127 127 private method CleanName { name } 128 private method InstallSharedFile { installdir file } 129 private method CreateSharedPath { path } 130 private method ExportURL { appName installdir } 131 private method ExportFile { src msgFile } 128 132 } 129 133 … … 213 217 buildMenu $itk_component(help).menu $url $_appName 214 218 215 if 0 {216 # To be eliminated with menu changes.217 itk_component add about {218 button $itk_component(hubcntls).about \219 -text "About this tool" \220 -command [list Rappture::filexfer::webpage \221 "$url/tools/$_appName"]222 } {223 usual224 ignore -font225 rename -background -simcontrolcolor simControlColor Color226 rename -highlightbackground -simcontrolcolor simControlColor Color227 }228 pack $itk_component(about) -side top -anchor w229 230 itk_component add questions {231 button $itk_component(hubcntls).questions -text Questions? \232 -command [list Rappture::filexfer::webpage \233 "$url/resources/$_appName/questions"]234 } {235 usual236 ignore -font237 rename -background -simcontrolcolor simControlColor Color238 rename -highlightbackground -simcontrolcolor simControlColor Color239 }240 pack $itk_component(questions) -side top -anchor w241 if { $url == "" || $_appName == "" } {242 $itk_component(questions) configure -state disabled243 $itk_component(about) configure -state disabled244 } else {245 $itk_component(questions) configure -state normal246 $itk_component(about) configure -state normal247 }248 }249 219 itk_component add simstatus { 250 220 text $itk_component(simbg).simstatus -borderwidth 0 \ … … 477 447 # check to see if simulation is really needed 478 448 $_tool sync 479 if {[$_resultset contains [$_tool xml object]] 480 &&![string equal $_control "manual-resim"]} {449 if {[$_resultset contains [$_tool xml object]] && 450 ![string equal $_control "manual-resim"]} { 481 451 # not needed -- show results and return 482 452 $itk_component(notebook) current analyze … … 569 539 # check to see if simulation is really needed 570 540 $_tool sync 571 if {![$_resultset contains [$_tool xml object]] 572 ||[string equal $_control "manual-resim"]} {541 if {![$_resultset contains [$_tool xml object]] || 542 [string equal $_control "manual-resim"]} { 573 543 # if control mode is "auto", then simulate right away 574 544 if {[string match auto* $_control]} { … … 1158 1128 # Scan through and pick out any =RAPPTURE-PROGRESS=> messages first. 1159 1129 # 1160 1161 while {[regexp -indices \ 1162 {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} $message \ 1163 match percent mesg]} { 1130 set pattern {=RAPPTURE-PROGRESS=> *([-+]?[0-9]+) +([^\n]*)(\n|$)} 1131 while {[regexp -indices $pattern $message match percent mesg]} { 1164 1132 1165 1133 foreach {i0 i1} $percent break … … 1203 1171 # 1204 1172 $itk_component(runinfo) configure -state normal 1205 1206 while {[regexp -indices \ 1207 {=RAPPTURE-([a-zA-Z]+)=>([^\n]*)(\n|$)} $message \ 1208 match type mesg]} { 1209 1173 set pattern {=RAPPTURE-([a-zA-Z]+)=>([^\n]*)(\n|$)} 1174 while {[regexp -indices $pattern $message match type mesg]} { 1210 1175 foreach {i0 i1} $match break 1211 1176 set first [string range $message 0 [expr {$i0-1}]] … … 1250 1215 set name [$itk_component(viewselector) value] 1251 1216 if {[info exists _label2desc($name)] && 1252 1217 [string length $_label2desc($name)] > 0} { 1253 1218 append tip "$_label2desc($name)\n\n" 1254 1219 } … … 1518 1483 continue 1519 1484 } 1520 if 0 {1521 # Recurse over all child nodes.1522 _trajToSequence $xmlobj $current1523 }1524 1485 } 1525 1486 } … … 1550 1511 if { [FindSimsetsForApp $_appName] == 0 } { 1551 1512 $m entryconfigure "Load Simulations" -state disable 1552 $m entryconfigure " PublishSimulations" -state disable1513 $m entryconfigure "Share Simulations" -state disable 1553 1514 $m entryconfigure "Delete Simulations" -state disabled 1554 1515 } else { 1555 1516 $m entryconfigure "Load Simulations" -state normal 1556 $m entryconfigure " PublishSimulations" -state normal1517 $m entryconfigure "Share Simulations" -state normal 1557 1518 $m entryconfigure "Delete Simulations" -state normal 1558 1519 } … … 1578 1539 set webcmd Rappture::filexfer::webpage 1579 1540 set group "app-$_appName" 1541 if { [info exists env(SESSION)] } { 1542 set referer "&referrer=$url/tools/$appName/session?sess=$env(SESSION)" 1543 } else { 1544 set referer "" 1545 } 1580 1546 $m add command -label "About this tool" \ 1581 1547 -command [list $webcmd "$url/tools/$appName"] \ … … 1585 1551 -state $state 1586 1552 $m add command -label "Tickets" -state $state \ 1587 -command [list $webcmd "$url/feedback/report_problems?group=$group "]1553 -command [list $webcmd "$url/feedback/report_problems?group=$group$referer"] 1588 1554 $m add command -label "Wish List" -state disabled 1589 1555 $m add separator … … 1597 1563 -command [itcl::code $this SelectSimsetForDeletion] \ 1598 1564 -state $state 1599 $m add command -label " PublishSimulations" \1600 -command [itcl::code $this SelectSimsetTo Publish] \1565 $m add command -label "Share Simulations" \ 1566 -command [itcl::code $this SelectSimsetToShare] \ 1601 1567 -state $state 1602 1568 return $m … … 1683 1649 itcl::body Rappture::Analyzer::SelectSimsetNameAndSave {} { 1684 1650 if { [EditSimset] } { 1685 set appDir [file normalize ~/data/saved/$_appName] 1686 file mkdir $appDir 1687 set fileName [file join $appDir [CleanName $_saved(Name).sav]] 1651 set name [CleanName $_saved(Name)] 1652 set saveDir [file join ~/data/saved $_appName $name] 1653 set saveDir [file normalize $saveDir] 1654 file mkdir $saveDir 1655 set fileName [file join $saveDir $name.sav] 1688 1656 if { [file exists $fileName] } { 1689 1657 if { ![OverwriteSaveFile] } { … … 1700 1668 # Use the table to omit specific results 1701 1669 # Use file chooser to save to specific 1702 itcl::body Rappture::Analyzer::SelectSimsetTo Publish{} {1703 if { [GetSimset " publish"] } {1670 itcl::body Rappture::Analyzer::SelectSimsetToShare {} { 1671 if { [GetSimset "share"] } { 1704 1672 global env 1705 set shareDir [file join /data/tools/shared $_appName $env(USER)] 1673 set name [CleanName $_saved(Name)] 1674 set shareDir [file join /data/tools/shared $env(USER) $_appName $name] 1706 1675 if { [catch { 1707 file mkdir $shareDir 1708 file attributes $shareDir -permissions o+r,g+rw 1676 CreateSharedPath $shareDir 1709 1677 } errs] != 0 } { 1710 1678 puts stderr errs=$errs 1711 1679 return 1712 1680 } 1713 set fileName [file join $shareDir [CleanName $_saved(Name).sav]]1681 set fileName [file join $shareDir $name.sav] 1714 1682 if { [file exists $fileName] } { 1715 1683 if { ![OverwriteSaveFile] } { … … 1718 1686 } 1719 1687 WriteSimsetFile $_appName $fileName 1 1688 ExportURL $_appName $shareDir 1720 1689 } 1721 1690 } … … 1783 1752 array unset _saved 1784 1753 array set _saved [$_tree get $node] 1785 set root [file root$_saved(FileName)]1754 set saveDir [file dirname $_saved(FileName)] 1786 1755 set files {} 1787 1756 foreach file $_saved(Files) { 1788 1757 if { [file pathtype $file] == "relative" } { 1789 set file [file join $ root$file]1758 set file [file join $saveDir $file] 1790 1759 } 1791 1760 lappend files $file … … 1798 1767 # WriteSimsetFile -- 1799 1768 # 1800 # Write the .sav file and the runfiles in the ~/data/saved/$_appName1801 # directory. The subdirectory where the runfiles are written is1802 # the root of the .save file name.1803 # 1804 itcl::body Rappture::Analyzer::WriteSimsetFile { appName fileName publish } { 1805 # The runfiles directory is the root of the filename. For example, if 1806 # the simset file is /path/to/myName.sav, the runfile directory is 1807 # /path/to/myName 1808 set root [file root$fileName]1809 if { [file exists $ root] } {1810 file delete -force $ root1769 # Write the .sav file and the runfiles in the 1770 # ~/data/saved/$_appName/$name 1771 # directory. 1772 # The run files will be in the same directory as the .sav file. 1773 # For example, if the simset file is /path/to/appName/myName/myName.sav, 1774 # the runfile directory is /path/to/appName/myName. 1775 # 1776 itcl::body Rappture::Analyzer::WriteSimsetFile { appName fileName share } { 1777 set saveDir [file dirname $fileName] 1778 if { [file exists $saveDir] } { 1779 file delete -force $saveDir 1811 1780 } 1812 1781 if { [catch { 1813 file mkdir $root 1782 if { $share } { 1783 CreateSharedPath $saveDir 1784 } else { 1785 file mkdir $saveDir 1786 } 1814 1787 set f [open $fileName "w"] 1815 1788 puts $f [list "Name" $_saved(Name)] … … 1823 1796 foreach file $_saved(Files) { 1824 1797 set tail [file tail $file] 1825 set dest [file join $root $tail] 1826 file copy -force $file $dest 1827 if { $publish } { 1828 file attributes $dest -permissions o+r,g+rw 1798 set dest [file join $saveDir $tail] 1799 if { $share } { 1800 InstallSharedFile $saveDir $file 1801 } else { 1802 file copy -force $file $dest 1829 1803 } 1830 1804 lappend runfiles $tail … … 1832 1806 puts $f [list "Files" $runfiles] 1833 1807 close $f 1834 if { $ publish} {1808 if { $share } { 1835 1809 file attributes $fileName -permissions o+r,g+rw 1836 1810 } … … 1849 1823 Rappture::Balloon $popup -title "Save set of simulations..." 1850 1824 set inner [$popup component inner] 1851 1825 1852 1826 label $inner.name_l -text "Simulation Set Name" 1853 1827 entry $inner.name -background white … … 1914 1888 return 0 1915 1889 } 1916 set root [file root$fileName]1890 set saveDir [file dirname $fileName] 1917 1891 foreach file $_saved(Files) { 1918 1892 if { [file pathtype $file] == "relative" } { 1919 set file [file join $ root$file]1893 set file [file join $saveDir $file] 1920 1894 } 1921 1895 if { ![file readable $file] } { … … 1938 1912 itcl::body Rappture::Analyzer::LoadSimulations { files } { 1939 1913 set loadobjs {} 1940 set root [file root$_saved(FileName)]1914 set saveDir [file dirname $_saved(FileName)] 1941 1915 foreach runfile $files { 1942 1916 if { [file pathtype $runfile] == "relative" } { 1943 set runfile [file join $ root$runfile]1917 set runfile [file join $saveDir $runfile] 1944 1918 } 1945 1919 if { ![file exists $runfile] } { … … 1959 1933 $win.pager current analyzer 1960 1934 $win.pager configure -nosim 0 1961 if 0 {1962 # Load the inputs for the very last run1963 global tool1964 $tool load $runobj1965 }1966 1935 } 1967 1936 … … 1974 1943 } 1975 1944 if { [GetSimset "delete"] } { 1976 set root [file root $_saved(FileName)] 1977 file delete -force $root 1978 file delete -force $_saved(FileName) 1945 set saveDir [file dirname $_saved(FileName)] 1946 file delete -force $saveDir 1979 1947 } 1980 1948 } … … 1984 1952 # 1985 1953 itcl::body Rappture::Analyzer::FindSimsetsForApp { appName } { 1954 if { $appName == "" } { 1955 puts stderr "No application name found" 1956 return 0 1957 } 1986 1958 $_tree delete 0 1987 foreach fileName [glob -nocomplain ~/data/saved/$appName/* .sav] {1959 foreach fileName [glob -nocomplain ~/data/saved/$appName/*/*.sav] { 1988 1960 if { [ReadSimsetFile $fileName] } { 1989 1961 if { $_revision > 0 && [info exists _saved(Revision)] && … … 2020 1992 scrollbar $inner.ys -orient vertical -command "$tv yview" 2021 1993 frame $inner.controls 2022 1994 2023 1995 $tv column insert end "Name" "Description" "Date" "Creator" 2024 1996 $tv column configure treeView -hide yes … … 2092 2064 # Create the print dialog widget and add it to the the balloon popup. 2093 2065 label $popup.title -text " " \ 2094 2095 2066 -padx 10 -pady 10 \ 2067 -background grey92 2096 2068 button $popup.yes -text "Yes" \ 2097 2098 2099 2069 -highlightthickness 0 \ 2070 -bd 2 \ 2071 -command [itcl::code $this Save] 2100 2072 button $popup.no -text "No" \ 2101 2102 2103 2073 -highlightthickness 0 \ 2074 -bd 2 \ 2075 -command [itcl::code $this Cancel] 2104 2076 blt::table $popup \ 2105 2106 2107 2077 0,0 $popup.title -cspan 2 -fill x -pady 4 \ 2078 1,0 $popup.yes -width { 0 1i .6i } -pady 4 \ 2079 1,1 $popup.no -width { 0 1i .6i } -pady 4 2108 2080 blt::table configure $popup r2 -height 0.125i 2109 2081 } … … 2116 2088 set popup .question 2117 2089 if { ![winfo exists $popup] } { 2118 2090 BuildQuestionDialog $popup 2119 2091 } 2120 2092 set text "Simulation set \"$_saved(Name)\" already exists. Overwrite?" … … 2143 2115 return $doSave 2144 2116 } 2117 2118 itcl::body Rappture::Analyzer::InstallSharedFile { installdir file } { 2119 set dst [file join $installdir [file tail $file]] 2120 file copy -force $file $dst 2121 file attributes $dst -permissions g+rw,o+r 2122 return $dst 2123 } 2124 2125 itcl::body Rappture::Analyzer::CreateSharedPath { path } { 2126 set dir "" 2127 foreach file [file split $path] { 2128 set dir [file join $dir $file] 2129 if { [file exists $dir] } { 2130 if { ![file isdirectory $dir] } { 2131 error "error in path \"$path\": \"$dir\" is not a directory." 2132 } 2133 } else { 2134 file mkdir $dir 2135 file attributes $dir -permissions g+rwx,o+rx 2136 } 2137 } 2138 } 2139 2140 itcl::body Rappture::Analyzer::ExportURL { appName installdir } { 2141 set fileName [file join $installdir url.txt] 2142 set name [file tail $installdir] 2143 set f [open $fileName "w"] 2144 puts $f "https://nanohub.org/tools/$appName/invoke?params=file(simset):$installdir/$name.sav\n" 2145 close $f 2146 file attributes $fileName -permissions g+rw,o+r 2147 if { [file exists /usr/bin/exportfile] } { 2148 set msgFile [file join $::Rappture::installdir export.html] 2149 ExportFile $fileName $msgFile 2150 } 2151 } 2152 2153 itcl::body Rappture::Analyzer::ExportFile { src msgFile } { 2154 set dstdir ~/.filexfer/exportfile 2155 file mkdir $dstdir 2156 set dst [file join $dstdir [file tail $src]] 2157 if { [file exists $dst] } { 2158 puts stderr "could be a problem: already waiting to export $dst" 2159 } 2160 file copy -force $src $dst 2161 # Now export the file. 2162 if { [catch { 2163 global exportFileVar 2164 set exportFileVar 0; # Kill any previous export. 2165 set mesg "Select file to export to desktop/laptop" 2166 update 2167 set cmd "/usr/bin/exportfile --delete $dst --timeout 3 " 2168 if { [file exists $msgFile] } { 2169 append cmd "--message $msgFile" 2170 } 2171 blt::bgexec exportFileVar /bin/sh -c $cmd & 2172 } errs] != 0 } { 2173 global errorInfo 2174 puts stderr "err: $errorInfo" 2175 file delete -force $dst 2176 } 2177 } 2178
Note: See TracChangeset
for help on using the changeset viewer.