After some researching I found out that I can install a truetype font for the current user by just making a new string value in HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts with NAME set to the font's name and DATA set to the font's path. Removing a font is also similar, first you remove the string value for the specified font and then delete the font file itself.
I tried to do it manually and it does work (both installing and removing a font). But recreating everything in python lands me into a problem. I'm able to install font using the above method but when I try to remove the font then windows tells me that the font file is currently being used by "System". My program is able to remove the registry value but fails to delete the font file.
My helper registry editor functions can be found at -> https://github.com/nk521/phonts/blob/07a4d6de5165d5c19861c2f28708c60d52f33df9/core/helpers/win.py
This function installs a font -> https://github.com/nk521/phonts/blob/07a4d6de5165d5c19861c2f28708c60d52f33df9/core/win.py#L15
This function deletes a font -> https://github.com/nk521/phonts/blob/07a4d6de5165d5c19861c2f28708c60d52f33df9/core/win.py#L35
This line will generate a PermissionError -> https://github.com/nk521/phonts/blob/07a4d6de5165d5c19861c2f28708c60d52f33df9/core/win.py#L41
On Windows, GDI may lock font files that have been used. You might not be able to delete the font file until that user session has ended. If you delete the registry entry, then the font won't get loaded into GDI in the next session. Try deleting the reg entry, then log off and back on, that might unlock the file; or if it has locked it in a different session, you might need to reboot.
Related
Operating System: Win10, QT:PySide2
I implemented a programm in python, that aquires images from a camera. This image-aquisition sequence is triggered by pushing a button "Start Sequence". To determine a saving directory for the images I am using QFileDialog. The button "Start Sequence" therefore first opens up a filebrowser where the user can choose the folder, where it wants the sequence to be stored. Then the image aquisition is started. The code for the filebrowser looks like the following:
def get_dir(self, name) # name is only a string
start_dir = "D://data_someperson//"
dialog = QFileDialog()
options = dialog.Options()
options |= dialog.DontUseNativeDialog # i dont know what this is doing, but without it nothing works
dialog.setFileMode(QFileDialog.Directory)
filename = dialog.getExistingDirectory( None, name, start_dir, options = options)
return filename
As mentioned the code above opens a filebrowser in the "start_dir" location. So the filebrowser would start up in "D://data_someperson//" from where the user can create a new folder or choose an existing one. This is then returned as "filename", where the image aquisition code stores the camera pictures. Now this works under the condition that the start_dir is equal to the working directory of my program. E.g. I run my main program via VScode in "D://data_otto" and start_dir is set to "D://data_otto". Here the file browser displays instantly (as it pops up) all existing files in "D://data_otto" and the user can easily create new folders without any problems.
My Problem now is the following: If "start_dir" is not equal to "D://data_otto" (eg, it start_dir is equal to "D://data_peter") the file browser pops up as usual in "start_dir" but basicly tries to "load" every existing file on my machine before it displays the files in "start_dir", where the user is supposed to choose a saving directory. This is also true when the user creates a new folder in "start_dir". If the user creates a new folder and confirms it in the gui, the function "getExistingDirectory" still waits for all files to be loaded, sort of in the background.
This delays my data aquisition by up to a minute. "D://" is a Hard Drive DT01ACA100 1TB and ~800Gb are occupied. I think my problem could be solved by using a faster drive, but there must be a way to restrict the Filebrowser's scope of files it loads to display, but i cant find such a workaround in the documentation... I observed, that the folders and files in start_dir are cached once they were loaded for a short amount of time. Extending this time would help aswell...
Ok it appears as I solved my problem by disconnecting two unaccessible "Network locations" that appeared under "This PC" as the drives "Y:" and "Z:". They where unaccessible (indicated as a Red cross in the Explorer), since the PC was disconnected from its local network and was moved to a different one. So just hit right click on them and choose "Disconnect" in the drop down menu to remove these "Network Locations". After that I had no more problems with the File Browser and everything needed is displayed instantly. No more delays/loading/buffering. THANKS goes to https://stackoverflow.com/users/2001654/musicamante.
I've searched all over and can't seem to find a solution. Python's IDLE just looks terrible on my laptop (Lenovo Yoga 2 Pro) with a 3200x1800 display running 8.1
I've attached a screenshot so you can see what I'm talking about. Has anyone figured out how to configure this? Thanks for the help!
Add a file like %USERPROFILE%\.idlerc\config-main.cfg
Add the following lines:
[EditorWindow]
font-size = 14
font = monaco
Or pick your favorite font and size.
I presume 'terrible looking' applies to the old Courier (typewriter) font. IDLE's tk Text windows (Shell, Editor, and Output) default to using 10 point 'TkFixedFont'. On Windows, (and only on Windows), that resolves to 'Courier'. I believe that this is or at least used to be standard on Windows.
The best solution is to select Options on the top menu bar and then Configure IDLE. One is then presented with a dialog with the Fonts/Tabs tab selected and the current font selected in the Base Editor Font box and the current size next to Size. There is an example box showing some text in the current font and size. Change either the font or size and the example is updated. Select OK or Apply and current text windows are updated.
Choices other than default are written to config-main.cfg in directory %USERPROFILE%/.idlerc/. The directory and file are created if necessary.
I personally use the fixed-pitch Lucida Console. I occasionally use variable-pitch Lucida Sans Unicode when using strings with non-Latin characters. One can tell from the example in the box whether a font is fixed or variable in character width by whether characters line up neatly in columns or not. (One of my goals is to add examples from several other scripts so one can also see the unicode coverage offered by a font.)
There are terminal and python console in pycharm, which are very convenient. But I found that the font size was too small to recognize in terminal or python console. How can change the font size in the terminal or python console?
In PyCharm 2016.3, the console font setting is squirrelled away under Settings > Editor > Colors & Fonts > Console Font:
Note: Changes to the colors and font are not visible immediately, you have to restart the terminal session to apply them. It's not enough to just hide and reopen the terminal. Just click the red cross button on the terminal's toolbar (Close Terminal Session) and reopen it. The same is valid also for the Python Console.
The location of console font changed in the latest versions of Pycharm.
Settings -> Editor -> Color Scheme -> Console Font
Go to File\Settings\Editor\Color & Fonts and choose save as to save currently used schema by a new name in order to make changes on a new schema. Then in mentioned direction go to console font and set size.
I thought it doesn't work for me either but the problem was that:
you have to close all terminal windows to see the spacing effect.
A simple google search would have lead you here.
You just need to create a personal scheme under settings >Editor > color and fonts.
Edit:Here this further explanation may help more.
1.In color and fonts choose save as and give a scheme name.
2.Go to console font and change size and primary font, which will be inaccessible if you didn't choose the personal scheme you created earlier.
Both this question Add a custom font in Qt and this link mentioning the ability to add fonts through c++. Is this possible through python and the Qt Designer framework? I have attempted adding the ttf to resources and compiling the qrc file. Then in the stylesheet defining the font.
When launching the app nothing happens. Is there something else that needs to be done? The example discusses loading binary files.
You need to also add it to the QFontDatabase:
First add the font file “yourfont” to the resource editor (which you have done) and then to the fontdatabase
QFontDatabase fontDatabase;
fontDatabase.addApplicationFont(":/fonts/yourfont");
Now you can use yourfont with setFont for instance on a QLabel.
Since there is no mention in the answers/comments about QtDesigner, neither here nor in the linked posts, this is what I found about QtDesigner standalone (5.6) - about a font that is not installed in the system:
I've used a free font called AutobusBold.ttf. First, path to this file needs to end up in your qrc file, mostly for the sake of Python - you can use Resource Browser/Edit Resources (the pencil) for this; you will end up with something like this in the .qrc file:
<file>myfont/AutobusBold.ttf</file>
If you open the .ttf file with fontview.exe on Windows, you'll see its name is Autobus Bold - with a space.
Then you need to close the .ui file in QtDesigner, then go to Settings/Additional Fonts... in QtDesigner (if an .ui file is open, then this option is greyed out); there click the + ("Add font file"), find the .ttf font file, and add it by selecting it and hitting Open. From now on, this font will appear whenever the Font dialog is opened in QtDesigner, mixed with the system fonts.
Then, reopen your .ui file, find the element you want to apply this font to and select it, in its styleSheet option click the three dots, and from the resulting dialog window, click Add Font - you'll get the Font dialog, with all system fonts - but also the custom font will be there; select it, and you'll get a .qss stanza like this: font: 75 8pt "Autobus Bold";
That first 75 is probably font-weight, you can also delete it, it will work the same; the 8pt is font-size, and "Autobus Bold" is font-family. Notice here that the font name in font-family is quoted, as it has a space in the name - without the quotes, everything fails!
Then, if you write an extern .qss file, you can rewrite the font: stanza as separate font-family (with quoted font name!) and font-size stanzas - and it should work the same.
Of course, if you want to transfer all this to Python, then you need to additionally addApplicationFont as described in the answer by #GPPK.
I'm trying to write a font viewer for TrueType / OpenType fonts with VB6 / VB5 code (under Windows).
it is surprisingly difficult:
1) in VB / winAPI, i did not find how to extract the font's name, or font properties in general.
2) i can install the font (using AddFontResource API function), but then have to uninstall it. However, while (AddFontResource" expects a pathname, removing the font requires the font's name which is unknown to me.
is there a way to use an non-installed font ttf) ?
is there a way to extract a font's properties using vb6 ?
(I can write the program in wxPython but i know even less about fonts in python than with VB)
You could use the FreeType library.
It indeed is. I have faced the same problem myself (see my question). I ended up writing my own parser though because I needed to detect if the font was corrupt or not. There is a AddFontMemResourceEx function which:
When the function succeeds, the caller of this function can free the memory pointed to by pbFont because the system has made its own copy of the memory. To remove the fonts that were installed, call RemoveFontMemResourceEx. However, when the process goes away, the system will unload the fonts even if the process did not call RemoveFontMemResource.
Also, you can use the Font and Text Functions to get the font metrics.