| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : objects.tcl |
|---|
| 3 | # PURPOSE : This file contains a namespace called Objects with its functions. |
|---|
| 4 | # It's for creating and managing compound widgets asociated with a |
|---|
| 5 | # variable. We have: |
|---|
| 6 | # - Date Chooser |
|---|
| 7 | # - File Chooser |
|---|
| 8 | # - Directory Chooser |
|---|
| 9 | # - Font Selector |
|---|
| 10 | # - Color Selector |
|---|
| 11 | # - Position Selector |
|---|
| 12 | # - Line Style Selector |
|---|
| 13 | # - Order list |
|---|
| 14 | # |
|---|
| 15 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 16 | |
|---|
| 17 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 18 | # TESTING |
|---|
| 19 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 20 | # Put if {1} for testing this file. |
|---|
| 21 | if {0} { |
|---|
| 22 | package require Tk |
|---|
| 23 | package require BWidget |
|---|
| 24 | # force BWidget autoload |
|---|
| 25 | Bitmap::use |
|---|
| 26 | set toltk_script_path [file dirname [info script]] |
|---|
| 27 | set toltk_images_path [file join ${toltk_script_path} images] |
|---|
| 28 | if { [lsearch $Bitmap::path $toltk_images_path] == -1 } { |
|---|
| 29 | lappend Bitmap::path [file join $toltk_script_path images] |
|---|
| 30 | } |
|---|
| 31 | package require msgcat |
|---|
| 32 | namespace import msgcat::* |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | namespace eval ::Objects { |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | proc ::Objects::ChooseDateCreate {var path} { |
|---|
| 40 | set Instance ::Objects::ChooseDate$path |
|---|
| 41 | namespace eval $Instance { |
|---|
| 42 | variable data |
|---|
| 43 | } |
|---|
| 44 | upvar \#0 ${Instance}::data data |
|---|
| 45 | set data(path) [frame $path] |
|---|
| 46 | |
|---|
| 47 | set data(ftop) [frame $path.f] |
|---|
| 48 | Entry $path.f.e -textvariable $var -state disabled -width 16 |
|---|
| 49 | Button $path.f.b -image [::Bitmap::get Date]\ |
|---|
| 50 | -command [list eval ::Objects::ChooseDateChange $Instance $var $path] |
|---|
| 51 | grid $path.f.e $path.f.b -padx 0 -sticky nw |
|---|
| 52 | pack $path.f |
|---|
| 53 | |
|---|
| 54 | ::date::Init |
|---|
| 55 | # set ::date::a(otherday) 0 |
|---|
| 56 | set w [toplevel $data(path).t] |
|---|
| 57 | set data(fbottom) $w |
|---|
| 58 | wm resizable $w 0 0 |
|---|
| 59 | #wm transient $w [winfo toplevel $data(path)] |
|---|
| 60 | wm overrideredirect $w 1 |
|---|
| 61 | wm withdraw $w |
|---|
| 62 | |
|---|
| 63 | upvar \#0 $var variable |
|---|
| 64 | if [info exist variable] { |
|---|
| 65 | set year [lindex $variable 0] |
|---|
| 66 | set month [lindex $variable 1] |
|---|
| 67 | } else { |
|---|
| 68 | set year [lindex [::tol::date now] 0] |
|---|
| 69 | set month [lindex [::tol::date now] 1] |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | set this [::date::Chooser $w.c $month $year [list OnDoubleDay "::Objects::ChooseDateGetDay $Instance $var $path"]] |
|---|
| 73 | #$w.c configure -bd 0 |
|---|
| 74 | frame $w.f -bd 1 -bg white -relief solid |
|---|
| 75 | |
|---|
| 76 | Button $w.f.bby -text "<<" -height 1 -bg white\ |
|---|
| 77 | -command [list ::date::Adjust $this 0 -1] -relief link -width 2\ |
|---|
| 78 | -helptext [mc "Moves to previous year"] |
|---|
| 79 | Button $w.f.bbm -text "< " -height 1 -bg white\ |
|---|
| 80 | -command [list ::date::Adjust $this -1 0] -relief link -width 2\ |
|---|
| 81 | -helptext [mc "Moves to previous month"] |
|---|
| 82 | Button $w.f.bnm -text " >" -height 1 -bg white\ |
|---|
| 83 | -command [list ::date::Adjust $this 1 0] -relief link -width 2\ |
|---|
| 84 | -helptext [mc "Moves to next month"] |
|---|
| 85 | Button $w.f.bny -text ">>" -height 1 -bg white\ |
|---|
| 86 | -command [list ::date::Adjust $this 0 1] -relief link -width 2\ |
|---|
| 87 | -helptext [mc "Moves to next year"] |
|---|
| 88 | frame $w.f.f |
|---|
| 89 | |
|---|
| 90 | grid $w.f.bby $w.f.bbm $w.f.f $w.f.bnm $w.f.bny -sticky nw -padx 2 |
|---|
| 91 | grid columnconfigure $w.f 2 -weight 1 |
|---|
| 92 | |
|---|
| 93 | grid $w.f -sticky nwe -padx 2 |
|---|
| 94 | grid $w.c -sticky nwe -padx 2 |
|---|
| 95 | |
|---|
| 96 | return $path |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | proc ::Objects::ChooseDateChange {this var path} { |
|---|
| 100 | upvar \#0 ${this}::data data |
|---|
| 101 | upvar \#0 $var variable |
|---|
| 102 | |
|---|
| 103 | if {[winfo viewable $data(fbottom)] == 1} { |
|---|
| 104 | wm withdraw $data(fbottom) |
|---|
| 105 | grab release $data(fbottom) |
|---|
| 106 | } else { |
|---|
| 107 | set vwidth [winfo reqwidth $data(fbottom)] |
|---|
| 108 | set vheight [winfo reqheight $data(fbottom)] |
|---|
| 109 | wm deiconify $data(fbottom) |
|---|
| 110 | wm geometry $data(fbottom) \ |
|---|
| 111 | "${vwidth}x${vheight}+[winfo rootx $data(ftop)]+[expr \ |
|---|
| 112 | [winfo rooty $data(ftop)]+[winfo height $data(ftop)]]" |
|---|
| 113 | focus -force $data(fbottom) |
|---|
| 114 | grab -global $data(fbottom) |
|---|
| 115 | bind $data(fbottom) <ButtonPress> [list ::Objects::ChooseDateClose $this %X %Y] |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | proc ::Objects::ChooseDateClose {this x y} { |
|---|
| 120 | upvar \#0 ${this}::data data |
|---|
| 121 | if {[expr $x==-1 && $y==-1]} { |
|---|
| 122 | wm withdraw $data(fbottom) |
|---|
| 123 | grab release $data(fbottom) |
|---|
| 124 | } else { |
|---|
| 125 | set obj [winfo containing $x $y] |
|---|
| 126 | if {[string length $obj]} { |
|---|
| 127 | if {[winfo toplevel $obj] != $data(fbottom)} { |
|---|
| 128 | wm withdraw $data(fbottom) |
|---|
| 129 | grab release $data(fbottom) |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | } |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | proc ::Objects::ChooseDateGetDay {this var path day month year tags} { |
|---|
| 136 | upvar \#0 ${this}::data data |
|---|
| 137 | upvar \#0 $var variable |
|---|
| 138 | set variable [list $year $month $day] |
|---|
| 139 | wm withdraw $data(fbottom) |
|---|
| 140 | grab release $data(fbottom) |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | proc ::Objects::ChooseDirCreate {var path args} { |
|---|
| 145 | Button $path -image [::Bitmap::get open]\ |
|---|
| 146 | -command [list eval ::Objects::ChooseDirChange $var $path $args] |
|---|
| 147 | |
|---|
| 148 | set cmdTrace [list ::Objects::ChooseDirUpdate $path $var] |
|---|
| 149 | trace variable $var w $cmdTrace |
|---|
| 150 | bind $path <Destroy> [list ::Objects::ClearTrace $var $cmdTrace] |
|---|
| 151 | #Si la variable ya tiene valor actualizo el widget |
|---|
| 152 | if [info exists $var] { |
|---|
| 153 | ChooseDirUpdate $path $var |
|---|
| 154 | } |
|---|
| 155 | return $path |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | proc ::Objects::ChooseDirChange {var widget args} { |
|---|
| 159 | upvar \#0 $var variable |
|---|
| 160 | set parent [winfo parent $widget] |
|---|
| 161 | if [info exist variable] { |
|---|
| 162 | lappend args -initialdir $variable |
|---|
| 163 | } |
|---|
| 164 | set temp [eval tk_chooseDirectory -parent $parent -mustexist true $args] |
|---|
| 165 | if {$temp != ""} { |
|---|
| 166 | set variable $temp |
|---|
| 167 | $widget configure -helptext "[mc [list Choose directory]]: ($variable)" |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | proc ::Objects::ChooseDirUpdate {path var args} { |
|---|
| 172 | upvar \#0 $var variable |
|---|
| 173 | $path configure -helptext "[mc [list Choose directory]]: ($variable)" |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | proc ::Objects::ChooseFileCreate {var path args} { |
|---|
| 177 | Button $path -image [::Bitmap::get bopen] -relief link\ |
|---|
| 178 | -command [list eval ::Objects::ChooseFileChange $var $path $args] \ |
|---|
| 179 | -helptext [mc "Choose file"] |
|---|
| 180 | |
|---|
| 181 | set cmdTrace [list ::Objects::ChooseFileUpdate $path $var] |
|---|
| 182 | trace variable $var w $cmdTrace |
|---|
| 183 | bind $path <Destroy> [list ::Objects::ClearTrace $var $cmdTrace] |
|---|
| 184 | #Si la variable ya tiene valor actualizo el widget |
|---|
| 185 | if [info exists $var] { |
|---|
| 186 | ChooseFileUpdate $path $var |
|---|
| 187 | } |
|---|
| 188 | return $path |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | proc ::Objects::ChooseFileChange {var widget args} { |
|---|
| 192 | upvar \#0 $var variable |
|---|
| 193 | |
|---|
| 194 | set parent [winfo parent $widget] |
|---|
| 195 | |
|---|
| 196 | # jima begin |
|---|
| 197 | # This code is commented out as calls from outside shoudl use |
|---|
| 198 | # -initialdir directly |
|---|
| 199 | # if [info exist variable] { |
|---|
| 200 | # lappend args -initialdir [file dirname $variable] |
|---|
| 201 | # lappend args -initialfile [file tail $variable] |
|---|
| 202 | # } |
|---|
| 203 | # jima end |
|---|
| 204 | |
|---|
| 205 | set temp [eval tk_getOpenFile -parent $parent $args] |
|---|
| 206 | if {$temp != ""} { |
|---|
| 207 | set variable $temp |
|---|
| 208 | $widget configure -helptext "[mc {Choose file}]: ($variable)" |
|---|
| 209 | } |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | proc ::Objects::ChooseFileUpdate {path var args} { |
|---|
| 213 | upvar \#0 $var variable |
|---|
| 214 | $path configure -helptext "[mc [list Choose file]]: ($variable)" |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | proc ::Objects::FontCreate {var path args} { |
|---|
| 219 | upvar \#0 $var variable |
|---|
| 220 | Button $path -image [::Bitmap::get font]\ |
|---|
| 221 | -command [list eval ::Objects::FontChange $var $path $args] |
|---|
| 222 | set cmdTrace [list ::Objects::FontUpdate $path $var] |
|---|
| 223 | trace variable $var w $cmdTrace |
|---|
| 224 | bind $path <Destroy> [list ::Objects::ClearTrace $var $cmdTrace] |
|---|
| 225 | |
|---|
| 226 | #Si la variable ya tiene valor actualizo el widget |
|---|
| 227 | if [info exists $var] { |
|---|
| 228 | FontUpdate $path $var |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | proc ::Objects::FontUpdate {path var args} { |
|---|
| 233 | upvar \#0 $var variable |
|---|
| 234 | $path configure -helptext "[mc [list Change font]]: ($variable)" |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | proc ::Objects::FontChange {var widget args} { |
|---|
| 238 | upvar \#0 $var variable |
|---|
| 239 | |
|---|
| 240 | set parent [winfo parent $widget] |
|---|
| 241 | if [info exists variable] { |
|---|
| 242 | lappend args -font $variable |
|---|
| 243 | } |
|---|
| 244 | set temp [eval SelectFont .sf -parent $parent $args] |
|---|
| 245 | if {$temp != ""} { |
|---|
| 246 | set variable $temp |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | proc ::Objects::ColorCreate {var path {helptext ""} {null 0} args} { |
|---|
| 251 | frame $path -bd 1 -relief sunken |
|---|
| 252 | frame $path.fcolor -height 4 |
|---|
| 253 | bind $path.fcolor <Button-1> [list eval ::Objects::ColorChange $var $path $args] |
|---|
| 254 | |
|---|
| 255 | #button $path.bcolor -image [::Bitmap::get pen] \ |
|---|
| 256 | \# -command [list eval ::Objects::ColorChange $var $path $args] |
|---|
| 257 | |
|---|
| 258 | Button $path.bcolor -relief link\ |
|---|
| 259 | -command [list eval ::Objects::ColorChange $var $path $args] \ |
|---|
| 260 | -height 12 -image [::Bitmap::get pen] |
|---|
| 261 | |
|---|
| 262 | if [string equal $helptext ""] { |
|---|
| 263 | set helptext [mc "Change color"]: |
|---|
| 264 | } |
|---|
| 265 | set cmdTrace [list ::Objects::ColorUpdate $path $var $helptext] |
|---|
| 266 | trace variable $var w $cmdTrace |
|---|
| 267 | bind $path.fcolor <Destroy> [list ::Objects::ClearTrace $var $cmdTrace] |
|---|
| 268 | #Si la variable ya tiene valor actualizo el widget |
|---|
| 269 | if [info exists $var] { |
|---|
| 270 | ColorUpdate $path $var $helptext |
|---|
| 271 | } |
|---|
| 272 | pack $path.bcolor $path.fcolor -expand true -fill x |
|---|
| 273 | if $null { |
|---|
| 274 | #Creación de un menú contextual |
|---|
| 275 | #upvar \#0 $var variable |
|---|
| 276 | set menu [menu $path.m -tearoff 0] |
|---|
| 277 | bind $path.fcolor <Button-3> "::Objects::PostEmptyColor $path" |
|---|
| 278 | bind $path.bcolor <Button-3> "::Objects::PostEmptyColor $path" |
|---|
| 279 | } |
|---|
| 280 | if [string equal $null 1] { |
|---|
| 281 | $menu add command -label [mc "Without color"] -command "set $var {}" |
|---|
| 282 | } |
|---|
| 283 | if [string equal $null 2] { |
|---|
| 284 | $menu add command -label [mc "Default color"] -command "set $var defcolor" |
|---|
| 285 | } |
|---|
| 286 | if [string equal $null 3] { |
|---|
| 287 | $menu add command -label [mc "Without color"] -command "set $var {}" |
|---|
| 288 | $menu add command -label [mc "Default color"] -command "set $var defcolor" |
|---|
| 289 | } |
|---|
| 290 | return $path |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 293 | proc ::Objects::ClearTrace { v cmd } { |
|---|
| 294 | trace vdelete $v w $cmd |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | proc ::Objects::PostEmptyColor { w } { |
|---|
| 298 | set x [winfo rootx $w] |
|---|
| 299 | set y [expr [winfo rooty $w] + [winfo height $w]] |
|---|
| 300 | tk_popup $w.m $x $y |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | proc ::Objects::ColorUpdate {path var helptext args} { |
|---|
| 304 | upvar \#0 $var variable |
|---|
| 305 | if {[string length $variable] && ![string equal $variable "defcolor"]} { |
|---|
| 306 | $path.fcolor configure -bg $variable |
|---|
| 307 | } else { |
|---|
| 308 | $path.fcolor configure -bg [$path cget -bg] |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | $path.bcolor configure -helptext "$helptext ($variable)" |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | proc ::Objects::ColorChange {var widget args} { |
|---|
| 315 | upvar \#0 $var variable |
|---|
| 316 | |
|---|
| 317 | set parent [winfo parent $widget] |
|---|
| 318 | if {[info exists variable] && ![string equal $variable ""] && ![string equal $variable "defcolor"]} { |
|---|
| 319 | set temp [eval tk_chooseColor -initialcolor $variable -parent $parent $args] |
|---|
| 320 | } else { |
|---|
| 321 | set temp [eval tk_chooseColor -parent $parent $args] |
|---|
| 322 | } |
|---|
| 323 | if {$temp != ""} { |
|---|
| 324 | set variable $temp |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | proc ::Objects::ComboCreate {var path vwidth vheight} { |
|---|
| 329 | set Instance ::Objects::ComboCreate$path |
|---|
| 330 | namespace eval $Instance { |
|---|
| 331 | variable data |
|---|
| 332 | } |
|---|
| 333 | upvar \#0 ${Instance}::data data |
|---|
| 334 | set data(path) $path |
|---|
| 335 | frame $data(path) |
|---|
| 336 | bind $data(path) <Destroy> [list ::Objects::Destroy $Instance] |
|---|
| 337 | set data(ftop) [frame ${data(path)}.top] |
|---|
| 338 | set data(fbottom) [toplevel ${data(path)}.bottom \ |
|---|
| 339 | -height ${vheight} -width ${vwidth} \ |
|---|
| 340 | -bg white -borderwidth 1 -relief solid] |
|---|
| 341 | wm resizable $data(fbottom) 0 0 |
|---|
| 342 | #wm transient $data(fbottom) [winfo toplevel $data(fbottom)] |
|---|
| 343 | wm overrideredirect $data(fbottom) 1 |
|---|
| 344 | wm withdraw $data(fbottom) |
|---|
| 345 | |
|---|
| 346 | puts [wm geometry $data(fbottom)] |
|---|
| 347 | |
|---|
| 348 | set data(canvas) [canvas $data(ftop).c -bg white -height 16 -width [expr $vwidth -16 ] -relief sunken] |
|---|
| 349 | |
|---|
| 350 | set data(fbutton) [ArrowButton $data(ftop).button \ |
|---|
| 351 | -dir bottom -command [list ::Objects::ComboUpdate $Instance]] |
|---|
| 352 | pack $data(canvas) $data(fbutton) -expand true -fill both -side left |
|---|
| 353 | |
|---|
| 354 | set cmdTrace [list ::Objects::ComboChange $Instance $var] |
|---|
| 355 | trace variable $var w $cmdTrace |
|---|
| 356 | bind $path <Destroy> [list ::Objects::ClearTrace $var $cmdTrace] |
|---|
| 357 | |
|---|
| 358 | pack $data(ftop) |
|---|
| 359 | return $Instance |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | proc ::Objects::Destroy {this} { |
|---|
| 363 | namespace delete $this |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | proc ::Objects::ComboUpdate {this} { |
|---|
| 367 | upvar \#0 ${this}::data data |
|---|
| 368 | if {[winfo viewable $data(fbottom)] == 1} { |
|---|
| 369 | wm withdraw $data(fbottom) |
|---|
| 370 | grab release $data(fbottom) |
|---|
| 371 | } else { |
|---|
| 372 | set vwidth [winfo reqwidth $data(fbottom)] |
|---|
| 373 | set vheight [winfo reqheight $data(fbottom)] |
|---|
| 374 | wm deiconify $data(fbottom) |
|---|
| 375 | wm geometry $data(fbottom) \ |
|---|
| 376 | "${vwidth}x${vheight}+[winfo rootx $data(ftop)]+[expr \ |
|---|
| 377 | [winfo rooty $data(ftop)]+[winfo height $data(ftop)]]" |
|---|
| 378 | focus -force $data(fbottom) |
|---|
| 379 | grab -global $data(fbottom) |
|---|
| 380 | bind $data(fbottom) <ButtonPress> [list ::Objects::ComboClose $this %X %Y] |
|---|
| 381 | } |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | proc ::Objects::ComboChange {this var args} { |
|---|
| 385 | upvar \#0 ${this}::data data |
|---|
| 386 | upvar \#0 $var variable |
|---|
| 387 | set widget $data(canvas) |
|---|
| 388 | $widget delete all |
|---|
| 389 | set valueUser $variable |
|---|
| 390 | if {[info exist data(fillSpecial)]} { |
|---|
| 391 | $data(fillSpecial) $valueUser $widget |
|---|
| 392 | } else { |
|---|
| 393 | set center [expr [$widget cget -height] / 2] |
|---|
| 394 | $widget create text 5 $center -text $valueUser -anchor w |
|---|
| 395 | } |
|---|
| 396 | } |
|---|
| 397 | |
|---|
| 398 | proc ::Objects::ComboClose {this x y} { |
|---|
| 399 | upvar \#0 ${this}::data data |
|---|
| 400 | if {[winfo toplevel [winfo containing $x $y]] != $data(fbottom)} { |
|---|
| 401 | wm withdraw $data(fbottom) |
|---|
| 402 | grab release $data(fbottom) |
|---|
| 403 | } |
|---|
| 404 | } |
|---|
| 405 | |
|---|
| 406 | proc ::Objects::MatrixFCreate {var path} { |
|---|
| 407 | set Instance ::Objects::MatrixFCreate$path |
|---|
| 408 | namespace eval $Instance { |
|---|
| 409 | variable data |
|---|
| 410 | } |
|---|
| 411 | upvar \#0 ${Instance}::data data |
|---|
| 412 | set data(path) $path |
|---|
| 413 | set data(coord) [list nw n ne w center e sw s se] |
|---|
| 414 | set vwidth [$data(path) cget -width] |
|---|
| 415 | set vheight [$data(path) cget -height] |
|---|
| 416 | set vwidthf [expr $vwidth / 3] |
|---|
| 417 | set vheightf [expr $vheight / 3] |
|---|
| 418 | set cont 0 |
|---|
| 419 | for {set i 1} {$i <= 3} {incr i 1} { |
|---|
| 420 | set fila [frame $data(path).$i -width $vwidth -height $vheightf] |
|---|
| 421 | for {set j 1} {$j <= 3} {incr j 1} { |
|---|
| 422 | set tcoord [lindex $data(coord) $cont] |
|---|
| 423 | set data(widget,$tcoord) [frame $data(path).$i.$tcoord \ |
|---|
| 424 | -width $vwidthf -height $vheightf -relief flat -borderwidth 2] |
|---|
| 425 | pack $data(widget,$tcoord) -side left |
|---|
| 426 | bind $data(widget,$tcoord) <ButtonPress-1> \ |
|---|
| 427 | "[list ::Objects::MatrixFClose $Instance $var $tcoord]" |
|---|
| 428 | bind $data(widget,$tcoord) <Enter> [list $data(widget,$tcoord) configure -bg grey40] |
|---|
| 429 | bind $data(widget,$tcoord) <Leave> [list $data(widget,$tcoord) configure -bg grey] |
|---|
| 430 | incr cont 1 |
|---|
| 431 | } |
|---|
| 432 | grid $fila -sticky w |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | set cmdTrace [list ::Objects::MatrixFUpdate $Instance $var] |
|---|
| 436 | trace variable $var w $cmdTrace |
|---|
| 437 | bind $path <Destroy> [list ::Objects::ClearTrace $var $cmdTrace] |
|---|
| 438 | |
|---|
| 439 | $data(path) configure -relief ridge -borderwidth 2 |
|---|
| 440 | return $Instance |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | proc ::Objects::MatrixFUpdate {this var args} { |
|---|
| 445 | upvar \#0 ${this}::data data |
|---|
| 446 | upvar \#0 $var coord |
|---|
| 447 | foreach tcoord $data(coord) { |
|---|
| 448 | $data(widget,$tcoord) configure -relief flat |
|---|
| 449 | } |
|---|
| 450 | $data(widget,$coord) configure -relief ridge |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | proc ::Objects::MatrixFChange {var value} { |
|---|
| 456 | upvar \#0 $var variable |
|---|
| 457 | set variable $value |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | proc ::Objects::MatrixFClose {this var value} { |
|---|
| 461 | upvar \#0 ${this}::data data |
|---|
| 462 | upvar \#0 $var variable |
|---|
| 463 | set variable $value |
|---|
| 464 | if {[info exist data(closeFrame)]} { |
|---|
| 465 | eval $data(closeFrame) |
|---|
| 466 | } |
|---|
| 467 | } |
|---|
| 468 | |
|---|
| 469 | proc ::Objects::ComboUnTranslateDbl {combo list var} { |
|---|
| 470 | upvar \#0 $var variable |
|---|
| 471 | if {[$combo getvalue] != -1} { |
|---|
| 472 | set variable [lindex $list [expr 2*[$combo getvalue]]] |
|---|
| 473 | } |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | proc ::Objects::ComboSetIniDbl {combo list var} { |
|---|
| 477 | upvar \#0 $var variable |
|---|
| 478 | set idx [lsearch -exact $list $variable] |
|---|
| 479 | if {$idx != -1} { |
|---|
| 480 | $combo setvalue @[expr $idx/2] |
|---|
| 481 | } |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | proc ::Objects::ComboUnTranslate {combo list var} { |
|---|
| 485 | #Tolcon_Trace "Llamada a ComboUnTranslate combo: $combo, list: $list, var: $var" |
|---|
| 486 | upvar \#0 $var variable |
|---|
| 487 | if {[$combo getvalue] != -1} { |
|---|
| 488 | set variable [lindex $list [$combo getvalue]] |
|---|
| 489 | } |
|---|
| 490 | #Tolcon_Trace "Ahora var ($var) vale $variable" |
|---|
| 491 | } |
|---|
| 492 | |
|---|
| 493 | proc ::Objects::ComboSetIni {combo list var} { |
|---|
| 494 | # Actualizo el valor en el combo |
|---|
| 495 | ComboUpdateVar $combo $list $var |
|---|
| 496 | # Trazo la variable, para q la actualización se haga siempre |
|---|
| 497 | set cmdTrace [list ::Objects::ComboUpdateVar $combo $list $var] |
|---|
| 498 | trace variable $var w $cmdTrace |
|---|
| 499 | bind $combo <Destroy> +[list ::Objects::ClearTrace $var $cmdTrace] |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | proc ::Objects::ComboUpdateVar {combo list var args} { |
|---|
| 503 | upvar \#0 $var variable |
|---|
| 504 | set idx [lsearch -exact $list $variable] |
|---|
| 505 | if {$idx != -1} { |
|---|
| 506 | $combo setvalue @$idx |
|---|
| 507 | } |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | proc ::Objects::DashesCreate {var path} { |
|---|
| 511 | set Instance ::Objects::DashesCreate$path |
|---|
| 512 | namespace eval $Instance { |
|---|
| 513 | variable data |
|---|
| 514 | } |
|---|
| 515 | upvar \#0 ${Instance}::data data |
|---|
| 516 | set vwidth [$path cget -width] |
|---|
| 517 | set vheight [$path cget -height] |
|---|
| 518 | set data(sb) [scrollbar $path.sb -command [list $path.c yview] -orient vertical] |
|---|
| 519 | set data(path) [canvas $path.c -width [expr $vwidth - 16] -height $vheight -bd 0 \ |
|---|
| 520 | -bg white -yscrollcommand [list $data(sb) set]] |
|---|
| 521 | bind $data(path) <Destroy> [list ::Objects::Destroy $Instance] |
|---|
| 522 | set lmax [expr [$data(path) cget -width] - 5] |
|---|
| 523 | set lista [list {} {1} {1 1} {2 1 1 1} {2 1} {2 2} {3 1} {4 1 1 1} {4 2}] |
|---|
| 524 | set llista [llength $lista] |
|---|
| 525 | set yini 2 |
|---|
| 526 | for {set i 0} {$i < $llista} {incr i 1} { |
|---|
| 527 | set center [expr $yini + 8] |
|---|
| 528 | set idrect [$data(path) create polygon \ |
|---|
| 529 | 2 $yini $lmax $yini $lmax [expr $yini + 16] 2 [expr $yini + 16] \ |
|---|
| 530 | -activefill gray60 -fill {}] |
|---|
| 531 | set idline [$data(path) create line \ |
|---|
| 532 | 5 $center [expr $lmax - 5] $center -width 2 -fill black -dash [lindex $lista $i]] |
|---|
| 533 | $data(path) bind $idline <Enter> [list $data(path) itemconfigure $idrect -fill gray60] |
|---|
| 534 | $data(path) bind $idline <Leave> [list $data(path) itemconfigure $idrect -fill {}] |
|---|
| 535 | $data(path) bind $idline <ButtonPress-1> "[list ::Objects::DashesClose $Instance $var [lindex $lista $i]]" |
|---|
| 536 | $data(path) bind $idrect <ButtonPress-1> "[list ::Objects::DashesClose $Instance $var [lindex $lista $i]]" |
|---|
| 537 | set yini [expr $yini + 16] |
|---|
| 538 | } |
|---|
| 539 | $data(path) configure -scrollregion "1 1 $vwidth [expr [expr $llista * 16] + 5]" |
|---|
| 540 | |
|---|
| 541 | set cmdTrace [list ::Objects::DashesUpdate $Instance $var] |
|---|
| 542 | trace variable $var w $cmdTrace |
|---|
| 543 | bind $path <Destroy> [list ::Objects::ClearTrace $var $cmdTrace] |
|---|
| 544 | |
|---|
| 545 | pack $data(path) -side left |
|---|
| 546 | pack $data(sb) -expand true -fill both -side left |
|---|
| 547 | return $Instance |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | proc ::Objects::DashesUpdate {this var args} { |
|---|
| 551 | upvar \#0 ${this}::data data |
|---|
| 552 | upvar \#0 $var coord |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | proc ::Objects::DashesChange {var value} { |
|---|
| 556 | upvar \#0 $var variable |
|---|
| 557 | set variable $value |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | proc ::Objects::DashesClose {this var value} { |
|---|
| 561 | upvar \#0 ${this}::data data |
|---|
| 562 | upvar \#0 $var variable |
|---|
| 563 | set variable $value |
|---|
| 564 | if {[info exist data(closeFrame)]} { |
|---|
| 565 | eval $data(closeFrame) |
|---|
| 566 | } |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | proc ::Objects::ComboPosFill {value widget} { |
|---|
| 570 | set lista [list nw top-left n top ne top-right \ |
|---|
| 571 | w left center center e right \ |
|---|
| 572 | sw bottom-left s bottom se bottom-right] |
|---|
| 573 | array set arrCoord $lista |
|---|
| 574 | set valueUser $arrCoord($value) |
|---|
| 575 | set center [expr [$widget cget -height] / 2] |
|---|
| 576 | $widget create text 5 $center -text $valueUser -anchor w |
|---|
| 577 | } |
|---|
| 578 | |
|---|
| 579 | proc ::Objects::ComboPosCreate {var path} { |
|---|
| 580 | set InstanceCombo [::Objects::ComboCreate $var $path 75 36] |
|---|
| 581 | upvar \#0 ${InstanceCombo}::data dataCombo |
|---|
| 582 | set dataCombo(fillSpecial) ::Objects::ComboPosFill |
|---|
| 583 | set InstanceMatrix [::Objects::MatrixFCreate $var $dataCombo(fbottom)] |
|---|
| 584 | upvar \#0 ${InstanceMatrix}::data dataMatrix |
|---|
| 585 | set dataMatrix(closeFrame) [list ::Objects::ComboUpdate $InstanceCombo] |
|---|
| 586 | set $var [set $var] ;# para inicializar en el valor de var |
|---|
| 587 | return $dataCombo(path) |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | proc ::Objects::ComboDashesFill {value widget} { |
|---|
| 591 | set center [expr [$widget cget -height] / 2] |
|---|
| 592 | set lmax [expr [$widget cget -width] - 5] |
|---|
| 593 | $widget create line 5 $center $lmax $center -width 2 -fill black -dash $value |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | proc ::Objects::ComboDashesCreate {var path} { |
|---|
| 597 | set InstanceComboD [::Objects::ComboCreate $var $path 100 50] |
|---|
| 598 | upvar \#0 ${InstanceComboD}::data dataComboD |
|---|
| 599 | set dataComboD(fillSpecial) ::Objects::ComboDashesFill |
|---|
| 600 | set InstanceDashes [::Objects::DashesCreate $var $dataComboD(fbottom)] |
|---|
| 601 | upvar \#0 ${InstanceDashes}::data dataDashes |
|---|
| 602 | set dataDashes(closeFrame) [list ::Objects::ComboUpdate $InstanceComboD] |
|---|
| 603 | set $var [set $var] ;# para inicializar en el valor de var |
|---|
| 604 | return $dataComboD(path) |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | proc ::Objects::ComboAutoFillCreate {path args} { |
|---|
| 608 | set Instance ::Objects::ComboAutoFill$path |
|---|
| 609 | namespace eval $Instance { |
|---|
| 610 | variable data |
|---|
| 611 | } |
|---|
| 612 | upvar \#0 ${Instance}::data data |
|---|
| 613 | set data(path) $path |
|---|
| 614 | eval ComboBox $path $args |
|---|
| 615 | bind $data(path) <Destroy> [list ::Objects::Destroy $Instance] |
|---|
| 616 | $data(path) configure -command [list ::Objects::ComboAutoFillCheck $Instance] |
|---|
| 617 | return $data(path) |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | proc ::Objects::ComboAutoFillCheck {this} { |
|---|
| 621 | upvar \#0 ${this}::data data |
|---|
| 622 | focus $data(path) |
|---|
| 623 | set lvalues [$data(path) cget -values] |
|---|
| 624 | set value [$data(path) cget -text] |
|---|
| 625 | if {[lsearch $lvalues $value] == -1} { |
|---|
| 626 | lappend lvalues $value |
|---|
| 627 | $data(path) configure -values $lvalues |
|---|
| 628 | } |
|---|
| 629 | } |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | |
|---|