Tk - Ruby/Tk core library design questions

D

David Tran

I forgot which old version is, on that old version, the widget.pack
method always returns nil.
So people have to write something like:

b =3D TkButton.new {
pack
}

Now the pack returns self, what's great improvement, so we can write
something like:
b =3D TkButton.new.pack.command { puts "Hello" }

Now, my ruby version is : ruby 1.8.2 (2004-12-25) [i386-mswin32]
and my Tcl/Tk version is : 8.4
I have some Ruby/Tk design questions :

(1) Layout Manager:
there are:
widget.pack ; TkPack.pack ; Tk.pack
widget.grid ; TkGrid.grid ; Tk.grid
widget.place ; TkPlace.place
methods, why there is no Tk.place method ?
This seems inconsistent for me.

(2) Since we try to wrap Tcl/Tk on OO, why some Tcl commands are not
treat like options ?
Most options have getter and setter method, there are many way to do
it, for example:
# setter
button.bg =3D :red
button.bg:)red)
button.configure:)bg, :red)
# getter
puts button.bg
puts button.cget:)bg)

Now, for example, root.title and root.iconbitmap ... etc are command
but not options on Tcl/Tk language.
But, I feel this will be nice if we "wrap" them like options, so we
can write something like:
TkRoot.new:)title=3D>'Hello') or
TkButton.new:)text=3D>'set title').command { Tk.root.title =3D "some title"=
}
For me, it seems title is just like an option for TkRoot.
(But in current version, it is not, so I cannot use :title=3D>... or
root.title =3D ... syntax )

(3)
require 'tk'
c =3D TkCanvas.new.pack
TkcRectangle.new(c, 10, 10, 50, 50)
Tk.mainloop

The above code works fine, but if I rewrite it to become

require 'tk'
TkcRectangle.new(TkCanvas.new.pack, 10, 10, 50, 50)
Tk.mainloop

I got this error: uninitialized constant TkcRectangle (NameError)

Rewrite it again like:

require 'tk'
TkCanvas
TkcRectangle.new(TkCanvas.new.pack, 10, 10, 50, 50)
Tk.mainloop

It works fine again.

So, what's going wrong with:
require 'tk' ; TkcRectangle.new(TkCanvas.new.pack, 10, 10, 50, 50) ; Tk.mai=
nloop
Why should I reference TkCanvas ( at least class ) first ?

Thank you.
 
H

Hidetoshi NAGAI

From: David Tran <[email protected]>
Subject: Tk - Ruby/Tk core library design questions
Date: Tue, 2 Aug 2005 06:53:52 +0900
Message-ID: said:
(1) Layout Manager:
there are:
widget.pack ; TkPack.pack ; Tk.pack
widget.grid ; TkGrid.grid ; Tk.grid
widget.place ; TkPlace.place
methods, why there is no Tk.place method ?

'tk.rb' on CVS already has the method.

# committed at 2005/03/02
(2) Since we try to wrap Tcl/Tk on OO, why some Tcl commands are not
treat like options ? (snip)
Now, for example, root.title and root.iconbitmap ... etc are command
but not options on Tcl/Tk language.
But, I feel this will be nice if we "wrap" them like options, so we
can write something like:
TkRoot.new:)title=>'Hello') or
TkButton.new:)text=>'set title').command { Tk.root.title = "some title" }
For me, it seems title is just like an option for TkRoot.
(But in current version, it is not, so I cannot use :title=>... or
root.title = ... syntax )

Hmmm...
On CVS, "TkRoot.new:)title=>'Hello')" works, but
"Tk.root.title = 'some title'" doesn't.
If you want 'title=' method only, that is very easy.
-----------------------------------------
module Tk::Wm
alias title= title
end
-----------------------------------------
However, it is not so simple to supprt :title=>"..." on
configure method.
To do it, we must check all keys of the configure argument,
and select to call 'wm' command or 'configure' command.
If you request it strongly, I'll try to implement.
(3) (snip)
Why should I reference TkCanvas ( at least class ) first ?

Probably you can find the reason on 'tk/autoload.rb'
Definitions for canvas widgets and canvas items are witten
on 'tk/canvas.rb'.
If you don't need a canvas widget on your application,
you don't need to require 'tk/canvas.rb'.
So, Ruby/Tk uses autoload mechanism to load the necessary library.
Current Ruby/Tk doesn't define autoload for canvas items.
I thought that is enough because canvas items needs a parent
canvas widget.
Don't you think so?
 
E

email55555

