UI::PollInput — Checks for pending user input. Does not wait. Returns a widget ID or nil if no input is available.
PollInput() is very much like UserInput(), but it doesn't wait. It only checks if there is a user event pending - the user may have clicked on a button since the last call to PollInput() or UserInput().
If there is one, the ID of the widget (usually a button unless other widgets have the notify option set) is returned. If there is none, nil (the YCP value for "nothing", "invalid") is returned.
Use PollInput() to check if the user wishes to abort operations of long duration that are performed in a loop. Notice that PollInput() will result in a "busy wait", so don't simply use it everywhere instead of UserInput().
Notice there is also TimeoutUserInput() and WaitForEvent() that both accept a millisecond timeout argument.
// PollInput.ycp // // Example for common usage of UI::PollInput() { // Build dialog with two labels and a "stop" button. integer count = 0; integer count_max = 10000; UI::OpenDialog( `VBox( `Label( "Calculating..." ), `Label(`id(`count ), sformat( "%1 of %2", count, count_max ) ), `PushButton(`id(`stop), "&Stop" ) ) ); any widget_id = nil; // Event loop repeat { widget_id = UI::PollInput(); // Simulate heavy calculation sleep(200); // milliseconds // Update screen to show that the program is really busy count = count + 1; UI::ChangeWidget(`id(`count), `Value, sformat( "%1 of %2", count, count_max ) ); UI::RecalcLayout(); // Might be necessary when the label becomes wider } until ( widget_id == `stop || count >= count_max ); UI::CloseDialog(); }