get active selection from tk iwidgets radiobox

U

Unwen

Hi there,
I have created a radiobox with various entries and want to read the
currently selected entry.
For some reason I can't get it to work.
From what I see "get" would be the appropriate method but it expects
an argument, which seems odd to me as it should return the active
entry.

Any help?
Thanks

Stefan
 
7

7stud --

Unwen said:
Hi there,
I have created a radiobox with various entries and want to read the
currently selected entry.
For some reason I can't get it to work.
From what I see "get" would be the appropriate method but it expects
an argument, which seems odd to me as it should return the active
entry.

Any help?
Thanks

Stefan

I can't test this because my tk installation no longer works, but you
need to:

1) Create a TkVariable, e.g.

val = TkVariable.new

2) Create your radio button with the 'variable' option set to the
TkVariable, e.g.

variable val

3) ...and set the 'value' option of each radio button to a unique value,
e.g.

value 1



Thereafter, when a radio button is checked, ruby will automatically
assign the value attribute of the radio button to the TkVariable. You
can determine which radio button is checked by checking the value of the
TKVariable. If you want to programmatically set a radio button to
checked, then assign the value of the radio button to the TkVariable.
 
A

Asd Sda

1) Create a TkVariable, e.g.
val = TkVariable.new

I found an example using this approach but it only applies to the use of
individual radiobuttons not the radiobox.
In tcl the way to get the active button is "pathname get".
But the Ruby API expects an argument for "get" which seems to be exactly
that information I'd like to read.

Does someone have an example of the usage of get with the Iwidgets
radiobox in Ruby?

Stefan
 
H

Hidetoshi NAGAI

From: Unwen <[email protected]>
Subject: get active selection from tk iwidgets radiobox
Date: Tue, 12 Feb 2008 23:39:56 +0900
Message-ID: said:
I have created a radiobox with various entries and want to read the
currently selected entry.
For some reason I can't get it to work.
From what I see "get" would be the appropriate method but it expects
an argument, which seems odd to me as it should return the active
entry.

I'm very sorry. That is a bug.
Please wait for the patch. I'll send it in a few days.

# Why does nobody report such serious bug? (;_;)
# I need bug reports and feature requests to improve Ruby/Tk.
 
M

Morton Goldberg

# Why does nobody report such serious bug? (;_;)
# I need bug reports and feature requests to improve Ruby/Tk.


I am a regular user of Ruby/Tk, so perhaps I may be permitted to
comment on this.

Ruby/Tk is a huge, complex library with very little English
documentation. Neither ri nor the Pickaxe Book, which I rely on when
I run into problems with Ruby, are of much help with Ruby/Tk beyond
the most elementary level. That means I must rely on your examples
posted on ruby-lang.org and your Ruby ML posts whenever I venture
into new Ruby/Tk territory. These are very helpful, but by following
closely in your footsteps, I never go where the bugs live. I only go
where you have already been and where you have chased the bugs away.
Therefore, I'm not likely to encounter bugs. But there is another
story. Suppose I do try something not covered by your examples and it
doesn't work: I don't think I found a bug. I merely think I don't
understand Ruby/Tk or the underlying Tk/Tcl (another huge and complex
library) well enough.

As for new features, there are already so many features I have yet to
master that it would seem the utmost arrogance for me to request
anything beyond what is already there.

Regards, Morton
 
S

Stefan Schelm

I'm very sorry. That is a bug.
Please wait for the patch. I'll send it in a few days.

# Why does nobody report such serious bug? (;_;)
# I need bug reports and feature requests to improve Ruby/Tk.

Thanks for the info!

Wow, a bug was the last thing I was thinking about :)
I'm a newbie when it comes to Ruby but I have some experience with
tcl/tk which is one reason why I want to use Ruby Tk for GUI stuff.

With regard to the feature request question I can only confirm what
Morton said, first I need to wade through the features that are already
there. Maybe there will be some input when I increase my usage of Ruby
Tk.

Stefan
 
H

Hidetoshi NAGAI

From: Hidetoshi NAGAI <[email protected]>
Subject: Re: get active selection from tk iwidgets radiobox
Date: Thu, 14 Feb 2008 11:40:38 +0900
Message-ID: said:
I'm very sorry. That is a bug.
Please wait for the patch. I'll send it in a few days.

Sorry. I came down with a cold the last weekend,
and my physical strength has not recovered yet.
Please give me more two or three days.
 
H

Hidetoshi NAGAI

From: Hidetoshi NAGAI <[email protected]>
Subject: Re: get active selection from tk iwidgets radiobox
Date: Mon, 18 Feb 2008 12:39:53 +0900
Message-ID: said:
Please give me more two or three days.

Sorry, too late. The following is the patch.

'Tk::Iwidgets::Radiobox#get_tag' (and 'Radiobox#get) returns
the tag name of the selected button.
'Tk::Iwidgets::Radiobox#get_obj' returns the component object
which denotes the selected button.
You can get the tag name of the button component object
by 'name' method of the object.

The patch includes bug fix of Tk::Iwidgets::Checkbox too.
'Tk::Iwidgets::Checkbox#get_tags' returns tag name list of
selected buttons, and 'Tk::Iwidgets::Checkbox#get_objs'
returns component list of selected buttons.
'Tk::Iwidgets::Checkbox#get(idx)' returns status (boolean
value) of the checkbutton 'idx'.
And 'Tk::Iwidgets::Checkbox#get' (with no argument) returns
the same result of 'Tk::Iwidgets::Checkbox#get_tags'
(it follows the feature of the Tcl/Tk function).

Index: ext/tk/lib/tkextlib/iwidgets/radiobox.rb
===================================================================
--- ext/tk/lib/tkextlib/iwidgets/radiobox.rb (revision 15558)
+++ ext/tk/lib/tkextlib/iwidgets/radiobox.rb (working copy)
@@ -85,12 +85,15 @@
self
end

- def get(idx)
- simplelist(tk_call(@path, 'get', index(idx))).collect{|id|
- Tk::Itk::Component.id2obj(self, id)
- }
+ def get_tag
+ ((tag = tk_call_without_enc(@path, 'get')).empty?)? nil: tag
end
+ alias get get_tag

+ def get_obj
+ (tag = get_tag)? Tk::Itk::Component.id2obj(self, tag): nil
+ end
+
def index(idx)
number(tk_call(@path, 'index', tagid(idx)))
end
Index: ext/tk/lib/tkextlib/iwidgets/checkbox.rb
===================================================================
--- ext/tk/lib/tkextlib/iwidgets/checkbox.rb (revision 15558)
+++ ext/tk/lib/tkextlib/iwidgets/checkbox.rb (working copy)
@@ -85,12 +85,24 @@
self
end

- def get(idx)
- simplelist(tk_call(@path, 'get', index(idx))).collect{|id|
+ def get_tags
+ simplelist(tk_call_without_enc(@path, 'get'))
+ end
+
+ def get_objs
+ simplelist(tk_call_without_enc(@path, 'get')).collect{|id|
Tk::Itk::Component.id2obj(self, id)
}
end

+ def get(idx=nil)
+ if idx
+ bool(tk_call_without_enc(@path, 'get', index(idx)))
+ else
+ get_tags
+ end
+ end
+
def index(idx)
number(tk_call(@path, 'index', tagid(idx)))
end
Index: ext/tk/lib/tkextlib/itk/incr_tk.rb
===================================================================
--- ext/tk/lib/tkextlib/itk/incr_tk.rb (revision 15558)
+++ ext/tk/lib/tkextlib/itk/incr_tk.rb (working copy)
@@ -156,7 +156,7 @@
master = master.to_s
end
return id unless ComponentID_TBL.key?(master)
- (ComponentID_TBL.key?(id))? ComponentID_TBL[master][id]: id
+ (ComponentID_TBL[master].key?(id))? ComponentID_TBL[master][id]: id
end

def self.new(master, component=nil)
 

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

Forum statistics

Threads
474,284
Messages
2,571,411
Members
48,104
Latest member
Hellmary01

Latest Threads

Top