Module: WidgetWrapper::Menus::Frame

Defined in:
lib/wx_wrapper/menu.rb

Instance Method Summary collapse

Instance Method Details

#create_menu_events(menu_bar) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/wx_wrapper/menu.rb', line 17

def create_menu_events(menu_bar)
  menu_bar.menus.each do |menu|
    menu.items.each do |item|
      evt_menu(item.get_id) { send(menu_item_label_to_method(item.get_label)) }
    end
  end
end

Creates a menu bar for the frame. Example syntax:

frame.menu_bar do |menu_bar|
  menu_bar.menu do |menu|
  end
end

Yields:

  • (new_menu_bar)


10
11
12
13
14
15
# File 'lib/wx_wrapper/menu.rb', line 10

def menu_bar
  new_menu_bar = Wx::MenuBar.new
  yield(new_menu_bar) if block_given?
  create_menu_events(new_menu_bar)
  set_menu_bar(new_menu_bar)
end

Returns names for menu items prefixed with on_. ie on_save



26
27
28
# File 'lib/wx_wrapper/menu.rb', line 26

def menu_item_label_to_method(label)
  'on_' + label.downcase.gsub(/[^a-zA-Z0-9 ]/, '').gsub(/[ ]/, '_')
end