UI label with italics?
-
I'm trying to create a label that has one of the words italicized for vocabulary lists, eg:
लाल laal red
नीला neela blue
...Is this possible? I only see Label.font and Label.text_color which seem to be for the whole label. Is it possible maybe to concatenate several labels with different attributes?
-
@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”.
-
last edited by
-
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 @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.
-
@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('-', ' ')
-
@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.