Tkinter - Underline only letters in Labels? - python-2.7

a = Label(root,text='h e l l o',underline=0)
So basically I want to be able to choose which parts of the string I want to underline. Right now it only lets me choose one at a time. If I try:
a = Label(root,text='h e l l o',underline=0,1)
I get the error:
a = Label(root,text='h e l l o',underline=0,2)
SyntaxError: non-keyword arg after keyword arg
I have looked at other posts and they suggest making a font to make the whole string underlined. I want to make just the letters underlined. Is there a way to do this?

Multiple character underlining is possible with unicode '\u0332' (underline of previous character). This avoids using the underline styling of the tkinter Label widget and allows multiple items to be underlined. To make just the letters underlined, use list comprehension and isalpha() to identify the letters. In the example below, the required text is moved to a string (mylabel) and preprocessed using:
mylabel='h e l l o'
utext=''.join([letter+'\u0332' if letter.isalpha() else letter for letter in mylabel])
a = Label(root,text=utext)
The above was tested on Python 3.7 on Windows 10. Note the previous limitations identifed with using unicode '\u0332' on some platforms.

Your choice with a Label is to underline a single character with the underline option, or to underline the entire string by using a font with underline option turned on.
The text widget allows you to underline individual characters, so my recommendation is to use a single-line text widget, or to use a canvas widget with multiple text items for each group of characters that are to be underlined or not.

Related

How to make QTextCursor::WordUnderCursor include more characters or larger words

I'm trying to show a tooltip when the cursor is over a keyword in a text editor using:
QTextCursor cursor = cursorForPosition(pos);
cursor.select(QTextCursor::WordUnderCursor);
This works well but the definition of a word does not fits my needs. For exemple the keyword \abcde is recognized as 2 words \ and abcde. Similarly the word a1:2 is recognized in three parts a1, : and 1. Basically what I'd like is to change the behavior such as a word is defined as a set of characters separated by space.
I tryied QTextCursor::BlockUnderCursor but it does the same than QTextCursor::LineUnderCursor and returns the entire line.

Conditional Formatting Cells in a Column Only Containing Letters F-Z Excluding RR

How could I highlight cells using conditional formatting if I want to only highlight cells containing letters F-Z? The formula would also need to exclude RR.
For example, if a cell in that column contains RR or any letter from A to E, I don't want to highlight it. But, if it contains any letter from F all the way to Z, I want it automatically highlighted.
Tried using regexmatch, but it's not working.
use:
=REGEXMATCH(A2, "[F-Z]")*(REGEXMATCH(A2, "RR")=FALSE)

Split mixed upper and lowercase in the same word into two lines

I have a string in cells that is lacking new lines.
It looks like this:
Text Text TextText Text Text T5df Tdfcv TextNeu
In other words:
If there is a change from Lowercase to Uppercase within a word, this is where a new line should be inserted as \n.
So the example would convert to
Text Text Text
Text Text Text T5df Tdfcv Text
Neu
Resp.:
Text Text Text\nText Text Text T5df Tdfcv Text\nNeu
I found
String[] r = s.split("(?=\\p{Lu})");
I tried REGAUS(F2;"(?=\\p{Upper})";"\n";"g") yet I get a 502, as something is wrong with the regex.
Which formula do I need for calc to do this?
With english formula names, the following formula will do the trick:
=REGEX(A1;"([:lower:])([:upper:])";"$1"&CHAR(10)&"$2";"g")
Same on multiple lines for sake of readability:
=REGEX(
A1;
"([:lower:])([:upper:])";
"$1" & CHAR(10) & "$2";
"g"
)
It matches a lower-case letter followed by an upper-case letter, and inserts a newline using the CHAR() function.
You'll have to adapt the line heigth manually, otherwise you will see only "Neu" (the last line).
For localised formula names (german), it would be:
=REGAUS(A1;"([:lower:])([:upper:])";"$1"&ZEICHEN(10)&"$2";"g")
I would have expected that inserting "\n" should work, too, but i did'nt manage got get it working, thus the recourse to CHAR(10).

Using Regex to match Arabic Text in R

I'm trying match elements in character vector that contain specific Arabic phrases.
So Far I have:
#load list of Arabic phrases
list.of.phrases <- read.table("arabic_phrases.txt")
#look for the first phrase
phrase1 <- arabic.text.vector[grepl(list.of.phrases[1],arabic.text.vector)]
Unfortunately, this approach or using raw Arabic text doesn't seem to return anything and I get this message:
Error in `[[<-.data.frame`(`*tmp*`, qname, value = 1) :
replacement has 1 row, data has 0
I know that I can match Arabic words using : [U0627-U06FF]+ as in:
#look for all cells containing arabic
arabic <-arabic.text.vector[grepl("[U0627-U06FF]+",arabic.text.vector)]
...
So far my approach is to convert the Arabic text to its Unicode point values and then use grep; however, I'm having trouble with the conversion.
Am I heading in the right direction or does anybody have another solution/approach?

Copying only the value at column n Vim

I have a file with long lines and need to see/ copy what the values are in a specic location(s) for the whole file but copy the rest of the line.
If the text width is small enough, ~184 columns, I can use :set colorcolumnnum to highlight the value. However over 184 characters it gets a bit unwieldy scrolling.
I tried :g/\%1237c/y Z, for one of the positions I needed, but that yanked the entire line.
eg for a smaller sample :g/\%49c/y Z will yank all of line 1 and 2 but I want to yank, or copy, the character at that column ie = on line 1 and x on line 2.
vim: filetype=help foldmethod=indent foldclose=all modifiable noreadonly
Table of Contents *sfcontents* *vim* *regex* *sfregex*
*sfsearch* - Search specific commands
|Ampersand-replaces-previous-pattern|
|append-a-global-search-to-a-register|
*sfHelp* Various Help related commands
There are two problems with your :g command:
For each matching line, the cursor is positioned on the first column. So even though you've matched at a particular column, that position is lost.
The \%c atom actually matches byte indices (what Vim somewhat confusingly names "columns"), so your measurement will be off for Tab and non-ASCII characters. Use the virtual column atom \%v instead.
Instead of :global, I would use :substitute with a replace-expression, in the idiom described at how to extract regex matches using vim:
:let t=[] | %s/\%49v./\=add(t, submatch(0))[-1]/g | let ## = join(t, "\n")
Alternatively, if you install my ExtractMatches plugin, I'd be that short command invocation:
:YankMatchesToReg /\%50v./