TkOptionMenu

M

Mark Volkmann

I'm trying to learn how to use TkOptionButtonmenu and haven't found
sufficient documentation yet. I know that I can specify the items to add to
the TkOptionButtonmenu using constructor parameters. I can also add them one
at a time using the add method.

Is there a method I can invoke after the constructor to add more than one? I
can call the menu method on the TkOptionButtonmenu to get the OptionMenu.
Other kinds of menus support a menuitems option for adding all the items at
once, but it doesn't seem that TkOptionButtonmenu or OptionMenu support
this.
 
H

Hidetoshi NAGAI

Hi,

From: "Mark Volkmann" <[email protected]>
Subject: TkOptionMenu
Date: Sun, 14 Nov 2004 14:44:48 +0900
Message-ID: said:
I'm trying to learn how to use TkOptionButtonmenu and haven't found

Probably, you said about TkOptionMenubutton. :)
^^^^^^^^^^
Is there a method I can invoke after the constructor to add more than one?

Unfortunately, the answer is "No".
However, is it important? You can define such a method very easily.
For example, please add the followings to your script.
-----------------------------------------------
class TkOptionMenubutton
alias _add add
def add(*values)
values.each{|value| _add(value)}
self
end

alias _insert insert
def insert(index, *values)
values.reverse_each{|value| _insert(index, value)}
# ^^^^^^^^^^^^ must be reverse order
self
end
end
-----------------------------------------------
Then, you can add or insert multiple values at one method call.
e.g.
-----------------------------------------------
require 'tk'

class TkOptionMenubutton
alias _add add
def add(*values)
values.each{|value| _add(value)}
self
end

alias _insert insert
def insert(index, *values)
values.reverse_each{|value| _insert(index, value)}
self
end
end

b = TkOptionMenubutton.new:)values=>%w(one two three)).pack
b.add:)seven, :eight, :nine)
b.insert(3, :four, :five, :six)

Tk.mainloop
 
M

Mark Volkmann

In the simple code below, when I select something from the
TkOptionMenubutton, it should cause the value in the TkEntry to be modified
through the TkVariable named entry_var. However, the change isn't visible
until I click the TkOptionMenubutton a second time. What am I missing? Is
there a better way to listen for a selection to be made from the
TkOptionMenubutton?

Thanks!

---

require 'tk'

root = TkRoot.new
entry_var = TkVariable.new(0)
option_var = TkVariable.new('other')

w = TkOptionMenubutton.new(root, option_var)
w.add('Marathon')
w.add('10K')
w.add('other')
w.pack

w.menu.bind('<MenuSelect>') do
entry_var.value =
if option_var.value == 'Marathon' then '26.2'
elsif option_var.value == '10K' then '6.2'
else '0'
end
end

TkEntry.new(root) do
pack
textvariable entry_var
end

Tk.mainloop
 
H

Hidetoshi NAGAI

Hi,

From: "Mark Volkmann" <[email protected]>
Subject: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 03:05:54 +0900
Message-ID: said:
However, the change isn't visible until I click the TkOptionMenubutton
a second time. What am I missing?

Hmmm...
On my environment (Linux, Ruby 1.8 HEAD, Tcl/Tk 8.4.7),
it seems working properly.
Maybe it fails to update widgets on your environment.
Please try to add 'Tk.update' at last of the callback.
 
M

Mark Volkmann

----- Original Message -----
From: "Hidetoshi NAGAI" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Sunday, November 14, 2004 8:12 PM
Subject: Re: update delay related to TkOptionMenu

Hi,

From: "Mark Volkmann" <[email protected]>
Subject: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 03:05:54 +0900


Hmmm...
On my environment (Linux, Ruby 1.8 HEAD, Tcl/Tk 8.4.7),
it seems working properly.
Maybe it fails to update widgets on your environment.
Please try to add 'Tk.update' at last of the callback.

Thanks for the suggestion. Unfortunately, that didn't change anything. I
still don't see the update to the TkEntry until I click the
TkOptionButtonmenu a second time. Is there a different event I could bind to
instead?
 
H

Hidetoshi NAGAI

Hi,

From: "Mark Volkmann" <[email protected]>
Subject: Re: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 11:39:00 +0900
Message-ID: said:
Thanks for the suggestion. Unfortunately, that didn't change anything. I
still don't see the update to the TkEntry until I click the
TkOptionButtonmenu a second time.

Could you tell me your environment?
Is there a different event I could bind to instead?

You can use TkVariable.trace.
For example,
-----------------------------------------------------------------
require 'tk'

root = TkRoot.new

value_tbl = {
'Marathon' => 26.2,
'10K' => 6.2,
'other' => 0,
}
value_tbl.default = 0

init_val = 'other'
option_var = TkVariable.new(init_val)
entry_var = TkVariable.new(value_tbl[init_val])

w = TkOptionMenubutton.new(root, option_var)
w.insert(init_val, 'Marathon')
w.insert(init_val, '10K')
w.pack

TkEntry.new(root, :textvariable=>entry_var).pack

option_var.trace('w'){
entry_var.value = value_tbl[option_var.value]
}

Tk.mainloop
 
Z

Zach Dennis

Is there any way to template RDOC's output? I don't mind the output it
gives by default, but sometimes I would like to be able to list and
navigate modules and classes differently then what is normally there.

Zach
 
M

Mark Volkmann

----- Original Message -----
From: "Hidetoshi NAGAI" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Sunday, November 14, 2004 9:04 PM
Subject: Re: update delay related to TkOptionMenu

Hi,

From: "Mark Volkmann" <[email protected]>
Subject: Re: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 11:39:00 +0900


Could you tell me your environment?

Windows XP SP 2
Is there a different event I could bind to instead?

You can use TkVariable.trace.
For example,
-----------------------------------------------------------------
require 'tk'

root = TkRoot.new

value_tbl = {
'Marathon' => 26.2,
'10K' => 6.2,
'other' => 0,
}
value_tbl.default = 0

init_val = 'other'
option_var = TkVariable.new(init_val)
entry_var = TkVariable.new(value_tbl[init_val])

w = TkOptionMenubutton.new(root, option_var)
w.insert(init_val, 'Marathon')
w.insert(init_val, '10K')
w.pack

TkEntry.new(root, :textvariable=>entry_var).pack

option_var.trace('w'){
entry_var.value = value_tbl[option_var.value]
}

Tk.mainloop
 
J

Jamis Buck

Zach said:
Is there any way to template RDOC's output? I don't mind the output it
gives by default, but sometimes I would like to be able to list and
navigate modules and classes differently then what is normally there.

Zach

As a matter of fact, you can. Use the -T (or --template) option to rdoc
to specify a template.

rdoc only comes with a few templates by default (looking in
rdoc/generators/template/html I see 'hefss', 'html', 'kilmer',
'old_html', and 'one_page_html'), but you can make your own. Just look
at those existing templates to get an idea of how to make your own.

- Jamis
 
H

Hidetoshi NAGAI

Hi,

From: "Mark Volkmann" <[email protected]>
Subject: Re: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 12:49:41 +0900
Message-ID: said:
Windows XP SP 2

Not enough. :)
Ruby's version (result of 'ruby -v') and Tcl/Tk's version
(result of 'ruby -r tk -e "p Tk::TK_PATCHLEVEL"') are required.
 

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
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top