1. EuGTK - Q: how to show a picture before main()
- Posted by Jerry_Story Aug 02, 2010
- 1589 views
I have the following EuGTK code fragment.
show_all(splash) -- This shows a picture to look at while the data loads. getUSDAdata() -- This takes a few seconds to load the data. hide(splash) -- After the data is loaded, the picture goes away.
What happens is:
1. No picture, data loads, taking a few seconds.
2. After the data is loaded, the picture shows, if I comment out hide(splash).
It ain't supposed to work that way. The purpose of the picture is to tell the user that the computer is doing something and did not hang up.
How can I get the picture to show before the data starts loading?
2. Re: EuGTK - Q: how to show a picture before main()
- Posted by useless Aug 05, 2010
- 1474 views
Did you try threads?
useless
3. Re: EuGTK - Q: how to show a picture before main()
- Posted by jimcbrown (admin) Aug 05, 2010
- 1462 views
Did you try threads?
useless
Won't work. In general, most UI frameworks require that all updates and UI events be processed in a single thread that is dedicated to the UI.
4. Re: EuGTK - Q: how to show a picture before main()
- Posted by jimcbrown (admin) Aug 05, 2010
- 1505 views
I have the following EuGTK code fragment.
show_all(splash) -- This shows a picture to look at while the data loads. getUSDAdata() -- This takes a few seconds to load the data. hide(splash) -- After the data is loaded, the picture goes away.
What happens is:
1. No picture, data loads, taking a few seconds.
2. After the data is loaded, the picture shows, if I comment out hide(splash).
It ain't supposed to work that way. The purpose of the picture is to tell the user that the computer is doing something and did not hang up.
How can I get the picture to show before the data starts loading?
Without your full code, it's hard for me to say, but I'd guess where and how you call gtk_main() is an issue here.
Maybe you can get a better idea of what needs to be done by looking at http://www.gtkforums.com/viewtopic.php?t=1298 and http://faq.pygtk.org/index.py?req=show&file=faq20.005.htp
At least one person gave up and wrote a separate application just to be able to get the splash screen to show up correctly: http://ricochen.wordpress.com/2009/10/12/splash-screen-with-gtk/
5. Re: EuGTK - Q: how to show a picture before main()
- Posted by useless Aug 05, 2010
- 1494 views
Did you try threads?
useless
Won't work. In general, most UI frameworks require that all updates and UI events be processed in a single thread that is dedicated to the UI.
But technically there is no UI, it's a pretty splash screen to gaze in awe and rapture at until the program has started running behind it and gotten initialised. If nothing else, the picture placer code should be able to finish it's task of getting the pic up before the app starts loading, which i think is the intent of the programmer. I do not know why his picture isn't coming up, but i assume if the pic is using all the thread time available and the loading portion isn't given any time to run (because we can control that) until the picture is completely drawn (because we can detect that?), there's still not UI going on, but it keeps the OS from completeing the two tasks out of sequence set by the programmer. Right?
useless
6. Re: EuGTK - Q: how to show a picture before main()
- Posted by Jerry_Story Aug 06, 2010
- 1419 views
Without your full code, it's hard for me to say, but I'd guess where and how you call gtk_main() is an issue here.
The full relevant code is
include GtkEngine.e -- some code here global constant Win = create(GtkWindow) -- some code here constant splash = create(GtkWindow) -- some code here show_all(splash) -- This is supposed to show -before- the data is loaded. getUSDAdata() hide(splash) -- some code here show_all(Win) main() -- But this is where both splash and Win show, if I comment out hide.
7. Re: EuGTK - Q: how to show a picture before main()
- Posted by useless Aug 06, 2010
- 1341 views
But you don't have a function/procedure main().
useless
8. Re: EuGTK - Q: how to show a picture before main()
- Posted by Jerry_Story Aug 07, 2010
- 1374 views
But you don't have a function/procedure main().
useless
main() is in GtkEngine.e
9. Re: EuGTK - Q: how to show a picture before main()
- Posted by jimcbrown (admin) Aug 07, 2010
- 1361 views
Without your full code, it's hard for me to say, but I'd guess where and how you call gtk_main() is an issue here.
The full relevant code is
include GtkEngine.e -- some code here global constant Win = create(GtkWindow) -- some code here constant splash = create(GtkWindow) -- some code here show_all(splash) -- This is supposed to show -before- the data is loaded. getUSDAdata() hide(splash) -- some code here show_all(Win) main() -- But this is where both splash and Win show, if I comment out hide.
Yep, after you call show_all(splash) (and before you call getUSDAdata() or hide(splash) ) you need to call the EuGTK version of this:
while (gtk_events_pending()) { gtk_main_iteration(); }
The GTK code in http://faq.pygtk.org/index.py?req=show&file=faq20.005.htp should show you exactly what you need to do.
10. Re: EuGTK - Q: how to show a picture before main()
- Posted by jimcbrown (admin) Aug 07, 2010
- 1333 views
But technically there is no UI, it's a pretty splash screen
"Technically", a splash screen is a UI. The user can't use it or interface with it, but the same limitations on threads apply.
11. Re: EuGTK - Q: how to show a picture before main()
- Posted by jimcbrown (admin) Aug 07, 2010
- 1413 views
Without your full code, it's hard for me to say, but I'd guess where and how you call gtk_main() is an issue here.
The full relevant code is
include GtkEngine.e -- some code here global constant Win = create(GtkWindow) -- some code here constant splash = create(GtkWindow) -- some code here show_all(splash) -- This is supposed to show -before- the data is loaded. getUSDAdata() hide(splash) -- some code here show_all(Win) main() -- But this is where both splash and Win show, if I comment out hide.
Yep, after you call show_all(splash) (and before you call getUSDAdata() or hide(splash) ) you need to call the EuGTK version of this:
while (gtk_events_pending()) { gtk_main_iteration(); }
The GTK code in http://faq.pygtk.org/index.py?req=show&file=faq20.005.htp should show you exactly what you need to do.
I just tested the following code with EuGTK 4.1.5 and it seems to work. There's probably a more "correct" way of calling gtk_main_iteration() and gtk_events_pending() from EuGTK but I'll let Irv comment on that.
procedure getUSDAdata() integer k k = -1 while k = -1 do k = get_key() end while end procedure include GtkEngine.e include std/dll.e -- some code here global constant Win = create(GtkWindow) -- some code here constant splash = create(GtkWindow) -- some code here constant gtk_events_pending_ = define_c_func(GTK, "gtk_events_pending", {}, C_INT) constant gtk_main_iteration_ = define_c_proc(GTK, "gtk_main_iteration", {}) show_all(splash) -- This shows -before- the data is loaded. while c_func(gtk_events_pending_, {}) do c_proc(gtk_main_iteration_, {}) end while getUSDAdata() hide(splash) -- some code here show_all(Win) main()
12. Re: EuGTK - Q: how to show a picture before main()
- Posted by Jerry_Story Aug 07, 2010
- 1335 views
I just tested the following code with EuGTK 4.1.5 and it seems to work. There's probably a more "correct" way of calling gtk_main_iteration() and gtk_events_pending() from EuGTK but I'll let Irv comment on that.
procedure getUSDAdata() integer k k = -1 while k = -1 do k = get_key() end while end procedure include GtkEngine.e include std/dll.e -- some code here global constant Win = create(GtkWindow) -- some code here constant splash = create(GtkWindow) -- some code here constant gtk_events_pending_ = define_c_func(GTK, "gtk_events_pending", {}, C_INT) constant gtk_main_iteration_ = define_c_proc(GTK, "gtk_main_iteration", {}) show_all(splash) -- This shows -before- the data is loaded. while c_func(gtk_events_pending_, {}) do c_proc(gtk_main_iteration_, {}) end while getUSDAdata() hide(splash) -- some code here show_all(Win) main()
Thanks. That works.
13. Re: EuGTK - Q: how to show a picture before main()
- Posted by irv Aug 16, 2010
- 1294 views
There's another way to do this - see the "FlightGear Helper" demo here: http://etcwebspace.com/users/irvm/flightsim.html