in reply to Re^6: Query the height of Tk::Text widget with word wrap
in thread Query the height of Tk::Text widget with word wrap

Here's what I have. It works, but it puts an icon in the system tray while it's doing the calculations. Any idea about how to get rid of that? My googling turns up nothing. I tried a Dialog instead of a toplevel window but dialogs stop everything and require the user to click a button to proceed. It looks like that feature can't be disabled.
It's also pretty slow. It takes about 3 or 4 seconds for 500 rows. I'm thinking about how to speed it up but I'm not sure.

use strict; use warnings; use Tk; use Tk::TableMatrix; require Tk::Dialog; my $mw = Tk::MainWindow->new; $mw->geometry('1000x800'); # TableMatrix my $t = $mw->Scrolled('TableMatrix', -rows => 500, -cols => 1, -colwidth => -500, -scrollbars => 'e' )->pack(-expand => 1, -fill => 'both');; my $width = $t->colWidth(0); # print "\ncolumn width: $width\n"; $width = $width * -1; my $heightwin = $mw->Toplevel(-title => 'Height set window'); $heightwin->geometry("${width}x1000-2000-2000"); my $twtest = $heightwin->Text(-wrap=>'word', -width=> $width)->pack(-e +xpand=> 1, -fill=>'both'); $mw -> focus; my @tw; while (<DATA>) { my $i = $. - 1; chomp; # $tw[$i] = $heightwin->Text(-wrap=>'word', -width=> $width)->pack +(-expand=> 1, -fill=>'both'); $twtest->delete('0.0','end'); $twtest->insert('end', $_); my $endidx = $twtest->index('end - 1 chars'); # print "end index: $endidx\n"; $twtest->update; my @dline = $twtest->dlineinfo($endidx); my $high = -1 * ($dline[1] + 17); #do customize '+ 17' based on + font size # print "\nSetting height of row $i to $high\n"; $t->rowHeight($i, $high); $tw[$i] = $mw->Text(-wrap=>'word', )->pack(qw/ -expand 1 -fill bot +h /); $tw[$i]->insert('end', "$i - $_"); $t->windowConfigure("$i,0", -window => $tw[$i]); # -sticky => 's' +, #put the Text widget in the tablematrix table } $heightwin->destroy; MainLoop; __DATA__ The general budget 1. The Head of the Agency shall provide the Steering Board by 30 June +each year with an overall estimate of the draft general budget for th +e following year, fully respecting the limits set down in the financi +al framework. 2. The Head of the Agency shall propose the draft general budget to th +e Steering Board by 30 September each year. The draft shall include: (a) the appropriations deemed necessary: (i) to cover the Agency's running, staffing and meeting costs; (ii) for procuring external advice, notably operational analysis, esse +ntial for the Agency to discharge its tasks, and for specific researc +h and technology activities for the common benefit of all participati +ng Member States, notably technical case-studies and pre-feasibility +studies; (b) a forecast of the revenue needed to cover expenditure. 3. The Steering Board shall aim to ensure that the appropriations refe +rred to in paragraph 2(a)(ii) shall represent a significant share of +the total appropriations referred to in paragraph 2. These appropriations shall reflect actual needs and shall allow for an + operational role for the Agency. 4. The draft general budget shall be accompanied by a detailed staff e +stablishment plan and detailed justifications. 5. The Steering Board, acting by unanimity, may decide that the draft +general budget shall furthermore cover a particular project or progra +mme where this is clearly for the common benefit of all participating + Member States. 6. The appropriations shall be classified in titles and chapters group +ing expenditure together by type or purpose, subdivided as necessary +into articles. 7. Each title may include a chapter entitled «provisional appropriatio +ns» . These appropriations shall be entered where there is uncertainty, base +d on serious grounds, about the amount of appropriations needed or th +e scope for implementing the appropriations entered.

Replies are listed 'Best First'.
Re^8: Query the height of Tk::Text widget with word wrap (tk without no tray icon overrideredirect splashscreen state zoomed deiconify
by Anonymous Monk on Dec 02, 2013 at 23:21 UTC

    no taskbar icon ... (or some other things) .. see Tk::Wm  perl -MTk -e " tkinit()->overrideredirect(1); MainLoop; "

    not sure where i learned it, probably from tk splashscreen or maybe reading Tk::Wm and trying everything :)

    $mw->overrideredirect(1); $heightwin ->overrideredirect(1); ... $mw->overrideredirect(0); ## 1 #~ 2 3 4 2 3 4 $mw->deiconify; $mw->geometry('+0+0'); $mw->raise; $mw->state('zoomed'); MainLoop;

    It's also pretty slow. It takes about 3 or 4 seconds for 500 rows. I'm thinking about how to speed it up but I'm not sure.

    you can always throw up a splashscreen :) but ~3 seconds is reasonable for me, half of that is loading/perl/tk... the other half is the dlineinfo loop ..

    If you were to startup spreadsheet program or browser its not significantly faster

    You could use dline/bbox on first line, and then guesstimate the width/height for the rest of the lines, but that only probably shaves at most half of ~1.5 seconds (not really sure which part of the dline/matrix equation takes the time, not gonna timeit)

      Thanks, I will play around with those things.
      To be clear, the 3-4 secs is the calculation/display itself.
      This table is refreshed every time the user runs a query (possibly hundreds of times in one session).
      Up until now, I drew the same table by directly inserting text into the TableMatrix widget and setting approximate row heights based on the number of characters in each cell. That took well under half a second for 500 rows. Here, I need to refresh a widget 500 times for the calculation and then draw 500 widgets for display, and this takes 3-4 sec. It's not intolerable as the first ones show up immediately, but it seems like it should be possible to do it quicker.

      Also, when I display a table that takes up the whole screen and then the next search produces only one hit (i.e. only one row needs to be displayed), the hits from the previous search remain there (not all of them, only the top ones that fit on the screen). The TableMatrix widget is correctly resized, but the Text widgets remain there anyway. I tried to update the $mw and the frame the table is in, but that doesn't help. I tried to delete the text from those widgets; the text disappears but the outline of the widget stays. I tried to destroy the widgets and that clears the screen, but it causes an error the next time I try to create a widget in the same cell. I have several columns, so each Text widget is created with
      my @tw; [...] $tw[$row][$col] = $mw->Text()