Class: Knj::Gtk2::Window

Inherits:
Object show all
Defined in:
lib/knj/gtk2_window.rb

Overview

Containing various helper methods for Gtk2-windows.

Constant Summary collapse

@@uniques =
Wref::Map.new

Class Method Summary collapse

Class Method Details

.get(id) ⇒ Object

Returns the object if it hasnt been destroyed.

Examples

Knj::Gtk2::Window.get(“my_window”) #=> nil Knj::Gtk2::Window.get(“my_window”) #=> Gtk::Builder-object



32
33
34
35
36
37
38
39
40
# File 'lib/knj/gtk2_window.rb', line 32

def self.get(id)
  instance = @@uniques.get!(id)

  if instance and !instance.gui["window"].destroyed?
    return instance
  end

  return nil
end

.unique!(id) ⇒ Object

Used to make a window-instance unique. If it already exists when unique! is called, then it will pass focus to the existing window instead of yielding the block, which should contain code to create the window.

Examples

This should only create a single window. Knj::Gtk2::Window.unique!(“my_window”) do

Gtk::Window.new

end

Knj::Gtk2::Window.unique!(“my_window”) do

Gtk::Window.new

end



17
18
19
20
21
22
23
24
25
26
# File 'lib/knj/gtk2_window.rb', line 17

def self.unique!(id)
  instance = @@uniques.get!(id)

  if instance and !instance.gui["window"].destroyed?
    instance.gui["window"].present
  else
    obj = yield
    @@uniques[id] = obj
  end
end