Ruby/Tk core library desing question (TkCanvas#create)

D

David Tran

For TkCanvas#create method, it returns "1" seems useless ...
( Does "1" means successful ? )

To fit in "Ruby" world, it would be better TkCanvas#create returns self.

So you can write something like:
TkCanvas.new.pack.create(TkcRectangle, 0, 0, 5, 5).create(TkcOvale,
50, 50, 70, 70)

Currently, you cannot, the TkCanvas#create returns Fixnum 1.

Thank you.
 
D

David Tran

Or maybe the TkCanvas#create return the item created. Like:
line =3D TkCanvas.new.pack.create(TkcLine, 0, 0, 100, 100)
so the line is TkcLine instance object.

But I still prefer TkCanvas#create returns self.
( so I can "chain" the TkCanvas methods )

Anyway, currentely returns 1 just seems useless to me.

Thank you.
 
H

Hidetoshi NAGAI

From: David Tran <[email protected]>
Subject: Ruby/Tk core library desing question (TkCanvas#create)
Date: Tue, 9 Aug 2005 06:53:28 +0900
Message-ID: said:
For TkCanvas#create method, it returns "1" seems useless ...
( Does "1" means successful ? )

No. That is the identifier of the canvas item.
TkCanvas#create method is used when you don't want to create
a ruby object for a canvas item (for example, you worry about
memory costs for many items).
And then, to configure the item, you have to use the identifier
(if you don't give canvas tags to the item).
You shouldn't assume that the return value is a number.
 
D

David Tran

No. That is the identifier of the canvas item.
TkCanvas#create method is used when you don't want to create=20
a ruby object for a canvas item (for example, you worry about
memory costs for many items).
And then, to configure the item, you have to use the identifier=20
(if you don't give canvas tags to the item).
You shouldn't assume that the return value is a number.
--=20
Hidetoshi NAGAI ([email protected])

I missunderstood the return value.

require 'tk'
c =3D TkCanvas.new.pack
r =3D c.create(TkcRectangle, 10, 10, 50, 50)
puts "r =3D #{r}; type =3D #{r.class}"=20
c.itemconfigure(r, :fill=3D>:red)
Tk.mainloop

Got it now, even the r is Fixnum class, it is item identifier.
So, later we can use it on itemconfigure to modify the item.

Thank you.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top