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.


    Print Console in TextView or ScrollView

    Pythonista
    5
    15
    11198
    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.
    • starrshaw
      starrshaw last edited by

      Hi, I am making a little old school text adventure and was just wondering if there was a way to have the console print out into UI TextView or ScrollView?

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

        one option is to write your adventure such that it would run in a normal python interpreter, (i.e with a Cmd loop) then use stash and python myscript from within stash. this gets you the benefits of the textview based console of stash, the command history, and you can use colors for example.
        (actually i think stash uses special commands to add colors, not pure ANSI. look at, for example, ls which uses colors)

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

          @JonB Thanks Jon, I was about to use stash, but I wanted to have some graphics and sound sort of like the Commodore 64 Fahrenheit 451 text adventure. https://www.youtube.com/watch?v=OGu_Urn4hek

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

            Here is a script to switch between console and text view. I hope it is useful.

            https://gist.github.com/balachandrana/6c8617382079e4486b12a4dd35f5c8c5

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

              If you just want to append text to a textview, just append to text (with tv.text +='You Are in an empty room.\n'). You have to scroll the tv yourself, this was an annoying bit in early versions of stash. Of course you could always iust use stash.terminal, without the stash executable.

              Those old style games i think has to basically manage their own graphics, including drawing text where it belonged...

              I started porting an apple 2 emulator , and had to implement a screen.py... which basically allows writing bits to a numpy array, and then updates an imageview. The screen code itself was reasonably fast, though of course pretty low resolution.

              1 Reply Last reply Reply Quote 1
              • starrshaw
                starrshaw last edited by

                Thanks guys! Both these ideas worked great!

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

                  Hi, I’m also a novice trying to make a UI for a text-y thing I started on in the console: https://github.com/weevil/adventurers_guild
                  Doesn’t PyUI depend on pygame to work? Doesn’t that make it unusable with Pythonista?

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

                    @wiley The ui module is based on the iOS UIKit framework, it has nothing to do with pygame. It's also specific to Pythonista, there's no way to use it on regular computers, since the underlying framework only exists on iOS.

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

                      Thank you!

                      Is there a comparable simple ui module that works both in and out of pythonista? I had looked at pyglet but it requires pygame. I'd like to be able to work in pythonista but still have the program run elsewhere. I only need a very minimal UI... basically just a box to dump text in and a button or two to refresh it.

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

                        @wiley There is a library called UniPAGe that provides a common API for Pythonista's ui module and the Kivy library. I haven't really used it myself, but it seems like the sort of library you're looking for.

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

                          I had to use a more portable ui module like I mentioned but I’m playing with pythonista‘ ui module and it’s really great! I can’t believe it’s got its own graphical editor. Is there a code example somewhere on how to populate the scroll view element? I’m not sure how to get output into it.

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

                            https://github.com/humberry/ui-tutorial

                            1 Reply Last reply Reply Quote 1
                            • wiley
                              wiley last edited by

                              Even in the scrollview example in there I don't see an attribute for like, .text or .content... what am I missing?

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

                                Scrollviews are just container views that contain subviews.
                                You use add_subview to add stuff to a scroll view (usually will be a single view that is larger than the scrollview.
                                You then use content_size to set the scrollable region -- usually would be the size of your subview. When content_size is larger than the scrollview frame, it will allow scrolling.

                                Note that both TableView and TextView are actually subclasses of ScrollView, so if you are just doing tabular or textual work, you don't need scrollview per se, but can still implement some of the delegate methods.

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

                                  Ah! Thank you!

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