[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

ruby and Tk:- Menu's calling other widgets

John Maclean

1/24/2006 6:14:00 PM

What's the best (and simplest) method of having a menu item produce
another widget (a menu for example)? So far I have code as shown below
which calls a simple button. I'd like to use the proc{foo} method so
that I can call another file. The idea is to have each type of widget
organised into many smaller files.

It the proc{require 'another_widget'} way possible or recommended?

here's a menu entry that calls another widget....


[['Blah', 0],
['command', proc {
toplevelwindow = TkToplevel.new(root) {
title "New window"
#geometry("50x50+100+100")
#configure('bg'=>"black")
}

toplevelbutton = TkButton.new(toplevelwindow) {
text "Close"
command proc { toplevelwindow.destroy }
}.place('x'=>10, 'y'=>10)
}],
],
[['Blah', 0],
['command', proc {
toplevelwindow = TkToplevel.new(root) {
title "New window"
#geometry("50x50+100+100")
#configure('bg'=>"black")
}

toplevelbutton = TkButton.new(toplevelwindow) {
text "Close"
command proc { toplevelwindow.destroy }
}.place('x'=>10, 'y'=>10)
}],
],


--
John Maclean
MSc (DIC)
07739 171 531



7 Answers

gmurray

1/24/2006 10:24:00 PM

0

An example is in the ruby source distribution:
ruby-1.8.4/ext/tk/sample/demos-en/widget

best regards,
Gerald

If you only want buttons you might try:

require 'tk'
#= windowmaker - create button array, each pops a window
#global $button[] holds buttons defined by this method
#parm root the frame which is to hold the button
#parm b_text the button text; also becomes toplevel title
#parm t_place String, "0x0+100+200", toplevel window size, place
#parm init_color String, "#000000", 2 hex digits for red, green, blue
#
def windowmaker(root,b_text,t_place,init_color="#000000")
toplevelwindow = -1
b = TkButton.new(root,
'text'=>b_text,
'command'=> proc {
toplevelwindow = TkToplevel.new(root, {
'title'=> "#{b.text}",
'geometry'=>t_place,
'bg'=>init_color
})
}
).pack('expand'=>'yes','fill'=>'x')
$buttons.push [b,toplevelwindow]
end

r = TkRoot.new
f = TkFrame.new(r)
$buttons = [] # each entry holds [button,toplevel]
windowmaker(f,"red","100x100","#ff0000")
windowmaker(f,"white","200x200","#ffffff")
windowmaker(f,"blue","300x300","#0000ff")
windowmaker(f,"0x400+100+100","dummy") # re-configured:
# show reconfiguration of the last button
$buttons[-1][0].configure('command'=>proc{r.destroy;
exit},'text'=>"Quit")
f.pack
Tk.mainloop

Hidetoshi NAGAI

1/25/2006 2:17:00 AM

0

John Maclean

1/25/2006 2:39:00 AM

0

Thank you Chaps,

I've managed to get it going with proc{load 'fo.rb'}. I know that it
may be "bad practice" but I'd like to cut my teeth into a certain
project.

On Wed, 25 Jan 2006 11:16:34 +0900 Hidetoshi NAGAI
<nagai@ai.kyutech.ac.jp> wrote:

> From: John Maclean <info@jayeola.org>
> Subject: ruby and Tk:- Menu's calling other widgets
> Date: Wed, 25 Jan 2006 03:13:34 +0900
> Message-ID: <20060125181233.5f308f41@localhost.localdomain>
> > that I can call another file. The idea is to have each type of
> > widget organised into many smaller files.
> >
> > It the proc{require 'another_widget'} way possible or recommended?
>
> It must be possible, but I don't recommend it.
> If your each type of widget is a class,
> 'autoload' may be a good solution.
> Please see some libraries in '<ruby-libs>/tkextlib/' directory
> (e.g. 'tkextlib/iwidgets.rb' and files in 'textlib/iwidgets/').


--
John Maclean
MSc (DIC)
07739 171 531



%

6/28/2013 5:06:00 PM

0

The Peeler wrote:
> On Fri, 28 Jun 2013 09:24:45 -0700, The Rectum, the resident
> psychopath of sci and scj, FAKING his time zone again and
> IMPERSONATING his master, The Peeler, wrote:
>
>>>>>>> EVERYONE does, The Rectum! <BG>
>>>>>>
>>>>>> They, DO The Grik anus! <GB>
>>>>>
>>>>> <BG> INDEED!
>>>>
>>>> <GB> INNIT!
>>>
>>> Certainly, my pwnling! <pat> <pat>
>>>
>>> LMAO!
>>
>> Certainly you, ARE The Grik anus! <KICK> <KICK>
>>
>> LMAO1
>
> <BG> LAME attempt at a "retort", poor bleeding psychopath!

The Peeler

6/29/2013 3:42:00 AM

0

On Fri, 28 Jun 2013 18:44:20 +0200, The Peeler
<finishingoff@themoronicRevd.invalid> wrote:


>>> Certainly, my pwnling! <pat> <pat>
>>>
>>> LMAO!
>>
>> Certainly you, ARE The Grik anus! <KICK> <KICK>
>>
>> LMAO1
>
><BG> I've just made a LAME attempt at a "retort", poor bleeding Grik psychopath that I am!

<GB> You, HAVE The Grik anus!

%

6/29/2013 3:55:00 AM

0

The Peeler wrote:
> On Fri, 28 Jun 2013 18:44:20 +0200, The Peeler
> <finishingoff@themoronicRevd.invalid> wrote:
>
>
>>>> Certainly, my pwnling! <pat> <pat>
>>>>
>>>> LMAO!
>>>
>>> Certainly you, ARE The Grik anus! <KICK> <KICK>
>>>
>>> LMAO1
>>
>> <BG> I've just made a LAME attempt at a "retort", poor bleeding Grik
>> psychopath that I am!
>
> <GB> You, HAVE The Grik anus!

and the griks grik each other

The Peeler

6/29/2013 10:38:00 AM

0

On Fri, 28 Jun 2013 20:41:31 -0700, The Rectum, the resident psychopath of
sci and scj, FAKING his time zone again and IMPERSONATING his master, The
Peeler, wrote:

>> >> Certainly, my pwnling! <pat> <pat>
>> >>
>> >> LMAO!
>> >
>> > Certainly you, ARE The Grik anus! <KICK> <KICK>
>> >
>> > LMAO1
>>
>> <BG> LAME attempt at a "retort", poor bleeding psychopath!
>
> <GB> You, HAVE The Grik anus!

I HAVE endless fun, poor desperate idiot! LOL

--
Retarded, anal, subnormal and extremely proud of it: our resident
psychopath, The Retard (aka "The Rectum").