Submenus are not ordered the same as commands or as preferred by user design
Closed this issue · 2 comments
Describe the bug
When building a menu, commands and menus do not get produced into Python code the same order they are saved in Pygubu files.
To Reproduce
Steps to reproduce the behavior:
(Build a project that has a Menu)
-
Click on Menu (default name is ok)
-
Click on Sub-Menu, Label it "File" (Ensure "File" Submenu is selected
-
Click on "Command", label it "First"
-
Click on Sub-Menu, label it "Second"
-
Observe that the preview shows "First" and "Second" in order (Steps continued after image)
-
Click Code, Code Script, Select the Main Menu
-
Observe method
create_menu_1
and note how all sub_menus are created before commands.
def create_menu_1(self, master):
menu_1 = tk.Menu(master)
self.File = tk.Menu(menu_1)
menu_1.add(tk.CASCADE, menu=self.File, label='File')
submenu_1 = tk.Menu(self.File)
self.File.add(tk.CASCADE, menu=submenu_1, label='Second')
self.File.add("command", label='First')
return menu_1
Expected behavior
The produced code should match the Pygubu Preview, ui xml order, and the order the user has indicated. The generated python code appears to be the only component unordered.
Your Environment (please complete the following information):
- OS: Windows 10
- Python version: Python 3.11
- Pygubu version: pygubu 0.30
- Designer version: pygubu-designer 0.35
** Additional Context - menu_ordering.ui **
<?xml version='1.0' encoding='utf-8'?>
<interface version="1.3">
<object class="tk.Toplevel" id="toplevel_1">
<property name="height">200</property>
<property name="width">200</property>
<child>
<object class="ttk.Frame" id="frame_1">
<property name="height">200</property>
<property name="width">200</property>
<layout manager="grid">
<property name="column">0</property>
<property name="row">0</property>
</layout>
</object>
</child>
</object>
<object class="tk.Menu" id="menu_1">
<child>
<object class="tk.Menuitem.Submenu" id="File" named="True">
<property name="label" translatable="yes">File</property>
<child>
<object class="tk.Menuitem.Command" id="command_1">
<property name="label" translatable="yes">First</property>
</object>
</child>
<child>
<object class="tk.Menuitem.Submenu" id="submenu_1">
<property name="label" translatable="yes">Second</property>
</object>
</child>
</object>
</child>
</object>
</interface>
Hello @ednpnoble, thanks for the bug report.
I will try to solve it as soon as possible.
Regards
Alejandro A.
Fixed in pygubu version 0.35.5