【问题标题】:Tcl Tk double click binding is blocked by another bindingTcl Tk 双击绑定被另一个绑定阻止
【发布时间】:2017-07-05 06:33:44
【问题描述】:

我使用 tcl 8.6

我有两个表格列表(由 Nehmeti 提供):

set pfd(frMain) [frame $fr.frMain]
set pfd(bottomFr) [frame $pfd(frMain).bfr]
set pfd(panWin) [panedwindow $pfd(bottomFr).pw -showhandle 1 -orient vertical -sashpad 0 -sashrelief raised -sashwidth 2]
set pfd(frKlaffNeupkt) [frame $pfd(panWin).frKlaffNeupkt]
pack $pfd(frMesswerte)   -anchor nw -expand 0 -fill both
pack $pfd(frKlaffNeupkt) -anchor nw -expand 0 -fill both
pack $pfd(panWin) -anchor nw -expand 1 -fill both
$pfd(panWin) add $pfd(frMesswerte) $pfd(frKlaffNeupkt)
set pfd(tali_mw) [tablelist::tablelist $pfd(frMesswerte).li.tali_mw \
                  -columns {0 "oid" l \
                            0 "status" l \             
                            0 "art" l \
                            0 "sollTyp" l \
                            0 "Nr" l \
                            0 "Typ" l \
                            0 "Gst" l \
                            0 "Hz" r \
                            0 "V" r \
                            0 "S" r \
                            0 "Q" r \
                            0 "L" r \
                            0 "AK" l\
                            0 "LSEX" l \
                            0 "lfdNrGes" l}\
                  -exportselection 0 \
                  -labelbackground #EEEEEE \
                  -background white \
                  -labelfont $tableheadfont\ 
                  -font $tableinhfont\
                  -stretch 12\
                  -selectbackground $vmVConfig::setVar(activeBG) \
                  -selectforeground $vmVConfig::setVar(activeFG) \
                  -selectmode single\
                  -borderwidth 1 \
                  -labelborderwidth 1 \
                  -selectborderwidth 0 \
                  -tooltipaddcommand [::itcl::code $this tooltipAddCmd] \
                  -tooltipdelcommand [::itcl::code $this tooltipDelCmd] \
                  -xscrollcommand [list vmTkTools::configSB "h" $pfd(mw_scrx)]\
                  -yscrollcommand [list vmTkTools::configSB "v" $pfd(mw_scry)]]


set pfd(noteb) [iwidgets::notebook $pfd(frKlaffNeupkt).noteb]
pack $pfd(noteb) -anchor nw -expand 1 -fill both
set pfd(frKlaffungen) [$pfd(noteb) add -label Klaffungen]

set pfd(tali_klaff) [tablelist::tablelist $pfd(frKlaffungen).li.tali_klaff \
                      -columns {0 "oid" l 0 "Nr" l 0 "dX" r 0 "dY" r 0 "GwX" r 0 "GwY" r 0 "Rdz" r 0 "lfdNrGes" r}\
                      -exportselection 0 \
                      -labelbackground #EEEEEE \
                      -background white \
                      -labelfont $tableheadfont\
                      -font $tableinhfont\
                      -stretch 7\
                      -selectbackground $vmVConfig::setVar(activeBG) \
                      -selectforeground $vmVConfig::setVar(activeFG) \
                      -selectmode single\
                      -labelrelief groove \
                      -borderwidth 1 \
                      -labelborderwidth 1 \
                      -selectborderwidth 0 \
                      -xscrollcommand [list vmTkTools::configSB "h" $pfd(klaff_scrx)]\
                      -yscrollcommand [list vmTkTools::configSB "v" $pfd(klaff_scry)]]

两个表列表都有绑定:

set body [$pfd(tali_mw) bodypath]
bind $body <Button-1> +[::itcl::code $this klickZeile %x %y %W]
bind $body <Double-1> +[::itcl::code $this doubleKlickMesswerte %x %y %W]

set body [$pfd(tali_klaff) bodypath]
bind $body <Button-1> [::itcl::code $this klickZeile %x %y %W]

方法klickZeile看起来像这样

itcl::body vmMaskHelmert::klickZeile {x y W} {
   puts "klickZeile"

   delCommonKreuz

   foreach {pfad xC yC} [tablelist::convEventFields $W $x $y] {}
   set row    [$pfad containing $yC]
   if {$row == -1} {
      set row end
   }

   if {[string first "tali_mw" $W] != -1} {
      # select the row
      $pfd(tali_mw) activate $row
      $pfd(tali_mw) selection clear 0 end
      $pfd(tali_mw) selection set $row $row
      anzeigePpMp
   } else {
      $pfd(tali_klaff) activate $row
      $pfd(tali_klaff) selection clear 0 end
      $pfd(tali_klaff) selection set $row $row
      anzeigePpMp4Klaff
   }
   return
}

看来,方法 klickZeile 阻止了我的双击绑定,方法 doubleKlickMesswerte 没有被调用。

在 klickZeile 中选择了两个表列表中的两个对应行。

我试图用“activate $row, selection clear 0 end and selection set $row $row”注释掉这两个块。在这种情况下,正在调用 doubleKlickMesswerte,但不幸的是方法 klickZeile 无法正常工作。似乎在这种情况下,该方法会为之前选择的行选择相应的行。

所以我有两个问题:

如何防止方法 klickZeile 阻止双击绑定? 或者,如果没有办法,我该怎么做才能使“klickZeile”方法在没有额外选择和激活的情况下正常工作?

感谢您的帮助!

【问题讨论】:

    标签: binding tcl selection tk


    【解决方案1】:

    没有修饰符(如 Control)的鼠标点击事件(至少单/双/三)将在设置绑定到三重并且用户三击目标元素时全部触发。 GUI 无法预测另一次点击即将到来。它必须先调度单击事件,然后是双击事件,然后是三击事件。

    最好的选择是使用修饰符,例如 a ,因为这是唯一的并且不依赖于顺序,只要先按下 Control 按钮即可;)

    proc doClick { widget } {
        puts "You clicked [$widget cget -text]"
    }
    
    proc doControlClick { widget } {
        puts "You control-clicked [$widget cget -text]"
    }
    
    set label_1 [label .l1 -text "This is label 1"]
    pack $label_1 -side top -fill both
    
    
    bind $label_1 <Control-Button-1> { doControlClick %W }
    bind $label_1 <Button-1> { doClick %W }
    

    【讨论】:

      猜你喜欢
      • 2022-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      相关资源
      最近更新 更多