Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Graphic Library with Perl Binding

by astroboy (Chaplain)
on Mar 20, 2012 at 00:34 UTC ( #960502=perlquestion: print w/ replies, xml ) Need Help??
astroboy has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I would like to create graphic objects, place them on a canvas, double-click on them and add attributes - i.e. provide features like your would see in MS Visio or an ERD or UML modelling tool. Is there a graphics library with Perl bindings that supports this? Obviously, I expect to code the functionality, but what I'm not after is a library that simply generates static diagrams, as I need to be able to interact with the various graphical elements

Comment on Graphic Library with Perl Binding
Re: Graphic Library with Perl Binding
by chromatic (Archbishop) on Mar 20, 2012 at 01:00 UTC

    I used Cairo briefly a couple of years ago, and it worked nicely. Chart::Clicker uses it internally to great effect. I can't speak to its applicability to your situation, but I'd start with it.


    Improve your skills with Modern Perl: the free book.

Re: Graphic Library with Perl Binding
by Anonymous Monk on Mar 20, 2012 at 04:30 UTC
Re: Graphic Library with Perl Binding
by zentara (Archbishop) on Mar 20, 2012 at 15:23 UTC
    I would like to create graphic objects, place them on a canvas, double-click on them and add attributes

    As has been said, most of the canvases usable by Perl can do this. When you create a canvas object, you can add to that object any attributes you want, either by adding 'tags', with addtag ( used in the Tk::Canvas and Zinc ) or just by adding them manually to the objects hash, like $circle->'myattributes' = 'whatever'. Below is a simple example of tags, where I use a simple Button-1 release to add a time tag. You can do anything you want with a click, like pop up an Entry for your new attribute to add. To be honest, DoubleClicks can get tricky, due to timing issues with the successive clicks. It's best to stick with Left click, Right click, Middle click, or key combos like Shift + Left-Button, etc.

    #!/usr/bin/perl use warnings; use strict; use Tk; my $top = new MainWindow; my $c=$top->Canvas->pack; my $circle = $c->createOval(30,30,100,100, -fill => 'blue', -tags =>['circle'], -stipple => 'gray12', ); my $rect1 = $c->createRectangle(10,10,44,44, -fill => 'green', -stipple => 'gray12', -tags =>['rect1'], ); my $rect2 = $c->createRectangle(93,93,200,200, -fill => 'yellow', -tags =>['rect2'], -stipple => 'gray12', ); my $poly1 = $c->createPolygon(0,0, 44,44, 55,55, 90,90, 200,200, 10,10 +0,0,0, -fill => 'red', -smooth => 1, -splinesteps => 100, -stipple => 'gray12', -tags =>['poly1'], ); $c->Tk::bind("<Motion>", [ \&print_xy, Ev('x'), Ev('y') ]); $c->CanvasBind('<B1-ButtonRelease>', [ \&add_something, Ev('x'), Ev('y +') ]); &print_xy($c, 42,42); MainLoop; sub print_xy { my ($canv, $x, $y) = @_; print "(x,y) = ", $canv->canvasx($x), ", ", $canv->canvasy($y), "\n"; #my $x1 = $x+1; #my $y1 = $y+1; #it will actually use a zero size rectangle my (@current) = $canv->find('overlapping', $x, $y, $x, $y); foreach my $id(@current){ print $canv->gettags($id),' '; } print "\n"; } sub add_something { my ($canv, $x, $y) = @_; print "(x,y) = ", $canv->canvasx($x), ", ", $canv->canvasy($y), "\n"; # here you can make a popup to get attributes, I just add time for # this demo my $current = $canv->find(qw/withtag current/); $canv->addtag('aTimeTag'.time, 'withtag', $current); print join ' ', $canv->gettags($current); print "\n"; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://960502]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-11-28 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (200 votes), past polls