1. EuGTK - Q: how to show a picture before main()

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?

new topic     » topic index » view message » categorize

2. Re: EuGTK - Q: how to show a picture before main()


Did you try threads?

useless

new topic     » goto parent     » topic index » view message » categorize

3. Re: EuGTK - Q: how to show a picture before main()

useless said...


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.

new topic     » goto parent     » topic index » view message » categorize

4. Re: EuGTK - Q: how to show a picture before main()

Jerry_Story said...

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/

new topic     » goto parent     » topic index » view message » categorize

5. Re: EuGTK - Q: how to show a picture before main()

jimcbrown said...
useless said...


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

new topic     » goto parent     » topic index » view message » categorize

6. Re: EuGTK - Q: how to show a picture before main()

jimcbrown said...

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. 
new topic     » goto parent     » topic index » view message » categorize

7. Re: EuGTK - Q: how to show a picture before main()


But you don't have a function/procedure main().

useless

new topic     » goto parent     » topic index » view message » categorize

8. Re: EuGTK - Q: how to show a picture before main()

useless said...


But you don't have a function/procedure main().

useless

main() is in GtkEngine.e

new topic     » goto parent     » topic index » view message » categorize

9. Re: EuGTK - Q: how to show a picture before main()

Jerry_Story said...
jimcbrown said...

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.

new topic     » goto parent     » topic index » view message » categorize

10. Re: EuGTK - Q: how to show a picture before main()

useless said...

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.

new topic     » goto parent     » topic index » view message » categorize

11. Re: EuGTK - Q: how to show a picture before main()

jimcbrown said...
Jerry_Story said...
jimcbrown said...

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() 
new topic     » goto parent     » topic index » view message » categorize

12. Re: EuGTK - Q: how to show a picture before main()

jimcbrown said...

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.

new topic     » goto parent     » topic index » view message » categorize

13. Re: EuGTK - Q: how to show a picture before main()

There's another way to do this - see the "FlightGear Helper" demo here: http://etcwebspace.com/users/irvm/flightsim.html

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu