omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Some Thoughts on the Console Module

    Pythonista
    4
    6
    3979
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • steffen84
      steffen84 last edited by

      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:

      1. Hide the console controls (input and the bar at the top). Or at least programatically hide the keyboard.
      2. 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).
      3. Get the device's orientation
      4. Keep imported modules loaded
      5. More input options for numeric or date/time values. Maybe even custom selections.
      6. Images with links.
      7. Control the scroll position - mainly scroll to top after printing.
      8. 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.

      Steffen

      1 Reply Last reply Reply Quote 0
      • filippocld223
        filippocld223 last edited by

        and console.copy() for copying text output

        1 Reply Last reply Reply Quote 0
        • Sebastian
          Sebastian last edited by

          @filippocld Why don't you use pythonistas clipboard.set(string) to copy stuff?

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by ccc

            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
            
            1 Reply Last reply Reply Quote 0
            • filippocld223
              filippocld223 last edited by

              console.copy is more simple than this boring script....

              1 Reply Last reply Reply Quote 0
              • filippocld223
                filippocld223 last edited by

                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

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors