PyGtk, What are The Hidden Chars in TextView? - pygtk

i meet a problem when i used get_text(start_iter, end_iter, include_hidden_chars) method of Gtk TextBuffer object. i didn't understand include_hidden_chars arg what it is and what it does?
can you give simple example about hidden chars in Gtk TextView?
Thanks

You can set some invisible text in the text buffer by using a text mark that sets the "invisible" property to true [1]
When you use the get_text method of the buffer you can decide if the method should or shouldn't include the hidden text in the return value
[1] https://developer.gnome.org/gtk3/stable/GtkTextTag.html#GtkTextTag--invisible

Related

How to remove all text color attributes from a QTextDocument?

I've got a QTextDocument read from an HTML file; given a QString of HTML data named topicFileData, I do topicFileTextDocument.setHtml(topicFileData);. I then want to strip off all of the color information, making the whole document just use the default foreground and background brush. (I do not want to explicitly set the text to be black text on a white background; I want to remove the color information from the document.) (Background info: the reason I need to do this is that there are spans within the document that are erroneously set with a black foreground color, rather than just having no color information set, and that causes those spans to display as black-on-black when my app is running in "dark mode", when Qt changes the default text background brush to be black instead of white.)
Here's what I tried:
QTextCursor tc(&topicFileTextDocument);
tc.select(QTextCursor::Document);
QTextCharFormat noColorFormat;
noColorFormat.clearForeground();
noColorFormat.clearBackground();
tc.mergeCharFormat(noColorFormat);
This does not work, unfortunately; it looks like mergeCharFormat() does not understand that I want the clearForeground() and clearBackground() actions to be merged in to strip off those attributes.
I can do tc.setCharFormat(noColorFormat); instead, of course, and that does strip off the color attributes correctly; but it also obliterates all of the other character format info (font, etc.), which is not acceptable.
So, ideally I'd like to find an API that lets me explicitly remove a given text attribute from a QTextDocument. Alternatively, I guess I need to loop through all the spans of the QTextDocument one by one, get the char format of the current span, remove the color attributes from the format, and set the modified format back onto the span. That would be fine; but I have no idea how to loop over spans in that way. Thanks for any help.
Instead of creating a new instance of QTextCharFormat, update the current format and reapply it on the QTextEdit;
default = QTextCharFormat()
charFormat = self.textCursor().charFormat()
charFormat.setBackground(default.background())
charFormat.setForeground(default.foreground())
self.textCursor().mergeCharFormat(charFormat)
A sub-optimal solution that I have found as a workaround is to actually edit the HTML data string before I create the QTextDocument, using a regex:
topicFileData.replace(QRegularExpression("(;? ?color: ?#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])"), "");
This works for my situation, because all of the colors in my HTML file are set with color: #XXXXXX style attributes that can be stripped out of the HTML itself. This is fragile, however; colors specified in other ways would not be stripped, and if the body text of the HTML document happened to contain text that matched the regex, the regex would modify it and thus corrupt the content of the document. So I don't recommend this solution, and I won't be accepting it. If somebody can offer a better solution that would be preferable.

How to disable Spacemacs logo from splash screen?

I want to remove the image because it unnecessarily takes space. I've tried fancy-splash-image nil but it didn't work.
What should I place in my .spacemacs (or wherever) and in which part.
There's a variable called dotspacemacs-startup-banner that you can set at your initialisation file in order to remove the banner.
Your initialisation file is either ~/.spacemacs or ~/.spacemacs.d/init.el. There you'll find a function called dotspacemacs/init which contains a list of variables and their values (with an explanation what each of them do), you just need to find dotspacemacs-startup-banner and replace its value to nil.
Here is the full documentation of the variable for the sake of completeness
dotspacemacs-startup-banner is a variable defined in
‘core-dotspacemacs.el’. Its value is ‘official’
Documentation:
Specify the startup banner. Default value is
‘official’, it displays the official spacemacs logo. An integer value
is the index of text banner, ‘random’ chooses a random text banner in
‘core/banners’ directory. A string value must be a path to a .PNG
file. If the value is nil then no banner is displayed.

Make TextField wrap to a new line, not overflow

I am using a simple TextField wrapped in a Container.
When the user types a long string, I want it to automatically wrap to a new line.
It currently flows off the screen, on a single line. How do I fix this?
Unlimited number of lines
new TextField(..., maxLines: null)
or limited number of lines
new TextField(..., maxLines: 3)
This way it starts scrolling when the content exceeds the height of the input field
https://docs.flutter.io/flutter/material/TextField/maxLines.html
You have to set maxLines property to null. It default to 1.

activating a text field on <cr> input

Trying to get codename1 textfields to activate when a newline is
entered, the best I've done is to define this in a textfield
subclass
public void keyPressed(int keycode)
{
if(keycode==-90) // where does this number come from?
{ fireDoneEvent();
}
}
Where does this mysterious constant "-90" come from.
Is there a better supported way to do this?
Key pressed will only be invoked in a physical keyboard and not on virtual keyboard so you are in a completely wrong direction. If this is a multiline text field you can easily recognize the newline with \n using the DataChangeListener if this is a single line text field you should use the done listener which will only work on the device (with the VKB).

Core Text's Paragraph's space is too huge on iOS

I used CoreText to render text as below:
Another very common typesetting operation is drawing a single line of text to use as a label for a user-interface element.
In Core Text this requires only two lines of code, one to create the line object with an attributed string and another to draw the line into a graphic context.
but it shows how to create an attributes dictionary and use it to create.
obvious there're 3 paragraphs. and I use default CTParagraphStyleSetting so that the ParagraphSpacing and ParagraphSpacingBefore is set to 0 by default.
But the rendered result shows the space is too HUGE
Any idea to reduce the paragraph space?
This might help:
Technical Q&A QA1698 - How do I work-around an issue where some lines in my Core Text output have extra line spacing?
u can try
kCTParagraphStyleSpecifierMinimumLineHeight
kCTParagraphStyleSpecifierMaximumLineHeight
kCTParagraphStyleSpecifierLineSpacing