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?
-
@mikael said:
Which format would you prefer
Even if the new format is less talkative, I prefer the html-like format, more usual, but that's only a personal feeling.
-
-
@cvp, thanks, for both comments.
Also, I added your code as an
html
method that takes, well, some html. -
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”.
-
-
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]"
-
-
@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!
-
@peiriannydd this works (case sensitive)
r = RichLabel( font=('Times New Roman', 24), background_color='white', alignment=ui.ALIGN_CENTER, number_of_lines=0, )
-
@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>, ]))
-
@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('-', ' ')
-