tags:

views:

63

answers:

2

I'm trying to get a Gtk::Spinner object to display while calculations are in progress but nothing appears to be happening. The snippet of code looks like...

{
    Gtk::Spinner spinner;
    spinner.start (); 
    // do some work...
    spinner.stop ();
}

I'd have thought the spinner needed to know which dialogue it appears over but I can't see any way of feeding that into the object. Does anyone know where I could find a worked example? I can find the Gtk documentation in many places, but that isn't helping much.

+2  A: 

Did you call

spinner.show ();

and add it to some window?

Moreover, your calculations may block the UI, so it is not updated. Call

while (Gtk::Main::events_pending ())
    Gtk::Main::iteration ();

once in a while.

el.pescado
Thanks for your suggestion. Now I've done spinner.show(), I realise perhaps I'm barking up the wrong tree. The spinner is the thing the arrow cursor turns into while the program's doing something, no? What Motif people call a watch-cursor? If not, what is that other thing called?
Brian Hooper
Nope, the spinner is a widget like the thing that appears in the tabs of many popular browsers while the page is loading, sometimes called a "throbber". See my answer for what you want.
ptomato
@el.pescado, thank you for your help; I've no doubt your answer would have solved the question I asked, but sadly the question I asked wasn't what I needed to know. Thank you all the same.
Brian Hooper
+1  A: 

To change the mouse cursor to "busy" you can do the following:

Glib::RefPtr<Gdk::Window> window = dialog.get_window();
if(window) {
    window->set_cursor(Gdk::Cursor(Gdk::WATCH));
    Gdk::flush();
}

To change it back, do

window->set_cursor();

instead.

Disclaimer: I usually work with GTK in C, and have translated this on the fly...

ptomato
Thanks for the tip, ptomato. I've looked through the documentation and what you suggest appears to be what was intended. Sadly, when I do it, it makes no difference. Is there anything that needs to be done elsewhere (I tracked the execution through the if-block with a diagnostics, and tried a selection of widgets including the main dialogue for the get_window method).
Brian Hooper
Oops, sorry... forgot `Gdk::flush()`. See edited answer.
ptomato
Thank you, ptomato, that's done the trick. It would have been a good long while before I found that particular fact.
Brian Hooper