source: tol/tolbase/lib/byswidget/blistboxplus/blistboxplus.tcl @ 23399d1

1941-docker-image-to-testdevel
Last change on this file since 23399d1 was 23399d1, checked in by Pedro Gea <pgea@…>, 10 years ago

Refs #1933
Se suben cambios en blistboxplus para usar wtree en lugar de treeview.
Se adapta wtree para responder a algunos métodos de blistboxplus que se delegaban en treeview.
Pendiente aún de revisión.

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

  • Property mode set to 100644
File size: 45.9 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : blistboxplus.tcl
3# PURPOSE : Bayes List Box. ListBox con opciones sobre su elementos y varias
4#           columnas
5#/////////////////////////////////////////////////////////////////////////////
6
7package require byscommon
8package require bfunctions
9package require bfieldsdialog
10
11proc debug_init { } {
12  catch {
13    file delete "/tmp/debug_tcl.out"
14  }
15}
16
17proc debug_msg { msg } {
18  catch {
19    set fd [open "/tmp/debug_tcl.out" "a"]
20    puts $fd $msg
21    close $fd
22  }
23}
24
25#/////////////////////////////////////////////////////////////////////////////
26::snit::widget blistboxplus {
27#
28# PURPOSE: ListBox con columnas, menu contextual y caracteristicas adicionales
29#
30#/////////////////////////////////////////////////////////////////////////////
31# opciones especificas
32# readonly -> componente en modo de lectura o lectura/escritura
33# keypress -> Activa la busqueda de filas mediante la pulsacion de teclas
34# colkeypress -> Indica por que columna se busca al pulsar una tecla
35# parent -> indica el padre donde se ubica el blistbox
36# cols -> columnas del listbox
37# hiddencols -> columnas del listbox que no se mostraran
38# filtercols -> columnas del listbox que por las que puede realizarse filtrado
39# initialdir -> directorio inicial para los dialogos de lec/esc de archivos,...
40# orientation -> orientation for de add dialog
41# icon -> icono que se mostrará como primera columna, si no hay icono la
42#  columna no se mostrará
43# nomenu -> Si es 1, no se mostrará el menu contextual
44# titles -> Lista con los titulos a mostrar en cada una de las columnas.
45# values -> List of initial values to load in widget
46# valuesinsert -> List of values to selection element
47# iniconfig -> Nombre que se asigna al listboxplus para identificar sus
48#           opciones en el archivo de configuración .ini por defecto "" en
49#           ese caso no se guardaran las opciones
50#
51# variables
52# listbox -> el treeview que hace de listbox propiamente
53# menu -> el menu contextual del listbox
54# xbar -> horizontal scrollbar
55# ybar -> vertical scrollbar
56# afterTime -> tiempo desde que se pulso la ultima tecla
57# listKey -> lista de teclas pulsadas
58#/////////////////////////////////////////////////////////////////////////////
59  widgetclass Blistboxplus
60
61  option -readonly  0
62  option -selectmode  extended
63  option -keypress    true
64  option -colkeypress ""   
65  option -parent    {}
66  option -cols {}
67  option -hiddencols {}
68  option -filtercols {}
69  option -initialdir {}
70  option -orientation vertical
71  option -showtitles true
72  option -icon ""
73  option -nomenu 0
74  option -titles {}
75  option -values {}
76  option -valuesinsert {}
77  option -iniconfig ""
78 
79  variable _listbox
80  variable menu
81  variable xbar
82  variable ybar
83 
84  variable afterTime 0
85  variable listKey   ""
86  variable currentId 0
87  variable created   0
88
89  #///////////////////////////////////////////////////////////////////////////
90  constructor {args} {
91  #
92  # PURPOSE: Constructor de un blistboxplus. Crea una instancia de un Listbox
93  #
94  # PARAMETERS:
95  #   args -> opciones
96  #
97  #///////////////////////////////////////////////////////////////////////////
98
99    debug_init
100
101    debug_msg "install listbox ..."
102
103    if {0} {
104      return
105      #@T install _listbox using ::blt::treeview $win.lb -hideroot yes \
106          -activeicons "" -icons {} -selectmode multiple \
107          -selectbackground grey -selectforeground white \
108          -highlightthickness 0 -borderwidth 1 -selectborderwidth 1 \
109          -nofocusselectbackground grey -font {Arial 9} -flat yes
110    } else {
111      set _listbox [::wtree $win.lb -table 0 -filter no \
112        -background white -showroot 0 -selectmode extended -showheader 1 \
113        -highlightbackground gray75 -highlightcolor black \
114        -highlightthickness 0 -font {Arial 9} \
115        -columns [::TolInspector::LNodeDef] ]
116      #@T set _listbox [::blt::treeview $win.lb -hideroot yes \
117                        -activeicons "" -icons {} -selectmode multiple \
118                        -selectbackground grey -selectforeground white \
119                        -highlightthickness 0 -borderwidth 1 \
120                        -selectborderwidth 1 \
121                        -nofocusselectbackground grey -font {Arial 9} -flat yes]
122    }
123
124    debug_msg "despues de install listbox"
125
126    install menu using menu $win.m -tearoff 0
127    install xbar using scrollbar $win.sbh -orient horizontal \
128                                           -command "$win xview"
129    install ybar using scrollbar $win.sbv -orient vertical \
130                                           -command "$win yview"
131
132    #bindtags is modified to make possible to associate binds to self
133    bindtags $_listbox [linsert [bindtags $_listbox] 2 $win]
134
135    #@T! $_listbox style  configure text     -bg white
136    #@T! to do
137
138    #@T! $_listbox column configure treeView -bg white
139    #@T! to do   
140
141    $self configure -readonly [from args -readonly]
142    $self _CreateMenu 
143   
144    # Apply all arguments given:
145    $self configurelist $args
146
147    #@T! $_listbox configure -xscrollcommand "$xbar set"
148    #@T! $_listbox configure -yscrollcommand "$ybar set"
149    #@T! to do   
150    if { $options(-parent) eq "" } {
151      $self configure -parent [winfo parent $win]
152    }
153   
154    # bind
155    #@T! $_listbox bind all <KeyPress> +[list $self _OnKeyPress %A]
156    #@T! to do   
157   
158    $self configure -nomenu [from args -nomenu]
159    $self configure -filtercols [from args -filtercols]
160
161    #pack
162    grid $_listbox -row 0 -column 0 -sticky news
163    grid $ybar -row 0 -column 1 -sticky ns
164    grid $xbar -row 1 -column 0 -sticky ew
165    grid columnconfigure $self 0 -weight 1
166    grid rowconfigure    $self 0 -weight 1
167
168    ::autoscroll::autoscroll $ybar
169    ::autoscroll::autoscroll $xbar
170    debug_msg "voy a pillarte: antes de _ReadIni"
171    $self _ReadIni
172    debug_msg "pase?"
173    set created 1
174  }
175
176  #///////////////////////////////////////////////////////////////////////////
177  destructor {
178  #
179  # PURPOSE: Funciones a evaluar al eliminar la instancia de blistboxplus.
180  #
181  # PARAMETERS:
182  #   self: toplevel
183  #
184  #///////////////////////////////////////////////////////////////////////////
185    # Save .ini
186    catch [list $self _WriteIni ]
187  }
188
189  #///////////////////////////////////////////////////////////////////////////
190  #
191  # PURPOSE: Metodos cget y configure
192  #
193  #///////////////////////////////////////////////////////////////////////////
194
195  onconfigure -cols { lst } {
196    set options(-cols) $lst
197    #@T! foreach col [$self column names] {
198    #@T!   $_listbox column delete $col
199    #@T! }
200    $_listbox column delete all
201    #@T! foreach col $options(-cols) {
202    #@T!   $_listbox column insert end $col -justify left
203    #@T!   $_listbox column configure $col -command "$self _SortByColumn [list $col]" -titleborderwidth 1
204    #@T! }
205   
206    set lstx [list [list image -label Icon -tags Icon] ]
207    foreach col $lst {
208      set colx [list text -label $col -tags $col]
209      lappend lstx $colx
210    }
211    Tolcon_Trace "lstx $lstx"
212    $_listbox configure -columns $lstx
213   
214    if { $options(-icon) == "" } {
215      #@T! $_listbox column configure "BLT TreeView $_listbox" -hide 1
216      $_listbox column configure Icon -visible 0
217    } else {
218      #@T! $_listbox column configure "BLT TreeView $_listbox" -hide 0
219      $_listbox column configure Icon -visible 1
220    }
221   
222    #@T adds
223    $_listbox column configure first -expand yes -weight 1
224    $_listbox column configure all -itembackground ""   
225  }
226
227  onconfigure -hiddencols { lst } {
228    set options(-hiddencols) $lst
229    foreach col [$self column names] {
230      if { "-1" eq [lsearch $options(-hiddencols) $col] } {
231        #@T! $_listbox column configure $col -hide 0
232        $_listbox column configure $col -visible 1
233      } else {
234        #@T! $_listbox column configure $col -hide 1
235        $_listbox column configure $col -visible 0
236      }
237    }
238  }
239
240  onconfigure -showtitles { bool } {
241    set options(-showtitles) $bool
242    $_listbox configure -showtitles $bool
243    $_listbox show
244  }
245
246  onconfigure -icon { icon } {
247    set options(-icon) $icon
248    if { $icon != "" } {
249      #@T! $_listbox column configure "BLT TreeView $_listbox" -min 16 -max 16 \
250      #@T!   -hide 0 -titleborderwidth 1
251      #@T! $_listbox configure -icons [list [Bitmap::get $icon] [Bitmap::get $icon]]
252      $_listbox column configure Icon -minwidth 16 -maxwidth 16 -visible 1 ;# -titleborderwidth 1
253     
254    } else {
255      #@T! $_listbox column configure "BLT TreeView $_listbox" -hide 1
256      $_listbox column configure Icon -visible 0
257    }
258  }
259
260  onconfigure -titles { titles } {
261    set options(-titles) $titles
262    set c 0
263    set cols [$self column names]
264    foreach col $cols {
265     $self column configure $col -title [mc [lindex $titles $c] ]
266     incr c 1     
267    }
268  }
269
270  onconfigure -values { lst } {
271    $self clear
272    eval $self insert end $lst
273  }
274
275  onconfigure -nomenu { bool } {
276    set options(-nomenu) $bool
277    if {$bool} {
278      # no mostrar menu
279      bind $self  <Button-3>   ""
280    } else {
281      # mostrar menu
282      bind $self  <Button-3>   "tk_popup $menu %X %Y"
283    }
284  }
285
286  onconfigure -readonly { bool } {
287    if {!($created)} {
288      set options(-readonly) $bool       
289    } else {
290      puts "Blistboxplus widget error: option -readonly only can be set on \
291            creation time"
292    }
293  }
294 
295  onconfigure -selectmode { mode } {
296    if { $mode eq "multiple" } {
297      set options(-selectmode) "extended"
298    } else {
299      set options(-selectmode) $mode
300    }
301  } 
302
303  onconfigure -filtercols { lst } {
304    set cols [$self cget -cols]   
305    set hiddencols [$self cget -hiddencols]
306    if { [llength cols] && [llength hiddencols]} {
307      set filtercols {}
308      foreach col $cols {
309        if {([lsearch -exact $hiddencols  $col])} {
310          lappend filtercols $col
311        }
312      }
313      set options(-filtercols) $filtercols   
314    } else {
315      if { [llength cols] } {
316        set options(-filtercols) $options(-cols)
317      }
318    }
319  }
320
321  #///////////////////////////////////////////////////////////////////////////
322  method _CreateMenu {args} {
323  #
324  # PURPOSE: Append menu to listbox.
325  #
326  #///////////////////////////////////////////////////////////////////////////
327    # read option
328    $menu add command -label [mc "Select all"] \
329      -command "$self _SelectAll"  -accelerator CTRL+E
330    $menu add command -label [mc "Unselect all"] \
331      -command "$self selection clearall" -accelerator CTRL+U
332    $menu add command -label [mc "Toggle selection"] \
333      -command "$self _ToggleSelection" -accelerator CTRL+I
334    # read/write option
335    if {!([$self cget -readonly])} {
336      # delete
337      $menu add separator
338      $menu add command -label [mc "Insert"] \
339                -command "$self _OpenWR" -accelerator Ins
340      $menu add command -label [mc "Delete all"]  \
341        -command "$self clear"  -accelerator CTRL+D
342      $menu add command -label [mc "Delete selected"] \
343        -command "lbDeleteSelection $self"
344    }
345    # read option
346    # copy
347    $menu add separator
348    $menu add command -label [mc "Filter"] -command "$self _OpenFD"
349    $menu add command -label [mc "Unfilter"] -command "$self _RemoveFilter"
350    $menu add separator
351    set mc [menu $menu.copy -tearoff 0]
352    $menu add cascade -label [mc "Copy"] -menu $mc
353    $mc add command -label [mc "Copy all"] \
354      -command "$self _CopyToClipBoard 1 1" -accelerator CTRL+A
355    $mc add command -label [mc "Copy selected"] \
356      -command "$self _CopyToClipBoard 1 0" -accelerator CTRL+C
357    $mc add command -label [mc "Copy unselect"] \
358      -command "$self _CopyToClipBoard 0 1"
359    # count
360    $menu add separator
361    $menu add command -label [mc "Count elements"] \
362      -command "$self _ShowCountItems" -accelerator CTRL+N
363    # file
364    $menu add separator
365    set mf [menu $menu.file -tearoff 0]
366    $menu add cascade -label [mc "File_lbp"] -menu $mf
367    $mf add command -label "[mc "Save to file"] ..." \
368      -command "$self _SaveToFile 1 1"
369    if {![$self cget -readonly]} {
370      $mf add command -label "[mc "Load form file"] ..." \
371        -command "$self _LoadFromFile"
372    }
373    # bindings   
374    #@T $self bind all <Control-KeyRelease> +[list $self _OnControlKey $self %K %k]
375    #@T $self bind all <Key-Delete>    "lbDeleteSelection $self"
376    #@T $self bind all <Key-Insert>    "$self _OpenWR"   
377    #@T $self bind all <Shift-Up>      "$self addPrevious"
378    #@T $self bind all <Shift-Down>    "$self addNext"
379    #@T $self bind all <Up>            "$self previous"
380    #@T $self bind all <Down>          "$self next"
381    #@T $self bind all <Home>          "$self first"
382    #@T $self bind all <End>           "$self last"
383    #@T $self bind all <Shift-Home>    "$self addAllPrevious"
384    #@T $self bind all <Shift-End>     "$self addAllNext"
385    #@T $self bind all <Button-1>      +[list focus -force %W]
386   
387    bind $_listbox.frameTree.t <Control-KeyRelease> +[list $self _OnControlKey $self %K %k]
388    bind $_listbox.frameTree.t <Key-Delete>    "lbDeleteSelection $self"
389    bind $_listbox.frameTree.t <Key-Insert>    "$self _OpenWR"   
390    bind $_listbox.frameTree.t <Shift-Up>      "$self addPrevious"
391    bind $_listbox.frameTree.t <Shift-Down>    "$self addNext"
392    bind $_listbox.frameTree.t <Up>            "$self previous"
393    bind $_listbox.frameTree.t <Down>          "$self next"
394    bind $_listbox.frameTree.t <Home>          "$self first"
395    bind $_listbox.frameTree.t <End>           "$self last"
396    bind $_listbox.frameTree.t <Shift-Home>    "$self addAllPrevious"
397    bind $_listbox.frameTree.t <Shift-End>     "$self addAllNext"
398    bind $_listbox.frameTree.t <Button-1>      +[list focus -force %W]   
399  }
400
401  #@//////////////////////////////////////////////////////////////////////////
402  method bind { args } {
403  #
404  # PURPOSE: modifies a particular case of bind
405  #
406  #///////////////////////////////////////////////////////////////////////////
407    if { [lindex $args 1] eq "<Selection>" } {
408      #@T no se usa
409      return [eval $_listbox notify bind $args]
410    } else {
411      return [bind $_listbox.frameTree.t [lindex $args 1] [lindex $args 2]]
412    }
413  }
414   
415  method curselection {} {
416    set cursel [$_listbox selection get]
417    if { [expr [llength $cursel] <= 1] } { return $cursel }
418    set curselx {}
419    foreach it $cursel {
420      lappend curselx [list $it [$_listbox item order $it]]
421    } 
422    set curselxs [lsort -index end $curselx]
423    set cursels {}
424    foreach it $curselxs {
425      lappend cursels [lindex $it 0]
426    }
427    return $cursels
428   
429    #set firstPos [$_listbox item order [lindex $cursel 0]]
430    #set lastPos [$_listbox item order [lindex $cursel end]]
431    #if { [expr $firstPos <= $lastPos] } {
432    #  Tolcon_Trace "right!"
433    #  foreach it $cursel {
434    #    Tolcon_Trace "$it [$_listbox item order $it]"
435    #  }
436    #  return $cursel
437    #} else {
438    #  Tolcon_Trace "reversed!"
439    #  foreach it $cursel {
440    #    Tolcon_Trace "$it [$_listbox item order $it]"
441    #  }   
442    #  return [lreverse $cursel]
443    #}
444  }
445     
446  #///////////////////////////////////////////////////////////////////////////
447  method getMenu { } {
448  #
449  # PURPOSE: Devuelve el menu del blistboxplus para poder modificarlo y
450  #          ampliarlo
451  #
452  # RETURN: La variable de instancia que apunta al menu
453  #
454  #/////////////////////////////////////////////////////////////////////////// 
455    return $menu
456  }
457
458  #///////////////////////////////////////////////////////////////////////////
459  method _OnKeyPress {key} {
460  #
461  # PURPOSE: Activa la fila que coincide con las teclas pulsadas. Distinge
462  #          entre muysuculas y minusculas
463  #
464  # PARAMETERS: key -> tecla pulsada
465  #
466  #///////////////////////////////////////////////////////////////////////////
467    if {[$self cget -keypress]} {
468      set diference 500
469      set result [lbOnKeyPress $self $key $listKey $afterTime $diference \
470        [$self cget -colkeypress]]
471      set listKey   [lindex $result 0]
472      set afterTime [lindex $result 1]
473    }
474  }
475
476  #///////////////////////////////////////////////////////////////////////////
477  method _OnControlKey {_lb keysym keycode} {
478  #
479  # PURPOSE: Controla es uso de teclas rápidas para le ejecución de funciones
480  #
481  # PARAMETERS: _lb -> self
482  #             keysym -> The keysym corresponding to the event,
483  #                       substituted as a textual string
484  #             keycode -> The keycode field from the event
485  #
486  #///////////////////////////////////////////////////////////////////////////
487    switch [string toupper $keysym] {
488      E { $_lb _SelectAll }
489      C { lbToClipBoard $_lb 1 0 }
490     
491      A { $self _CopyToClipBoard 1 1 }
492      D { $self clear }
493      I { $self _ToggleSelection }
494      U { $self selection clearall }
495      N { $self _ShowCountItems }
496    }
497  } 
498
499  #///////////////////////////////////////////////////////////////////////////
500  method _ShowCountItems {} {
501  #
502  # PURPOSE: Shows information on the selection of the elements
503  #
504  #///////////////////////////////////////////////////////////////////////////
505    set info [lbCountItems $self]
506    set msg "[mc "Total"]: [lindex $info 0] \n\
507             [mc "Selected"]: [lindex $info 1] \n\
508             [mc "Not Selected"]: [lindex $info 2]"
509    if {[string length [$self cget -parent]]} {
510      set par $self
511    } else {
512      set par [$self cget -parent]
513    }
514    tk_messageBox -default ok \
515                  -icon info  \
516                  -message $msg \
517                  -type ok \
518                  -parent $par \
519                  -title [mc "numero de elementos"]
520  }
521
522  #/////////////////////////////////////////////////////////////////////////////
523  method _ToggleSelection {} {
524  #
525  # PURPOSE: Toggle selection elements
526  #
527  #/////////////////////////////////////////////////////////////////////////////
528    foreach i [$self get] {
529      $self selection toggle $i
530    }
531  }
532
533  #///////////////////////////////////////////////////////////////////////////
534  method _SelectAll { } {
535  #
536  # PURPOSE: Selection all
537  #
538  #///////////////////////////////////////////////////////////////////////////
539    foreach i [$self get] {
540      $self selection set $i
541    }
542  }
543
544  #/////////////////////////////////////////////////////////////////////////////
545  method _CopyToClipBoard { sl unSe {pref ""} {suf ""} {sep "\n"}} {
546  #
547  # PURPOSE: copy the elements indicates in clipboard
548  #
549  # PARAMETERS:
550  #   sl   -> Copy items selections
551  #   unSe -> Copy items not selections
552  #   pref -> Text to concatenate in the beginning. Default ""
553  #   suf  -> Text to concatenate in the end. Default ""
554  #   sep  -> Separating text of elements. Default "\n"
555  #
556  #/////////////////////////////////////////////////////////////////////////////
557    # items to copy
558    set lst {}
559    if { $sl } {
560      foreach i [$self curselection] {
561        lappend lst [$self get $i]
562      }
563    }
564    if { $unSe } {
565      foreach i [$self selection get unselected] {
566        lappend lst [$self get $i]
567      }
568    }
569    # copy
570    set str [ListToStr $lst $sep $pref $suf]
571    clipboard clear
572    clipboard append $str
573  }
574
575  #/////////////////////////////////////////////////////////////////////////////
576  method _SaveToFile {se unSe {pref ""} {suf ""} {sep "\n"}} {
577  #
578  # PURPOSE: Save the content from listbox in a file
579  #
580  # PARAMETERS:
581  #    sl   -> Copy items selections
582  #   unSe -> Copy items not selections
583  #   pref -> Text to concatenate in the beginning. Default ""
584  #   suf  -> Text to concatenate in the end. Default ""
585  #   sep  -> Separating text of elements. Default "\n"
586  #
587  #/////////////////////////////////////////////////////////////////////////////
588    # select file
589    set filNam [tk_getSaveFile -parent $self -title [mc "File selector"] \
590                               -initialdir $options(-initialdir)]
591
592    if {$filNam != ""} {
593      set options(-initialdir) [file dirname $filNam]   
594      # open file to write
595      if { ![ catch { set fd [open $filNam w] } msgerr] } {
596        # text to save
597        set lst {}
598        if { $se } {
599          foreach i [$self selection get selected] {
600            lappend lst [$self get $i]
601          }
602        }
603        if { $unSe } {
604          foreach i [$self selection get unselected] {
605            lappend lst [$self get $i]
606          }
607        }
608        set str [ListToStr $lst $sep $pref $suf]
609        # write
610        puts -nonewline $fd $str
611        close $fd
612        return 1
613      }
614      error $msgerr
615    }
616  }
617
618  #/////////////////////////////////////////////////////////////////////////////
619  method  _LoadFromFile { } {
620  #
621  # PURPOSE: Load the content from listbox in a file
622  #
623  #/////////////////////////////////////////////////////////////////////////////
624    # select file   
625    set filNam [tk_getOpenFile -parent $self -title [mc "File selector"] \
626                               -initialdir $options(-initialdir)]   
627
628    if {$filNam != ""} {
629      set options(-initialdir) [file dirname $filNam]
630      # open file to read
631      if { ![ catch { set fd [open $filNam r] } msgerr] } {
632         while { [gets $fd line ] >= 0} {
633           Tolcon_Trace "adding $line"
634           $self add $line
635         }
636         close $fd     
637         return 1
638      }
639      error $msgerr
640    }
641  }
642
643  #///////////////////////////////////////////////////////////////////////////
644  method _SortByColumn { col } {
645  #
646  # PURPOSE: Sorts the ListBox by the values of the given column
647  # PARAMETERS:
648  #  col -> the column which the sort is performed
649  #
650  #///////////////////////////////////////////////////////////////////////////
651
652    set numofel [$self size]
653    set lst [list]
654    set fulllst [$self get]
655
656    foreach i $fulllst {
657      lappend lst [$self get $i ]
658    }
659# lst:    contains a list of values
660    set coln 0
661    set cols [$self cget -cols]
662    set hidcols [$self cget -hiddencols]
663    for { set j 0 } { $j < [llength $cols] } { incr j } {
664      if {[lindex $cols $j] eq $col} {
665        set coln $j
666      }
667    }
668# coln:   contains the index of the column to be ordered
669    set lst [lsort -index $coln $lst]
670    $self clear
671    for { set i 0 } { $i < $numofel } { incr i } {
672      set el [lindex $lst $i ]
673      $self insert end $el
674    }
675
676  }
677
678  #///////////////////////////////////////////////////////////////////////////
679  proc _AddWR { elem father } {
680  #
681  # PURPOSE: adds the item introduced in the dialog to the selected list
682  #
683  # PARAMETERS:
684  #  elem -> the element to insert from the add dialog
685  #  father -> The dialog's window pathname
686  #
687  #///////////////////////////////////////////////////////////////////////////
688    foreach ele $elem {
689      $father insert 0 $ele
690    }
691  }
692
693  #//////////////////////////////////////////////////////////////////////////
694  method _OpenWR {} {
695  #
696  # PURPOSE: Calls (and creates) an add dialog for insert by hand elements
697  #
698  #///////////////////////////////////////////////////////////////////////////
699    destroy $self.dw
700   
701    if {![catch {eval $options(-valuesinsert)} res]} {
702      set valuesinsert $res
703    } else {
704      set valuesinsert $options(-valuesinsert)
705    }
706   
707    if {$valuesinsert == ""} {
708      set dialog  [bfieldsdialog $self.dw -title [mc "Insert element"] \
709                  -parent $self -orientation $options(-orientation) \
710                  -fields $options(-cols) -procedure [codename _AddWR] \
711                  -buttons { add exit } -titles $options(-titles) \
712                  -list $valuesinsert]
713    } else {       
714      set dialog  [bfieldsdialog $self.dw -title [mc "Insert element"] \
715                  -parent $self -orientation $options(-orientation) \
716                  -fields $options(-cols) -procedure [codename _AddWR] \
717                  -buttons { add addall exit } -titles $options(-titles) \
718                  -list $valuesinsert]
719    }
720    $dialog draw
721  }
722
723  #///////////////////////////////////////////////////////////////////////////
724  proc _Filter { elem father } {
725  #
726  # PURPOSE: Filters the listbox with the filter suministred
727  #
728  # PARAMETERS:
729  #  elem -> the list with the filter fields
730  #  father -> The dialog's window pathname
731  #
732  #///////////////////////////////////////////////////////////////////////////
733    eval $father filter $elem
734  }
735
736  #//////////////////////////////////////////////////////////////////////////
737  method _OpenFD {} {
738  #
739  # PURPOSE: Calls (and creates) a add dialog for getting a filter
740  #
741  #///////////////////////////////////////////////////////////////////////////
742
743    destroy $self.fd
744    set dialog  [bfieldsdialog $self.fd -title [mc "Filter elements"] \
745                -parent $self -orientation $options(-orientation) \
746                -fields $options(-filtercols) -procedure [codename _Filter] \
747                -buttons { info apply accept cancel } \
748                -titles $options(-titles)]
749    $dialog configure -info \
750"Los filtros admiten expresiones regulares:
751
752  expresiones regulares básicas:
753    - literales: caracteres simples
754    - brackets:  conincide con cualquier caracter especificado dentro
755       tambien pueden expecificarse rangos pe \[a-d\] equivale a \[abcd\]
756       o indicar la no coincidencia colocando como primer caracter ^
757       rangos predefinidos:
758        \[:alnum:\] equivale a \[0-9a-zA-Z\]
759        \[:alpha:\] equivale a \[a-zA-Z\]
760        \[:digit:\] equivale a \[0-9\]
761        \\w equivale a \[:alnum:\]
762        \\W equivale a \[^:alnum:\]
763        para incluir el literal - ponerlo al final del braquet
764        para incluir el literal ^ ponerlo en cualquier lugar menos el primero
765    - punto . : coincide con cualquier caracter simple
766    - ^ y $ : coinciden respectivamente con el principio o final de linea
767    - caracteres especiales: los caracteres que tienen significado en las
768      expresiones regulares pueden escribirse precediendolos con \\
769   
770  operadores sobre las expresiones:
771    - <e1><e2>: concatenacion, la expresion resultante coincide si coinciden
772         secuencialmente las expresiones
773    - <e1>|<e2> : disyuncion, coincide si coincide alguna de las expresiones
774    - <e>? : opcionalidad, coincide si la expresion anterior coincide 0 o 1 vez
775    - <e>* : repeticion, coincide si la expresion anterior coincide 0 o mas veces
776    - <e>+ : repeticion, coincide si la expresion anterior coincide 1 o mas veces
777    - <e>{n} : repeticion, coincide si la expresion anterior coincide  n veces
778    - <e>{n,} : repeticion, coincide si la exp anterior coincide n o mas veces
779    - <e>{n,m} : repeticion, coincide si la exp anterior coincide por lo menos n
780         y no mas de m veces
781
782  precedencia de los operadores:
783    - los operadores de repeticion tienen preferencia sobre la concatenacion
784    - la concatenacion tiene preferencia sobre la disyuncion
785    - las reglas pueden alterarse con el uso de parentesis
786"
787       
788    $dialog draw
789  }
790
791  #///////////////////////////////////////////////////////////////////////////
792  method _WriteIni { } {
793  #
794  # PURPOSE: Guarda en el .ini informacion referente al blistboxplus
795  #
796  #
797  #///////////////////////////////////////////////////////////////////////////
798    if { [$self cget -iniconfig] ne "" } {
799      # comprobamos cargado namespace y variable de .ini
800      if {[namespace exists ::iniFile]} {
801        set wini ::iniFile::Write
802        set nm [$self cget -iniconfig]
803        if {![string length $nm]} {
804          set nm $self
805        }
806        $wini $nm initialdir $options(-initialdir)
807      }
808    }
809  }
810
811  #///////////////////////////////////////////////////////////////////////////
812  method _ReadIni { } {
813  #
814  # PURPOSE: Recupera del .ini informacion referente al blistboxplus
815  #
816  #
817  #///////////////////////////////////////////////////////////////////////////
818    if { [$self cget -iniconfig] ne "" } {
819      # comprobamos cargado namespace y variable de .ini
820      if {[namespace exists ::iniFile]} {
821        set rini ::iniFile::Read
822        set nm [$self cget -iniconfig]
823        if {![string length $nm]} {
824          set nm $self
825        }
826        set stt [::iniFile::ReadWMState $rini $nm]
827        set inid [$rini $nm initialdir ""]       
828        if {[string length $inid]} {
829            set options(-initialdir) $inid
830        }
831      }
832    }
833  }
834
835  #///////////////////////////////////////////////////////////////////////////
836  method selection { args } {
837  #
838  # PURPOSE: extends the original command to extend capabilities
839  #
840  # PARAMETERS:
841  #   args: arguments
842  #
843  #///////////////////////////////////////////////////////////////////////////
844    if { [lindex $args 0] eq "get" } {
845      if { [lindex $args 1] eq "unselected" } {
846        set result {}
847        set selected [$self curselection]
848        foreach i [$self get] {
849          if { "-1" eq [lsearch $selected $i] } {
850            lappend result $i
851          }
852        }
853        return $result
854      } else {
855        #@T! return [eval $_listbox curselection]
856        return [$self curselection]
857      }
858    }
859    eval $_listbox selection $args
860  }
861
862  #///////////////////////////////////////////////////////////////////////////
863  method insert { pos args } {
864  #
865  # PURPOSE: inserts an element into de listbox
866  #
867  # PARAMETERS:
868  #   args: a list of elements to insert, each element is a list with column
869  #   data
870  #
871  #///////////////////////////////////////////////////////////////////////////   
872    Tolcon_Trace "insert pos: $pos args: $args"
873    if { [lindex $args 0] eq "cols" } {
874      set cols [lindex $args 1]
875      set args [lrange $args 2 end]
876    } else {
877      set cols $options(-cols)
878    }
879   
880    switch [llength $cols] {
881      1 {
882        # una sola columna
883        foreach dats $args {
884          set datos [list [lindex $cols 0] $dats]
885          #@T! $_listbox insert $pos $currentId -data $datos
886          set node [$_listbox item create -parent root -button 0 -open 0]
887          eval $_listbox item text $node $datos
888          if { $options(-icon) != "" } {
889            $_listbox item image $node [Bitmap::get $options(-icon)]
890          }         
891          incr currentId
892        }       
893      }
894      default {
895        # mas de una columna
896        foreach dats $args {
897          set i 0
898          set datos {}
899          foreach col $cols {
900            lappend datos $col [lindex $dats $i]
901            incr i
902          }
903          #@T! $_listbox insert $pos $currentId -data $datos
904          set node [$_listbox item create -parent root -button 0 -open 0] ;# -parent $pos
905          eval $_listbox item text $node $datos
906          if { $options(-icon) != "" } {
907            $_listbox item image $node [Bitmap::get $options(-icon)]
908          }
909          incr currentId
910        }
911      }
912    }
913  }
914
915  #///////////////////////////////////////////////////////////////////////////
916  method add { args } {
917  #
918  # PURPOSE: appends elements to dthe listbox
919  #
920  # PARAMETERS:
921  #   args: a list of elements to insert, each element is a list with column
922  #   data
923  #
924  #///////////////////////////////////////////////////////////////////////////
925    eval $self insert end $args
926  }
927
928  #///////////////////////////////////////////////////////////////////////////
929  method delete { args } {
930  #
931  # PURPOSE: deletes elements from the listbox
932  #
933  # PARAMETERS:
934  #   args: the tags or ids of the items to be deleted
935  #   data
936  #
937  #///////////////////////////////////////////////////////////////////////////
938    if { "-1" eq [lsearch $args 0] } {
939      #@T! eval $_listbox delete $args
940      eval $_listbox item delete $args
941    } else {
942      puts "Root node can't be deleted"
943    }
944  }
945
946  #/////////////////////////////////////////////////////////////////////////// 
947  method getlb {} {
948  #
949  # PURPOSE: Get path of blistboxplus
950  #
951  #/////////////////////////////////////////////////////////////////////////// 
952    return $_listbox
953  }
954
955  #///////////////////////////////////////////////////////////////////////////
956  method get { {ids ""} {cols ""}} {
957  #
958  # PURPOSE: retrieves data from an entry identified by id
959  #
960  # PARAMETERS:
961  #  id: id list of nodes
962  #  cols: name of the cols from which retrieve data
963  #
964  #///////////////////////////////////////////////////////////////////////////
965    Tolcon_Trace "get ids: $ids cols: $cols"
966    if { $ids eq "" } {
967      #@T! return [lrange [$self find] 1 end]
968      set items [$_listbox item children root]
969      Tolcon_Trace "items $items"
970      return $items  ;#??
971    }
972 
973    set result {}
974 
975    if { "$cols" eq "" } {
976      set cols [$self column names]
977    }
978
979    foreach id $ids {
980   
981      set elem {}
982   
983      #@T! set data [$_listbox entry cget $id -data]   
984      #@T! foreach col $cols {
985      #@T!   set inx [lsearch $data $col]
986      #@T!   if { "-1" ne $inx } {
987      #@T!     incr inx
988      #@T!     lappend elem [lindex $data $inx]
989      #@T!   }
990      #@T! }
991     
992      foreach col $cols {
993        lappend elem [$_listbox item text $id $col]
994      }
995     
996      lappend result $elem
997    }
998     
999    if { [llength $ids] eq 1 } {
1000      Tolcon_Trace "get result: $result"
1001      Tolcon_Trace "get result0: [lindex $result 0]"       
1002      return [lindex $result 0]
1003    }
1004    Tolcon_Trace "get result: $result"   
1005    return $result
1006  }
1007
1008  #///////////////////////////////////////////////////////////////////////////
1009  method set { id data {cols ""}} {
1010  #
1011  # PURPOSE: inserts data to an entry identified by id
1012  #
1013  # PARAMETERS:
1014  #  id: id of the node
1015  #  data: data to insert
1016  #  cols: name of the cols from which retrieve data
1017  #
1018  #///////////////////////////////////////////////////////////////////////////
1019    Tolcon_Trace "set id: $id data: $data cols: $cols"
1020    if { "$cols" eq "" } {
1021      set cols [$self column names]
1022    }   
1023    set datos {}
1024    set i 0   
1025    foreach col $cols {
1026      lappend datos $col
1027      lappend datos [lindex $data $i]
1028      incr i
1029    }
1030    #@T! return [$_listbox entry configure $id -data $datos]
1031    return [eval $_listbox item text $id $datos]
1032  }
1033
1034  #///////////////////////////////////////////////////////////////////////////
1035  method first {} {
1036  #
1037  # PURPOSE: Selects and returns the first row of blistboxplus
1038  #
1039  # RETURN: The index of first row
1040  #
1041  #///////////////////////////////////////////////////////////////////////////
1042    set all [$self get]
1043    set selected [$self selection get]
1044    if {$selected != ""} {   
1045      foreach item $selected { 
1046        $self selection clear $item
1047      }
1048    }
1049    if { !([llength [$self get]] eq 0)} {
1050      $self selection set [lindex $all 0]
1051    }
1052    return [lindex $all 0]
1053  }
1054
1055  #///////////////////////////////////////////////////////////////////////////
1056  method last {} {
1057  #
1058  # PURPOSE: Selects and returns the last row of blistboxplus
1059  #
1060  # RETURN: The index of last row
1061  #
1062  #///////////////////////////////////////////////////////////////////////////
1063    set all [$self get]
1064    set selected [$self selection get]
1065    if {$selected != ""} {
1066      foreach item $selected {
1067        $self selection clear $item
1068      }             
1069    }
1070    if { !([llength [$self get]] eq 0)} {
1071      $self selection set [lindex $all [expr [llength $all] - 1]]
1072    }
1073    return [lindex $all [expr [llength $all] - 1]]           
1074  }
1075
1076  #///////////////////////////////////////////////////////////////////////////
1077  method addPrevious {} {
1078  #
1079  # PURPOSE: adds the row previous to the present selection
1080  #
1081  # RETURN: The index of the row previous
1082  #
1083  #///////////////////////////////////////////////////////////////////////////
1084    set all [$self get]
1085    set selected [$self selection get]
1086    if {$selected == ""} {
1087      return -1
1088    } else  {
1089      set firstSelected [lindex $selected 0]
1090      set first [lindex $all 0]
1091      if { $first == $firstSelected } {
1092        return [lindex $all 0]
1093      } else  {
1094        set allPosition [lsearch -exact $all $firstSelected]
1095        set firstSelected [lindex $all [expr $allPosition - 1]]
1096        #set firstSelected [expr $firstSelected - 1]
1097        $self selection set $firstSelected
1098        return $firstSelected
1099      }
1100    }
1101  }
1102
1103  #///////////////////////////////////////////////////////////////////////////
1104  method addNext {} {
1105  #
1106  # PURPOSE: Adds the following row to the present selection
1107  #
1108  # RETURN: The index of the following row
1109  #
1110  #///////////////////////////////////////////////////////////////////////////
1111    set all [$self get]
1112    set selected [$self selection get]
1113    if {$selected == ""} {
1114      return -1     
1115    } else  {
1116      set lastSelected [lindex $selected [expr [llength $selected] - 1] ]
1117      set last [lindex $all [expr [llength $all] - 1]]
1118      if { $last == $lastSelected } {
1119        return [lindex $all [expr [llength $all] - 1]]
1120      } else  {
1121        set allPosition [lsearch -exact $all $lastSelected]
1122        set lastSelected [lindex $all [expr $allPosition + 1]]
1123        $self selection set $lastSelected
1124        return $lastSelected
1125      }
1126    }   
1127  }
1128
1129  #///////////////////////////////////////////////////////////////////////////
1130  method previous {} {
1131  #
1132  # PURPOSE: selects the row previous to the present selection
1133  #
1134  # RETURN: The index of the row previous
1135  #
1136  #///////////////////////////////////////////////////////////////////////////
1137    set all [$self get]
1138    set selected [$self selection get]
1139    if {$selected == ""} {
1140      return -1
1141    } else  {
1142      foreach item $selected {
1143        $self selection clear $item
1144      }
1145      set firstSelected [lindex $selected 0]
1146      set first [lindex $all 0]
1147      if { $first == $firstSelected } {
1148        $self selection set $firstSelected
1149        return [lindex $all 0]
1150      } else  {
1151        set allPosition [lsearch -exact $all $firstSelected]
1152        set firstSelected [lindex $all [expr $allPosition - 1]]
1153        $self selection set $firstSelected
1154        return $firstSelected
1155      }
1156    }
1157  }
1158
1159  #///////////////////////////////////////////////////////////////////////////
1160  method next {} {
1161  #
1162  # PURPOSE: selects the following row to the present selection
1163  #
1164  # RETURN: The index of the following row
1165  #
1166  #///////////////////////////////////////////////////////////////////////////
1167    set all [$self get]
1168    set selected [$self selection get]
1169    if {$selected == ""} {
1170      return -1
1171    } else  {
1172      foreach item $selected {
1173        $self selection clear $item
1174      }
1175      set lastSelected [lindex $selected [expr [llength $selected] - 1] ]
1176      set last [lindex $all [expr [llength $all] - 1]]
1177      if { $last == $lastSelected } {
1178        $self selection set $lastSelected
1179        return [lindex $all [expr [llength $all] - 1]]
1180      } else  {
1181        set allPosition [lsearch -exact $all $lastSelected]
1182        set lastSelected [lindex $all [expr $allPosition + 1]]
1183        $self selection set $lastSelected
1184        return $lastSelected
1185      }
1186    }
1187  }
1188
1189  #///////////////////////////////////////////////////////////////////////////
1190  method addAllPrevious {} {
1191  #
1192  # PURPOSE: Selects all the previous rows
1193  #
1194  # RETURN: The index of the first row
1195  #
1196  #///////////////////////////////////////////////////////////////////////////
1197    set all [$self get]
1198    set selected [$self selection get]
1199    if {$selected == ""} {
1200      return -1
1201    } else  {
1202      set firstSelected [lindex $selected 0]
1203      set first [lindex $all 0]
1204      set allPosition [lsearch -exact $all $firstSelected]
1205      while { $allPosition != 0 } {
1206        $self addPrevious
1207        #$self selection set $firstSelected
1208        set selected [$self selection get]
1209        set allPosition [lsearch -exact $all $firstSelected]
1210        if { $allPosition != 0 } {
1211          set firstSelected [lindex $all [expr $allPosition - 1]]
1212        }
1213      } 
1214      return [lindex $firstSelected]
1215    }
1216  }
1217
1218  #///////////////////////////////////////////////////////////////////////////
1219  method addAllNext {} {
1220  #
1221  # PURPOSE: Selects all the following rows
1222  #
1223  # RETURN: The index of the last row
1224  #
1225  #///////////////////////////////////////////////////////////////////////////
1226    set all [$self get]
1227    set selected [$self selection get]
1228    if {$selected == ""} {
1229      return -1
1230    } else  {
1231      set lastSelected [lindex $selected [expr [llength $selected] - 1] ]
1232      set last [lindex $all [expr [llength $all] - 1]] 
1233      set allPosition [lsearch -exact $all $lastSelected]
1234      while {$allPosition != [expr [llength $all] -1]} {
1235        $self addNext
1236        set selected [$self selection get]
1237        set lastSelected [lindex $selected [expr [llength $selected] - 1] ]
1238        set allPosition [lsearch -exact $all $lastSelected]
1239      }
1240      return $lastSelected
1241    }
1242  }
1243
1244  #///////////////////////////////////////////////////////////////////////////
1245  method clear {} {
1246  #
1247  # PURPOSE: deletes all nodes
1248  #
1249  #///////////////////////////////////////////////////////////////////////////
1250    foreach i [$self get] {
1251      if { 0 eq $i } { continue }
1252      $self delete $i
1253    }
1254  }
1255
1256  #///////////////////////////////////////////////////////////////////////////
1257  method size {} {
1258  #
1259  # PURPOSE: calculates the listbox size
1260  #
1261  #///////////////////////////////////////////////////////////////////////////
1262    return [$_listbox entry size root]
1263  }
1264
1265  #///////////////////////////////////////////////////////////////////////////
1266  method column { args } {
1267  #
1268  # PURPOSE: modifies a particular case of column -> column names
1269  #
1270  #///////////////////////////////////////////////////////////////////////////
1271    #@T! if { [lindex $args 0] eq "names" } {
1272    #@T!   return [lrange [$_listbox column names] 1 end]
1273    #@T! }
1274    #@T! return [eval $_listbox column $args]
1275    if { [lindex $args 0] eq "names" } {
1276      set names {}
1277      foreach col [lrange [$_listbox column list] 1 end] {
1278        lappend names [$_listbox column tag names $col]
1279      }
1280      return $names
1281    }
1282    return [eval $_listbox column id $args]   
1283  }
1284
1285  #///////////////////////////////////////////////////////////////////////////
1286  method filter { filters } {
1287  #
1288  # PURPOSE: filters the listbox elements matching filters for each col in cols
1289  #
1290  # PARAMETERS:
1291  #  filters: list of filters for the columns above
1292  #
1293  #///////////////////////////////////////////////////////////////////////////
1294    $self configure -flat no
1295    foreach inx [$self get] {
1296      set datos [$self get $inx $options(-filtercols)]
1297      set match 1
1298      for { set i 0 } { $i < [llength $filters] } { incr i } {
1299        set match [expr $match & [regexp [lindex $filters $i] [lindex $datos $i]]]
1300      }
1301      if { ! $match } {
1302        $_listbox hide $inx
1303      } else {
1304        $_listbox show $inx
1305      }
1306    }
1307    $self configure -flat yes
1308
1309  }
1310
1311  #///////////////////////////////////////////////////////////////////////////
1312  method _RemoveFilter { } {
1313  #
1314  # PURPOSE: filters the listbox elements matching filters for each col in cols
1315  #
1316  # PARAMETERS:
1317  #  filters: list of filters for the columns above
1318  #
1319  #///////////////////////////////////////////////////////////////////////////
1320    $_listbox configure -flat no
1321    $_listbox show all
1322    $_listbox configure -flat yes
1323  }
1324
1325  #///////////////////////////////////////////////////////////////////////////
1326  method icon { id icon } {
1327  #
1328  # PURPOSE: changes the icon for an entry identified by id
1329  #
1330  # PARAMETERS:
1331  #  id: the identificator of the entry
1332  #  icon: the icon image (must be 16x16
1333  #
1334  #///////////////////////////////////////////////////////////////////////////
1335    $_listbox entry configure $id \
1336      -icons [list [Bitmap::get $icon] [Bitmap::get $icon]]
1337  }
1338
1339  # delegacion de metodos y opciones
1340  delegate method * to _listbox
1341  delegate option * to _listbox
1342}
1343
1344package provide blistboxplus 1.0
1345
1346# ------- TEST CODE ----
1347
1348#/////////////////////////////////////////////////////////////////////////////
1349proc test_blistboxplus {} {
1350#
1351# PURPOSE: Funcion de test de un blistcontrol
1352#
1353#///////////////////////////////////////////////////////////////////////////// 
1354  # defining the widgets
1355  variable data
1356  set data(-selected) 1
1357 
1358  destroy .top
1359  toplevel .top -width 200 -height 100
1360   
1361  TitleFrame .top.f1 -text "BListBoxPlus test"
1362  set f1 [ .top.f1 getframe ]
1363  blistboxplus $f1.blb -cols { col1 col2 col3 col4 } -parent $f1 \
1364                    -height 150 -width 500 -orientation vertical \
1365                    -hiddencols {col4}
1366  $f1.blb insert end {1 2 3 4} {one two three four} {uno dos tres cuatro} \
1367                     {k kk kkk kkkk} {0 0 0 0} {@ # $ %}
1368 
1369  TitleFrame .top.f2 -text "Configure"
1370  set f2 [ .top.f2 getframe ]
1371  LabelEntry $f2.lei -width 5 -label Index -text 1
1372  LabelEntry $f2.lee -width 5 -label End
1373  LabelEntry $f2.lec -width 50 -label Content -text "{hay que introducir cada} \
1374     {fila entre corchetes y} {entre estos los items}"
1375  checkbutton $f2.cb -text "Allow multiple selection" \
1376    -command { toggleSelectModeCmd }
1377  $f2.cb select
1378  button $f2.bi -text "Insert" -command { insertCmd }
1379  button $f2.bd -text "Delete" -command { deleteCmd }
1380  button $f2.br -text "Reset" -command { resetCmd }
1381  $f2.bi configure -width 20
1382  $f2.bd configure -width 20
1383  # packing all
1384 
1385  grid .top.f1 -row 0 -column 0 -sticky "new" -padx 10 -pady 10
1386  grid .top.f2 -row 1 -column 0 -sticky "new" -padx 10 -pady 10
1387  grid columnconfigure .top 0 -weight 1
1388  grid rowconfigure .top 0 -weight 0
1389  grid rowconfigure .top 1 -weight 1
1390 
1391  grid $f1.blb -row 0 -column 0 -sticky "new"
1392  grid columnconfigure $f1 0 -weight 1
1393  grid rowconfigure $f1 0 -weight 1
1394
1395  grid $f2.lec -row 0 -column 0 -sticky "new" -columnspan 3
1396  grid $f2.lei -row 1 -column 0 -sticky "new"
1397  grid $f2.lee -row 1 -column 1 -sticky "new"
1398   
1399  grid $f2.cb  -row 1 -column 2 -sticky "new"
1400  grid $f2.bi  -row 2 -column 0 -sticky "new"
1401  grid $f2.bd  -row 2 -column 1 -sticky "new"
1402  grid $f2.br  -row 2 -column 2 -sticky "new"
1403  grid columnconfigure $f2 0 -weight 0
1404  grid columnconfigure $f2 1 -weight 0
1405  grid columnconfigure $f2 2 -weight 1
1406  grid rowconfigure $f2 0 -weight 0
1407  grid rowconfigure $f2 1 -weight 0
1408  grid rowconfigure $f2 2 -weight 0
1409
1410  puts "WIDGET blistboxplus: $f1.blb"
1411 
1412  # commands attached to the widgets
1413  proc insertCmd {} {
1414    eval .top.f1.f.blb insert [.top.f2.f.lei cget -text] \
1415                              [.top.f2.f.lec cget -text]
1416  }
1417 
1418  proc deleteCmd {} {
1419    .top.f1.f.blb delete [.top.f2.f.lei cget -text] \
1420                         [.top.f2.f.lee cget -text]
1421  }
1422 
1423  proc resetCmd {} {
1424    .top.f1.f.blb clear
1425    .top.f1.f.blb insert end {1 2 3 4} {one two three four} \
1426      {uno dos tres cuatro} {k kk kkk kkkk} {0 0 0 0} {@ # $ %}
1427  }
1428 
1429  proc toggleSelectModeCmd {} {
1430    if { [.top.f1.f.blb cget -selectmode] eq "multiple" } {
1431      .top.f1.f.blb configure -selectmode single
1432    } else {
1433      .top.f1.f.blb configure -selectmode multiple
1434    }
1435  }
1436}
1437
Note: See TracBrowser for help on using the repository browser.