Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

ttk::combobox height and behaviour


Hi,

in the man page for ttk::combobox there is an option -height. I've
tried setting this but am getting an error saying the option is not
recognized. Am I setting it wrong?

ttk::combobox $l.cb -values $values -textvariable ::COMBO

grid  $l.cb -sticky e -padx 2 -pady 2
$l.cb current 0
$l.cb configure -height 5

What I want is that 5 rows are shown instead of the default 1.

Also, is it possible to make the dropdown button in the tkk:comboboc
wider?

M.

On 14 Mai, 01:59, Michael <chun.@evolving.com> wrote:

> ttk::combobox $l.cb -values $values -textvariable ::COMBO

> grid  $l.cb -sticky e -padx 2 -pady 2
> $l.cb current 0
> $l.cb configure -height 5

> What I want is that 5 rows are shown instead of the default 1.

I suppose the -height option refers to the dropdown menu. Comboboxes
always have a one-line entry.
On 14 May, 11:34, suchenwi <richard.suchenwirth-

bauersa@siemens.com> wrote:
> On 14 Mai, 01:59, Michael <chun.@evolving.com> wrote:

> > ttk::combobox $l.cb -values $values -textvariable ::COMBO

> > grid  $l.cb -sticky e -padx 2 -pady 2
> > $l.cb current 0
> > $l.cb configure -height 5

> > What I want is that 5 rows are shown instead of the default 1.

> I suppose the -height option refers to the dropdown menu. Comboboxes
> always have a one-line entry.

Thanks.

Is there another widget I could use? Maybe I will use an ttk::entry
and the a text box. If I use this method I want the user to be able to
select a line in the text box. When select the line is highlighted and
then entry box is updated with the selected entry. Is this possible?
How would I know that the line has been selected and how would I
highlight the line?

M.

What you describe is relatively easy. I'd recommend a listbox rather
than a text widget, as the listbox will generate a <<ListboxSelect>>
event you can bind to. Plus, the highlighting of the line is automatic.
It's possible to do with the text widget, though it takes a bit more work.

Experiment by creating an entry and listbox, then write a proc that gets
called whenever the listbox gets a <<ListboxSelect>> event. You should
be able to figure out from the documentation a) how to get the selected
line, and b) how to programatically update the entry widget.

If you get stuck, show us your code and we'll be glad to help further.

--
Bryan Oakley
http://www.tclscripting.com

Michael wrote:

>in the man page for ttk::combobox there is an option -height. I've
>tried setting this but am getting an error saying the option is not
>recognized. Am I setting it wrong?

The "-height" option was added relatively recently;
it's not supported in Tile 0.7.8.  It's present in Tk 8.5a6,
and will be in Tile 0.8 when it's released.

> [...]
>$l.cb configure -height 5

>What I want is that 5 rows are shown instead of the default 1.

There may be some confusion here -- "-height" specifies
the number of rows in the dropdown list (default 10 rows),
not the entry field.  Perhaps you want a listbox instead?

>Also, is it possible to make the dropdown button in the tkk:comboboc
>wider?

In some themes, yes, although the mechanism for doing so
varies from theme to theme.

--Joe English

On 14 May, 14:56, Bryan Oakley <oak@bardo.clearlight.com> wrote:

Thanks.

I have used the listbox as you've suggested.

set l [ttk::labelframe $pw.l -padding 0 -underline 0]
$pw add $l -weight 1

scrollbar $l.sb -command "$l.lb yview"
listbox $l.lb -yscroll "$l.sb set" -height 5
pack $l.lb $l.sb -side left -fill y -expand 1
$l.lb insert 0 a b c d e f g h i j k l m n o p o r s t

proc hello { w } {
    puts "hello $w [$w selection get]"

}

bind all <<ListboxSelect>> [list hello %W]

How can I get the selected row. Reading the man page it seems
"<pathname> selection get" is the way but this doesn't work. Any
ideas?

M.

I'm curious why you think "selection get" is the right way to go since
that's not a documented feature of the listbox. I suspect you are
reading the wrong man page.

You want to use [$w curselection]. That will return an integer
representing the row that is selected.

--
Bryan Oakley
http://www.tclscripting.com

On 14 May, 18:53, Bryan Oakley <oak@bardo.clearlight.com> wrote:

Thanks. Maybe it is the wrong man page. I see for ListBox from the
ActiveState help pages.

NAME
ListBox - ListBox widget
...

pathName selection cmd ?arg...?
Modifies the list of selected items following cmd:
clear remove all items of the selection.
set set the selection to all items in arg
add add all items of arg in the selection
remove remove all items of arg of the selection
get return the current selected items

The curselection is working well. Here is the updated code.

