• Issue with text widget command dlineinfo

    From Torsten@21:1/5 to All on Fri Dec 31 05:52:05 2021
    I tried the text widget command 'dlineinfo' in a program and it did not work. The following example can show the issue (Windows 10, tested with 8.6.6, 8.6.10, 8.6.11):
    ------------------------------------------------
    package require Tk

    text .txt1 -width 100 -height 30
    pack .txt1

    .txt1 replace 1.0 end {
    line 2
    line 3 line 3 line 3

    line 5
    line 6 line 6 line 6

    }

    .txt1 tag add tagtest 2.0 3.end
    .txt1 tag add tagtest 5.0 6.end
    .txt1 tag configure tagtest -background #f0f0f0

    foreach {tr1 tr2} [.txt1 tag ranges tagtest] {
    puts "$tr1 $tr2 >>[.txt1 dlineinfo $tr1]<<"
    }
    ------------------------------------------------
    In a wish started in a terminal or in TkCon the initial output is:
    0 3.22 >><<
    5.0 6.22 >><<

    When I repeat the last command, the output changes:
    % foreach {tr1 tr2} [.txt1 tag ranges tagtest] {
    puts "$tr1 $tr2 >>[.txt1 dlineinfo $tr1]<<"
    }
    2.0 3.22 >>2 18 64 16 12<<
    5.0 6.22 >>2 66 64 16 12<<

    Only at the second attempt, dlineinfo returns the values. It always happens in my program. In TkCon it works sometimes.

    What's wrong here?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Torsten on Fri Dec 31 15:12:23 2021
    Torsten <tma012009@googlemail.com> wrote:
    In a wish started in a terminal or in TkCon the initial output is:
    0 3.22 >><<
    5.0 6.22 >><<

    Under Linux, in a terminal, this is the output on the first try:

    2.0 3.22 >>3 17 56 14 11<<
    5.0 6.22 >>3 59 56 14 11<<

    So the lack of output may be a windows issue.

    Only at the second attempt, dlineinfo returns the values. It always
    happens in my program. In TkCon it works sometimes.

    What's wrong here?

    Try an "update" before you do your first attempt under windows. Maybe
    some portion of the update events are not finished running yet when
    your first try occurs.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From nemethi@21:1/5 to All on Fri Dec 31 17:16:52 2021
    Am 31.12.21 um 16:12 schrieb Rich:
    Torsten <tma012009@googlemail.com> wrote:
    In a wish started in a terminal or in TkCon the initial output is:
    0 3.22 >><<
    5.0 6.22 >><<

    Under Linux, in a terminal, this is the output on the first try:

    2.0 3.22 >>3 17 56 14 11<<
    5.0 6.22 >>3 59 56 14 11<<

    So the lack of output may be a windows issue.

    Only at the second attempt, dlineinfo returns the values. It always
    happens in my program. In TkCon it works sometimes.

    What's wrong here?

    Try an "update" before you do your first attempt under windows. Maybe
    some portion of the update events are not finished running yet when
    your first try occurs.


    Not quite right, Rich! You have probably used an interactive tclsh or
    wish. If the script is contained in a file, say, test.tcl, and you
    execute it via "tclsh test.tcl" or "wish test.tcl", then its behavior on
    Linux will be the same as on Windows: on both platforms, the dlineinfo
    result will be an empty string. The reason is contained in the last
    sentence of the description of the dlineinfo command in the "text" man page:

    "If the display line containing _index_ is not visible on the screen
    then the return value is an empty list."

    To get a non-empty dlineinfo result, you have to make sure that the
    display line containing the index passed to the command is visible on
    the screen. You can achieve this by inserting

    tkwait visibility .txt1

    or

    update idletasks

    before the foreach loop.

    --
    Csaba Nemethi https://www.nemethi.de mailto:csaba.nemethi@t-online.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Torsten@21:1/5 to All on Sat Jan 1 02:08:07 2022
    "If the display line containing _index_ is not visible on the screen
    then the return value is an empty list."

    To get a non-empty dlineinfo result, you have to make sure that the
    display line containing the index passed to the command is visible on
    the screen. You can achieve this by inserting

    tkwait visibility .txt1

    or

    update idletasks

    update idletasks solves the problem. Thank you nemethi.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)