Sha256: 283bd64bde9979bb90eda410311d9872f4abb3793858f3d3fdf2fd70b8c90f5b

Contents?: true

Size: 1.3 KB

Versions: 61

Compression:

Stored size: 1.3 KB

Contents

class Knj::Gtk2::Menu
  def initialize(paras)
    @paras = paras
    @items = []
    @mainmenu = Gtk::Menu.new
    @signal = ""
    
    count = 0
    if @paras["items"].respond_to?("reverse")
      items = @paras["items"].reverse
    else
      items = @paras["items"]
    end
    
    if items.is_a?(Array)
      items = Knj::ArrayExt.dict(items)
    end
    
    items.each do |signal, menuitem|
      if menuitem.is_a?(Array)
        old_mi = menuitem
        menuitem = {"text" => menuitem[0], "connect" => menuitem[1]}
      end
      
      newitem = Gtk::MenuItem.new(menuitem["text"])
      
      if menuitem["connect"]
        newitem.signal_connect("activate") do
          Knj::Php.call_user_func(menuitem["connect"])
        end
      else
        newitem.signal_connect("activate") do
          on_menuitem_activate
        end
      end
      
      @items[count] = {
        "gtkmenuitem" => newitem,
        "signal" => signal
      }
      @mainmenu.prepend(newitem)
      
      count += 1
    end
    
    event = Gdk::EventButton.new(Gdk::Event::BUTTON_PRESS)
    
    @mainmenu.show_all
    @mainmenu.popup(nil, nil, event.button, event.time)
  end
  
  def on_menuitem_activate(signal)
    @signal = signal
  end
  
  def signal() return @signal end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
knjrbfw-0.0.72 lib/knj/gtk2_menu.rb
knjrbfw-0.0.71 lib/knj/gtk2_menu.rb
knjrbfw-0.0.70 lib/knj/gtk2_menu.rb
knjrbfw-0.0.69 lib/knj/gtk2_menu.rb
knjrbfw-0.0.68 lib/knj/gtk2_menu.rb
knjrbfw-0.0.67 lib/knj/gtk2_menu.rb
knjrbfw-0.0.66 lib/knj/gtk2_menu.rb
knjrbfw-0.0.65 lib/knj/gtk2_menu.rb
knjrbfw-0.0.64 lib/knj/gtk2_menu.rb
knjrbfw-0.0.63 lib/knj/gtk2_menu.rb
knjrbfw-0.0.62 lib/knj/gtk2_menu.rb
knjrbfw-0.0.59 lib/knj/gtk2_menu.rb
knjrbfw-0.0.58 lib/knj/gtk2_menu.rb
knjrbfw-0.0.57 lib/knj/gtk2_menu.rb
knjrbfw-0.0.55 lib/knj/gtk2_menu.rb
knjrbfw-0.0.54 lib/knj/gtk2_menu.rb
knjrbfw-0.0.53 lib/knj/gtk2_menu.rb
knjrbfw-0.0.52 lib/knj/gtk2_menu.rb
knjrbfw-0.0.51 lib/knj/gtk2_menu.rb
knjrbfw-0.0.50 lib/knj/gtk2_menu.rb