Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Tk TableMatrix format part of cell

by IB2017 (Pilgrim)
on Dec 02, 2018 at 10:31 UTC ( [id://1226620]=perlquestion: print w/replies, xml ) Need Help??

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

Dear monks

I have been using TableMatrix for years now, and besides the problems of installing it on modern Strawberry Perl (starting 5.26), I've been always happy with its versatility. I am now improving parts of my code base and I need to format a substring displayed in a cell. Formatting the entire cell is not a problem using the tag functions. Is there any build-in function to tag only a part of the cell? As I could not find on, I resorted to add to any cell a ROText Widget (as text in this widget can be formatted very flexibly). It works fine for small tables, but my doubt is: if the table grows in size and is dynamically generated, i.e. its rows are continuously created and destroyed, will this have effects on performances or even on stability? Or am I worrying too much?

Replies are listed 'Best First'.
Re: Tk TableMatrix format part of cell
by zentara (Archbishop) on Dec 02, 2018 at 14:37 UTC

      Hi Zentara, not quite sure what the post you linked to has to do with my problem. curselection gives indices of the cells not of strings inside the cells. And I want to modify the formatting of a section of the content of a given cell (for which I would need some indices to indicate which part of the content should my formatting apply to).

        Sorry I didn't understand the question. From what I little I know, the only thing you can do with a TableMatrix is use the -selectcommand to pop a toplevel window with the cell's data into a text widget for editing. Maybe a smarter monk might know a way.

        I'm not really a human, but I play one on earth. ..... an animated JAPH
Re: Tk TableMatrix format part of cell
by zentara (Archbishop) on Dec 03, 2018 at 14:25 UTC
    It works fine for small tables, but my doubt is: if the table grows in size and is dynamically generated, i.e. its rows are continuously created and destroyed, will this have effects on performances or even on stability? Or am I worrying too much?........ The question is if the table becomes to "heavy"/unstable if it grows in size and is frequently changed.

    No, you are not worrying too much. An often overlooked problem with Tk problems is memory gain due to the repeated creation and destruction of widgets. Quite often it is discovered too late, and much work has to be discarded as a memory hog, so it is best you watch your memory consumption as you develop any complex Tk script.

    First, the only Tk widget that will allow this is the Tk::Canvas, so if you really want this feature, use a Canvas, build your own table of cells, and tag your cell text accordingly.

    If you really want to stick with the TableMatrix, your current method of sticking a Text widget in the cell, and using it's tag features is your best shot. I would just caution that you create just one text widget for this purpose and reuse it. This should eliminate any creation/destruction memory gains. See "perldoc -q clear" for how to keep your reusable Text widget free of old data.


    I'm not really a human, but I play one on earth. ..... an animated JAPH

      Thank you for your expertise. This is also the fear I have, and unfortunately I already make too much use of widget destroy and recreate in my big application (trying to convert it to a reuse policy).

Re: Tk TableMatrix format part of cell
by Aldebaran (Curate) on Dec 03, 2018 at 00:39 UTC

    Do you have a self-contained example of what works now and where in the code you would like to add this new feature?

      Here it is a basic one. I want to apply my formatting only to the string "world"

      #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::TableMatrix; my $ArrayWidget; my $mw = new MainWindow(); my $FontBold = $mw->Font( -weight => 'bold'); my ($rows,$cols) = (50, 4); foreach my $row (0..$rows){ $ArrayWidget->{"$row,0"} = "$row"; } foreach my $col (0..$cols){ $ArrayWidget->{"0,$col"} = "$col"; } my $table = $mw->Scrolled('TableMatrix', -state=>'disabled', -rows => $rows, -cols => $cols, -colwidth => 20, -height => 6, -titlerows => 1, -titlecols => 1, -variable => $ArrayWidget, -wrap=>1, -multiline=>1, -scrollbars => 'osoe', -relief => 'flat', -selecttitles => 0, -highlightthickness=>0 )->pack(); $table->tagConfigure ("bold", -bg => "#689bc0"); $ArrayWidget->{"2,2"} = "Hello world"; #Apply tag bold or different font to the string "world", i.e. not to t +he entire cell 2.2 MainLoop();

      In the mean time I came to the conclusion that this feature is not supported and that I need to insert in any cell another Widget supporting formatting. The question is if the table becomes to "heavy"/unstable if it grows in size and is frequently changed.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found