在gWidgets中切换一组图标 [英] toggling a group of icons in gWidgets

查看:93
本文介绍了在gWidgets中切换一组图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

适应示例我可以切换显示这样的图标:

Adapting an example I can toggle the display of an icon like this:

reject <- "D:/Pictures/web/close32.png"
accept <- "D:/Pictures/web/open32.png"
w= gwindow()
g1 <- ggroup(horizontal=TRUE, cont=w)
icon <- gimage(reject,cont=g1)
state <- FALSE # a global
changeState <- function(h,...) {
   if(state) {
     svalue(icon) <- reject
     } else {
       svalue(icon) <- accept
       }
   state <<- !state
}
addHandlerClicked(icon, handler=changeState)

但是,我想让它与一组图标一起使用 示例3x3图标分组http://cran.r-project. org/web/packages/gWidgets/vignettes/gWidgets.pdf 这样就可以切换每个图标,并且我可以将图标的状态作为矢量进行检索.目的是创建一个图形选择器,以选择要进行分析的观察对.这是我的尝试.它正确显示,但不响应单击以更改状态.我认识到我很困惑处理程序和操作参数如何共同起作用,并且希望对此代码进行任何澄清和修复.

However, I would like to get this to work with a group of icons example 3x3 icon grouping http://cran.r-project.org/web/packages/gWidgets/vignettes/gWidgets.pdf so that each icon can be toggled and I can retrieve the state of the icons as a vector. The purpose is to create a graphical selector for picking pairs of observations to perform analysis on. Here is my attempt. It displays correctly, but does not respond to clicks to change the state. I recognize that I am confusing how the handler and action parameters act together and would appreciate any clarifications and fixes for this code.

reject <- "D:/Pictures/web/close32.png"
accept <- "D:/Pictures/web/open32.png"
w= gwindow()
g1 <- ggroup(horizontal=TRUE, cont=w)
lyt <- glayout(cont=g1, spacing=10)
icon <- rep(reject,times=9)
state <- rep(FALSE, times=9)

changeState <- function(h,...) {
  if(state[index]) {
    svalue(icon[index]) <- reject
  } else {
    svalue(icon[index]) <- accept
  }
  state[index] <<- !state[index]
}

for(i in 1:3){
  for(j in 1:3){
    ind <- (i-1) * 3 +j
    lyt[i,j] <- gimage(icon[ind], cont=lyt)
    addHandlerClicked(lyt[i,j], handler=changeState, action= index <-ind)
  }  
}

1 c: http://i.stack.imgur.com/4kbwK.png

推荐答案

必须从处理程序(index <- h$action)中的h$action检索index值.同样,该位action=index <- ind仅需要为action=ind.

The index value must be retrieved from h$action in your handler (index <- h$action). As well, this bit action=index <- ind need only be action=ind.

这篇关于在gWidgets中切换一组图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