问题
I have written a GUI in R with RGTK2 and Tcltk that does a lot of fairly heavy calculations and aggregations on big data sets.
I would like to find a way to stop the user interface from accepting user inputs while it is processing a large data set, and ideally, change the interface color, popup a dialogue, or change the mouse pointer to an hourglass/spinner to indicate to users that the application is active.
The implementation that I want would look something like:
gSignalConnect(bigRedButton,"clicked",
f=function(widget)
{
something$start() # object with method that blocks further user input
# and pops up loading bar or "Processing" dialogue
# (or possibly spins the mouse)
# Code that does a very big set of calculations
something$stop() # unblocks user inputs and removes visual impedance
}
)
I have tried using gtkDialogue to solve the problem, but this seems to stop execution of the whole program until one closes the dialogue, which rather defeats the purpose.
Any help would be greatly appreciated.
回答1:
So the magic method is gtkWidgetSetSensitive:
gSignalConnect(bigRedButton,"clicked",
f=function(widget)
{
gtkWidgetSetSensitive(Window,FALSE)
# Code that does a very big set of calculations
gtkWidgetSetSensitive(Window,TRUE)
}
)
This method turns the targeted widget (which can be an individual button, textEntry, comboBox, etc...) gray and blocks input.
来源:https://stackoverflow.com/questions/19061986/rgtk2-block-user-input-while-processing