Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: Tk performance and "UpdateWrapper: Failed to create container"

by cavac (Vicar)
on Jan 18, 2022 at 13:59 UTC ( #11140563=note: print w/replies, xml ) Need Help??

in reply to Re^2: Tk performance and "UpdateWrapper: Failed to create container"
in thread Tk performance and "UpdateWrapper: Failed to create container"

There are two related ways that i know to speed this up dramatically. Both have to do with the fact that the main spreadsheet area doesn't actually have to use "real" widgets. In both cases, you just draw the data and any visual sugar as graphics.

The first way is the classic spreadsheet way: You have one long editable field near the top of the screen. If you select a cell (calculate from the mouse click on the graphics which cells this would be), put its value in the edit field. Every time that value changes, redraw the appropriate part of the graphics, so the user thinks they are simultaneously editing the actual value in the table.

The second way is one i have used before for HTML/JavaScript based tables (i think DataTables does it that way as well): again, use a generated image as the spreadsheet proper. If the user selects a cell, just spawn in an appropriate widget for editing on top of the image. When the user is done, remove the widget.

The main advantage of doing the spreadsheet as simple graphics is speed and memory usage: All you do is print some text and paint some lines. Doesn't need to bless a gazillion instances and register a gazillion callbacks. You basically only have two callbacks: Mouseclicks (selecting cells) and scrolling.

For moving between cells with the cursor/tab keys, you would just get those from the one and only editable widget.

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
  • Comment on Re^3: Tk performance and "UpdateWrapper: Failed to create container"
  • Download Code

Replies are listed 'Best First'.
Re^4: Tk performance and "UpdateWrapper: Failed to create container"
by olgo (Acolyte) on Jan 19, 2022 at 15:46 UTC
    Hi cavac, and thanks for your effort.
    I actually combined your idea with Marshall's and ended up with a blazingly fast simple Tk::TableMatrix based spreadsheet in which I replace the cell over which the mouse pointer currently hovers with an actual editable widget. I had to rewrite quite a few GUI mechanisms (binds, binds, binds...) but some 10 hours later I am pretty much back to where I started, only with a responsive GUI.
    Only things I miss are autowidth of columns (my data differs quite a bit in size within the columns) and balloons. I guess you just can't have it all. Maybe I could attach a balloon to the cell I am currently hovering over but that would require me to first replace the TableMatrix cell with a (Tk::Label) widget, like I do for editable cells.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11140563]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-09-30 05:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found