Sha256: f2a7f7cf7c6d2537f3d91002364acf6415b77c127dc87bf232c9f210a1393bcb

Contents?: true

Size: 1.74 KB

Versions: 30

Compression:

Stored size: 1.74 KB

Contents

module Knj::Gtk2::Cb
  def self.init(paras)
    return paras["cb"].init(paras["items"])
  end
  
  def self.sel(cb)
    return cb.sel
  end
end

class Gtk::ComboBox
  def init(items)
    @knj = {
      "items" => []
    }
    
    ls = Gtk::ListStore.new(String, String)
    cr = Gtk::CellRendererText.new
    self.pack_start(cr, false)
    self.add_attribute(cr, "text", 0)
    
    if items.is_a?(Array)
      items.each do |appendob|
        iter = ls.append
        
        if appendob.is_a?(String)
          iter[0] = appendob
        elsif appendob.respond_to?("is_knj?")
          iter[0] = appendob.title
          @knj["items"] << {
            "iter" => iter,
            "object" => appendob
          }
        end
      end
    else
      raise "Unsupported type: " + items.class.to_s
    end
    
    self.model = ls
    
    self.active = 0
  end
  
  def sel
    iter = self.active_iter
    
    if @knj["items"].length > 0
      @knj["items"].each do |item|
        if item["iter"] == iter
          return item["object"]
        end
      end
      
      return false
    else
      return {
        "active" => self.active,
        "text" => iter[0]
      }
    end
  end
  
  def sel=(actob)
    if actob.respond_to?("is_knj?")
      @knj["items"].each do |item|
        if item["object"].id == actob.id
          self.active_iter = item["iter"]
          return nil
        end
      end
    else
      self.model.each do |model, path, iter|
        text = self.model.get_value(iter, 0)
        
        if text == actob
          self.active_iter = iter
          return nil
        end
      end
    end
    
    raise "Could not find such a row: " + textval
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
knjrbfw-0.0.38 lib/knj/gtk2_cb.rb
knjrbfw-0.0.37 lib/knj/gtk2_cb.rb
knjrbfw-0.0.36 lib/knj/gtk2_cb.rb
knjrbfw-0.0.35 lib/knj/gtk2_cb.rb
knjrbfw-0.0.34 lib/knj/gtk2_cb.rb
knjrbfw-0.0.33 lib/knj/gtk2_cb.rb
knjrbfw-0.0.32 lib/knj/gtk2_cb.rb
knjrbfw-0.0.31 lib/knj/gtk2_cb.rb
knjrbfw-0.0.30 lib/knj/gtk2_cb.rb
knjrbfw-0.0.29 lib/knj/gtk2_cb.rb
knjrbfw-0.0.28 lib/knj/gtk2_cb.rb
knjrbfw-0.0.27 lib/knj/gtk2_cb.rb
knjrbfw-0.0.26 lib/knj/gtk2_cb.rb
knjrbfw-0.0.25 lib/knj/gtk2_cb.rb
knjrbfw-0.0.24 lib/knj/gtk2_cb.rb
knjrbfw-0.0.23 lib/knj/gtk2_cb.rb
knjrbfw-0.0.22 lib/knj/gtk2_cb.rb
knjrbfw-0.0.21 lib/knj/gtk2_cb.rb
knjrbfw-0.0.20 lib/knj/gtk2_cb.rb
knjrbfw-0.0.19 lib/knj/gtk2_cb.rb