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?
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.
···
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?
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?
···
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.
The Tk code works for me, while the Ruby one doesn't.
···
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.
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?
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.)
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.
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
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.
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?
Although I don't remember the specification of old TkcGroup#add
(I think that was included in Ruby-1.0 or Ruby-1.1b),
probably there is no difference.
So, for users who read such very old document,
I'll add an alias TkcGroup#add --> TkcGroup#include.
···
From: Joe Van Dyk <joevandyk@gmail.com>
Subject: Re: tk canvas question
Date: Thu, 23 Jun 2005 01:35:29 +0900
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
Apparently, I can just delete the group. I'm not sure why it didn't
work before, but it is now.
The reason is that "add" method call adds no canvas-tag to target
widgets.
TkcGroup has no "add" instance method.
Then, Ruby/Tk assumes that it is configuration of "-add" option.
Of course, canvas items don't have such option.
However, if the target of configuration is a canvas-tag which is not
assigned to any items, Tk generates no error and returns an empty
string.
So, TkcGroup#add does nothing and returns "" without errors.
TkcGroup#include works properly, that is, adds its canvas-tag to
target widgets.
After that, TkcGroup#add will raise an exception 'unknown option
"-add"'.
···
From: Joe Van Dyk <joevandyk@gmail.com>
Subject: Re: tk canvas question
Date: Thu, 23 Jun 2005 04:03:26 +0900
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
On 6/22/05, Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> wrote:
From: Joe Van Dyk <joevandyk@gmail.com>
Subject: Re: tk canvas question
Date: Thu, 23 Jun 2005 04:03:26 +0900
Message-ID: <c715e6405062212036981cfe7@mail.gmail.com>
> Apparently, I can just delete the group. I'm not sure why it didn't
> work before, but it is now.
The reason is that "add" method call adds no canvas-tag to target
widgets.
TkcGroup has no "add" instance method.
Then, Ruby/Tk assumes that it is configuration of "-add" option.
Of course, canvas items don't have such option.
However, if the target of configuration is a canvas-tag which is not
assigned to any items, Tk generates no error and returns an empty
string.
So, TkcGroup#add does nothing and returns "" without errors.
TkcGroup#include works properly, that is, adds its canvas-tag to
target widgets.
After that, TkcGroup#add will raise an exception 'unknown option
"-add"'.