TkOptionMenu

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.

Hi,

···

From: "Mark Volkmann" <volkmann2@charter.net>
Subject: TkOptionMenu
Date: Sun, 14 Nov 2004 14:44:48 +0900
Message-ID: <020601c4ca0d$0da613f0$0200a8c0@MarkDesktop>

I'm trying to learn how to use TkOptionButtonmenu and haven't found

Probably, you said about TkOptionMenubutton. :slight_smile:
                                 ^^^^^^^^^^

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
-----------------------------------------------
--
                                  Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

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

Hi,

···

From: "Mark Volkmann" <volkmann2@charter.net>
Subject: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 03:05:54 +0900
Message-ID: <030d01c4ca74$94cc4a90$0200a8c0@MarkDesktop>

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.

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

      Tk.update # <== HERE

end

--
                                  Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Hi,

From: "Mark Volkmann" <volkmann2@charter.net>
Subject: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 03:05:54 +0900
Message-ID: <030d01c4ca74$94cc4a90$0200a8c0@MarkDesktop>

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.

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?

···

----- Original Message ----- From: "Hidetoshi NAGAI" <nagai@ai.kyutech.ac.jp>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Sunday, November 14, 2004 8:12 PM
Subject: Re: update delay related to TkOptionMenu

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

     Tk.update # <== HERE

end

--
                                 Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Hi,

···

From: "Mark Volkmann" <volkmann2@charter.net>
Subject: Re: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 11:39:00 +0900
Message-ID: <042701c4cabc$43bc8ff0$0200a8c0@MarkDesktop>

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
-----------------------------------------------------------------
--
                                  Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Message-ID: <20041115.120457.71083440.nagai@ai.kyutech.ac.jp>

You can use TkVariable.trace.

              ^^^^^^^^^^^^^^^^
              TkVariable#trace

Sorry.

···

From: Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Subject: Re: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 12:04:58 +0900
--
                                  Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Hi,

From: "Mark Volkmann" <volkmann2@charter.net>
Subject: Re: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 11:39:00 +0900
Message-ID: <042701c4cabc$43bc8ff0$0200a8c0@MarkDesktop>

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?

Windows XP SP 2

···

----- Original Message ----- From: "Hidetoshi NAGAI" <nagai@ai.kyutech.ac.jp>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
Sent: Sunday, November 14, 2004 9:04 PM
Subject: Re: update delay related to TkOptionMenu

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
-----------------------------------------------------------------
--
                                 Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

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

Hi,

···

From: "Mark Volkmann" <volkmann2@charter.net>
Subject: Re: update delay related to TkOptionMenu
Date: Mon, 15 Nov 2004 12:49:41 +0900
Message-ID: <045201c4cac6$256ea4c0$0200a8c0@MarkDesktop>

> Could you tell me your environment?

Windows XP SP 2

Not enough. :slight_smile:
Ruby's version (result of 'ruby -v') and Tcl/Tk's version
(result of 'ruby -r tk -e "p Tk::TK_PATCHLEVEL"') are required.
--
                                         永井 秀利 (九工大 知能情報)
                                             nagai@ai.kyutech.ac.jp

Zach Dennis wrote:

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

···

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis