Reputation: 7705
From a Python script that is started under X, I want to get the font path.
The script passes the font path to Xvnc
(part of TightVNC and TigerVNC). Yes, I know, to start a VNC server, one can use startvnc
, which takes care of setting up the font path. However, startvnc
does some things that are not desired in this case. Also, I want to use the exact same font path as on the X server that the script is started on.
I considered parsing the output of xset q
. However:
I don't know how reliable that is, i.e. if output is always formatted the same way.
The output may contain placeholders that are not actually paths. For
example, built-ins
in:
/usr/share/fonts/misc,/usr/share/fonts/Type1,built-ins
Upvotes: 1
Views: 1118
Reputation: 320
From reading the manual for xorg.conf, your safest bet would be to parse the configuration file (which I'm assuming setx q
parses) for FontPath
lines, which look like:
FontPath "path" sets the search path for fonts. This path is a comma separated list of font path elements which the Xorg server searches for font databases.
Using python's re module, the font paths (because multiple FontPath
s can be specified) can be parsed like this:
import re
regex = re.compile(r'^\s*FontPath\s+(.*)\s*$', re.MULTILINE)
with open('xorg.conf') as f:
data = f.read()
matches = regex.findall(data)
Upvotes: 1