pmbarrett314 / curses-menu

A simple console menu system in python using the curses library
MIT License
475 stars 53 forks source link

how to get output from a function #34

Closed SimplySeth closed 4 years ago

SimplySeth commented 6 years ago

I can see that there is a way to call a function with FunctionItem, but how I quite can't figure out how to get the output of the function I call.

nickcounts commented 6 years ago

@SimplySeth have you made any progress with this? I'm having trouble with FunctionItem calls as well. I'm not even totally sure my function callbacks (or whatever it's appropriate to call them) are executing

cheers

SimplySeth commented 6 years ago

@SimplySeth have you made any progress with this? I'm having trouble with FunctionItem calls as well. I'm not even totally sure my function callbacks (or whatever it's appropriate to call them) are executing

cheers

actually, I gave up. I was never able to figure it out.

nickcounts commented 6 years ago

One crazy issue I ran into was that because the menu system is threaded (still not sure about the advantage there) it means that if you pass a string as the args value it interprets each character as a separate argument!

I had to explicitly set each FunctionItem() argument and wrap the args value to pass a tuple that the threaded call would parse correctly. It took me a lot of head scratching to sort that out.

thisSubmenuItem = FunctionItem(text=f, function=downloadSelectedFile, args=(f,), kwargs=argDict)

If you try this, don't forget the , after your parentheses!

myTuple=('tupleString'),

Cheers

Flurrywinde commented 4 years ago

I wondered the same thing. Put something like input('Press Enter to continue') at the end of the function, and then the output will stay around.