'tk.rb' on CVS already has the method.
OK. Thank you. ( I always behind ... )
To do it, we must check all keys of the configure argument,
and select to call 'wm' command or 'configure' command.
If you request it strongly, I'll try to implement.
I just feel this would be a nice feature, but not sure how many people
needed,
and I know it is not trivial ( check all commands, make sure they have
getter/setter
behaviour, and wrap them like options ... ). I am not strongly needed,
but if
many people think that would be nice, then maybe give it a try? ;-)
BTW: if we really do it, then we may need to keep maintenance in the
future for
new version of TK ( maybe new command come out and need to wrap ... etc
)
So, think again those complexity ...
I thought that is enough because canvas items needs a parent
canvas widget.
Don't you think so?
I think so too. :)
I just try to write a quick demo as short as possible, then that error
came out.
After your explication, I know what I have to rewrite it ...
Here is the classic way:
require 'tk' ; TkCanvas.new { |c| TkcRectangle.new(c, 1, 1, 2, 2)
}.pack; Tk.mainloop
My short version which not works:
require 'tk'; TkcRectangle.new(TkCanvas.new.pack, 1,1,2,2);
Tk.mainloop;
Just rewrite it to become:
require 'tk/canvas.rb'; TkcRectangle.new(TkCanvas.new.pack, 1,1,2,2);
Tk.mainloop;
and it is short and works fine.

Thank you again for your help.
 
E

email55555

To do it, we must check all keys of the configure argument,
and select to call 'wm' command or 'configure' command.
If you request it strongly, I'll try to implement.

Not only the 'wm' command, I also think something like:

TkScale.new:)form=>10, :to=>100, :value=>40, :variable=>v).pack
As you can see there is side-effect.
Hash has no notion of order.
So the set value 40 will modifiy the variable v
depend on the order of :value=>40 and :variable=>v
 
H

Hidetoshi NAGAI

From: (e-mail address removed)
Subject: Re: Tk - Ruby/Tk core library design questions
Date: Wed, 3 Aug 2005 01:21:05 +0900
Message-ID: said:
Not only the 'wm' command, I also think something like:

TkScale.new:)form=>10, :to=>100, :value=>40, :variable=>v).pack
As you can see there is side-effect.
Hash has no notion of order.
So the set value 40 will modifiy the variable v
depend on the order of :value=>40 and :variable=>v

If the order is important, such parameters should not be
treated on a Hash argument.
I'll not unify TkScale#value= to the configure hash.
However, instead of your short example, you can write:
TkScale.new:)from=>10, :to=>100, :variable=>v.set_value(40)).pack
 
H

Hidetoshi NAGAI

From: (e-mail address removed)
Subject: Re: Tk - Ruby/Tk core library design questions
Date: Tue, 2 Aug 2005 22:26:04 +0900
Message-ID: said:
I just feel this would be a nice feature, but not sure how many people
needed,
and I know it is not trivial ( check all commands, make sure they have
getter/setter
behaviour, and wrap them like options ... ). I am not strongly needed,
but if
many people think that would be nice, then maybe give it a try? ;-)
BTW: if we really do it, then we may need to keep maintenance in the
future for
new version of TK ( maybe new command come out and need to wrap ... etc
)
So, think again those complexity ...

I've commit that to CVS (HEAD and 1.8 branch).
Please try it. ;-)
 
E

email55555

Hidetoshi said:
I've commit that to CVS (HEAD and 1.8 branch).
Please try it. ;-)

Yes, I tried it. It works.
TkRoot.new:)title=>'you name it.').title += ' OK!'

I still use Ruby 1.8 stable version,
and now get the latest Ruby/Tk from CVS (HEAD)

This kind of mix, I only get one error message.
ruby/lib/ruby/1.8/tk/event.rb:397:
NoMethodError: undefined method `_define_attribute_aliases'
for CallbackSubst:Class

I just replace the new event.rb by old (1.8 stable) event.rb
and everything works fine.

I feel that you guy did a lot of "performance" imporvement.
My program seems start up (and run) fast compare to old 1.8 statble
Ruby/Tk.

Thank you.
 
H

Hidetoshi NAGAI

From: (e-mail address removed)
Subject: Re: Tk - Ruby/Tk core library design questions
Date: Fri, 5 Aug 2005 01:16:06 +0900
Message-ID: said:
This kind of mix, I only get one error message.
ruby/lib/ruby/1.8/tk/event.rb:397:
NoMethodError: undefined method `_define_attribute_aliases'
for CallbackSubst:Class

This method is defined on tkutil.c.
Please get and recompile it, and re-install tkutil.so.

Current Ruby/Tk has no difference between 1.9 and 1.8
without layout of source files.
 
H

Hidetoshi NAGAI

From: Hidetoshi NAGAI <[email protected]>
Subject: Re: Tk - Ruby/Tk core library design questions
Date: Fri, 5 Aug 2005 07:03:07 +0900
Message-ID: said:
This method is defined on tkutil.c.
Please get and recompile it, and re-install tkutil.so.

Maybe, you need get and recompile "tcltklib" also.
 
E

email55555

Hidetoshi said:
This method is defined on tkutil.c.
Please get and recompile it, and re-install tkutil.so.


Maybe, you need get and recompile "tcltklib" also.

Ok. Thanks for the info.
 

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

Similar Threads

Ruby/Tk 4
ruby/tk : hide TkFrame 1
Ruby TK 2
Ruby/Tk 10
Ruby/tk Help Please 19
Bug with Ruby/Tk encoding (ruby-1.9.1-rc1) 6
Tk and Tile with Tk8.5 9
Ruby/Tk running very slowly 2

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top