Problem in binding IWidget combobox to event

M

Markus Liebelt

Hello all together,

I managed lately to include an iwidget combobox in a UI I have written. If
normally used (by poking around with the mouse) everything works fine.
What I cannot manage if the user is using the keyboard.

Can anyone tell me how to bind the key events to the iwidget components
especially to the combobox?

My example goes like this (sorry for the lengthy boring example):
====================
require 'tk'
require 'tkextlib/iwidgets'

class Ex_Combo
def open
root = self.create_root
self.build_form(root)
Tk.mainloop
end
def build_form(root)
frame = self.create_frame:)form, root)
var = TkVariable.new
cb1 = Tk::Iwidgets::Combobox.new(frame, #:labeltext=>'Example:',
:selectioncommand=>proc{puts cb1.get_curselection;
$stdout.flush},
:textvariable=>var,
:editable=>false)
cb1.insert_list('end', *['First entry','Second entry','Third entry'])
cb1.grid('row'=>0, 'column'=>0, 'sticky'=>'news')
frame.pack('side'=>'left', 'expand'=>'yes')
end
def create_frame(name, super_widget, *args)
frame = TkFrame.new(super_widget, *args)
return frame
end
def create_root(title='No window title')
root = TkRoot.new('title'=>title)
return root
end
end

if __FILE__ == $0
Ex_Combo.new.open
end
====================

If you open that application, and drop down with the mouse and select with
the mouse, you see on $stdout your selection. If you open in any way, but
select then by using TAB (focus goes to drop down list) and ENTER, your
selection goes into the combo box, but is not reflected in the $stdout.

What do I have to get a binding for the different possibilities to use the
combo box? Or is there even an easier way, eg. by using a binding to the
variable that lays behind the combo box?

Thank you a lot for your help

Markus
 
H

Hidetoshi NAGAI

From: "Markus Liebelt" <[email protected]>
Subject: Problem in binding IWidget combobox to event
Date: Tue, 28 Jun 2005 23:05:40 +0900
Message-ID: said:
I managed lately to include an iwidget combobox in a UI I have written. If
normally used (by poking around with the mouse) everything works fine.
What I cannot manage if the user is using the keyboard. (snip)
If you open that application, and drop down with the mouse and select with
the mouse, you see on $stdout your selection. If you open in any way, but
select then by using TAB (focus goes to drop down list) and ENTER, your
selection goes into the combo box, but is not reflected in the $stdout.

It seems a specification limit of an iwidget combobox.
What do I have to get a binding for the different possibilities to use the
combo box? Or is there even an easier way, eg. by using a binding to the
variable that lays behind the combo box?

TkVariable#trace will be able to help you. Possibly, that is more
simple than getting the listbox component and binding to it.
For example,
-----------------------------------------------------------
class Ex_Combo
def build_form(root)
frame = self.create_frame:)form, root)
var = TkVariable.new
cb1 = Tk::Iwidgets::Combobox.new(frame, #:labeltext=>'Example:',
#:selectioncommand=>proc{puts cb1.get_curselection; $stdout.flush},
:textvariable=>var,
:editable=>false)
var.trace('w'){
# This is called twice when selecting an item.
# One is when clearing the entry and the another is when setting
# a new value to it.
# The following check is the one to ignore clearing step.
unless (val = var.value).empty?
puts val
$stdout.flush
end
}
cb1.insert_list('end', *['First entry','Second entry','Third entry'])
cb1.grid('row'=>0, 'column'=>0, 'sticky'=>'news')
frame.pack('side'=>'left', 'expand'=>'yes')
end
end
 
H

Hidetoshi NAGAI

From: Hidetoshi NAGAI <[email protected]>
Subject: Re: Problem in binding IWidget combobox to event
Date: Wed, 29 Jun 2005 00:52:32 +0900
Message-ID: said:
TkVariable#trace will be able to help you. Possibly, that is more
simple than getting the listbox component and binding to it.

If you need to bind to the listbox for any reason,
you can get the target widget by 'component_widget' method.
 
M

Markus Liebelt

Hello Hidetoshi,

exactly what I was looking for. Seems a lot cleaner and more fitting to
MVC what I was looking for.

Thank you a lot

Markus

From: "Markus Liebelt" <[email protected]>
Subject: Problem in binding IWidget combobox to event
Date: Tue, 28 Jun 2005 23:05:40 +0900
Message-ID: said:
I managed lately to include an iwidget combobox in a UI I have written.
If
normally used (by poking around with the mouse) everything works fine.
What I cannot manage if the user is using the keyboard. (snip)
If you open that application, and drop down with the mouse and select
with
the mouse, you see on $stdout your selection. If you open in any way,
but
select then by using TAB (focus goes to drop down list) and ENTER, your
selection goes into the combo box, but is not reflected in the $stdout.

It seems a specification limit of an iwidget combobox.
What do I have to get a binding for the different possibilities to use
the
combo box? Or is there even an easier way, eg. by using a binding to the
variable that lays behind the combo box?

TkVariable#trace will be able to help you. Possibly, that is more
simple than getting the listbox component and binding to it.
For example,
-----------------------------------------------------------
class Ex_Combo
def build_form(root)
frame = self.create_frame:)form, root)
var = TkVariable.new
cb1 = Tk::Iwidgets::Combobox.new(frame, #:labeltext=>'Example:',
#:selectioncommand=>proc{puts cb1.get_curselection;
$stdout.flush},
:textvariable=>var,
:editable=>false)
var.trace('w'){
# This is called twice when selecting an item.
# One is when clearing the entry and the another is when setting
# a new value to it.
# The following check is the one to ignore clearing step.
unless (val = var.value).empty?
puts val
$stdout.flush
end
}
cb1.insert_list('end', *['First entry','Second entry','Third
entry'])
cb1.grid('row'=>0, 'column'=>0, 'sticky'=>'news')
frame.pack('side'=>'left', 'expand'=>'yes')
end
end
-----------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top