set l [ttk::labelframe $pw.l -padding 0 -underline 0]
$pw add $l -weight 1

scrollbar $l.sb -command "$l.lb yview"
listbox $l.lb -yscroll "$l.sb set" -height 5
pack $l.lb $l.sb -side left -fill y -expand 1
set selection [list a b c d e f g h i j k l m n o p o r s t]
set i 0
foreach item $selection {
   $l.lb insert $i $item
   incr i

}

proc hello { w } {
    puts "hello $w [lindex $::selection [$w curselection]]"
    # TODO: Update entry box
}

bind all <<ListboxSelect>> [list hello %W]

So now when I select an item in the listbox I can update update the
entry box.

Now the next thing I want to do is allow a user to enter text in the
entry box and that the listbox is updated as each character is
entered. Is an event triggered when a user enters text into an entry
box?

I also want to be able to use the wheel on my mouse to scroll up and
down. Is this possible too?

M.

Ah. That's not a Tk listbox, that is a BWidget listbox and it does
indeed have a slightly different interface.

The code you posted, FWIW, uses the tk "listbox" command rather than the
BWidget ListBox command.

> Now the next thing I want to do is allow a user to enter text in the
> entry box and that the listbox is updated as each character is
> entered. Is an event triggered when a user enters text into an entry
> box?

There are many different ways to get the desired behavior. Perhaps the
easiest for you to use would be to define a -validatecommand for the
entry, and set -validate to "key".

> I also want to be able to use the wheel on my mouse to scroll up and
> down. Is this possible too?

Yes, it's possible. The default bindings are to scroll the window with
keyboard focus, but it's easy to make it scroll any widget:

bind $entry <MouseWheel> [list scrollListbox $l.lb %D]

proc scrollListbox {listbox delta} {
     $listbox yview scroll [expr {- ($delta / 120) * 4}] units

}

--
Bryan Oakley
http://www.tclscripting.com
On 14 May, 20:00, Bryan Oakley <oak@bardo.clearlight.com> wrote:

Thanks is working nicely. Great almost all the componets are in my
application. Now the next is to deal with the widgit placing and
colour. I will post start a different thread for this. Thanks all for
your help sofar - almost there.

M.

On 14 May, 20:27, Michael <chun.@evolving.com> wrote:

I forgot here is the updated code with.

set ::addr ""
proc addressInput { w s} {
    puts "addressSelect $w $::addr $s"
    return 1

}

## Address
set l3 [ttk::labelframe $pw.l3 -padding 0 -underline 0]
ttk::entry $l3.addr -textvariable ::addr  -validate key -
validatecommand [list addressInput $l3 %S]
grid $l3.addr -sticky ew -padx 2 -pady 2
$pw add $l3 -weight 1

# List of address retrieved
set l [ttk::labelframe $pw.l -padding 0 -underline 0]
$pw add $l -weight 1
grid columnconfigure $l  0 -weight 1
grid rowconfigure    $l  7 -weight 1
scrollbar $l.sb -command "$l.lb yview"
listbox $l.lb -yscroll "$l.sb set" -height 5
pack $l.lb $l.sb -side left -fill y -expand 1
set selection [list a b c d e f g h i j k l m n o p o r s t]
set i 0
foreach item $selection {
   $l.lb insert $i $item
   incr i

}

proc addressSelect { w } {
    # Set Address Entry box to selected address (from listbox)
    set ::addr [lindex $::selection [$w curselection]]
}

bind all <<ListboxSelect>> [list addressSelect %W]

# Binding for wheel on mouse
bind all  <MouseWheel> [list scrollListbox $l.lb %D]
proc scrollListbox {listbox delta} {
     $listbox yview scroll [expr {- ($delta / 120) * 4}] units

}

M.
On 14 May, 21:05, Michael <chun.@evolving.com> wrote:

Here is the code for changing the selected listbox item as the user is
entering text in the entry box:

set selection [list a b c d e f g h i j k l m n o p o r s t abc ac ad
af ag]
set ::addr ""
proc addressInput { w s } {
    set i 0
    set match 0
    foreach item $::selection {
        if {[string match -nocase $::addr${s} $item]} {
            $::pw.l.lb selection clear 0 end
            $::pw.l.lb selection set $i
            $::pw.l.lb yview $i
            set match 1
            break
        }
        incr i
    }
    set i 0
    if {!$match} {
       set match 0
       foreach item $::selection {
          if { [string first [string tolower $::addr${s}] [string
tolower $item]] > -1} {
             $::pw.l.lb selection clear 0 end
             $::pw.l.lb selection set $i
             $::pw.l.lb yview $i
          }
          incr i
       }
    }
    return 1

}

