| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : guifunction.tcl |
|---|
| 3 | # PURPOSE : This file contains a namespace called GuiFunction with its |
|---|
| 4 | # functions. It's for creating a general dialog that takes values |
|---|
| 5 | # for arguments of a given function. Finally it calls to this |
|---|
| 6 | # function |
|---|
| 7 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 8 | |
|---|
| 9 | package require byscommon |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 13 | ::snit::widgetadaptor bguifunction { |
|---|
| 14 | # |
|---|
| 15 | # PURPOSE: Defincición de las funcionalidades de un |
|---|
| 16 | # |
|---|
| 17 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 18 | |
|---|
| 19 | # |
|---|
| 20 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 21 | option -regpars |
|---|
| 22 | variable parInf |
|---|
| 23 | |
|---|
| 24 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 25 | constructor {args} { |
|---|
| 26 | # |
|---|
| 27 | # PURPOSE: guifunction constructor |
|---|
| 28 | # |
|---|
| 29 | # PARAMETERS: |
|---|
| 30 | # args -> |
|---|
| 31 | # |
|---|
| 32 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 33 | installhull using Dialog |
|---|
| 34 | # Apply default arguments |
|---|
| 35 | $self configure -modal local -default 0 -cancel 1 -separator true |
|---|
| 36 | # Apply all options passed at creation time. |
|---|
| 37 | $self configurelist $args |
|---|
| 38 | set lstPar [$self get parameters] |
|---|
| 39 | |
|---|
| 40 | if [llength $lstPar] { |
|---|
| 41 | |
|---|
| 42 | wm protocol $self WM_DELETE_WINDOW [list $self withdraw] |
|---|
| 43 | |
|---|
| 44 | set f [$self getframe] |
|---|
| 45 | foreach idx $lstPar { |
|---|
| 46 | set tfp [$self createParForm $f $idx] |
|---|
| 47 | grid $tfp -sticky news |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | # Botones |
|---|
| 51 | $self add -text [mc Accept] -compound left -helptext [mc "Load"] \ |
|---|
| 52 | -relief link -command [list $self LoadFunction] |
|---|
| 53 | $self add -text [mc Cancel] -helptext [mc Cancel] -relief link\ |
|---|
| 54 | -command [list $self withdraw] |
|---|
| 55 | |
|---|
| 56 | grid columnconfigure $f 0 -weight 1 |
|---|
| 57 | grid rowconfigure $f $idx -weight 1 |
|---|
| 58 | $self draw |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 64 | # |
|---|
| 65 | # PURPOSE: Metodos cget y configure |
|---|
| 66 | # |
|---|
| 67 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 71 | onconfigure -regpars {value} { |
|---|
| 72 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 73 | array set parInf $value |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | # delegacion de metodos y opciones |
|---|
| 77 | delegate method * to hull |
|---|
| 78 | delegate option * to hull |
|---|
| 79 | |
|---|
| 80 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 81 | method assocVarChooseDir {var} { |
|---|
| 82 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 83 | upvar #0 $var variable |
|---|
| 84 | set variable [tk_chooseDirectory] |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 88 | method createParForm {w idx} { |
|---|
| 89 | # |
|---|
| 90 | # |
|---|
| 91 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 92 | set tf [TitleFrame $w.tf$idx -text [mc $parInf($idx,nameGui)] -bd 1] |
|---|
| 93 | set f [$tf getframe] |
|---|
| 94 | |
|---|
| 95 | label $f.label -text [mc $parInf($idx,nameGui)]: |
|---|
| 96 | switch [expr int( $parInf($idx,typeSel) )] { |
|---|
| 97 | 0 { |
|---|
| 98 | set lstValues [::tol::info variable $parInf($idx,typePar)] |
|---|
| 99 | ComboBox $f.entry -width 18 -height 5 -editable false\ |
|---|
| 100 | -values $lstValues \ |
|---|
| 101 | -textvariable ${selfns}::parInf($idx,value) |
|---|
| 102 | grid $f.label $f.entry -sticky nw |
|---|
| 103 | } |
|---|
| 104 | 1 { |
|---|
| 105 | ComboBox $f.entry -width 18 -height 5 -editable false\ |
|---|
| 106 | -values $parInf($idx,lstVal)\ |
|---|
| 107 | -textvariable ${selfns}::parInf($idx,value) |
|---|
| 108 | grid $f.label $f.entry -sticky nw |
|---|
| 109 | } |
|---|
| 110 | default { |
|---|
| 111 | switch $parInf($idx,typePar) { |
|---|
| 112 | "Dir" { |
|---|
| 113 | Entry $f.entry -state normal -width 30 \ |
|---|
| 114 | -textvariable ${selfns}::parInf($idx,value) |
|---|
| 115 | |
|---|
| 116 | Button $f.button -compound left -padx 10 \ |
|---|
| 117 | -height 16 -relief link \ |
|---|
| 118 | -helptext [mc "Choose a directory"] \ |
|---|
| 119 | -image [Bitmap::get open] \ |
|---|
| 120 | -command [list $self assocVarChooseDir ${selfns}::parInf($idx,value)] |
|---|
| 121 | grid $f.label $f.entry $f.button -sticky nw |
|---|
| 122 | } |
|---|
| 123 | default { |
|---|
| 124 | Entry $f.entry -textvariable ${selfns}::parInf($idx,value) |
|---|
| 125 | grid $f.label $f.entry -sticky nw |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | grid columnconfigure $f 1 -weight 1 |
|---|
| 132 | grid rowconfigure $f 0 -weight 1 |
|---|
| 133 | return $tf |
|---|
| 134 | |
|---|
| 135 | } |
|---|
| 136 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 137 | method get {item {idx ""}} { |
|---|
| 138 | # |
|---|
| 139 | # PURPOSE: Returns items of guifunction dialog. Item can be: |
|---|
| 140 | # parameters -> Returns a list of all parameters of function |
|---|
| 141 | # value idx -> Returns the value given by the user of the parameter idx |
|---|
| 142 | # |
|---|
| 143 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 144 | #puts "method get. item=$item, idx=$idx" |
|---|
| 145 | set res "" |
|---|
| 146 | switch -- $item { |
|---|
| 147 | type { |
|---|
| 148 | if {$idx eq ""} { |
|---|
| 149 | error "You must specify an index: shold be get type index" |
|---|
| 150 | } else { |
|---|
| 151 | set res $parInf($idx,typePar) |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | value { |
|---|
| 155 | if {$idx eq ""} { |
|---|
| 156 | error "You must specify an index: shold be get value index" |
|---|
| 157 | } else { |
|---|
| 158 | switch [$self get type $idx] { |
|---|
| 159 | "Text" - |
|---|
| 160 | "Dir" { set res \"$parInf($idx,value)\" } |
|---|
| 161 | default { set res $parInf($idx,value) } |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | values { |
|---|
| 166 | set lst "" |
|---|
| 167 | foreach p [$self get parameters] { |
|---|
| 168 | lappend lst [$self get value $p] |
|---|
| 169 | } |
|---|
| 170 | set res $lst |
|---|
| 171 | } |
|---|
| 172 | parameters { |
|---|
| 173 | regsub -all ,nameGui \ |
|---|
| 174 | [array names ${selfns}::parInf *,nameGui] "" lstArgs |
|---|
| 175 | set res [lsort -integer $lstArgs] |
|---|
| 176 | } |
|---|
| 177 | default { |
|---|
| 178 | error "Invalid option '$item': should be parameters or value" |
|---|
| 179 | } |
|---|
| 180 | } |
|---|
| 181 | #puts "method get. Devuelvo $res" |
|---|
| 182 | return $res |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 186 | method LoadFunction {} { |
|---|
| 187 | # |
|---|
| 188 | # |
|---|
| 189 | #/////////////////////////////////////////////////////////////////////////// |
|---|
| 190 | #Chequear que los parámetros obligatorios se hayan rellenado |
|---|
| 191 | set lstPar [$self get parameters] |
|---|
| 192 | foreach idp $lstPar { |
|---|
| 193 | if {$parInf($idp,value) eq ""} { |
|---|
| 194 | tk_messageBox -type ok -icon warning \ |
|---|
| 195 | -message [mc "Debe rellenar el parámetro %1\$s" $parInf($idp,nameGui)]\ |
|---|
| 196 | -parent . -title [mc Warning] |
|---|
| 197 | return |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | $self enddialog ok |
|---|
| 201 | } |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | package provide bguifunction 1.0 |
|---|
| 207 | |
|---|
| 208 | # -------- TEST CODE ------ |
|---|
| 209 | |
|---|
| 210 | proc test_bguifunction { } { |
|---|
| 211 | |
|---|
| 212 | set idx 0 |
|---|
| 213 | |
|---|
| 214 | incr idx |
|---|
| 215 | set regPar($idx,nameGui) TimeSet |
|---|
| 216 | set regPar($idx,typePar) TimeSet |
|---|
| 217 | set regPar($idx,typeSel) 2 |
|---|
| 218 | |
|---|
| 219 | incr idx |
|---|
| 220 | set regPar($idx,nameGui) Statistic |
|---|
| 221 | set regPar($idx,typePar) Code |
|---|
| 222 | set regPar($idx,typeSel) 1 |
|---|
| 223 | |
|---|
| 224 | set regPar($idx,lstVal) [list SumS LastS FirstS AvrS StDsS MinS MaxS MedianS] |
|---|
| 225 | |
|---|
| 226 | set gui [bguifunction .t -title "Cambio de Fechado" -regpars [array get regPar]] |
|---|
| 227 | puts "values= [$gui get values]" |
|---|
| 228 | #puts "El usuario ha elegido timeset=$::timeset, sta=$::statistic" |
|---|
| 229 | destroy $gui |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | #test_bguifunction |
|---|