Some Thoughts on the Console Module
With the console module and its ability to print links, it is very easy to create interactive text based apps that work very well on a touch screen. The links always call the same script but with different parameters.
Here are some ideas that would further improve the usage of the console module:
- Hide the console controls (input and the bar at the top). Or at least programatically hide the keyboard.
- Define a custom popup menu for links (print_link() with an optional link list that are shown in a popup menu when the link is hold).
- Get the device's orientation
- Keep imported modules loaded
- More input options for numeric or date/time values. Maybe even custom selections.
- Images with links.
- Control the scroll position - mainly scroll to top after printing.
- Suppress update of the console output until all text has been printed. Especially useful in combination with 7.
It would be great if some of these ideas could be realized in the next version of pythonista.
and console.copy() for copying text output
@filippocld Why don't you use pythonistas clipboard.set(string) to copy stuff?
http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python # Will only work in single threaded apps! from contextlib import contextmanager from StringIO import StringIO @contextmanager def stdoutRedirected(): """Save current stdout, redirect stdout to an in-memory file and then restore stdout when leaving the 'with' clause.""" saveStdout = sys.stdout # Save the current stdout. sys.stdout = StringIO() # Redirect stdout > in-memory file try: yield None finally: sys.stdout = saveStdout # Restore original stdout redirectedText = '' # Holds the text after 'with' completes. with stdoutRedirected(): # Redirect stdout to in-memory file. print('\n'.join('This text will not appear on the console but will instead be stored in an in-memory file.'.split())) # Final line of 'with' clause MUST save redirected text. redirectedText = sys.stdout.getvalue() # Save hidden text print('The "with stdoutRedirected():" clause has completed.') print('=' * 54) print(redirectedText) # Show that we still have hidden text
console.copy is more simple than this boring script....
I want to set the "out" variable to the entire output....all that's displayed on the output area....I don't want to copy it