Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

composite canvas widgets
Hi,
As part of a graphical editor, I would like to be able to use composite
widgets on a canvas - i.e. a symbol consisting of circles, polygons,
lines etc.

I think I would be able to generate the necessary widgets with minimal
trouble, but what has me stumped is a way to move these composite
widgets as a unit.

Some widgets will need to be filled, so a polygon or multi-segment line
approximation is not really an (easy) option.

Is Tk_CreateItemType the only way to go?

Are there any workable examples of Tk_CreateItemType (for Perl/Tk?) ?

Any comments or ideas would be most welcome.


Arnold

Report this thread to moderator Post Follow-up to this message
Old Post
Arnold Wiegert
11-06-04 01:56 AM


Re: composite canvas widgets
Arnold Wiegert wrote:

> I think I would be able to generate the necessary widgets with minimal
> trouble, but what has me stumped is a way to move these composite
> widgets as a unit.

Just tag all related items with the same string, and use this tag in
your move() call.

> Some widgets will need to be filled, so a polygon or multi-segment line
> approximation is not really an (easy) option.

I don't understand. You can fill a polygon.

> Is Tk_CreateItemType the only way to go?

This function is not accessible though the regular Tk API. It's mainly
used (AFAIK) internally in the Canvas's C code.

What exactly are you trying to do? Can you show us an example of what
your "widget" is supposed to look like?

--Ala

Report this thread to moderator Post Follow-up to this message
Old Post
Ala Qumsieh
11-06-04 01:56 AM


Re: composite canvas widgets
"Arnold Wiegert" <awiegert-remove-this-@telus.net> wrote in message
news:53Sid.54872$VA5.16567@clgrps13...
> Hi,
> As part of a graphical editor, I would like to be able to use composite
> widgets on a canvas - i.e. a symbol consisting of circles, polygons,
> lines etc.

To clarify - we call these "canvas items" - not composite widgets. Composite
widgets are another beast altogether.

>
> I think I would be able to generate the necessary widgets with minimal
> trouble, but what has me stumped is a way to move these composite
> widgets as a unit.

Use Ala's suggestion of tagging them [i.e. items - not widgets :-) ]all with
the same tag. Or you can use the undocumented "group" functionality. See
this older post:

http://groups.google.ca/groups?selm=v8_18.163$t64.97843@newsfeed.slurp.net

>
> Some widgets will need to be filled, so a polygon or multi-segment line
> approximation is not really an (easy) option.
>
> Is Tk_CreateItemType the only way to go?

Only if you have a specific item that cannot be shown/drawn using the
existing items (i.e. polygons, lines, text etc).

>
> Are there any workable examples of Tk_CreateItemType (for Perl/Tk?) ?

None that I know of. That would be way beyond my knowledge-base and
certainly not something "I" would consider doing.

Also - check out Tk::Zinc. It has additional item types over and above the
basic canvas which might prove helpful to achieving whatever goal you have
in mind.

Jack



Report this thread to moderator Post Follow-up to this message
Old Post
Jack D
11-06-04 01:56 AM


Re: composite canvas widgets
On Fri, 05 Nov 2004 21:14:41 GMT, Arnold Wiegert
<awiegert-remove-this-@telus.net> wrote:

>Hi,
>As part of a graphical editor, I would like to be able to use composite
>widgets on a canvas - i.e. a symbol consisting of circles, polygons,
>lines etc.
>
>I think I would be able to generate the necessary widgets with minimal
>trouble, but what has me stumped is a way to move these composite
>widgets as a unit.
>
>Some widgets will need to be filled, so a polygon or multi-segment line
>approximation is not really an (easy) option.
>
>Is Tk_CreateItemType the only way to go?
>
>Are there any workable examples of Tk_CreateItemType (for Perl/Tk?) ?
>
>Any comments or ideas would be most welcome.

Use the group feature of canvas.
Of course you could do it all manually with tags, but groups
are easier IMO.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = MainWindow->new();

# first create a canvas widget
my $canvas = $mw->Canvas(width => 300, height => 200)->pack();
my $one = $canvas->createOval(5,  0, 20, 30, -fill => 'blue');
my $two = $canvas->createRectangle(0, 20, 50, 75, -fill => 'red');

my $group = $canvas->createGroup([0, 0], -members => [$one, $two]);

my $dx = 1;
my $dy = 1;
my $id = Tk::After->new($canvas,10,'repeat',
sub {$canvas->move($group, $dx,$dy);
my ($x,$y) = $canvas->bbox($group);
print "$x $y\n";
if($y >= 100){$dy = -1};
if($x >= 200){$dy = 1; $dx = -1};
if($x < -5){$dx=1;$dy=1};
});

my $ebutton = $mw->Button(-text => 'Exit',
-command => 'Tk::exit')->pack();

my $sbutton = $mw->Button(-text => 'Stop',
-command => sub{$id->cancel;})->pack();


MainLoop();
__END__











--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Report this thread to moderator Post Follow-up to this message
Old Post
zentara
11-06-04 01:56 PM


Re: composite canvas widgets
Thank you all for your help.

It looks like the 'group' functionality will do the trick for me.

I had looked at Zinc, but the lack of PS output was a factor in not even
trying it.

Ala Qumsieh wrote:
> Arnold Wiegert wrote:
> 
>
>
> Just tag all related items with the same string, and use this tag in
> your move() call.
I didn't read that possibility into the docs I have. But I guess the
'group'  feature will really do the trick for me
> 
>
>
> I don't understand. You can fill a polygon.
My fuzzy thinking - see below :-)
> 
>
>
> This function is not accessible though the regular Tk API. It's mainly
> used (AFAIK) internally in the Canvas's C code.
>
> What exactly are you trying to do? Can you show us an example of what
> your "widget" is supposed to look like?
>
some symbols are squares with additional lines at various angles, others
are circles with radial lines. I suppose polygons could have non-closed
'tails' - but I didn't like that idea too much.

Again, thanks.

Arnold

Report this thread to moderator Post Follow-up to this message
Old Post
Arnold Wiegert
11-06-04 08:55 PM


Re: composite canvas widgets
Arnold Wiegert <awiegert-remove-this-@telus.net> writes:

> Hi,
> As part of a graphical editor, I would like to be able to use
> composite widgets on a canvas - i.e. a symbol consisting of circles,
> polygons, lines etc.
>
> I think I would be able to generate the necessary widgets with minimal
> trouble, but what has me stumped is a way to move these composite
> widgets as a unit.
>
> Some widgets will need to be filled, so a polygon or multi-segment
> line approximation is not really an (easy) option.
>
> Is Tk_CreateItemType the only way to go?
>
> Are there any workable examples of Tk_CreateItemType (for Perl/Tk?) ?
>

See the Tk::Canvas::Point module at CPAN for an example how to add a
new canvas type to the Perl/Tk canvas. However, the ability to add
mega or composite or completely new canvas items in pure perl would be
neat. A lot of grouping problems can be solved with clever tag
definitions or the "group" canvas item, but some problems remain
complex (for example scaling --- see the "scale_width" function in my
"bbbike" application).

Regards,
Slaven

--
Slaven Rezic - slaven <at> rezic <dot> de

tktimex - project time manager
http://sourceforge.net/projects/ptktools/

Report this thread to moderator Post Follow-up to this message
Old Post
Slaven Rezic
11-07-04 01:56 AM


Re: composite canvas widgets
On Sat, 06 Nov 2004 17:52:40 GMT, Arnold Wiegert
<awiegert-remove-this-@telus.net> wrote:

>Thank you all for your help.
>
>It looks like the 'group' functionality will do the trick for me.
>
>I had looked at Zinc, but the lack of PS output was a factor in not even
>trying it.

The Zinc authors are working on PS output, in the mean time you can use
WinPhoto to capture Zinc, if on linux.

Zinc is really the way to go when you want to use groups. You can
rotate, scale-zoom, and clip groups in Zinc. Very powerful, and not
much harder than Canvas.

Just my opinion. :-)

--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Report this thread to moderator Post Follow-up to this message
Old Post
zentara
11-07-04 01:56 PM


Re: composite canvas widgets
zentara wrote:

> On Sat, 06 Nov 2004 17:52:40 GMT, Arnold Wiegert
> <awiegert-remove-this-@telus.net> wrote:
>
> 
>
>
> The Zinc authors are working on PS output, in the mean time you can use
> WinPhoto to capture Zinc, if on linux.
>
That is good to hear, I'll try to keep it in mind
Also, I do want to keep it workable on both Winxx and *nix since this is
supposed to be a replacement for an older (incomplete) X-windows program
that would/could see more use if usable/available on a Winxx platform.

> Zinc is really the way to go when you want to use groups. You can
> rotate, scale-zoom, and clip groups in Zinc. Very powerful, and not
> much harder than Canvas.
>
> Just my opinion. :-)
>
Unless I run into some very serious problems, I think I'm too far gone
down the 'canvas' road to change now - or perhaps too lazy/scared to
start over and hope for the PS output to show up ;-)

Still, it is good to know it is an alternative.

Arnold

Report this thread to moderator Post Follow-up to this message
Old Post
Arnold Wiegert
11-08-04 08:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:46 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.