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.


    Easy way to display formatted text

    Pythonista
    4
    10
    4274
    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.
    • ihf
      ihf last edited by

      I have a script that outputs some text to the console and all I want to do is display it in a specific size and font. It appears I could use Scene, UI, Hydrogen, HTML (to the internal browser), and maybe other ways. What is the simplest way? Does anyone have a code snippet to share?

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

        The console module has the set_font and set_color functions, which are probably the easiest way to "upgrade" your script to output formatted text.

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

          You can do it with the console module. Example:

          console.set_font('Zapfino', 48)  
          console.set_color(1.00, 0.50, 0.00)  
          print 'Hello'  
          console.set_font()  
          console.set_color(0.00, 0.00, 0.00)  
          print 'world!'
          
          1 Reply Last reply Reply Quote 0
          • ihf
            ihf last edited by

            @dgelessus, @Gerzer Very helpful, thanks. Now if I want to go a step further and dynamically update a displayed value, what do you recommend using?

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

              Really low budget animation via console.clear().

              import console, time
              for i in xrange(10):
                  for char in '/-\\|':
                      console.clear()
                      print(char)
                      time.sleep(0.25)
              
              1 Reply Last reply Reply Quote 0
              • ihf
                ihf last edited by

                @ccc That may be a bit lower budget than I was seeking :-) Next step up?

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

                  http://omz-software.com/pythonista/docs/ios/ui.html ;-)

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

                    Sorry if this is a very basic question but if I were to use ui, then I presume I want to use the label object? If so, can you give me a script fragment that would display the value of a variable as a label created in the UI designer?

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

                      What I came up with:

                      import ui
                      v=ui.load_view('My UI')
                      v['label1'].text='Text to display'
                      v.present('sheet')
                      

                      Does this look reasonable?

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

                        Looks like all the right stuff to me. If you want to see dynamic updating of the text you could import time and add the following two lines to the end of your code above:

                        while v.on_screen:
                            v['label1'].text= 'The current time is: {}'.format(time.ctime())
                        

                        You will probably need to go into the UI Designer and stretch your label to the right to see all the text.

                        My strong recommendation at this point is that you check out the UI Tutorial examples in the UI section of Pythonista Tools. It is a great way to learn the ui module and there are great tips and tricks there. You can submit pull requests if you have ideas for improving that content.

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