Issues adding sub-menu items

Hello All,

I’m new to the list and to Ruby.

I was trying to use one of the examples as a skeleton for something that
I’m working on.

I’m currently stuck when it comes to adding another item to the
sub-menus.
I have a menu item by the name of “Tools” and I would like to add a
sub-menu item called “Find Unique Fields” but it doesn’t show up when I
try to run it.

If I add a Wx::ID_UNIQUE and a handle for the event the program fails.

What do I need to do or what I’m I missing. I appreciate your response.

Thanks,

Glenn

#!/usr/bin/env ruby

begin


class HL7Query < Wx::Frame
def initialize(title)

super(nil, :title => title, :size => [ 850, 600 ])


menu_bar = Wx::MenuBar.new

# The "file" menu
menu_file = Wx::Menu.new
menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
menu_bar.append(menu_file, "&File")

# The "Tools" menu
menu_tools = Wx::Menu.new
#menu_tools.append(Wx::ID_UNIQUEFIELDS, "Find Unique Fields", "Find

Unique Fields")
menu_tools.append(nil, “Find Unique Fields”, “Find Unique Fields”)
menu_bar.append(menu_tools, “Tools”)

# The "help" menu
menu_help = Wx::Menu.new
# Using Wx::ID_ABOUT default id means the menu item will be placed
# in the correct platform-specific place - eg on OS X
menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
menu_bar.append(menu_help, "&Help")

# Assign the menubar to this frame
self.menu_bar = menu_bar

# Create a status bar
create_status_bar(2)
self.status_text = "Welcome to HL7Query!"

# Set it up to handle menu events using the relevant methods
evt_menu Wx::ID_EXIT, :on_quit
evt_menu Wx::ID_ABOUT, :on_about

end

def on_quit
close()
end



Wx::App.run do
self.app_name = ‘HL7Query’
frame = HL7Query.new(":::HL7Query:::")
frame.show
end

Glenn Pringle wrote:

I’m currently stuck when it comes to adding another item to the
sub-menus.
I have a menu item by the name of “Tools” and I would like to add a
sub-menu item called “Find Unique Fields” but it doesn’t show up when I
try to run it.

If I add a Wx::ID_UNIQUE and a handle for the event the program fails.

What do I need to do or what I’m I missing. I appreciate your response.

Your example (the row that wasn’t commented out) had nil as the menu
item id, which will fail. Either you have to supply your own valid ID
value (starting from 100 going upwards is a good idea) or you use
Wx::ID_ANY as the ID and you’ll get an automatically assigned id (use
get_id for the returned menu item object to know the ID).

You have many ways to go here. Since you seem to choose to set up IDs
yourself, first try a numerical value (for example 101) so you see how
it works:
menu_tools.append(101, “Find Unique Fields”, “Find Unique
Fields”)
…and set up the menu item event handler…
evt_menu 101, :on_unique_fields
…and then create the event handler method…
def on_unique_fields
p “on unique fields menu item selected”
end

Now, replace the number 101 with ID_UNIQUE:
ID_UNIQUE = 101

menu_tools.append(ID_UNIQUE, “Find Unique Fields”, “Find Unique Fields”)

evt_menu ID_UNIQUE, :on_unique_fields

Please note that the Wx:: prefix should NOT be used prior to your own
constant names - you don’t want your own constants to interfere with the
wxRuby name scope.

Best regards,

Jari W.

Jari W. wrote:

Glenn Pringle wrote:

Please note that the Wx:: prefix should NOT be used prior to your own
constant names - you don’t want your own constants to interfere with the
wxRuby name scope.

Best regards,

Jari W.

Thanks