[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problem in binding IWidget combobox to event

Markus Liebelt

6/28/2005 2:01:00 PM

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

--
Markus Liebelt; markus.liebelt@online.de
3 Answers

Hidetoshi NAGAI

6/28/2005 3:53:00 PM

0

Hidetoshi NAGAI

6/29/2005 6:29:00 AM

0

Markus Liebelt

7/2/2005 12:19:00 PM

0

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

On Tue, 28 Jun 2005 17:52:32 +0200, Hidetoshi NAGAI
<nagai@ai.kyutech.ac.jp> wrote:

> From: "Markus Liebelt" <markus.liebelt@online.de>
> Subject: Problem in binding IWidget combobox to event
> Date: Tue, 28 Jun 2005 23:05:40 +0900
> Message-ID: <op.ss21fixc444ivd@localhost>
>> 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
> -----------------------------------------------------------



--
Markus Liebelt; markus.liebelt@online.de