Ruby Forum Ruby-Gnome 2 > screen splash

Posted by Martin Vales (martin_gnu)
on 21.04.2008 11:08
Hi:

how can i make an screen splash to see before application was open??


It´s important for me beacuse i need put a company logo. It´s something
like institutional, nor functional.

pd: I am using libglade.

Regards.
Posted by Joachim Glauche (joaz)
on 21.04.2008 12:43
> how can i make an screen splash to see before application was open??
> 
> 
> It´s important for me beacuse i need put a company logo. It´s something
> like institutional, nor functional.
> 
> pd: I am using libglade.

Hi,

Please define "before". Until ruby & gtk is loaded, you cannot do such 
thing. But then it's just a window with an image.
Posted by Martin Vales (martin_gnu)
on 21.04.2008 12:47
Hi:

I have found a PHP GTK sample here:
http://phpexperts.blogspot.com/2007/05/splash-screens-with-php-gtk.html


this is my ruby version.

It works fine but the callback doesnt´s work. Any help?
Someone know like conect a signal inside a class:

class One
 def initialize(callback)
   callback
 end

end

class Main
 def initialize
   One.new("talk_with_me")
 end

 def talk_with_me
   puts "i am here"
 end

end


GTK version by now:
_________________________________________________
require 'gtk2'

class SplashScreen < Gtk::Window

  def initialize(img_dir,callback)
    super(Gtk::Window::POPUP)
    self.window_position=Gtk::Window::POS_CENTER
    vbox=Gtk::VBox.new
    img=Gtk::Image.new(img_dir)
    vbox.pack_start(img,false,false)
    self.add(vbox)
    self.show_all
    Gtk.timeout_add(100) {
      callback
    }
  end


  def hide
    self.hide
  end
end




class Application

  def initialize
    @splash=SplashScreen.new("screen.png","end_splash")

  end


  def end_splash
    @splash.hide
    puts "i am not here!!!"
  end
end


Application.new

Gtk.main
Posted by Martin Vales (martin_gnu)
on 21.04.2008 12:54

Hi:
>
> Hi,
>
> Please define "before". Until ruby & gtk is loaded, you cannot do such 
> thing. But then it's just a window with an image.

I know, i don´t need create a screen splash professional and real. The 
most important is the company logo, because the software is a fake :-D . 
it´s only for publicity.


thanks.
Posted by Joachim Glauche (joaz)
on 21.04.2008 12:55
> It works fine but the callback doesnt´s work. Any help?
> Someone know like conect a signal inside a class:
Sure it doesn't work like. You're giving a string parameter to the 
Splashscreen class. You can't expect a String to call a function :)

Try using blocks:

def initialize(img_dir,&callback)
[...]
   Gtk.timeout_add(100) {
      callback.call
    }
end


And then
@splash=SplashScreen.new("screen.png"){
  end_splash
}
Posted by Martin Vales (martin_gnu)
on 21.04.2008 13:13
thanks joaz:

this is my final version of the fake:
I have added a timeout remove because create infinite windows, and i 
have added a time parameter to be configurable.


require 'gtk2'

class SplashScreen < Gtk::Window

  def initialize(img_dir,time,&callback)
    super(Gtk::Window::POPUP)
    self.window_position=Gtk::Window::POS_CENTER
    vbox=Gtk::VBox.new
    img=Gtk::Image.new(img_dir)
    vbox.pack_start(img,false,false)
    self.add(vbox)
    self.show_all
    @id_timeout=Gtk.timeout_add(time) {
      callback.call
    }
  end


  def hide_splash
    self.hide
    Gtk.timeout_remove(@id_timeout)

  end
end




class Application

  def initialize
    @splash=SplashScreen.new("screen.png",1000){
    end_splash
    }

  end


  def end_splash
    @splash.hide_splash
    @window=Gtk::Window.new
    @window.signal_connect("destroy") { Gtk.main_quit }
    @window.window_position=Gtk::Window::POS_CENTER
    @window.show_all
  end
end


Application.new

Gtk.main

Posted by Guillaume Cottenceau (Guest)
on 21.04.2008 17:12
(Received via mailing list)
>  Application.new
>
>  Gtk.main

this part is probably dangerous. your Application object is normally
reclaimable by the garbage collector, as you hold no references on it
when you trigger Gtk.main.

--
Guillaume Cottenceau - http://zarb.org/~gc/
Posted by Martin Vales (martin_gnu)
on 21.04.2008 17:55
Guillaume Cottenceau wrote:
>>  Application.new
>>
>>  Gtk.main
> 
> this part is probably dangerous. your Application object is normally
> reclaimable by the garbage collector, as you hold no references on it
> when you trigger Gtk.main.
> 
> --
> Guillaume Cottenceau - http://zarb.org/~gc/

Thanks Guillaume. I don´t know the garbage collector system in ruby.

What is it a better solution then??


Posted by Detlef Reichl (Guest)
on 21.04.2008 18:48
(Received via mailing list)
Am Montag, den 21.04.2008, 12:47 +0200 schrieb Martin Vales:
>     super(Gtk::Window::POPUP)

Popups are only intended for things like menus or tooltips.

Better use

your_window.decorated = false

Cheers, detlef
Posted by Guillaume Cottenceau (Guest)
on 22.04.2008 11:15
(Received via mailing list)
On Mon, Apr 21, 2008 at 5:55 PM, Martin Vales
<ruby-forum-incoming@andreas-s.net> wrote:
>  > --
>  > Guillaume Cottenceau - http://zarb.org/~gc/
>
>  Thanks Guillaume. I don´t know the garbage collector system in ruby.
>
>  What is it a better solution then??

You just need to retain a reference on your object. As the application
is global to the program, I find the use of global variables logical,
so I can do like:

$app = Application.new

--
Guillaume Cottenceau - http://zarb.org/~gc/