I am trying to write a utility to check through the fonts on OSX and remove duplicates - so far I've had success iterating through the folder structure and writing out an xml file containing fonts and paths. The drawback is that this doesn't find duplicates as the same font can be installed twice in different locations but with a different file name; font family information is internal to the font file.
I have found this: List of installed fonts OS X / C
import Cocoa
manager = Cocoa.NSFontManager.sharedFontManager()
font_families = list(manager.availableFontFamilies())
Which uses PyObjC to list installed fonts. This looks like a possible solution but I'm not a heavy weight coder and know nothing about PyObjC! I did have a play around in a terminal with dir(manager)and dir(NSFontManager)to see if I could find a method that returned the file paths of installed fonts but to no avail.
Any help gratefully received.
Best wishes
//Simon
Install the fonttools package and take a look at this blog post. There's a script there that gives the font name of its first argument and I'm sure you could adapt it to your use case.
Thanks once again for the replies - I just wanted to update this in the hope it helps. I'm looking at fontTools now, but admit I am having trouble finding documentation. According to the developer's page there are libraries to handle other fonts apart from ttf, but I'm still looking with little success just yet!
In the mean time, I did turn up this page on Using Apple Font tools, which seems get half way to what I need - ie listing installed fonts and locations. It looks like the ftxinstalledfonts command will accept a pipe so in theory I could pipe the output to my existing python script that builds an xml database. I'm assuming I can do this by calling ftxinstalledfonts via the sys module but am not clear as to how to get the output... I'll go and plunder the python docs but if there's no luck and someone has 10 secs to give a pointer I'd be grateful.
As a quick aside, the Font Geek site above has some very useful stuff about TTX as well.
Best wishes
//Simon
Related
I'm looking for a way to convert my AsciiMath (or MathML) sources to SVG and/or PNG. I've found a nodeJS library for SVG conversion but calling that from Python is not very convenient and the output is not entirely satisfying.
Taking the fact I'd like to render mathematical formulas to svg/png it seems logical to look for a solution in math libraries (NumPy, SciPy, Pandas, Matplotlib, Sympy, etc...) but to no avail. All my google results combining all possible permutations of asciimath+mathml+svg+png lead to nothing which is strange.
Please recommend me either search patterns to find a solution or share your experiences/ideas to get this seemingly simple job done in Python.
All help would be highly appreciated!
I just created ziamath for exactly this purpose. It comes bundled with the STIX math font, so no setup is required beyond the pip install, but it should also work with other math-enabled fonts. Pure-Python, so it does not need a Latex installation or anything else to work. This first version doesn't quite cover the full MathML specification, but the most useful parts are in there.
To bundle it into an app with something like PyInstaller, you'll need to make sure the STIX font gets included, but that should just be one line in the PyInstaller config.
I have used this for years without issues. It is written in python.
https://sourceforge.net/projects/svgmath/files/svgmath/0.3.3/
I am creating some python files with extensions .pyt. Every thing is working fine except syntax highlighting.
My new .pyt files are not syntax highlighted as normal .py files do.
Ofcourse, I can change in
view>Highlight Mode> Script > python
manually for every file, but there are around 1200 files and they keep growing. I really dont want to do this manually for each file for the the first opening.
Is there any way to apply default python syntax highlighting to my new .pyt files.
Any Help will be highly appriciated.
P.S. I have read how to do this for gedit 2.0 in many pages like page1, page2 and many more pages but couldn't find any good working processes for gedit 1.0.
Although you (the OP) wrote that you found pages that were meant for gedit 3, I'm going to suggest that you look at this question.
Basically, even if gedit 1.0 used an older version of gtksourceview, as long as you can find the python.lang file in your system and change it, you can probably make it work. After all, it must have some way of specifying on which files it's used.
For new (Gtksourceview 2.0) lang files, this is done by adding either the mimetypes or globs property within the language's tag. So when you find the python.lang file, look for the *.py extension, and see if you can add *.pyt there, as is detailed in the question I linked above.
I like PySide, and have used it for a while now, but in the program I am working on at the moment, I need an advanced code editor.
I have found QScintilla, but that is for PyQt. Is that compatible with PySide and if so, how would I go about using it?
I have also looked at PySide-QScintilla, but all that is is a couple of .h files and an __init.py__ and the __init__.py doesn't even have anything relating to the .h files! Has anyone used that? How do you include it in a program?
I also saw qutepart but it seems to be mush too basic for what I need.
I would accept solutions other than QScintilla, but they have to have:
Error Highlighting
Syntax Highlighting
Code Suggestion (a drop down menu while typing)
Line Numbers
Custom Colors
Must be at least GPL (LGPL would be nice)
Any other features are great.
Doing a quick Google search brought up the following:
http://gitorious.org/pyside-qscintilla
https://github.com/LuaDist/scintilla/tree/master/qt/ScintillaEditPy
I suspect the first one is a direct port, whereas the second is some kind of Scintilla wrapper instead of a QScintilla port.
I'm trying to extract some version information from a DLL using python. I read this question:
Python windows File Version attribute
It was helpful, but I also need to get the 'Assembly version' from the DLL. It's there when I right click and look on the versions tab, but not sure how I extract this with python.
On this page:
http://timgolden.me.uk/python/win32_how_do_i/get_dll_version.html
Tim Golden says:
You can use the slightly more messy
language-dependent code in the demos
which come with pywin32 to find the
strings in the box beneath it.
Can someone point me to the example that might be useful? I looked in the win32api directories but there's nothing obvious. Would I find a solution there?
If you would rather not introduce a dependency on Python.Net, you can also use the win32 api directly:
from win32api import GetFileVersionInfo, LOWORD, HIWORD
def get_version_number (filename):
info = GetFileVersionInfo (filename, "\\")
ms = info['FileVersionMS']
ls = info['FileVersionLS']
return HIWORD (ms), LOWORD (ms), HIWORD (ls), LOWORD (ls)
Source: http://timgolden.me.uk/python/win32_how_do_i/get_dll_version.html
I'm not sure you can get at this information by using native code. The usual way of obtaining the assembly info is by running .Net code (e.g. C#). So I'm guessing in order to be able to do the same from python you'll need to run some .Net python interpreter. See for example http://pythonnet.github.io/
I've seen numerous ways of retrieving installed programs on WinXP+ in python. What is the proper and most robust way of doing this?
Currently I'm accessing HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall and reading each of the keys from there to get a list. (I've been told this isn't the proper way of doing things) I've seen examples of using WMI/Win32com to do this as well but have seen comments along with those implementations that WMI might be turned off on certain machines and that it's not a very reliable solution.
Is there a method which is both proper, and reliable to get a list of installed programs? None of the WMI examples I've seen have worked on this machine (hence my reluctance to use it, I'm only running WinFLP; which is a stripped vers of XP.)
I seem to have also found the TechNet article which my searches have turned up which is provided to a similar answer on my question: http://gallery.technet.microsoft.com/ScriptCenter/en-us/154dcae0-57a1-4c6e-8f9f-b215904485b7 Note that Vista/7 listed under Platforms very clearly says "Nope"...won't work. So the WMI deal seems like it's a no-go...
Being able to retrieve the installed path would be an upside as well, as right now my current code does not account for someone installing on another drive, or in a non-default directory.
The technet script you refer to perfectly works under Win 7 (with Python 2.5 32bits), and I really cannot see why it shouldn't.
Actually, the real weakness of the WMI approach is that it only lists products installed through the Windows Installer. So it's will not give you the full list. Many programs use different installers. Just compare the results between the (Select * from Win32_Product) and what is displayed in the Control Panel. So, unless you are sure that the program that interset you in your listing are installed with MSI, WMI is definitely not an answer.
So it may be not very pythonic, but the best way, as far as I know, is to use the registry as you've done. This is actually how the control panel works, so at least Windows considers it to be the most robust way to do it.
WMI is the correct way to look for installed programs as it will work across different versions of the OS and will be supported going forward. Looking for specific regkeys may work fine for specific versions of Windows but is not guaranteed to work in the future. Here is some simple python code to check for Box Sync which I just tried on Windows 7. Note that not all fields will be available for every product so be aware these will be 'None.'
import wmi
w = wmi.WMI()
for p in w.Win32_Product():
if 'Box, Inc.' == p.Vendor and p.Caption and 'Box Sync' in p.Caption:
print 'Installed {}'.format(p.Version)
The downside I have seen with WMI is it is very slow to start up.