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

I still can't get dlineinfo to work. It works in the code you posted, but in my own code, which does the same thing as far as I can tell, it only works if the index is 1.0. I have no idea what is going on.
use strict; use warnings; use Tk; my $mw = Tk::MainWindow->new; $mw->geometry('400x300'); my $tw = $mw->Text(-wrap=>'word')->pack(qw/ -expand 1 -fill both /); $tw->insert('end', q{"There must be some kind of way out of here," Said the joker to the +thief. "There's too much confusion, I can't get no relief. Businessme +n, they drink my wine, Plowmen dig my earth. None of them along the l +ine Know what any of it is worth." "No reason to get excited," The th +ief he kindly spoke. "There are many here among us Who feel that life + is but a joke. But you and I, we've been through that, And this is n +ot our fate. So let us not talk falsely now, The hour is getting late +." All along the watchtower, Princes kept the view, While all the wom +en came and went -- Barefoot servants too. Outside in the cold distan +ce, A wildcat did growl. Two riders were approaching, and The wind be +gan to howl. http://www.reasontorock.com/tracks/watchtower.html}); $tw->pack(); my @indexes = qw/ 1.0 1.11 1.20 /; for my $index (@indexes) { my @dline = $tw->dlineinfo("$index wordstart"); print "dline info for $index: " . join (' ', @dline) . "\n"; } MainLoop;


dline info for 1.0: 3 3 7 1 11 dline info for 1.11: dline info for 1.20:

Replies are listed 'Best First'.
Re^4: Query the height of Tk::Text widget with word wrap
by Anonymous Monk on Dec 01, 2013 at 13:04 UTC

    This part response to Re^2: Query the height of Tk::Text widget with word wrap

    This part response to Re^3: Query the height of Tk::Text widget with word wrap

    I still can't get dlineinfo to work.

    Remember how I (my program) had a button? Meaning you only (it only) call dlineinfo after MainLoop starts and draws everything on screen?

    If the widgets (text ...) aren't drawn, dlineinfo can't return coordinates ... so if you want it to work in this program you need to draw the widget, you need $tw->update; before dlineinfo stuff

    I used $tw->update; print "now its drawn, now it will be visible\n"; sleep 1;

    The window can be located off-the-monitor while the initial drawing takes place :)  $mw->geometry('-1000-1000');

      Thanks, ->update fixes it.
      I now have a simple script that automatically sets the correct height on rows based on the pixel values from dlineinfo. However, it only works on the cells that are in the screen; it fails on the cells that are off the bottom.
      I could cycle through all the cells, putting the contents of each one into cell 0,0 (first row), storing the required height for each one. Then I could draw the final table with those values. But I would probably get a lot of flickering as the cell is refreshed. I can't just move the $mw off the screen because it's visible already when this process starts. Maybe I could try creating a new toplevel and withdrawing it right away... but of course that only works if dlineinfo returns values from a withdrawn window. Perhaps create a new toplevel, move it off the screen and try to hide the icon in the taskbar somehow? Perhaps use a Dialog instead of a toplevel window so I don't get a taskbar icon?
      I'll be trying these things but I'd be grateful for tips in case they don't work or there is a better option.
        well, you only need one single appropriately sized text widget to determine how the wraps wrap before adjusting the matrix ... and yes it can be off-screen as long as its being drawn ...