[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

tk canvas question

Joe Van Dyk

6/21/2005 8:27:00 PM

Hi,

I'm drawing stuff on a TkCanvas. Essentially, a bunch of shapes that
move around. I need to keep track of where each shape has been, so I
can draw the shape's history if needed (a "slug track").

So every time a shape move, I store its position. When I want to view
a shape's history, I draw a line connecting each stored position.

I'm currently drawing all of these lines directly on to the main canvas.

The problem is when I want to hide the history lines. There can be
400 shapes, and each of them could have thousands of lines that detail
their previous history. Going through and deleting all the TkcLines
is taking a very long time.

Is there a way to "group" each shape's history lines and then be able
to give one command that shows and hides the lines in that group?

Thanks,
Joe


11 Answers

Joe Van Dyk

6/21/2005 8:42:00 PM

0

On 6/21/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> Hi,
>
> I'm drawing stuff on a TkCanvas. Essentially, a bunch of shapes that
> move around. I need to keep track of where each shape has been, so I
> can draw the shape's history if needed (a "slug track").
>
> So every time a shape move, I store its position. When I want to view
> a shape's history, I draw a line connecting each stored position.
>
> I'm currently drawing all of these lines directly on to the main canvas.
>
> The problem is when I want to hide the history lines. There can be
> 400 shapes, and each of them could have thousands of lines that detail
> their previous history. Going through and deleting all the TkcLines
> is taking a very long time.
>
> Is there a way to "group" each shape's history lines and then be able
> to give one command that shows and hides the lines in that group?
>
> Thanks,
> Joe


Aha. I found something called TkcGroup. I'm having difficulties
figuring out how to remove and/or hide the canvas objects that are in
each group though.


Joe Van Dyk

6/21/2005 9:16:00 PM

0

On 6/21/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> On 6/21/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> > Hi,
> >
> > I'm drawing stuff on a TkCanvas. Essentially, a bunch of shapes that
> > move around. I need to keep track of where each shape has been, so I
> > can draw the shape's history if needed (a "slug track").
> >
> > So every time a shape move, I store its position. When I want to view
> > a shape's history, I draw a line connecting each stored position.
> >
> > I'm currently drawing all of these lines directly on to the main canvas

Joe Van Dyk

6/21/2005 9:20:00 PM

0

On 6/21/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> On 6/21/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> > On 6/21/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> > > Hi,
> > >
> > > I'm drawing stuff on a TkCanvas. Essentially, a bunch of shapes that
> > > move around. I need to keep track of where each shape has been, so I
> > > can draw the shape's history if needed (a "slug track").
> > >
> > > So every time a shape move, I store its position. When I want to view
> > > a shape's history, I draw a line connecting each stored position.
> > >
> > > I'm currently drawing all of these lines directly on to the main canvas.
> > >
> > > The problem is when I want to hide the history lines. There can be
> > > 400 shapes, and each of them could have thousands of lines that detail
> > > their previous history. Going through and deleting all the TkcLines
> > > is taking a very long time.
> > >
> > > Is there a way to "group" each shape's history lines and then be able
> > > to give one command that shows and hides the lines in that group?
> > >
> > > Thanks,
> > > Joe
> >
> >
> > Aha. I found something called TkcGroup. I'm having difficulties
> > figuring out how to remove and/or hide the canvas objects that are in
> > each group though.
>
> I found this code out there somewhere:
>
> #!/usr/bin/env ruby
>
> require "tk"
>
> canvas = TkCanvas.new
> grp = TkcGroup.new(canvas)
> grp.add(TkcRectangle.new(canvas, '1c', '2c', '3c', '3c',
> 'outline' => 'black', 'fill' => 'blue'))
> canvas.pack
>
> canvas.bind 'Enter' do
> grp.configure 'fill', 'red'
> end
> canvas.bind 'Leave' do
> grp.configure 'fill', 'green'
> end
>
> Tk.mainloop
>
>
> I think it's supposed to have the rectangle change colors when the
> cursor enters and leaves the canvas. But I don't see any color change
> occuring. Can someone confirm this for me please?
>

Here's the link to the original tk code, and the corresponding Ruby code.

http://www2s.biglobe.ne.jp/~Nori/ruby/ja/tk-ref/itemconf...

The Tk code works for me, while the Ruby one doesn't.


Ryan Leavengood

6/21/2005 9:22:00 PM

0

Joe Van Dyk said:
> I think it's supposed to have the rectangle change colors when the
> cursor enters and leaves the canvas. But I don't see any color change
> occuring. Can someone confirm this for me please?

Confirmed. It doesn't change colors on my machine either (Windows XP, Ruby
1.8.2.)

Ryan



Hidetoshi NAGAI

6/22/2005 5:15:00 AM

