Sha256: 6b0ba8c8c7448ca153af8cf0a294dbe73fd91fc3e75c38281def2114e18fc9ed

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

Knj.gem_require(:wref)

#Containing various helper methods for Gtk2-windows.
class Knj::Gtk2::Window
  @@uniques = Wref::Map.new

  #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
  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

  #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
  def self.get(id)
    instance = @@uniques.get!(id)

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

    return nil
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
knjrbfw-0.0.116 lib/knj/gtk2_window.rb
knjrbfw-0.0.115 lib/knj/gtk2_window.rb
knjrbfw-0.0.114 lib/knj/gtk2_window.rb
knjrbfw-0.0.113 lib/knj/gtk2_window.rb
knjrbfw-0.0.111 lib/knj/gtk2_window.rb