Sha256: 543463334cd88c752ff806c55df7e1a2cb135d8aa37c8e5e2ac2d9d22de42455

Contents?: true

Size: 1.13 KB

Versions: 38

Compression:

Stored size: 1.13 KB

Contents

#Containing various helper methods for Gtk2-windows.
class Knj::Gtk2::Window
  require "wref" if !Kernel.const_defined?(:Wref)
  @@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

38 entries across 38 versions & 1 rubygems

Version Path
knjrbfw-0.0.101 lib/knj/gtk2_window.rb
knjrbfw-0.0.100 lib/knj/gtk2_window.rb
knjrbfw-0.0.99 lib/knj/gtk2_window.rb
knjrbfw-0.0.98 lib/knj/gtk2_window.rb
knjrbfw-0.0.97 lib/knj/gtk2_window.rb
knjrbfw-0.0.96 lib/knj/gtk2_window.rb
knjrbfw-0.0.95 lib/knj/gtk2_window.rb
knjrbfw-0.0.94 lib/knj/gtk2_window.rb
knjrbfw-0.0.93 lib/knj/gtk2_window.rb
knjrbfw-0.0.92 lib/knj/gtk2_window.rb
knjrbfw-0.0.91 lib/knj/gtk2_window.rb
knjrbfw-0.0.90 lib/knj/gtk2_window.rb
knjrbfw-0.0.89 lib/knj/gtk2_window.rb
knjrbfw-0.0.88 lib/knj/gtk2_window.rb
knjrbfw-0.0.87 lib/knj/gtk2_window.rb
knjrbfw-0.0.86 lib/knj/gtk2_window.rb
knjrbfw-0.0.85 lib/knj/gtk2_window.rb
knjrbfw-0.0.84 lib/knj/gtk2_window.rb
knjrbfw-0.0.83 lib/knj/gtk2_window.rb
knjrbfw-0.0.82 lib/knj/gtk2_window.rb