| [6d7779d] | 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : bfobjects.tcl -> bfo |
|---|
| 3 | # PURPOSE : Bayes Function Objects. Funciones sobre objetos |
|---|
| 4 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 5 | |
|---|
| 6 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | proc GetOptionValue {lst option {default ""}} { |
|---|
| 8 | # |
|---|
| 9 | # PURPOSE: Obtener el valor para un argumento de un cojunto de opciones |
|---|
| 10 | # |
|---|
| 11 | # PARAMETERS: |
|---|
| 12 | # lst -> Lista de opciones |
|---|
| 13 | # option -> Opcion a buscar el valor |
|---|
| 14 | # default -> Valor por defecto por si no esta especificada la opcion |
|---|
| 15 | # |
|---|
| 16 | # RETURN: El valor de la opcion especificada. De no existir devuelve "" |
|---|
| 17 | # |
|---|
| 18 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 19 | set value $default |
|---|
| 20 | set posi [lsearch -exact $lst $option] |
|---|
| 21 | if {$posi >= 0} { |
|---|
| 22 | set value [lindex $lst [expr $posi + 1]] |
|---|
| 23 | } |
|---|
| 24 | return $value |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 28 | proc DeleteOption {lst option} { |
|---|
| 29 | # |
|---|
| 30 | # PURPOSE: Elimina una opción de una lista de argumentos |
|---|
| 31 | # |
|---|
| 32 | # PARAMETERS: |
|---|
| 33 | # lst -> Lista de opciones |
|---|
| 34 | # option -> Opcion a eleiminar |
|---|
| 35 | # |
|---|
| 36 | # RETURN: La lista de argumentos sin la opcion espcificada |
|---|
| 37 | # |
|---|
| 38 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 39 | set posi [lsearch -exact $lst $option] |
|---|
| 40 | if {$posi >= 0} { |
|---|
| 41 | set arg [lreplace $lst $posi [expr $posi + 1]] |
|---|
| 42 | } else { |
|---|
| 43 | set arg $lst |
|---|
| 44 | } |
|---|
| 45 | return $arg |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 49 | proc BfoCleanPath {path} { |
|---|
| 50 | # |
|---|
| 51 | # PURPOSE: Limpia el contenido de todos los widget de un path |
|---|
| 52 | # |
|---|
| 53 | # PARAMETERS: |
|---|
| 54 | # path -> contenedor de widget a limpiar |
|---|
| 55 | # |
|---|
| 56 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 57 | foreach w [winfo children $path] { |
|---|
| 58 | BfoCleanWidget $w |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 63 | proc BfoCleanWidget {widget} { |
|---|
| 64 | # |
|---|
| 65 | # PURPOSE: Borra el contenido de un widget |
|---|
| 66 | # |
|---|
| 67 | # PARAMETERS: |
|---|
| 68 | # widget -> objeto a limpiar |
|---|
| 69 | # |
|---|
| 70 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 71 | # capturamos el tipo |
|---|
| 72 | set type [winfo class $widget] |
|---|
| 73 | # comprobamos |
|---|
| 74 | switch -exact $type { |
|---|
| 75 | "BSelectFields" |
|---|
| 76 | { |
|---|
| 77 | $widget SetValue "" |
|---|
| 78 | } |
|---|
| 79 | "BComboBox" |
|---|
| 80 | { |
|---|
| 81 | #$widget BClear |
|---|
| 82 | $widget list clear |
|---|
| 83 | } |
|---|
| 84 | "Bcomboboxplus" |
|---|
| 85 | { |
|---|
| 86 | $widget key clean |
|---|
| 87 | $widget values clean |
|---|
| 88 | } |
|---|
| 89 | "BEditMaster" |
|---|
| 90 | { |
|---|
| 91 | BfoCleanPath $widget |
|---|
| 92 | } |
|---|
| 93 | "BEntryDate" { |
|---|
| 94 | $widget ClearDate |
|---|
| 95 | } |
|---|
| 96 | "Frame" { |
|---|
| 97 | BfoCleanPath $widget |
|---|
| 98 | } |
|---|
| 99 | "Mclistbox" { |
|---|
| 100 | # Estudiar como limpiar los datos |
|---|
| 101 | BfoCleanPath $widget |
|---|
| 102 | } |
|---|
| 103 | "ComboBox" { |
|---|
| 104 | $widget configure -text "" |
|---|
| 105 | } |
|---|
| 106 | "Entry" { |
|---|
| 107 | set stt [$widget cget -state] |
|---|
| 108 | $widget configure -state normal |
|---|
| 109 | $widget delete 0 end |
|---|
| 110 | $widget configure -state $stt |
|---|
| 111 | } |
|---|
| 112 | "LabelEntry" { |
|---|
| 113 | set stt [$widget cget -state] |
|---|
| 114 | $widget configure -state normal |
|---|
| 115 | $widget.e delete 0 end |
|---|
| 116 | $widget configure -state $stt |
|---|
| 117 | } |
|---|
| 118 | "Listbox" { |
|---|
| 119 | set stt [$widget cget -state] |
|---|
| 120 | $widget configure -state normal |
|---|
| 121 | $widget delete 0 end |
|---|
| 122 | $widget configure -state $stt |
|---|
| 123 | } |
|---|
| 124 | "Text" { |
|---|
| 125 | set stt [$widget cget -state] |
|---|
| 126 | $widget configure -state normal |
|---|
| 127 | $widget delete 0.0 end |
|---|
| 128 | $widget configure -state $stt |
|---|
| 129 | } |
|---|
| 130 | "Label" { |
|---|
| 131 | } |
|---|
| 132 | "Button" { |
|---|
| 133 | } |
|---|
| 134 | "Checkbutton" { |
|---|
| 135 | set stt [$widget cget -state] |
|---|
| 136 | $widget configure -state normal |
|---|
| 137 | $widget deselect |
|---|
| 138 | $widget configure -state $stt |
|---|
| 139 | } |
|---|
| 140 | default |
|---|
| 141 | { |
|---|
| 142 | puts "BfoCleanWidget. Widget type not recognized: $type" |
|---|
| 143 | if [llength [winfo children $widget]] { |
|---|
| 144 | BfoCleanPath $widget |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 151 | proc BfoActivateWidget {widget stt} { |
|---|
| 152 | # |
|---|
| 153 | # PURPOSE: Borra el contenido de un widget esecificos disennados por |
|---|
| 154 | # Bayes Inference |
|---|
| 155 | # |
|---|
| 156 | # PARAMETERS: |
|---|
| 157 | # widget -> objeto a limpiar |
|---|
| 158 | # stt -> estado aplicar [normal | active | select | disabled | notactive] |
|---|
| 159 | # Nota: Si el widget no admite todas las opciones se cambia |
|---|
| 160 | # select -> normal |
|---|
| 161 | # disabled, notactive -> disabled |
|---|
| 162 | # |
|---|
| 163 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 164 | # capturamos el tipo |
|---|
| 165 | set type [winfo class $widget] |
|---|
| 166 | # comprobamos |
|---|
| 167 | switch -exact $type { |
|---|
| 168 | BSelectFields { |
|---|
| 169 | $widget Activate $stt |
|---|
| 170 | } |
|---|
| 171 | Bcomboboxplus { |
|---|
| 172 | $widget activate $stt |
|---|
| 173 | } |
|---|
| 174 | BEntryDate { |
|---|
| 175 | switch $stt { |
|---|
| 176 | readonly - |
|---|
| 177 | notactive { |
|---|
| 178 | set stt disabled |
|---|
| 179 | } |
|---|
| 180 | select { |
|---|
| 181 | set stt normal |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | $widget configure -bstate $stt |
|---|
| 185 | } |
|---|
| 186 | Frame { |
|---|
| 187 | # BfoCleanPath $widget |
|---|
| 188 | } |
|---|
| 189 | Mclistbox { |
|---|
| 190 | # BfoCleanPath $widget |
|---|
| 191 | } |
|---|
| 192 | ComboBox { |
|---|
| 193 | switch $stt { |
|---|
| 194 | active - |
|---|
| 195 | select { |
|---|
| 196 | set stt normal |
|---|
| 197 | } |
|---|
| 198 | readonly - |
|---|
| 199 | notactive { |
|---|
| 200 | set stt disabled |
|---|
| 201 | } |
|---|
| 202 | } |
|---|
| 203 | $widget configure -state $stt |
|---|
| 204 | } |
|---|
| 205 | Entry { |
|---|
| 206 | switch $stt { |
|---|
| 207 | active - |
|---|
| 208 | select { |
|---|
| 209 | set stt normal |
|---|
| 210 | } |
|---|
| 211 | notactive { |
|---|
| 212 | set stt disabled |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | $widget configure -state $stt |
|---|
| 216 | } |
|---|
| 217 | LabelEntry { |
|---|
| 218 | switch $stt { |
|---|
| 219 | active { |
|---|
| 220 | set edi true |
|---|
| 221 | set stt normal |
|---|
| 222 | } |
|---|
| 223 | normal - |
|---|
| 224 | select { |
|---|
| 225 | set edi true |
|---|
| 226 | set stt normal |
|---|
| 227 | } |
|---|
| 228 | disabled - |
|---|
| 229 | notactive { |
|---|
| 230 | set edi false |
|---|
| 231 | set stt disabled |
|---|
| 232 | } |
|---|
| 233 | } |
|---|
| 234 | $widget configure -state $stt |
|---|
| 235 | $widget configure -editable $edi |
|---|
| 236 | } |
|---|
| 237 | Listbox |
|---|
| 238 | { |
|---|
| 239 | switch $stt { |
|---|
| 240 | active - |
|---|
| 241 | select { |
|---|
| 242 | set stt normal |
|---|
| 243 | } |
|---|
| 244 | notactive { |
|---|
| 245 | set stt disabled |
|---|
| 246 | } |
|---|
| 247 | } |
|---|
| 248 | $widget configure -state $stt |
|---|
| 249 | } |
|---|
| 250 | Text |
|---|
| 251 | { |
|---|
| 252 | switch $stt { |
|---|
| 253 | active - |
|---|
| 254 | select { |
|---|
| 255 | set stt normal |
|---|
| 256 | } |
|---|
| 257 | notactive { |
|---|
| 258 | set stt disabled |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | $widget configure -state $stt |
|---|
| 262 | } |
|---|
| 263 | Label { |
|---|
| 264 | switch $stt { |
|---|
| 265 | active - |
|---|
| 266 | select { |
|---|
| 267 | set stt normal |
|---|
| 268 | } |
|---|
| 269 | notactive { |
|---|
| 270 | set stt disabled |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | $widget configure -state $stt |
|---|
| 274 | } |
|---|
| 275 | Button { |
|---|
| 276 | switch $stt { |
|---|
| 277 | notactive { |
|---|
| 278 | set stt disabled |
|---|
| 279 | } |
|---|
| 280 | select { |
|---|
| 281 | set stt normal |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | $widget configure -state $stt |
|---|
| 285 | } |
|---|
| 286 | ArrowButton { |
|---|
| 287 | switch $stt { |
|---|
| 288 | notactive { |
|---|
| 289 | set stt disabled |
|---|
| 290 | } |
|---|
| 291 | select { |
|---|
| 292 | set stt normal |
|---|
| 293 | } |
|---|
| 294 | } |
|---|
| 295 | $widget configure -state $stt |
|---|
| 296 | } |
|---|
| 297 | Checkbutton { |
|---|
| 298 | switch $stt { |
|---|
| 299 | notactive - |
|---|
| 300 | disabled |
|---|
| 301 | { |
|---|
| 302 | set stt disabled |
|---|
| 303 | } |
|---|
| 304 | select - |
|---|
| 305 | active |
|---|
| 306 | { |
|---|
| 307 | set stt normal |
|---|
| 308 | } |
|---|
| 309 | } |
|---|
| 310 | $widget configure -state $stt |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | default |
|---|
| 314 | { |
|---|
| 315 | puts "BfoActivateWidget. Widget type not recognized: $type" |
|---|
| 316 | } |
|---|
| 317 | } |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 321 | proc BfoGetText {widget} { |
|---|
| 322 | # |
|---|
| 323 | # PURPOSE: Obtiene el texto introducido en un objeto |
|---|
| 324 | # |
|---|
| 325 | # PARAMETERS: |
|---|
| 326 | # widget -> objeto |
|---|
| 327 | # |
|---|
| 328 | # RETURN: el texto introducido |
|---|
| 329 | # |
|---|
| 330 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 331 | #Tolcon_Trace "BfoGetText widget: $widget , tipo:[winfo class $widget]" |
|---|
| 332 | set txt "" |
|---|
| 333 | # capturamos el tipo |
|---|
| 334 | set type [winfo class $widget] |
|---|
| 335 | # comprobamos |
|---|
| 336 | switch -exact $type { |
|---|
| 337 | "BSelectFields" { |
|---|
| 338 | set txt [$widget GetCode] |
|---|
| 339 | } |
|---|
| 340 | "BEntryDate" { |
|---|
| 341 | set txt [$widget cget -btext] |
|---|
| 342 | } |
|---|
| 343 | "ComboBox" { |
|---|
| 344 | set txt [$widget cget -text] |
|---|
| 345 | } |
|---|
| 346 | "Entry" { |
|---|
| 347 | set txt [$widget cget -text] |
|---|
| 348 | } |
|---|
| 349 | "LabelEntry" { |
|---|
| 350 | set txt [$widget cget -text] |
|---|
| 351 | } |
|---|
| 352 | "Checkbutton" { |
|---|
| 353 | set var [$widget cget -variable] |
|---|
| 354 | eval set txt $$var |
|---|
| 355 | } |
|---|
| 356 | "Text" { |
|---|
| 357 | set txt2 [$widget get 1.0 end] |
|---|
| 358 | set txt [string replace $txt2 end end {}] |
|---|
| 359 | } |
|---|
| 360 | "Bcomboboxplus" { |
|---|
| 361 | set txt [$widget key get] |
|---|
| 362 | } |
|---|
| 363 | default |
|---|
| 364 | { |
|---|
| 365 | puts "BfoGetText. Widget type not recognized: $type" |
|---|
| 366 | } |
|---|
| 367 | } |
|---|
| 368 | return $txt |
|---|
| 369 | } |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 373 | proc BfoSetText {widget txt} { |
|---|
| 374 | # |
|---|
| 375 | # PURPOSE: Set the input text on a widget depending its type. |
|---|
| 376 | # |
|---|
| 377 | # PARAMETERS: |
|---|
| 378 | # widget -> object |
|---|
| 379 | # txt -> text |
|---|
| 380 | # |
|---|
| 381 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 382 | # capturing the type |
|---|
| 383 | set type [winfo class $widget] |
|---|
| 384 | # set the text on the widget |
|---|
| 385 | switch -exact $type { |
|---|
| 386 | "BEntryDate" { |
|---|
| 387 | $widget configure -btext $txt |
|---|
| 388 | } |
|---|
| 389 | "ComboBox" { |
|---|
| 390 | $widget configure -text $txt |
|---|
| 391 | } |
|---|
| 392 | "Entry" { |
|---|
| 393 | $widget configure -text $txt |
|---|
| 394 | } |
|---|
| 395 | "LabelEntry" { |
|---|
| 396 | $widget configure -text $txt |
|---|
| 397 | } |
|---|
| 398 | "Bcomboboxplus" { |
|---|
| 399 | $widget configure -text $txt |
|---|
| 400 | } |
|---|
| 401 | default |
|---|
| 402 | { |
|---|
| 403 | puts "BfoSetText. Widget type not recognized: $type" |
|---|
| 404 | } |
|---|
| 405 | } |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 409 | proc SetAttribute {w attribute value} { |
|---|
| 410 | # |
|---|
| 411 | # PURPOSE: Applies recursively an attribute value to all childs of widget w. |
|---|
| 412 | # If a child doesn't have this attribute, doesn't produce an error.A |
|---|
| 413 | # |
|---|
| 414 | # PARAMETERS: |
|---|
| 415 | # w -> widget |
|---|
| 416 | # attribute -> attribute to modify |
|---|
| 417 | # value -> value of attribute |
|---|
| 418 | # |
|---|
| 419 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 420 | foreach ch [winfo children $w] { |
|---|
| 421 | SetAttribute $ch $attribute $value |
|---|
| 422 | } |
|---|
| 423 | catch {$w configure -$attribute $value} |
|---|
| 424 | } |
|---|