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

Section separator not displayed if section break follows submenu #2193

Closed
freakboy3742 opened this issue Nov 5, 2023 · 0 comments · Fixed by #2237
Closed

Section separator not displayed if section break follows submenu #2193

freakboy3742 opened this issue Nov 5, 2023 · 0 comments · Fixed by #2237
Labels
bug A crash or error in behavior.

Comments

@freakboy3742
Copy link
Member

freakboy3742 commented Nov 5, 2023

Describe the bug

If you have a menu that contains a submenu in a section, a section change before or after the submenu will not cause a section break. As a result, the separator bar will not be displayed.

Steps to reproduce

Generate a menu where
Reproduction case:

import toga


class TestApp(toga.App):
    def do_stuff(self, widget, **kwargs):
        pass

    def startup(self):
        cmd1 = toga.Command(
            self.do_stuff, text="Action 1", tooltip="Perform action 1", section=1
        )
        cmd2 = toga.Command(
            self.do_stuff, text="Action 2", tooltip="Perform action 2", section=2
        )

        sub_menu = toga.Group("Sub Menu", parent=toga.Group.COMMANDS, section=3)
        cmd3 = toga.Command(
            self.do_stuff,
            text="Action 3",
            tooltip="Perform action 3",
            group=sub_menu,
        )
        cmd4 = toga.Command(
            self.do_stuff,
            text="Action 4",
            tooltip="Perform action 4",
            group=sub_menu,
        )

        cmd5 = toga.Command(
            self.do_stuff, text="Action 5", tooltip="Perform action 5", section=4
        )
        cmd6 = toga.Command(
            self.do_stuff, text="Action 6", tooltip="Perform action 6", section=5
        )

        self.commands.add(cmd1, cmd2, cmd3, cmd4, cmd5, cmd6)
        self.main_window = toga.MainWindow()
        self.main_window.content = toga.Box()
        self.main_window.show()


def main():
    return TestApp("Test App", "org.beeware.test")


if __name__ == "__main__":
    main().main_loop()

This has 5 "top level" menus; each of which is in a different section; Section 3 is a submenu. There should be a separator between each

Expected behavior

There should be a section separator line between "Action 2" and "Sub Menu", and between "Sub Menu" and "Action 5", as those three items are all in different sections.

Screenshots

macOS:
Screenshot 2023-11-05 at 9 46 03 am
GTK:
Screenshot 2023-11-05 at 9 53 04 am
Winforms:
Screenshot 2023-11-05 at 9 53 39 am

Interestingly, GTK does draw the separator for the item after the menu, due to a slight discrepancy in how the menu is constructed.

Environment

  • Operating System: All desktop
  • Python version: Any (tested on 3.10)
  • Software versions:
    • Toga: 0.4.0

Logs

n/a

Additional context

The issue appears to lie in CommandSet.__iter__(). The logic for emitting GROUP_BREAK and SECTION_BREAK doesn't correctly account for cases where a group break is preceded or followed by a section break.

There is also an inconsistency in how menus are constructed on GTK.

@freakboy3742 freakboy3742 added bug A crash or error in behavior. good first issue Is this your first time contributing? This could be a good place to start! labels Nov 5, 2023
@freakboy3742 freakboy3742 removed the good first issue Is this your first time contributing? This could be a good place to start! label Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant