vtkTkRenderWidget key binding
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
A CharEvent is fired into VTK for each KeyRelease and KeyPress. From /vtkinteraction/bindings.tcl:
proc cb_vtkw_key_binding {vtkw renwin x y ctrl shift event keycode keysym} {
set iren [$renwin GetInteractor]
# Not a bug, two times keysym, since 5th param expect a char, and
# $keycode is %k, which is a number
$iren SetEventInformationFlipY $x $y $ctrl $shift $keysym 0 $keysym
$iren Key${event}Event
$iren SetEventInformationFlipY $x $y $ctrl $shift $keysym 0 $keysym
$iren CharEvent
}
Two possible solutions:
- Fire a CharEvent only with a KeyPress event.
- Change the OnChar method in vtkInteractorStyle to a OnKeyPress method
Here a script to illustrate:
Example to illustrate bug with picking in a
vtkTkRenderWidget. For every one "p" key-press
there are two pick events triggered.
package require vtk package require vtkinteraction
vtkSphereSource sphere vtkPolyDataMapper sphereMapper sphereMapper SetInput [sphere GetOutput] vtkActor sphereActor sphereActor SetMapper sphereMapper
vtkTextMapper textMapper [textMapper GetTextProperty] SetColor 1 0 0 vtkActor2D textActor textActor SetMapper textMapper
vtkRenderer renderer renderer AddActor sphereActor renderer AddActor2D textActor renderer SetBackground 1 1 1 vtkRenderWindow renWin renWin AddRenderer renderer
set vtkw [vtkTkRenderWidget .ren
-width 300
-height 300
-rw renWin]
::vtk::bind_tk_render_widget $vtkw
button .quit -text "Quit" -command ::vtk::cb_exit pack $vtkw -side top -fill both -expand yes pack .quit -side top -fill x
#this is a work around #bind $vtkw <KeyRelease> { }
vtkCellPicker cellPicker [renWin GetInteractor] SetPicker cellPicker set picker [[renWin GetInteractor] GetPicker] $picker AddObserver EndPickEvent cbPick set numPick 0
proc cbPick {} { global numPick incr numPick textMapper SetInput "Number of Pick Events: $numPick" renWin Render }
wm protocol . WM_DELETE_WINDOW ::vtk::cb_exit