Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:59:19+00:00 2026-06-15T08:59:19+00:00

I’m writing a document based application in wxPython, by which I mean that the

  • 0

I’m writing a document based application in wxPython, by which I mean that the user can have open multiple documents at once in multiple windows or tabs. There are multiple kinds of documents, and the documents can all be in different “states”, meaning that there should be different menu options available in the main menu.

I know how to disable and enable menu items using the wx.EVT_UPDATE_UI event, but I can’t figure out how to pull off a main menu that changes structure and content drastically based on which document that currently has focus. One of my main issues is that the main menu is created in the top level window, and it has to invoke methods in grand children and great grand children that haven’t even been created yet.


Contrived example; when a document of type “JPEG” is open, the main menu should look like:

File      Edit      Compression     Help

And when the user switches focus (CTRL+Tab) to a document of type “PDF”, the main menu should change to:

File      Edit      PDF     Publish     Help

And the “Edit” menu should contain some different options from when the “JPEG” document was in focus.


Current I’m just creating the menu in a function called create_main_menu in the top level window, and the document panels have no control over it. What would be necessary to pull off the kind of main menu scheme I describe above, specifically in wxPython?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:59:20+00:00Added an answer on June 15, 2026 at 8:59 am

    I’ve figured out a pretty clean way to do this. First of all I create my “base” main menu bar, which contains the File and Help menu items. Then I defined a class EditorPanel than is a subclass of wx.Panel and defined the methods bind_main_menu_bar and release_main_menu_bar. The first of those methods receives the main menu bar when the panel is focused, and adds some items to it. Here is one of my implementations:

    def bind_main_menu_bar(self, main_menu_bar):
        main_frame = wx.GetApp().GetTopWindow()
    
        self.main_menu_bar = main_menu_bar
    
        # Create the edit menu.
        self.edit_menu = edit_menu = shared.create_menu([
            (const.ID_UNDO, self.LABEL_UNDO_EMPTY),
            (const.ID_REDO, self.LABEL_REDO_EMPTY)
        ])
    
        # Create the tools menu.
        self.tools_menu = tools_menu = shared.create_menu([
            (const.ID_SELECT_ADDRESS_COLUMNS, 'Select address columns...'),
            (),
            (const.ID_VALIDATE_ADDRESSES, 'Validate selected addresses'),
            (const.ID_VALIDATE_ALL_ADDRESSES, 'Validate all addresses')
        ])
    
        # Bind some menu event handlers to the main frame.
        main_frame.Bind(wx.EVT_MENU, self.on_menu)
        main_frame.Bind(wx.EVT_UPDATE_UI, self.on_menu_update)
    
        # Insert the new menus into the main menu bar.
        main_menu_bar.Insert(1, edit_menu, 'Edit')
        main_menu_bar.Insert(2, tools_menu, 'Tools')
    

    Now, when that editor panel is opened, the main menu receives an Edit menu and a Tools menu that is bound to event handlers in the EditorPanel, which is incredibly handy. When the editor loses focus, the release_main_menu_bar method is called, which should restore the main menu bar to it’s original state. This is counterpart of the code above:

    def release_main_menu_bar(self):
        main_frame = wx.GetApp().GetTopWindow()
    
        # Unbind the menu event handlers from the main frame.
        main_frame.Unbind(wx.EVT_MENU, handler=self.on_menu)
        main_frame.Unbind(wx.EVT_UPDATE_UI, handler=self.on_menu_update)
    
        # Remove the edit and tools menu from the main menu bar.
        self.main_menu_bar.Remove(1)
        self.main_menu_bar.Remove(1)
    
        # Reset the fields used for the menu.
        self.edit_menu = None
        self.tools_menu = None
        self.main_menu_bar = None
    

    So every editor that wants to edit the main menu just has to subclass those two methods and they have full control. The main frame will monitor when the user switches between editors and call the methods accordingly. The biggest problem was to figure out when the editor panel receives and loses focus, which is the topic of another question of mine: How do I monitor when wx.Panel receives and loses focus?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.