0

Joe Van Dyk

6/22/2005 4:35:00 PM

0

On 6/21/05, Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> wrote:
> From: Joe Van Dyk <joevandyk@gmail.com>
> Subject: Re: tk canvas question
> Date: Wed, 22 Jun 2005 06:15:41 +0900
> Message-ID: <c715e64050621141518afc887@mail.gmail.com>
> > I found this code out there somewhere:
> (snip)
> > grp.add(TkcRectangle.new(canvas, '1c', '2c', '3c', '3c',
> > 'outline' => 'black', 'fill' => 'blue'))
>
> Please use TkcGroup#include.
> For example,
> -----------------------------------------------
> require "tk"
>
> canvas = TkCanvas.new
> grp = TkcGroup.new(canvas)
> grp.include(TkcRectangle.new(canvas, '1c', '2c', '3c', '3c',
> 'outline' => 'black', 'fill' => 'blue'),
> TkcRectangle.new(canvas, '3c', '4c', '5c', '5c',
> 'outline' => 'black', 'fill' => 'blue'))
> canvas.pack
>
> grp.bind 'Enter' do
> grp.configure 'fill', 'red'
> end
> grp.bind 'Leave' do
> grp.configure 'fill', 'green'
> end
> Tk.mainloop
> -----------------------------------------------
>
> TkcGroup has some bugs.
> I'll fix it later. And then, I'll revive TkcGroup#add.

Thank you. How does TkcGroup#include differ from TkcGroup#add?


Joe Van Dyk

6/22/2005 4:39:00 PM

0

On 6/21/05, Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> wrote:
> From: Joe Van Dyk <joevandyk@gmail.com>
> Subject: Re: tk canvas question
> Date: Wed, 22 Jun 2005 06:15:41 +0900
> Message-ID: <c715e64050621141518afc887@mail.gmail.com>
> > I found this code out there somewhere:
> (snip)
> > grp.add(TkcRectangle.new(canvas, '1c', '2c', '3c', '3c',
> > 'outline' => 'black', 'fill' => 'blue'))
>
> Please use TkcGroup#include.
> For example,
> -----------------------------------------------
> require "tk"
>
> canvas = TkCanvas.new
> grp = TkcGroup.new(canvas)
> grp.include(TkcRectangle.new(canvas, '1c', '2c', '3c', '3c',
> 'outline' => 'black', 'fill' => 'blue'),
> TkcRectangle.new(canvas, '3c', '4c', '5c', '5c',
> 'outline' => 'black', 'fill' => 'blue'))
> canvas.pack
>
> grp.bind 'Enter' do
> grp.configure 'fill', 'red'
> end
> grp.bind 'Leave' do
> grp.configure 'fill', 'green'
> end
> Tk.mainloop
> -----------------------------------------------
>
> TkcGroup has some bugs.
> I'll fix it later. And then, I'll revive TkcGroup#add.

How can I hide and/or destroy all TkCanvas items that are in a group?


Joe Van Dyk

6/22/2005 7:03:00 PM

0

On 6/22/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> On 6/21/05, Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> wrote:
> > From: Joe Van Dyk <joevandyk@gmail.com>
> > Subject: Re: tk canvas question
> > Date: Wed, 22 Jun 2005 06:15:41 +0900
> > Message-ID: <c715e64050621141518afc887@mail.gmail.com>
> > > I found this code out there somewhere:
> > (snip)
> > > grp.add(TkcRectangle.new(canvas, '1c', '2c', '3c', '3c',
> > > 'outline' => 'black', 'fill' => 'blue'))
> >
> > Please use TkcGroup#include.
> > For example,
> > -----------------------------------------------
> > require "tk"
> >
> > canvas = TkCanvas.new
> > grp = TkcGroup.new(canvas)
> > grp.include(TkcRectangle.new(canvas, '1c', '2c', '3c', '3c',
> > 'outline' => 'black', 'fill' => 'blue'),
> > TkcRectangle.new(canvas, '3c', '4c', '5c', '5c',
> > 'outline' => 'black', 'fill' => 'blue'))
> > canvas.pack
> >
> > grp.bind 'Enter' do
> > grp.configure 'fill', 'red'
> > end
> > grp.bind 'Leave' do
> > grp.configure 'fill', 'green'
> > end
> > Tk.mainloop
> > -----------------------------------------------
> >
> > TkcGroup has some bugs.
> > I'll fix it later. And then, I'll revive TkcGroup#add.
>
> How can I hide and/or destroy all TkCanvas items that are in a group?

Apparently, I can just delete the group. I'm not sure why it didn't
work before, but it is now.


Hidetoshi NAGAI

6/23/2005 3:38:00 AM

0

Hidetoshi NAGAI

6/23/2005 3:38:00 AM

0