gtable(来自 R 包 gWidgets2)returns 先前的选择

gtable (from R package gWidgets2) returns previous selection

R 中 gWidgets2 包中的 gtable 小部件 returns 单击新值时以前 selected 的值。如果使用键盘箭头 select 一个值然后回车激活当前 selection 则返回。这对我来说是意想不到的行为。如果这是它应该如何设计的,我怎样才能在这两种情况下获得当前的 selection?

编辑: 使用 gWidgets 似乎可以正常工作,所以它可能是 gWidgets2 中的一个错误。启动一个新的 R 会话并在下面的示例中更改为 gWidgets2 -> gWidgets 和 gvbox -> ggroup。

require(gWidgets2)

# Select by clicking (Clicked) or hit Enter (Changed)
# Move using mouse or arrow keys.

# Create the example (adopted from the gtable example)
w <- gwindow("gtable example", visible=FALSE)
g <- gvbox(cont=w)
tbl <- gtable(mtcars, cont=g, expand=TRUE, fill=TRUE)

addHandlerClicked(tbl, handler = function(h, ...) {

  print("Clicked returns the previously selected value.")

  print(svalue(tbl))

} )

addHandlerChanged(tbl, handler = function(h, ...) {

  print("Changed returns the currently selected value.")

  print(svalue(tbl))

} )

visible(w) <- TRUE

R 版本 3.4.1 (2017-06-30),平台:x86_64-w64-mingw32/x64(64 位),运行 下:Windows 7 x64 (内部版本 7601)服务包 1 包:gWidgets2_1.0-7,gWidgets2RGtk2_1.0-6,RGtk2_2.20.33

@jverzani 在 GitHub https://github.com/jverzani/gWidgets2/issues/94#issuecomment-316739581

上的回答

Sorry, I don't have a good solution here. I thought I did, but can't figure it out. The issue is the gWidgets2 observer is called before the widget is updated. I thought staging the handlers differently would work, but ...

The workaround would be to not connect this way, but rather use addHandlerSelectionChanged This gives single click and keyboard response, but doesn't play nicely with double click. Alternatively, double click is supposed to "activate" the cell initiating a callback, so not assigning to the click handler is possible and just assigning to the change handler gives you double click and keyboard selection, but not single click, which just sets the selection but doesn't initiate a callback.

它似乎在我的应用程序中按预期工作。我在一个地方只使用 addHandlerChanged,在另一个地方只使用 addHandlerSelectionChanged