tcltk: Как получить другую подсказку для ячеек сетки? - PullRequest
0 голосов
/ 04 мая 2020

I sh, чтобы показать всплывающую подсказку только для ячеек сетки, где текст не помещается в пределах ограниченной ширины. В настоящее время для ячеек, где текст соответствует , подсказка не появляется, что я и хочу. Проблема заключается в том, что всякий раз, когда я наводю указатель мыши на подчеркнутый текст, он всегда показывает самый последний текст всплывающей подсказки, который был set.

. sit amet, co "должен быть полный текст," Lorem ipsum dolor sit amet, consitteur adipiscing elit ", но вместо этого он показывает полный текст, предназначенный для другой подсказки," sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ".

enter image description here

  1. Что я делаю не так, или это вообще возможно?

  2. Есть ли встроенный способ для переноса текста всплывающей подсказки, или мне нужно свернуть свой собственный код переноса (что я могу сделать).

Я новичок в tcltk, так если есть явные проблемы с кодом, буду признателен.

Вот код, который генерирует вышеописанное. Я тестирую на ActiveTCL 8.6.8, но это также будет использоваться на компьютерах Ma c и Linux.

package require tooltip

set wmGeometry "52x20+0+139"

set WrapLines "none"

set gridTextWidth 50

font create FixedFont -family 8514oem -size 12 -weight normal -slant roman -underline 0 -overstrike 0

set colWidth1 10
set colWidth2 10
set colWidth3 10
set colWidth4 30

wm title . "Grid Cell Tooltip Test"
wm protocol . WM_DELETE_WINDOW exit
menu .menubar
. configure -menu .menubar
set headings ""
append headings [format "%-${colWidth1}.${colWidth1}s%s" "Column1" " "]
append headings [format "%-${colWidth2}.${colWidth2}s%s" "|Column2" " "]
append headings [format "%-${colWidth3}.${colWidth3}s%s" "|Column3" " "]
append headings [format "%-${colWidth4}.${colWidth4}s%s" "|Column4" " "]

ttk::label .la -text $headings -justify left -font FixedFont
grid .la -row 1 -sticky w -columnspan 2
set m .menubar
menu $m.file
$m add cascade -menu $m.file -label File
$m.file add command -label Quit -command {exit}

text .vh -width $gridTextWidth -height 4 -yscrollcommand ".ys set" \
    -state disabled -setgrid 1 -wrap $WrapLines -font FixedFont
grid [ttk::scrollbar .ys -command ".vh yview"] \
      -column 1 -row 0 -sticky ns -pady 10 -padx 5
grid .vh -row 2 -sticky nsew -padx 2 -pady 2
grid .ys -row 2 -column 1 -sticky ns -pady 2

grid columnconfigure . 0 -weight 1
grid rowconfigure . 2 -weight 1

update

wm geometry . $wmGeometry

.vh configure -state normal

for {set count 1} {$count < 11} {incr count} {

    set colText1 [format "%-${colWidth1}.${colWidth1}s" [string repeat "A" $count]]
    set colText2 [format "%-${colWidth2}.${colWidth2}s" [string repeat "B" $count]]
    set colText3 [format "%-${colWidth3}.${colWidth3}s" [string repeat "C" $count]]
    set colText4 [format "%-${colWidth4}.${colWidth4}s" [string repeat "D" $count]]

    set longtext ""

    if {$count eq 3} {
       set longtext "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
       set colText4 [format "%-${colWidth4}.${colWidth4}s" "$longtext"]
    } else {
      if {$count eq 7} {
         set longtext "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
         set colText4 [format "%-${colWidth4}.${colWidth4}s" "$longtext"]
      }
    }

    .vh insert end "$colText1 "   col1tag \
                   "$colText2 "   col2tag \
                   "$colText3 "   col3tag

    if {$longtext != ""} {
       .vh tag configure tiptag -underline 1
       ::tooltip::tooltip .vh -tag tiptag "$longtext"  
       .vh insert end "$colText4" tiptag 
    } else {
       .vh tag configure col4tag -underline 0
       .vh insert end "$colText4" col4tag
    }

    .vh insert end "\n"

}

.vh yview moveto 1.0
.vh configure -state disabled
if {[lindex [.vh yview] 0] + [lindex [.vh yview] 1] == 1.0} {
    grid .ys
}

vwait forever
...