Stefan JansevanRensburg <Stefan.JansevanRensburg <at> resbank.co.za> writes:
> Dear list, > > Using gWidgets, I'm trying to construct a simple GUI where a user can select a variable (in a data.frame) > from a drop-down list and then set a limit using a spin-button. Additionally, I want the default to, from > and value arguments of the spin-button to equal the min, max and mean of the selected variable, respectively. > > How do I get the spin-button to update when the user selects a different variable from the drop-down list? There are no methods in gWidgets to update the spinbutton values. (Should be though. What is the right API, perhaps [<- checking that the sequence is regular?) In the meantime, I can think of a few possibilities: 1) pack the spinbox in a ggroup container, then to update it delete the old one, add a new one. Any handlers would need to be added again, so you would need to do some bookkeeping. With a default handler, it would look like this: library(gWidgets) w <- gwindow() g <- ggroup(cont = w) sb <- gspinbutton(cont = g, handler = defaultHandler) delete(g, sb) [1] TRUE sb1 <- gspinbutton(from=1, to = 10, by = .5, cont = g, handler=defaultHandler) # replace with another 2) if you are using just one toolkit, say RGtk2, then you can access the toolkit object with getToolkitWidget and update that. For RGtk2, this might look like the following: library(gWidgets) options(guiToolkit="RGtk2") w <- gwindow() sb <- gspinbutton(from=0,to=100, by = 10, value=20, cont = w) ## Gtk code to modify library(RGtk2) sbwidget <- getToolkitWidget(sb) sbwidget$setRange(0,50) sbwidget$setIncrements(1,5) sbwidget$setValue(10) > > Here is my amateurish attempt at doing this, but the results are not satisfactory, since it simple keeps > adding new spin buttons and it doesn't start up with a spin button. > > .simple <- function(x){ > addSpin <- function(h, ...){ > data <- eval(parse(text = paste("x$", svalue(varis), sep = ""))) > spin <- gspinbutton(from = min(data), to = max(data), value = > mean(data)) > add(mainG, spin) > } > win <- gwindow("Example") > mainG <- ggroup(horizontal = FALSE, container = win) > varis <- gdroplist(names(x), container = mainG) > addhandlerchanged(varis, handler = addSpin) > } > > Any help whatsoever would be most appreciated. > > Kind regards, > > Stefan Janse van Rensburg > Macroprudential Division > Financial Stability Department > SARB > Tel : 012-313 4687 > Fax : 012 313 4772 > > [[alternative HTML version deleted]] > _______________________________________________ R-SIG-GUI mailing list R-SIG-GUI@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-gui