[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

TkOptionMenu

Mark Volkmann

11/14/2004 5:45:00 AM

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.




10 Answers

Hidetoshi NAGAI

11/14/2004 1:32:00 PM

0

Mark Volkmann

11/14/2004 6:06:00 PM

0

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




Hidetoshi NAGAI

11/15/2004 2:12:00 AM

0

Mark Volkmann

11/15/2004 2:39:00 AM

0

----- 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


> 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?

>> 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)
>
>




Hidetoshi NAGAI

11/15/2004 3:05:00 AM

0

Hidetoshi NAGAI

11/15/2004 3:07:00 AM

0

Zach Dennis

11/15/2004 3:38:00 AM

0

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


Mark Volkmann

11/15/2004 3:50:00 AM

0

----- 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


> 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

>> 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)
>
>




Jamis Buck

11/15/2004 3:52:00 AM

0

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...


Hidetoshi NAGAI

11/15/2004 4:12:00 AM

0