aegirhall / console-menu

A simple Python menu system for building terminal user interfaces.
MIT License
365 stars 58 forks source link

Does not dynamically update submenus #72

Open RazielRV13 opened 2 years ago

RazielRV13 commented 2 years ago

I have created a main menu that has as options scan the time and add it to a file if the numbers are even, on this same main menu I have an option that accesses a submenu that loads the file data to place them as options.

The problem I have is that if I add data to the file on execution when I try to enter the submenu it only shows me the options that the file had when I executed es script.py and not the ones that were added now. How can I make the submenu dynamic, that is, load the new values that were added to the file?

adriancuevas99 commented 4 months ago

Hi! I have the same problem, could you solve it? I see you can redraw the console with the method draw() but i can't make it to work or is not what I am looking for.

gnalbandian commented 3 months ago

Same issue here. Any workarounds?

EDIT: After 5 minues reading the code I found where is the issue.

Well, its not an issue itself, but just the way in which the library is done.

The FunctionItem class inherits from ExternalItem which inherits from MenuItem.

In MenuItem is where the tet property is, and is the one that holds the string. The string inside text is static. It will not change even thou we change a variable that was part of the text as buiding the menu: ie: func_item = FunctionItem(f"Set minimun ratio[{config_parameters.min_ratio}]", set_ratio_threshole, [config_parameters])

I'll try to refactor the library and come up with a solution.

EDIT 2: After 5 more minutes reading... You can pass a Callable to the text argument. i.e:

func_item = FunctionItem(lambda :f"Set minimun ratio[{config_parameters.min_ratio}]", set_ratio_threshole, [config_parameters])

This will make the library call the lambda function everytime it needs to rewrite the menu