Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

YadaConfig.tcl

00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## YadaConfig - the configuration document 00013 ## \ingroup YadaConfiguration 00014 ## 00015 ## \author Michael Daum 00016 ## 00017 ## $Id: YadaConfig.tcl,v 1.15 2004/03/25 13:58:23 ddreyer Exp $ 00018 ## ---------------------------------------------------------------------------- 00019 class YadaConfig { 00020 inherit YadaDocument 00021 00022 00023 # variables ---------------------------------------------------------------- 00024 private variable _currentDocumentName "" 00025 00026 # methods ------------------------------------------------------------------ 00027 public method init {} 00028 public method load {} 00029 public method save {} 00030 public method activationHandle {} 00031 public method deActivationHandle {} 00032 public method document {docName args}; ## \type TclString, TclList 00033 00034 constructor {args} {}; ## \type TclList 00035 00036 private method _activateDocument {docName}; ## \type TclString 00037 }; 00038 00039 ## ---------------------------------------------------------------------------- 00040 ## constructor 00041 ## ---------------------------------------------------------------------------- 00042 body YadaConfig::constructor {args} { 00043 00044 # 00045 # the big tabno 00046 # 00047 itk_component add tabno { 00048 iwidgets::tabnotebook $itk_component(childsite).tabno \ 00049 -borderwidth 2 \ 00050 -tabpos e \ 00051 -backdrop gray90 \ 00052 -angle 10 \ 00053 -bevelamount 4 \ 00054 -raiseselect 1 \ 00055 -tabbackground gray80 00056 } {} 00057 00058 # 00059 # experiments 00060 # 00061 set experimentPage [$itk_component(tabno) add \ 00062 -label "Experiments"] 00063 00064 itk_component add experiments { 00065 YadaExperiments $experimentPage.experiments -name "experiments" 00066 } {} 00067 00068 $itk_component(tabno) pageconfigure "Experiments" \ 00069 -command [code $this _activateDocument "experiments"] 00070 00071 # 00072 # the grammars 00073 # 00074 set grammarPage [$itk_component(tabno) add \ 00075 -label "Grammars"] 00076 00077 itk_component add grammars { 00078 YadaGrammars $grammarPage.grammars -name "grammars" 00079 } {} 00080 00081 $itk_component(tabno) pageconfigure "Grammars" \ 00082 -command [code $this _activateDocument "grammars"] 00083 00084 00085 # 00086 # the machines 00087 # 00088 set machinesPage [$itk_component(tabno) add \ 00089 -label "Machines"] 00090 00091 itk_component add machines { 00092 YadaMachines $machinesPage.machines -name "machines" 00093 } {} 00094 00095 $itk_component(tabno) pageconfigure "Machines" \ 00096 -command [code $this _activateDocument "machines"] 00097 00098 00099 # 00100 # misc settings 00101 # 00102 set miscPage [$itk_component(tabno) add \ 00103 -label "Misc"] 00104 00105 itk_component add misc { 00106 YadaGenerals $miscPage.misc 00107 } {} 00108 00109 $itk_component(tabno) pageconfigure "Misc" \ 00110 -command [code $this _activateDocument "misc"] 00111 00112 # bindings 00113 00114 # packing + gridding 00115 pack $itk_component(tabno) -side top -expand 1 -fill both -padx 2 -pady 5 00116 pack $itk_component(experiments) -expand 1 -fill both 00117 pack $itk_component(grammars) -expand 1 -fill both 00118 pack $itk_component(machines) -expand 1 -fill both 00119 pack $itk_component(misc) -expand 1 -fill both 00120 00121 00122 eval itk_initialize $args 00123 .main registerDocument $this 00124 } 00125 00126 00127 ## ---------------------------------------------------------------------------- 00128 ## load 00129 ## ---------------------------------------------------------------------------- 00130 body YadaConfig::load {} { 00131 global env 00132 if { [$itk_component(tabno) view] == 0} { 00133 if { [catch {$itk_component(experiments) load} errorMessage] } { 00134 printMessage "Cannot load: $errorMessage" 00135 } 00136 00137 } elseif { [$itk_component(tabno) view] == 1} { 00138 if { [catch {$itk_component(grammars) load} errorMessage] } { 00139 printMessage "Cannot load: $errorMessage" 00140 } else { 00141 $itk_component(grammars) _show 00142 } 00143 00144 } elseif { [$itk_component(tabno) view] == 2} { 00145 if { [catch {$itk_component(machines) load} errorMessage] } { 00146 printMessage "Cannot load: $errorMessage" 00147 } 00148 } elseif { [$itk_component(tabno) view] == 3} { 00149 if { [catch {$itk_component(misc) load} errorMessage] } { 00150 printMessage "Cannot load: $errorMessage" 00151 } 00152 } else { 00153 printMessage "WARNING: YadaConfig::load under construction" 00154 } 00155 } 00156 00157 ## ---------------------------------------------------------------------------- 00158 ## save 00159 ## ---------------------------------------------------------------------------- 00160 body YadaConfig::save {} { 00161 global env 00162 if { [$itk_component(tabno) view] == 0} { 00163 $itk_component(experiments) save 00164 } elseif { [$itk_component(tabno) view] == 1} { 00165 $itk_component(grammars) save 00166 $itk_component(grammars) _show 00167 } elseif { [$itk_component(tabno) view ] == 2 } { 00168 $itk_component(machines) save 00169 00170 } elseif { [$itk_component(tabno) view ] == 3 } { 00171 $itk_component(misc) save 00172 } else { 00173 printMessage "WARNING: YadaConfig::save under construction" 00174 } 00175 } 00176 00177 ## ---------------------------------------------------------------------------- 00178 ## initialize the YADA configuration. 00179 ## This method initializes the yada config document and all its subdocuments, 00180 ## that is all init scripts are sourced. Doing so we generate YadaConfigItem 00181 ## objects and collet them all separately in the appropriate subdocuments. 00182 ## So the following init scripts in YADA_ETC are sourced in the given order: 00183 ## - \c configure.tcl: this is an application level init script 00184 ## - \c grammars.tcl: generate all YadaGrammar objects and assert them into YadaGrammars 00185 ## - \c machines.tcl: generate all YadaMachine objects and assert them into YadaMachines 00186 ## - \c experiments.tcl: generate all YadaExperiment objects and assert them into YadaExperiments 00187 ## Hint: the init scripts might source further init scripts. This lets you 00188 ## organize different init scripts for different purposes. 00189 ## ---------------------------------------------------------------------------- 00190 body YadaConfig::init {} { 00191 if {$_isInitialized} { 00192 return 00193 } 00194 00195 chain 00196 00197 # load data from rcFiles 00198 global env 00199 set rcFileName [file join $env(YADA_ETC) "configure.tcl"] 00200 00201 if {[file exists $rcFileName]} { 00202 # load resource file 00203 if {[catch {source $rcFileName}]} { 00204 bgerror "There's an error in your init file!" 00205 } 00206 } else { 00207 # set some hardcoded default experiments 00208 # puts "INFO: configure file `$rcFileName' not found, using defaults" 00209 } 00210 00211 # init subddocs, oder matters 00212 $itk_component(grammars) init 00213 $itk_component(machines) init 00214 $itk_component(misc) init 00215 $itk_component(experiments) init 00216 00217 # default selection 00218 _activateDocument "experiments" 00219 $itk_component(tabno) view "Experiments" 00220 } 00221 00222 ## ---------------------------------------------------------------------------- 00223 ## activationHandle 00224 ## ---------------------------------------------------------------------------- 00225 body YadaConfig::activationHandle {} { 00226 chain 00227 $itk_component(fileMenu) entryconfigure "Close" -state disabled 00228 _activateDocument $_currentDocumentName 00229 } 00230 00231 ## ---------------------------------------------------------------------------- 00232 ## _activateDocument 00233 ## ---------------------------------------------------------------------------- 00234 body YadaConfig::_activateDocument {docName} { 00235 00236 # call the deactivation handle 00237 if {$_currentDocumentName != "" && $_currentDocumentName != $docName} { 00238 $itk_component($_currentDocumentName) deActivationHandle 00239 } 00240 00241 # keep track of the active document 00242 set _currentDocumentName $docName 00243 00244 # remove the edit menu 00245 set editButton [.main component editButton] 00246 $editButton configure -menu "" 00247 00248 # call the activation handle 00249 $itk_component($docName) activationHandle 00250 } 00251 00252 ## ---------------------------------------------------------------------------- 00253 ## deActivationHandle 00254 ## ---------------------------------------------------------------------------- 00255 body YadaConfig::deActivationHandle {} { 00256 chain 00257 $itk_component(fileMenu) entryconfigure "Close" -state active 00258 if {$_currentDocumentName != ""} { 00259 $itk_component($_currentDocumentName) deActivationHandle 00260 } 00261 } 00262 00263 ## ---------------------------------------------------------------------------- 00264 ## document 00265 ## ---------------------------------------------------------------------------- 00266 body YadaConfig::document {docName args} { 00267 eval $itk_component($docName) $args 00268 }

YADA 2.0-alpha (20 Oct 2004)