Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify MenuBar arguments. #390

Open
GoodClover opened this issue Nov 14, 2020 · 4 comments
Open

Simplify MenuBar arguments. #390

GoodClover opened this issue Nov 14, 2020 · 4 comments

Comments

@GoodClover
Copy link

GoodClover commented Nov 14, 2020

The current way the MenuBar constructor is set out is a bit messy and can be hard to manage.

So I propose it is changed from lists, to dictionaries in one argument rather than two.

Rather than this:

menubar = MenuBar(app, toplevel=["File", "Edit"],
    options=[
        [
            ["File option 1", file_function],
            ["File option 2", file_function]
        ],
        [
            ["Edit option 1", edit_function],
            ["Edit option 2", edit_function]
        ]
    ])

it could be like this:

menubar = MenuBar(app,
    menu={
        "File": {
            "File option 1": file_function,
            "File option 2": file_function
        },
        "Edit": {
            "Edit option 1": edit_function,
            "Edit option 2": edit_function
        }
    })

(I was unsure what to call the argument, menu might not be a good name for it.)

As the toplevel values are essentially keys to the option lists anyways,
and having a a key and function makes more sense than a list with the name and function in my opinion.

The old way should probably be kept in order to not break existing things.

@GoodClover
Copy link
Author

On this note, it would be nice to have those horizontal rules that many programs use:
image

However I am unsure on how this would be done, especially in my new proposed method.

@martinohanlon
Copy link
Collaborator

I can see the benefit of using a dictionary for the menubar description.

Note: - the change would need to be compatible with previous versions.

@GoodClover
Copy link
Author

GoodClover commented Nov 18, 2020

If you haven't seen already I've worked on this a bit in pull request #391

My code hopefully makes it backwards compatible.
It has the old arguments still and if they are present it will use them with the old code, if the new one is present it will take charge and get used.
And in case they are used as position arguments rather than keyword arguments it should detect that.

The tests use positional arguments as they are most likely to break.

The actual change to the dictionary was only very small, minor adjustment to the exising code, most of it is the backwards-compatibility :P

@martinohanlon
Copy link
Collaborator

I included this for review in v1.3.0 but after looking at the MenuBar code base I think a refactor should be considered and am pushing back.

I like the idea of using a dict to set options, its seems more intuitive.

I think additional methods should also be added to create menu items in real time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants