feklee
feklee

Reputation: 7705

How to get X font path from Python script?

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:

Upvotes: 1

Views: 1118

Answers (1)

robobrobro
robobrobro

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 FontPaths 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

Related Questions