source: tol/tolbaseBLT/lib/byswidget/bentrydate/bentrydate.tcl @ 56ade3b

1941-docker-image-to-testdevel
Last change on this file since 56ade3b was 56ade3b, checked in by Jorge Pérez <josp.jorge@…>, 10 years ago

fixes #1932, se ha creado la rama trunk/tolbaseBLT copia de trunk/tolbase

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@7330 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 24.8 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : bentrydatetcl
3# PURPOSE : Entry Date. Componente que nos permite seleccionar un
4#           seleccionar una fecha de un calendario. Permite seleccinar fechas
5#           nulas.
6# TODO: pensar en algo para la edicion de horas:minutos:segundos         
7#/////////////////////////////////////////////////////////////////////////////
8 
9package require byscommon
10package require snit
11
12#/////////////////////////////////////////////////////////////////////////////
13# date
14#/////////////////////////////////////////////////////////////////////////////
15package require bcombobox
16
17#/////////////////////////////////////////////////////////////////////////////
18namespace eval date {
19#
20# PURPOSE: Namespace for a widget of a calendar with an only month.
21#
22#/////////////////////////////////////////////////////////////////////////////
23  variable a
24}
25
26#/////////////////////////////////////////////////////////////////////////////
27proc ::date::Init {} {
28#
29# PURPOSE: Initializes a moth calendar
30#
31#/////////////////////////////////////////////////////////////////////////////
32  variable a
33  # Position and separation between the elements of calendar
34  set a(x0) 20
35  set a(dx) 18
36  set a(dxmax) 26
37  set a(dxmin) 14
38  set a(y0) 35
39  set a(dy) 14
40  set a(dymax) 22
41  set a(dymin) 10
42  # Months of the year
43  set a(mn) { . January February March April May June July August
44      September October November December }
45  # Days of the week 
46  set a(weekdays)  {Sun Mon Tue Wed Thu Fri Sat}
47  array set a {
48    format,ja {%y\u5e74 %m\u6708}
49    format,zh {%y\u5e74 %m\u6708}
50  }
51  # Options of presentation for the calendar of the month.
52  # No es necesario porque se debe cargar en ReadIni
53  array set a {
54    -titlefont    {Helvetica 10 bold}  -titlefill    black
55    -weekdaysfont {Helvetica 9}        -weekdaysfill blue
56    -dayfont      {Helvetica 9}        -dayfill      black
57    -otherfont    {Helvetica 9}        -otherfill    grey
58    -h1font       {Helvetica 9 bold}   -h1color      red
59    -h2font       {Helvetica 9 italic} -h2color      orange
60    -h1type oval  -h1fill LightYellow  -h1outline    red
61    -h2type rect  -h2fill white        -h2outline    blue
62    -bg white     -mon 0
63  }
64    set a(otherday) 1   
65}   
66   
67#/////////////////////////////////////////////////////////////////////////////
68proc ::date::OnClickDay { instance } {
69#
70# PURPOSE: It selects a day, when doing click in that day on the calendar.
71#
72#/////////////////////////////////////////////////////////////////////////////
73  upvar \#0 ${instance}::data data
74   
75  if { [string length $data(OnClickDay)] } {
76    # Takes all the items that are in the calendar.
77    set item [$data(canvas) find withtag current]
78    set tags [$data(canvas) itemcget $item -tags]
79    # We obtain the selected day.
80    set day [$data(canvas) itemcget $item -text]   
81    eval $data(OnClickDay) $day $data(month) $data(year) [list $tags]
82  }
83}
84
85#/////////////////////////////////////////////////////////////////////////////
86proc ::date::OnDoubleDay { instance } {
87#
88# PURPOSE: It selects a day, when doing double-click in that day on the
89#          calendar.
90#
91#/////////////////////////////////////////////////////////////////////////////
92  upvar \#0 ${instance}::data data
93 
94  if { [string length $data(OnDoubleDay)] } {
95    # Takes all the items that are in the calendar.       
96    set item [$data(canvas) find withtag current]
97    set tags [$data(canvas) itemcget $item -tags]
98    # We obtain the selected day.   
99    set day [$data(canvas) itemcget $item -text]
100    eval $data(OnDoubleDay) $day $data(month) $data(year) [list $tags]
101  }
102}
103
104#/////////////////////////////////////////////////////////////////////////////
105proc ::date::Chooser {path month year events} {
106#
107# PURPOSE: Creates an instance of date
108#
109# PARAMETERS:
110#     path ->   Path to instance.
111#     month ->  Month of calendar.
112#     year ->   Year of calendar.
113#     events -> It is a list of associated events and handlers to the dates.
114#               {OnClickDay Hdlr1 CheckDate Hdlr1 OnDoubleDay Hdlr3}
115#               It must be of even length, is used with Array Set.
116#
117# RETURN: The instance created.
118#
119#/////////////////////////////////////////////////////////////////////////////
120  variable a
121  set instance ::date::${path}
122  if { [lsearch [namespace children ::date] $instance] != -1 } {
123    error "$instance already exists as a children of ::date"
124  }
125  namespace eval $instance {
126    variable data
127  }
128  upvar #0 ${instance}::data data
129  # creates list of events and handlers
130  array set data [list OnClickDay "" OnDoubleDay "" CheckDate "" \
131            day 1 year $year month $month]
132  array set data $events
133  # creates canvas of the calendar
134  set data(canvas) [canvas $path -bg $a(-bg) \
135     -relief solid -bd 1 -highlightthickness 1]
136  # events of the canvas
137  $data(canvas) bind day <1>            +[list ::date::OnClickDay $instance]
138  $data(canvas) bind day <Double-1> +[list ::date::OnDoubleDay $instance]
139   
140  bind $data(canvas) <Destroy> [list ::date::Destroy $instance]
141   
142  Display $instance
143  return $instance
144}
145
146#/////////////////////////////////////////////////////////////////////////////
147proc ::date::Destroy { instance } {
148#
149# PURPOSE: Destroys the instance of date.
150#
151#/////////////////////////////////////////////////////////////////////////////   
152  namespace delete $instance
153}
154
155#/////////////////////////////////////////////////////////////////////////////
156proc ::date::Display {instance} {
157#
158# PURPOSE: Display the calendar of month.
159#
160#/////////////////////////////////////////////////////////////////////////////       
161  upvar #0 ${instance}::data data
162  variable a
163 
164  set c $data(canvas)
165  foreach tag {title otherday day} {$c delete $tag}
166   
167  # Establishes the horizontal and vertical position and separation between
168  # the days.
169  set x0 $a(x0)
170  set y0 $a(y0)
171  set x  $x0
172  set y  $y0
173  set dx $a(dx)
174  set dy $a(dy)
175   
176  set xmax [expr {$x0+$dx*6}]
177   
178  # Height and width of calendar of the month
179  $c configure -width  [expr {$x0+$dx*6+$x0-2}]   
180  $c configure -height [expr {$y0+$dy*6+10-2}]
181  # Header of calendar
182  set title [Format [MonthName $data(month)] $data(year)]
183  $c create text [expr ($xmax+$dx)/2] [expr $y-20] -text $title\
184            -fill $a(-titlefill) -font $a(-titlefont) -tag title
185  # Week days of calendar
186  set weekdays $a(weekdays)
187  if !$a(-mon) {lcycle weekdays}
188  foreach i $weekdays {
189    $c create text $x $y -text [mc $i] -fill $a(-weekdaysfill) \
190            -font $a(-weekdaysfont) -tag title
191    incr x $dx
192  }
193  # It obtains the number and week day of the first day of the month
194  set first [list $data(year) [RemovePre0 $data(month)] 1 0 0 0.0]
195  set weekday [::tol::date weekday $first]
196  if !$a(-mon) {set weekday [expr {($weekday+6)%7}]}
197  # Position of beginning to draw.
198  set x [expr {$x0+$weekday*$dx}]
199  set x1 $x; set offset 0
200  incr y $dy
201 
202  if {$a(otherday)} {
203    while {$weekday} {
204      set day [lindex [::tol::date +day $first -[incr offset]] 2]
205      $c create text [incr x1 -$dx] $y -text $day \
206              -fill $a(-otherfill) -font $a(-otherfont) -tag otherday
207      incr weekday -1
208    }
209  }
210  # It obtains the number of day that has the month
211  set dmax [::tol::date days $data(year) [RemovePre0 $data(month)]]
212  for {set d 1} {$d<=$dmax} {incr d} {
213    # Number of present day   
214    set txt [::format "%2s" $d]
215    # Number of element that will occupy within canvas
216    set id [$c create text $x $y -text $txt -tag day -font $a(-dayfont)\
217            -fill $a(-dayfill)]
218    # To graticulate the days
219    if { ($data(CheckDate) != {}) } {
220      set result 0
221      set result [eval $data(CheckDate) $d $data(month) $data(year)]
222      # This day is totally emphasized
223      if { $result == 1 } {
224        $c create $a(-h1type) [$c bbox $id] -fill $a(-h1fill)\
225                -outline $a(-h1outline) -tags [list day type$result]
226        $c itemconfigure $id -font $a(-h1font) -fill $a(-h1color)
227      }
228      # This day is partially emphasized
229      if { $result == 2 } {
230        $c create $a(-h2type) [$c bbox $id] -fill $a(-h2fill)\
231                -outline $a(-h2outline) -tags [list day type$result]
232        $c itemconfigure $id -font $a(-h2font) -fill $a(-h2color)
233      }
234      # Shows it into the canvas
235      $c raise $id
236      # The new tag is added to canvas
237      $c addtag type$result withtag $id
238    }
239    # The position is updated to add the following day
240    if {[incr x $dx] > $xmax} {
241      set x $x0
242      incr y $dy
243    }
244  }
245  if {$a(otherday)} {
246    if {$x != $x0} {
247      for {set d 1} {$x<=$xmax} {incr d; incr x $dx} {
248        $c create text $x $y -text $d -fill $a(-otherfill)\
249                -font $a(-otherfont) -tag otherday
250      }
251    }
252  }
253}
254
255#/////////////////////////////////////////////////////////////////////////////
256proc ::date::Adjust {instance dmonth dyear} {
257#   
258# PURPOSE: Move to a calendar established in a concrete month and year to
259#          another, with a displacement.
260#
261# PARAMETERS:
262#     dmonth -> Amount of months to displace. Example: 1 next or -1 previous
263#     dyear -> Amount of years to displace. Example: 1 next or -1 previous
264#
265#/////////////////////////////////////////////////////////////////////////////       
266  upvar #0 ${instance}::data data
267  # Obtains the present month
268  set data(month) [RemovePre0 $data(month)]
269  # The increases or decrements are applied
270  incr data(year)  $dyear
271  incr data(month) $dmonth
272  # Increases the year of the calendar
273  if {$data(month)>12} {
274    incr data(year)  [expr $data(month)/12]
275    set data(month)  [expr $data(month)%12]
276  }
277  # Decreases the year of the calendar
278  if {$data(month)<1}  {
279    incr data(year) -[expr 1+abs($data(month))/12]
280    set data(month) [expr 12 - (abs($data(month))%12)]
281  }
282  # It obtains the number of day that has the month
283  set maxday [::tol::date days $data(year) [RemovePre0 $data(month)]]
284  if {$maxday < $data(day)} {
285    set data(day) $maxday
286  }
287  # Displays the calendar of the updated month and year
288  Display $instance
289}
290
291#/////////////////////////////////////////////////////////////////////////////
292proc ::date::SetMonth {instance month year} {
293#/////////////////////////////////////////////////////////////////////////////
294  upvar #0 ${instance}::data data
295  set data(year) $year
296  set data(month) $month
297  # It obtains the number of day that has the month
298  set maxday [::tol::date days $data(year) [RemovePre0 $data(month)]]
299  if {$maxday < $data(day)} {
300    set data(day) $maxday
301  }
302  # Displays the calendar of the updated month and year
303  Display $instance
304}
305 
306#/////////////////////////////////////////////////////////////////////////////
307proc ::date::Format {month year} {
308#
309# PURPOSE: Defines the format of the header of the calendar for a month.
310#
311# PARAMETERS:
312#     month -> Present month.
313#     year -> Present year.
314#
315#/////////////////////////////////////////////////////////////////////////////       
316  variable a
317   
318  if ![info exists a(format,[::msgcat::mclocale])] {
319    set format "%m - %y" ;# default format
320  } else {
321    set format $a(format,[::msgcat::mclocale]) ;# locale format
322  }
323  # Apply the format 
324  foreach {from to} [list %m $month %y $year] {
325    regsub $from $format $to format
326  }
327  subst $format
328}
329
330#/////////////////////////////////////////////////////////////////////////////
331proc ::date::RemovePre0 {value} {
332#/////////////////////////////////////////////////////////////////////////////       
333 if {[string range $value 0 0] eq 0} {
334     set newValue [string range $value 1 1]
335  } else {
336    set newValue $value
337  }
338  return $newValue
339}
340
341#/////////////////////////////////////////////////////////////////////////////
342proc ::date::MonthName {pos} {
343#
344# PURPOSE: Returns the name of the month which position in the year is given
345#          by pos. Example: 1 -> January, 2 -> February, ...
346#
347# PARAMETERS:
348#    pos -> Position of the month within the year.
349#
350#/////////////////////////////////////////////////////////////////////////////
351  variable a
352   
353  set res [mc [lindex $a(mn) [RemovePre0 $pos]]]
354}
355
356#/////////////////////////////////////////////////////////////////////////////
357proc ::date::lcycle {_list} {
358#/////////////////////////////////////////////////////////////////////////////
359  upvar $_list list
360    set list [concat [lrange $list 1 end] [list [lindex $list 0]]]
361}
362
363
364#/////////////////////////////////////////////////////////////////////////////
365::snit::widget bentrydate {
366#
367# PURPOSE: Defincición de las funcionalidades de un BayeEntryDate
368#
369#/////////////////////////////////////////////////////////////////////////////
370#/////////////////////////////////////////////////////////////////////////////
371# options:
372#  -bdate  : inizializamos una fecha del selector
373#  -btext  : texto a mostrar en el entry de fechas
374#  -bstate : state del componente
375#  -btextvariable: variable asociada al entry
376#  -bformat : formato a aplicar a la fecha
377#  -postcommand: comando a ejecutar tras obtener la fecha
378
379# variable
380#  bdate : almacenamos la fecha a mostrar en el caledario y  la seleccionada
381#  data : array interno de almacenamiento
382#  dateTxt : fecha seleccionada en texto
383#
384#/////////////////////////////////////////////////////////////////////////////
385  widgetclass BEntryDate
386
387  option -bdate
388  option -btext
389  option -bstate normal
390  option -btextvariable {}
391  option -bformat %Y%m%d
392  option -postcommand {}
393
394  variable bdate
395  variable data
396  variable dateTxt
397  variable wentry
398
399  #///////////////////////////////////////////////////////////////////////////
400  constructor {args} {
401  #
402  # PURPOSE: bentrydate constructor
403  #
404  # PARAMETERS:
405  #   args ->
406  #
407  #/////////////////////////////////////////////////////////////////////////// 
408    # Apply all options passed at creation time.
409    $self configurelist $args
410    # Create widget
411    $self CreateWidget
412  }
413
414  #///////////////////////////////////////////////////////////////////////////
415  #
416  # PURPOSE: Metodos cget y configure
417  #
418  #///////////////////////////////////////////////////////////////////////////
419
420  oncget -bdate {
421    if {[info exists bdate]} {
422      return $bdate
423    } else {
424      return ""
425    }
426  }
427
428  oncget -btext {
429    if {[info exists dateTxt]} {
430      return $dateTxt
431    } else {
432      return ""
433    }
434  }
435
436  oncget -btextvariable {
437    if {[info exists data(entry)]} {
438      $data(entry) cget -textvariable
439    }
440  }
441
442  onconfigure -bdate {value} {
443    if {[expr [llength $value] == 1]} {
444      set value [lindex $value 0]
445      set value [list [string range $value 0 3] \
446                      [string range $value 4 5] \
447                      [string range $value 6 7]]
448    }
449    set bdate $value
450   
451    if [llength $value] {
452      set year  [lindex $value 0]
453      set month [lindex $value 1]
454      set day   [lindex $value 2]
455      if {$month ne ""} { set month [format "%02d" [::date::RemovePre0 $month]] }
456      if {$day   ne ""} { set day   [format "%02d" [::date::RemovePre0 $day]]}
457      set bdate [list $year $month $day]
458      set dateTxt ${year}${month}${day}
459      if {[string length $options(-bformat)]} {
460        catch {
461          set dateTxt [clock format [clock scan $dateTxt] -format $options(-bformat)]
462        } res
463      }
464    } else {
465      set dateTxt {}
466    }
467    if {[info exists data(entry)]} {
468      $data(entry) configure -text $dateTxt
469    }
470  }
471
472  onconfigure -btext {value} {
473    set bdate [list [string range $value 0 3]\
474                    [string range $value 5 6]\
475                    [string range $value 8 9]]
476    $self configure -bdate $bdate
477  }
478
479  onconfigure -bstate {value} {
480    if {[info exists data(entry)]} {
481      $data(entry)  configure -state $value
482    }
483    if {[info exists data(button)]} {
484      $data(button) configure -state $value
485    }
486  }
487
488  onconfigure -btextvariable {value} {
489    if {[info exists data(entry)]} {
490      $data(entry) configure -textvariable $value
491    }
492  }
493
494  #///////////////////////////////////////////////////////////////////////////
495  method CreateWidget {args} {
496  #
497  # PURPOSE: Creacion de los objetos que compones el widget
498  #
499  # PARAMETERS:
500  #   args ->
501  #
502  #///////////////////////////////////////////////////////////////////////////
503    set data(ftop) [frame $self.f]
504    # Entry Date
505    set txt {}
506    if {[info exists dateTxt]} {
507      set txt $dateTxt
508    }
509    install wentry using Entry $self.f.e -editable false -width 12 -text $txt
510    set data(entry) $wentry
511    set data(button) [Button $self.f.b -image [::Bitmap::get Date] \
512      -command [list eval $self DateChange]]
513 
514    #grid $self.f.e $self.f.b -padx 0 -sticky nw
515    pack $self.f.b -side right
516    pack $self.f.e -side left -fill x -expand true
517    pack $self.f -expand true -fill both
518    grid columnconfigure $self.f 2 -weight 1
519 
520    # Selector Date
521    ::date::Init
522   
523    set w [toplevel $self.t]
524    set data(fbottom) $w
525    wm resizable $w 0 0
526    wm overrideredirect $w 1
527    wm withdraw $w
528
529    # definir una variable donde almacenar la informacion
530     if {[info exists bdate]} {
531      set year  [lindex $bdate   0]
532      set month [lindex $bdate   1]
533    } else {
534      set ahora [clock format [clock seconds] -format "%Y %m %d"]
535      set year  [lindex $ahora  0]
536      set month [lindex $ahora  1]
537    }
538    set this [::date::Chooser $w.c $month $year \
539        [list OnDoubleDay "$self DateGetDay"]]
540
541    #$w.c configure -bd 0
542    frame $w.f -bd 1 -bg white -relief solid
543 
544    Button $w.f.bby -text "<<" -height 1 -bg white\
545      -command [list ::date::Adjust $this 0 -1] -relief link -width 2\
546      -helptext [mc "Moves to previous year"]
547    Button $w.f.bbm -text "< " -height 1 -bg white\
548      -command [list ::date::Adjust $this -1  0] -relief link -width 2\
549      -helptext [mc "Moves to previous month"]
550    Button $w.f.clear -text " X" -height 1 -bg white\
551      -command [list $self ClearDate] -relief link -width 2\
552      -helptext [mc "Clear date"]
553    Button $w.f.bnm -text " >" -height 1 -bg white\
554      -command [list ::date::Adjust $this 1 0] -relief link -width 2\
555      -helptext [mc "Moves to next month"]
556    Button $w.f.bny -text ">>" -height 1 -bg white\
557     -command [list ::date::Adjust $this  0  1] -relief link -width 2\
558     -helptext [mc "Moves to next year"]
559
560    grid $w.f.bby $w.f.bbm $w.f.clear $w.f.bnm $w.f.bny -sticky nwes  -padx 2
561
562    grid columnconfigure $w.f 2 -weight 1
563
564    grid $w.f -sticky nwe  -padx 2
565    grid $w.c -sticky nwe  -padx 2
566  }
567
568  #///////////////////////////////////////////////////////////////////////////
569  method getentry {} {
570  #
571  # PURPOSE: funcion para obtener el path del entry donde se visualiza la
572  #          fecha
573  # RETURN: El path completo del entry
574  #
575  #///////////////////////////////////////////////////////////////////////////
576    variable data
577    return $data(entry)
578  }
579
580  #///////////////////////////////////////////////////////////////////////////
581  method getbutton {} {
582  #
583  # PURPOSE: Funcion para obtener el path del button que muesta el calendario
584  # RETURN: El path completo del button
585  #
586  #///////////////////////////////////////////////////////////////////////////
587    variable data
588    return $data(button)
589  }
590
591  #///////////////////////////////////////////////////////////////////////////
592  method DateChange {} {
593  #
594  # PURPOSE: Funcion a aplicar al presiona el boton calendario. Muestra un
595  #          calendario para seleccionar una fecha
596  #
597  #///////////////////////////////////////////////////////////////////////////
598    if {[winfo viewable $data(fbottom)] == 1} {
599      wm withdraw  $data(fbottom)
600      grab release $data(fbottom)
601    } else {
602      wm deiconify $data(fbottom)
603      focus -force $data(fbottom)
604      grab -global $data(fbottom)
605      # Positioning the dialog
606      set posh [winfo rootx $data(entry)]
607      set posv \
608            [expr [winfo rooty $data(entry)]+[winfo height $data(entry)]]
609      set right [expr $posh + [winfo width $data(fbottom)]]
610      set bottom [expr $posv + [winfo height $data(entry)] + \
611          [winfo height $data(fbottom)]]
612      if { $right > [winfo vrootwidth $self] } {
613        #It is necessary to change the horizontal location
614        set posh [expr [winfo rootx $data(entry)] + \
615               [winfo width $data(entry)] - [winfo width $data(fbottom)] ]
616      }   
617      if { $bottom > [winfo vrootheight $self] } {
618        #It is necessary to change the vertical location
619        set posv [expr [winfo rooty $data(entry)] - \
620                       [winfo height $data(fbottom)] ]
621      }   
622      set width [winfo width $data(fbottom)]
623      set height [winfo height $data(fbottom)]
624
625      # Apply geometry
626      wm geometry $data(fbottom) ${width}x${height}+$posh+$posv
627      bind $data(fbottom) <ButtonPress> [list $self DateClose %X %Y]
628    }
629  }
630
631  #///////////////////////////////////////////////////////////////////////////
632  method DateGetDay {day month year tags} {
633  #
634  # PURPOSE: Funcion a aplicar al seleccionar una fecha del selector. Al
635  #          seleccionar una fecha se muestra en el entry 
636  #
637  #///////////////////////////////////////////////////////////////////////////
638    $self configure -bdate [list $year $month $day]
639    wm withdraw  $data(fbottom)
640    grab release $data(fbottom)
641    # Agregar un postcommand para el control de la fecha.
642    if {[string length [$self cget -postcommand]]} {
643      update
644      eval [$self cget -postcommand]
645      update
646    }   
647  }
648
649  #///////////////////////////////////////////////////////////////////////////
650  method DateClose {x y} {
651  #
652  # PURPOSE: Cerramos el selector de fechas haciendo click fuera del widget
653  #
654  #///////////////////////////////////////////////////////////////////////////
655    if {[expr $x==-1 && $y==-1]}  {
656      wm withdraw  $data(fbottom)
657      grab release $data(fbottom)
658    } else  {
659      set obj [winfo containing $x $y]
660      if {[string length $obj]} {
661        if {[winfo toplevel $obj] != $data(fbottom)} {
662          wm withdraw  $data(fbottom)
663          grab release $data(fbottom)
664        }
665      }
666    }
667  }
668
669  #///////////////////////////////////////////////////////////////////////////
670  method ClearDate {} {
671  #
672  # PURPOSE: Selector de fecha null
673  #
674  #///////////////////////////////////////////////////////////////////////////
675    $self configure -bdate {}
676    wm withdraw  $data(fbottom)
677    grab release $data(fbottom)
678    if {[string length [$self cget -postcommand]]} {
679      update
680      eval [$self cget -postcommand]
681      update
682    }   
683  }
684
685
686  #/////////////////////////////////////////////////////////////////////////////
687  method Set { year month day} {
688  #/////////////////////////////////////////////////////////////////////////////
689  puts "$self configure -bdate [list $year $month $day]"
690    $self configure -bdate [list $year $month $day]
691    set data(month) $month
692    set data(year) $year
693  }
694
695  # delegation of methods and options to entry
696  delegate method * to wentry
697  delegate option * to wentry
698}
699
700package provide bentrydate 1.0
701
702#/////////////////////////////////////////////////////////////////////////////
703proc test_bentrydate {} {
704#
705# PURPOSE: Funcion de test de un bentrydate
706#
707#///////////////////////////////////////////////////////////////////////////// 
708   # defining the widgets
709  variable data
710  set data(-selected) 1 
711  set formatos {{sql} {fecha tol}}
712 
713  destroy .top
714  toplevel .top -width 200 -height 200 
715 
716  TitleFrame .top.f1 -text "Bentrydate test"
717  set f1 [ .top.f1 getframe ]
718  bentrydate $f1.bed -btextvariable data(txtbed) -btext "20081010" -bdate "20081010"
719  button $f1.bObtener -text "Obtener" -command {takeDate}
720 
721  TitleFrame .top.f2 -text "Configuración"
722  set f2 [ .top.f2 getframe ]
723  blistbox $f2.bcbox -listvariable blblist
724
725  button $f2.bOk -text "Aplicar" -command {aplicar}
726  button $f2.bCancel -text "Salir" -command {salir}
727  LabelEntry $f2.leresultado    -label "Fecha  " -textvariable LEres -editable 0 -text ""
728  LabelEntry $f2.leformatoFecha -label "Formato" -textvariable LEforFec -editable 0 -text "" -width 40
729   
730  grid .top.f1 -sticky news
731  grid $f1.bed - $f1.bObtener -sticky news
732  grid .top.f2 -sticky news -sticky news
733  grid $f2.bcbox -rowspan 2 -sticky news
734  grid $f2.leresultado -row 0 -column 1 -sticky ew
735  grid $f2.leformatoFecha -row 1 -column 1 -sticky ew
736  grid $f2.bOk $f2.bCancel -sticky news
737
738  .top.f2.f.bcbox delete 0 end
739  .top.f2.f.bcbox insert end {"Formato tol"}
740  .top.f2.f.bcbox insert end {"Formato sql"}
741 
742  puts "bentrydate --> .top.f2.f.bcbox"
743 
744  proc takeDate {} {
745    .top.f2.f.leresultado configure -text [ .top.f1.f.bed cget -btext ]
746  }
747 
748  proc salir {} {
749    .top.f2.f.bcbox delete 1
750    .top.f2.f.bcbox delete 0
751
752    .top.f2.f.leresultado configure -text ""
753    .top.f2.f.leformatoFecha configure -text ""
754   
755    destroy .top
756  }
757 
758  proc aplicar {} {
759    set txtLista [.top.f2.f.bcbox curselection]
760    if {$txtLista == 0} {
761      set txtFecha [.top.f1.f.bed cget -bdate]
762      .top.f2.f.leformatoFecha configure -text [ DateTol $txtFecha ]
763    } elseif {$txtLista == 1} {
764      set txtFecha [.top.f1.f.bed cget -btext]
765      .top.f2.f.leformatoFecha configure -text [SqlFormatField $txtFecha "date" Mys "%Y%m%d"]
766      set LEforFec $txtLista
767    } else {
768      set LEforFec "Error, selecciona una fecha"
769    }   
770  }
771}
Note: See TracBrowser for help on using the repository browser.