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.


    UI label with italics?

    Pythonista
    5
    48
    12285
    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.
    • mikael
      mikael @cvp last edited by

      @cvp, thanks, for both comments.

      Also, I added your code as an html method that takes, well, some html.

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

        For reference, here’s also @peiriannydd’s original request in both markup options:

        "लाल laal <i><c red>red</c></i>"

        """नीला neela &
        i + c blue: blue"""
        

        Hmm, the latter might not be tag-verbose, i.e. more DRY, but it is ”line-verbose”.

        cvp 1 Reply Last reply Reply Quote 0
        • cvp
          cvp @mikael last edited by

          @mikael said:

          line-verbose

          Yes sir

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

            Aaand the last idea for this evening, use different tag delimiters because they act as better vertical separators, and Pythonista editor nicely matches closing pairs. Combined with the idea of ad-hoc combined tag creation.

            "लाल laal {i + c red}red{i}"

            Hmm, does not work nicely with f-strings, and that is a clear requirement.

            So:
            "लाल laal [i + c red]red[i]"

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

              @mikael @cvp I’m indifferent to the format, as you said, HTML is more usual, but any other format with at least as much flexibility would be fine. I think this a fantastic feature in any case.

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

                @mikael I have enjoyed using your richlabels (thank you!!). One thing I haven’t figured out - When I try to change the font with

                <f times new roman 15>

                I get an error that it can't find a font named times. It seems like it is looking for the first word only in the font name. I don’t know python syntax well enough - is there a way I can write my code that will combine the whole three-word string when passed to the richlabels parser to have a multiword font, or is this a limitation of the richlabels module?

                Thanks again!

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @peiriannydd last edited by cvp

                  @peiriannydd this works (case sensitive)

                      r = RichLabel(
                          font=('Times New Roman', 24),
                          background_color='white',
                          alignment=ui.ALIGN_CENTER,
                          number_of_lines=0,
                      )
                  
                  1 Reply Last reply Reply Quote 0
                  • peiriannydd
                    peiriannydd last edited by peiriannydd

                    @cvp yes, but I was hoping to change the font within the label, and <f 'Times New Roman' 60> doesn't work. For example, this doesn't work:

                        r = RichLabel(
                          font=('Chalkboard SE', 60),
                          background_color='white',
                          alignment=ui.ALIGN_CENTER,
                          number_of_lines=0,
                        )
                    
                        r.rich_text("\n".join([
                          "First font",
                          "<f 'Times New Roman' 60>Second font</f>, 
                        ]))
                    
                    mikael 1 Reply Last reply Reply Quote 0
                    • mikael
                      mikael @peiriannydd last edited by

                      @peiriannydd, needed a little change in code, but now you can do:

                      <f Times-New-Roman 60>
                      

                      Unfortunately I am just in the process of rearranging my repo. If you want this to work now, you can make a change to the file on line 85, I think:

                      Current:

                      self.font_name = node_font or self.font_name
                      

                      Change to:

                      self.font_name = (node_font or self.font_name).replace('-', ' ')
                      
                      1 Reply Last reply Reply Quote 0
                      • peiriannydd
                        peiriannydd last edited by

                        @mikael fantastic! Thank you so much. It works great. I really appreciate your time and @cvp to help out an inexperienced python user like me.

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