Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Duplicate views to a single canvas using Perl TK

by Helter (Chaplain)
on May 03, 2008 at 04:07 UTC ( [id://684302]=perlquestion: print w/replies, xml ) Need Help??

Helter has asked for the wisdom of the Perl Monks concerning the following question:

I'm very new to Perl TK (read my first info this morning, so be easy correcting my possible slip ups in terminology...)

I'm assisting a co-worker in editing an existing Perl TK application we use for debug. Currently it is a window, with a single frame, and a canvas in that frame.

We would like to split the window so that we have the same content in an upper and lower view of the same data we had in the canvas already, but with independant scroll bars.

We find that using this tool it would be helpful to have the header information that is printed at the top most of the time, but fairly often it would be nice to pull down the top canvas so we can compare things going on above and below (like splitting an editor screen in half and seeing 2 parts of the same file...at least in concept)

We think we can solve this by duplicating the entirety of the canvas objects, but that seems heavy handed and sometimes the data that goes into generating these is fairly complex and time consuming.

I wanted to believe that there was an easier way to do this than duplication, but my searches (for the last few hours) has come up empty.

$top->title("Diagram Viewer"); $top->configure(-background => 'white'); #<a menu bar at the top>...skipping some details my $menu_bar = $top->Frame()->pack(-side => 'top', -fill => 'x'); #skipping adding buttons to menu_bar.... # the next frames my $top_canvas_frame = $top->Frame()->packAdjust(-side => 'top', -expa +nd => 'both', -fill => 'both'); my $bottom_canvas_frame = $top->Frame()->pack(-side => 'bottom', -expa +nd => 'both', -fill => 'both'); my $blankCanvas = { canvas => newCanvas($top_canvas_frame)}; # here is where I can't figure out a way to insert another view $blank +Canvas into $bottom_canvas_frame so we can get dual views... <readmore>

Replies are listed 'Best First'.
Re: Duplicate views to a single canvas using Perl TK
by zentara (Archbishop) on May 03, 2008 at 15:56 UTC
    What you want is very hard to do, especially for a beginner. If you try and copy or clone the canvas, it will just overwrite the first at the exact locations on the screen. You are looking for some sort of deep object copying and blessing of the new object, and it dosn't work well with Tk. You might have some luck if you subclassed your Canvas, and used Clone (or something similar) on it. But, it will probably be buggy at a very deep level, which would drive a beginner crazy. Your best bet, is to do either one of 2 things.

    1. Every time you add or delete and object in 1 canvas, duplicate that move in the other, or maintain a log, and use the log to modify the other Canvas like an undo/redo script.

    2. Stick to a single Canvas, and when you create 1 item in the Canvas, create another at an offset, to appear like in a second Canvas. Maybe have a key to prevent the cloning, or to erase from only a single canvas.

    When you get into involved Canvas apps, you need to use the power of "tagging items". With creative-descriptive tagging, you can find and manipulate items easily.


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Unfortunately the drawing to the canvas is a third party sort-of code that we don't want to muck too deeply with.

      It seems like there isn't a real way to create 2 views of the same data, so our best bet is to just create 2 of the canvas. This will give us the most functionality, and we have some preliminary tests that say the impact on memory footprint isn't bad enough for this not to work.

      Thanks for the suggestions, I'll keep them in mind for future projects working with TK.

      If someone does have a way to do it I'd still love to hear about it, but for now I think we have a method that might work.
        This is probably your best bet.

        As you noticed, having multiple canvases does not impact memory usage that much since much of the memory is shared between multiple instantiations of the same widget.

        The only other optimization I can think of is that you don't need to invoke the third party code twice. What you can probably do is invoke it once to get the object drawn on one canvas, then grab the coords of the new object (using the coords() method), and draw it on the second canvas. Probably a bit faster.

        HTH.
Re: Duplicate views to a single canvas using Perl TK
by Anonymous Monk on May 03, 2008 at 07:32 UTC
    Only easy way I can think of is to create snapshot using $canvas->postscript, then display that
      Thanks anonymous, One of the debug features of the canvas is that if you hover your mouse over some of the arrows useful information pops up. I believe I would lose that with the postscript solution, but if memory usage becomes an issue that may be an acceptable alternative to duplicating the canvas.

      Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found