Reputation: 33
How can I change gbutton text without run the function associated to its handler?
Consider the following code:
library(gWidgets2)
w <- gwindow("Buttons", visible=FALSE)
g <- ggroup(cont=w, horizontal=FALSE)
b2 <- gbutton("ouvrir", cont=g)
## with a handler
b4 <- gbutton("click me",
handler=function(h,...) {
if(svalue(b2) == "open")
svalue(b2) <- "ouvrir"
else
svalue(b2) <- "open"
},
action = NULL, cont=g)
visible(w) <- TRUE
svalue(b4) <- "Please not call the handler!!"
In gWidgets2 when I change the text of a button through the svalue() command, the button handler is called! However, I would like to call the handler just when the button is clicked. Any suggestion to solve this situation.
Thanks in advance.
Upvotes: 0
Views: 247
Reputation: 5700
The code calls invoke_change_handler()
when setting the label. There are a few ways to work around this:
Block handlers before setting (blockHandlers
) then unblock (unblockHandlers
)
Ir you could grab the underlying widget and set the text, in RGtk2 with gWidgets2 something like obj$widget$setText("new value")
should work.
Upvotes: 1