## Address
set l3 [ttk::labelframe $pw.l3 -padding 0 -underline 0]
ttk::entry $l3.addr -textvariable ::addr  -validate key -
validatecommand [list addressInput $l3 %S]
grid $l3.addr -sticky ew -padx 2 -pady 2
$pw add $l3 -weight 1

I haven't handle the deletion of characters from the entry box but I
know how to do this with the %d bind subsitution.

M.

Michael wrote:
> Here is the code for changing the selected listbox item as the user is
> entering text in the entry box:

> set selection [list a b c d e f g h i j k l m n o p o r s t abc ac ad af ag]
> set ::addr ""
> proc addressInput { w s } {
>     set i 0
>     set match 0
>     foreach item $::selection {
>         if {[string match -nocase $::addr${s} $item]} {

Are you sure you want 'string match' here?  I'm not seeing any
wildcards, so why use it?

>             $::pw.l.lb selection clear 0 end
>             $::pw.l.lb selection set $i
>             $::pw.l.lb yview $i
>             set match 1
>             break
>         }
>         incr i
>     }

Furthermore, it looks like the entire foreach is equivalent to:

set match [lsearch -glob -- $::selection $::addr$s]
if {$match != -1} { ...

>     set i 0
>     if {!$match} {
>        set match 0
>        foreach item $::selection {
>           if { [string first [string tolower $::addr${s}] [string
> tolower $item]] > -1} {

OK, I'm confused ... this is a substring search ... somehow this should
be merged with the above and some use of wildcards.  Better yet, it is
all in the lsearch.

Jeff

On 15 May, 00:27, Jeff Hobbs <j@activestate.com> wrote:

Hi and Thanks, I see that the lsearch is better and will use this. I'm
not sure how to merge the second loop.
The first loop does an exact match. So if I type something in the
entry box and there is an exact match in the list then this item is
selected. The second search is if no exact match is found so I look to
see if there is a item in the list that starts with the characters
entered. If there is then I stop and highlight the first found item
that starts with the characters entered. If no items are found that
fit the two criterias above then nothing is done to the listbox.

M.

Michael wrote:
>> set match [lsearch -glob -- $::selection $::addr$s]
>> if {$match != -1} { ...
        ...
> Hi and Thanks, I see that the lsearch is better and will use this. I'm
> not sure how to merge the second loop.
> The first loop does an exact match. So if I type something in the
> entry box and there is an exact match in the list then this item is
> selected. The second search is if no exact match is found so I look to
> see if there is a item in the list that starts with the characters
> entered. If there is then I stop and highlight the first found item
> that starts with the characters entered. If no items are found that
> fit the two criterias above then nothing is done to the listbox.

OK, so you want
        set match [lsearch -exact -- $::selection $::addr$s]
        if {$match == -1} {
                set match [lsearch -glob -- $::selection $::addr$s*]
        }
        if {$match != -1} {
                # adjust listbox
        }

Boils down the code example a lot ...

Jeff

On 15 May, 18:04, Jeff Hobbs <j@activestate.com> wrote:

Hi, yes. here is the latest code for this function. I've added the
check for deletion.

# w - widget
# s - character to add/remove
# a - 1 add, 0 delete
proc addressInput {w s a} {
    if {$a} {
       set s $::addr${s}
    } else {
       if {[string length $::addr] > 1} {
          set s [string range $::addr 0 end-1]
       }
    }
    set match [lsearch -exact $::selection $::addr$s]
    if {$match > -1} {
            $::pw.l.lb selection clear 0 end
            $::pw.l.lb selection set $match
            $::pw.l.lb yview $match
    } else {
       set i 0
       foreach item $::selection {
          if { [string first [string tolower $s] [string tolower
$item]] == 0} {
             $::pw.l.lb selection clear 0 end
             $::pw.l.lb selection set $i
             $::pw.l.lb yview $i
             break
          }
          incr i
       }
    }
    return 1

}

M.
On 15 May, 18:26, Michael <chun.@evolving.com> wrote:

ok, I see what you have done with the lsearch glob. I will use this.
Here is the updated function.

# w - widget
# s - character added/removed
# a - 1 add, 0 delete
proc addressInput {w s a} {
    if {$a} {
       set s $::addr${s}
    } else {
       if {[string length $::addr] > 1} {
          set s [string range $::addr 0 end-1]
       }
    }
    set match [lsearch -exact $::selection $s]
    if {$match < 0} {
        set match [lsearch -glob $::selection $s*]
    }
    if {$match > -1} {
            $::pw.l.lb selection clear 0 end
            $::pw.l.lb selection set $match
            $::pw.l.lb yview $match
    }
    return 1

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc