Is there a way to change which character is used for QT's QTextOption.ShowTabsAndSpaces flag?
I find that the default character that's used for viewing whitespace (specifically spaces) stands out a little too much. I'd like to change the font or character used so that it's less distinct.
It looks like the character used is unicode "Middle Dot", ยท (U+00B7) and I'd like to use, say, U+02D1 ห.
Ideally I'd like to be able to set it to whatever the user wants.
I've been searching through the Qt docs and have only been able to find how to turn this flag on (here).
EDIT:
I guess I should show some code... Here's how I'm currently adding the whitespace indicators:
opts = self.document().defaultTextOption()
opts.setFlags(opts.flags() | QTextOption.ShowTabsAndSpaces)
self.document().setDefaultTextOption(opts)
Running Python 3.4 and PyQt4, but should be able to port C++ code over.
EDIT2:
Thanks to Andrei Shikalev's answer below, I've posted a feature request for this on the QT tracker: https://bugreports.qt.io/browse/QTBUG-46072
Currently we could not change characters for tabs and white space. This characters hardcoded in Qt source for QTextLayout:
QChar visualTab(0x2192);
...
QChar visualSpace((ushort)0xb7);
More info in source for QTextLayout on GitHub.
You can create feature request for tabs and white spaces custom characters. IMHO this feature will be useful for custom-looking editors, based on Qt.
Related
The Unicode character U+1d134 is the musical symbol for "common time"; it looks like a capital 'C'.
But using Python 3.6, when I specify '\U0001d134' I get a glyph that seems to indicate an unknown symbol. On my Mac, it looks like a square with a question-mark in it.
Is the inability to display the corresponding glyph simply a font limitation, or is it something else? (Like maybe something I'm doing wrong....)
For clarity, I want to use this and other such symbols in an app I'm writing, and would like to find out if there's a way to do this.
The problem lies not in your code but in your local system. You don't have any font installed that contains the character ๐ด "MUSICAL SYMBOL COMMON TIME".
That is also the reason none of your browsers can display it. Usually, browsers are quite good in hunting down any font that can display a certain character. Reason they all fail is what's in the paragraph above.
But โ as it happened,
>>> print ('\U0001d134')
๐ด
worked for me, displaying this:
I pasted it into UnicodeChecker, which helpfully listed 'all' fonts that contain this character: only one, Bravura. It's an Open Source font so go ahead and download it. (Be careful to follow proper procedures if you want to distribute it along with your app.)
To think that I only had that font installed because of an earlier SO question.
I'm writing a curses program in Python. I'm a beginner of curses but I've used terminal control sequences for colored output.
Now there's some code snippets to print inside the window, I'd like them be syntax highlighted, and it's better done with libraries like pygments, which outputs highlighted code with control sequences.
Initially I feed pygments output directly to window.addstr(), but it is turned out that the control sequences is escaped and the whole highlighted string is printed on the screen (just like this: https://too-young.me/web/repos/curses-highlight.png). How can I display it directly with curses, just like cat?
There's the "culour" python module which does exactly that.
Install it using pip install culour, and then you can use it to print pre-colored strings:
import culour
culour.addstr(window, colored_string)
This will print the string colored in your window.
This has been asked several times, with the same answer: you could write a parser to do this. For related discussion:
How to use ANSI escape codes inside mvwprintw in ncurses?
Comment on Parsing ANSI color escape sequences
Handle escape sequences with ncurses? Does printf handle escape sequences?
It is not suitable as an extension to ncurses for example because:
curses produces escape sequences, but for a wide variety of devices (which may not be "ANSI color escapes").
ncurses (see the FAQ Why aren't my bugs being fixed?) does not provide it as an extension because a parser of this type would not rely upon any of ncurses' internals.
On GitHub there is a free to use, study, modify and re-distribute High Level GUI library, at "https://github.com/rigordo959/tsWxGTUI_PyVx_Repository".
It is implemented in Python 2x & 3x using the "curses" Low Level GUI package. The Linux nCurses implementation has typically replaced the original Unix Curses implementation.
Your application programs can be programmed using a character-mode subset of the pixel-mode "wxPython" High Level GUI API. It supports displays with keyboard and mouse input and various terminal emulators including the color xterms (8-color with 64-color pairs and 16-color with 256-color pairs) and non-color vt100/vt220.
Curses enables you to colorize text strings by inserting an attribute (for color, underline, bold, reverse etc.) token before the text and one to restore the previous attribute after the text. For example:
sampleWindow.attron(curses.A_REVERSE |
curses.color_pair(color_pair_number))
sampleWindow.addstr(begin_y + 3,
begin_x + 48,
' ')
sampleWindow.attroff(curses.A_REVERSE |
curses.color_pair(color_pair_number))
For a program of mine I have a database full of street name (using GIS stuff) in unicode. The user selects any part of the world he wants to see (using openstreetmap, google maps or whatever) and my program displays every streets selected using a nice font to show their names. As you may know not every font can display non latin characters... and it gives me headaches. I wonder how to tell my program "if this word is written in chinese, then use a chinese font".
EDIT: I forgot to mention that I want to use non-standard fonts. Arial, Courier and some other can display non-latin words, but I want to use other fonts (I have a specific font for chinese, another one for japanese, another one for arabic...). I just have to know what font to chose depending of the word I want to write.
You need information about the language of the text.
And when you decide what fonts you want, you do a mapping from language to font.
If you try to do it automatically, it does not work. The fonts for Japanese, Chinese Traditional, and Chinese Simplified look differently even for the same character. They might be inteligible, but a native would be able to tell (ok, complain) that the font is wrong.
Plus, if you do anything algorithmically, there is no way to consider the estethic part (for instance the fact that you don't like Arial :-)
Use utf-8 text and a font that has glyphs for every possible character defined, like Arial/Verdana in Windows. That bypasses the entire detection problem. One font will handle everything.
Is there a way to show "Soft Tabs" (spaces) in TextMate? View โ Show Invisibles works well for keeping track of indentation if you're using tabs for indentation. Unfortunately in languages where indentation is semantic you generally have to use spaces.
(Python, YAML, HAML, CoffeeScript)
Any suggestions for showing this whitespace or keeping track of soft indentation in TextMate? Should I keep holding out for Textmate2?
Alternative strategies and suggestions are also welcome.
The latest version of TextMate 2 highlights spaces when Show Invisibles is enabled.
EDIT:
You can even customize which invisibles to show with which character by modifying the invisiblesMap property in .tm_properties file.
From the TextMate changelog:
This can be set to a string which is used to control which glyphs are used for invisible characters. Add either \n, \t, or a space to the string, followed by the glyph that should be used to render the character, or prefix it with ~ to disable rendering of that character. For example to disable rendering of spaces and render tabs as โ add this to .tm_properties: invisiblesMap = "~ \tโ".
Sidenote:
THIS IS NOT THE CASE ANYMORE, functionality has been restored.
According to the Log of 2013-10-23 (v2.0-alpha.9489): "Show Invisibles will no longer treat space as an invisible (which was added in previous build) as it was causing issues with right-to-left rendering and combining marks used after spaces. The feature might be back, but needs to be implemented differently."
You can use soft tabs - as described here. I have also problem to find it when I needed this feature;)
PEP 8 says:
Python accepts the control-L (i.e. ^L)
form feed character as whitespace;
Many tools treat these characters as
page separators, so you may use them
to separate pages of related sections
of your file
This look like a great idea for me, but in the text editor I use(kate) "control+L" is for save all files. Someone have any solution?
... or I'm losing something here?
Ctrl-L simply refers to the character with ASCII code 12 (form feed, new page). It is called Ctrl-L only because some editors allow you to enter it with Ctrl-L. (For instance, in vim, one can type Ctrl-Q Ctrl-L to enter that character, and it also appears as ^L). In Kate, Ctrl-L is a shortcut for saving all files, so you cannot type it that way and I'm not sure there is any way of entering that character easily.
As a Kate developer, I unfortunately have to tell you that such control sequences are not supported. In fact, Kate often treats these files as binary files, since such characters are not human readable text. So in short: Try to avoid ^L.
You can create a plugin, and disable the shortcut Ctrl + L from the menu: Settings -> Configure shortcuts