Use fonts.monospace properly
This commit is contained in:
parent
4562a3574b
commit
78d7ac311f
@ -611,6 +611,8 @@ def init(parent=None):
|
|||||||
val = ConfigContainer(instance)
|
val = ConfigContainer(instance)
|
||||||
key_instance = KeyConfig(instance)
|
key_instance = KeyConfig(instance)
|
||||||
|
|
||||||
|
configtypes.Font.monospace_fonts = val.fonts.monospace
|
||||||
|
|
||||||
config_commands = ConfigCommands(instance, key_instance)
|
config_commands = ConfigCommands(instance, key_instance)
|
||||||
objreg.register('config-commands', config_commands)
|
objreg.register('config-commands', config_commands)
|
||||||
|
|
||||||
|
@ -39,11 +39,6 @@ DATA = None
|
|||||||
|
|
||||||
# FIXME:conf what to do about this?
|
# FIXME:conf what to do about this?
|
||||||
DEFAULT_FONT_SIZE = '10pt' if sys.platform == 'darwin' else '8pt'
|
DEFAULT_FONT_SIZE = '10pt' if sys.platform == 'darwin' else '8pt'
|
||||||
MONOSPACE = (' xos4 Terminus, Terminus, Monospace, '
|
|
||||||
'"DejaVu Sans Mono", Monaco, '
|
|
||||||
'"Bitstream Vera Sans Mono", "Andale Mono", '
|
|
||||||
'"Courier New", Courier, "Liberation Mono", '
|
|
||||||
'monospace, Fixed, Consolas, Terminal')
|
|
||||||
|
|
||||||
|
|
||||||
Option = collections.namedtuple('Option', ['name', 'typ', 'default',
|
Option = collections.namedtuple('Option', ['name', 'typ', 'default',
|
||||||
|
@ -1685,7 +1685,11 @@ fonts.monospace:
|
|||||||
Vera Sans Mono", "Andale Mono", "Courier New", Courier, "Liberation Mono", monospace,
|
Vera Sans Mono", "Andale Mono", "Courier New", Courier, "Liberation Mono", monospace,
|
||||||
Fixed, Consolas, Terminal
|
Fixed, Consolas, Terminal
|
||||||
type: Font
|
type: Font
|
||||||
desc: Default monospace fonts.
|
desc: >-
|
||||||
|
Default monospace fonts.
|
||||||
|
|
||||||
|
Whenever "monospace" is used in a font setting, it\'s replaced with the
|
||||||
|
fonts listed here.
|
||||||
|
|
||||||
fonts.completion.entry:
|
fonts.completion.entry:
|
||||||
default: 8pt monospace
|
default: 8pt monospace
|
||||||
|
@ -849,6 +849,8 @@ class Font(BaseType):
|
|||||||
* Size: _number_ `px`/`pt`
|
* Size: _number_ `px`/`pt`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Gets set when the config is initialized.
|
||||||
|
monospace_fonts = None
|
||||||
font_regex = re.compile(r"""
|
font_regex = re.compile(r"""
|
||||||
^(
|
^(
|
||||||
(
|
(
|
||||||
@ -875,6 +877,8 @@ class Font(BaseType):
|
|||||||
# as family.
|
# as family.
|
||||||
raise configexc.ValidationError(value, "must be a valid font")
|
raise configexc.ValidationError(value, "must be a valid font")
|
||||||
|
|
||||||
|
if value.endswith(' monospace') and self.monospace_fonts is not None:
|
||||||
|
return value.replace('monospace', self.monospace_fonts)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@ -955,6 +959,8 @@ class QtFont(Font):
|
|||||||
# hopefully nobody will ever have a font with quotes in the family (if
|
# hopefully nobody will ever have a font with quotes in the family (if
|
||||||
# that's even possible), we take a much more naive approach.
|
# that's even possible), we take a much more naive approach.
|
||||||
family = family.replace('"', '').replace("'", '')
|
family = family.replace('"', '').replace("'", '')
|
||||||
|
if family == 'monospace':
|
||||||
|
family = self.monospace_fonts
|
||||||
font.setFamily(family)
|
font.setFamily(family)
|
||||||
return font
|
return font
|
||||||
|
|
||||||
|
@ -1260,6 +1260,16 @@ class TestFont:
|
|||||||
with pytest.raises(configexc.ValidationError):
|
with pytest.raises(configexc.ValidationError):
|
||||||
klass().to_py(val)
|
klass().to_py(val)
|
||||||
|
|
||||||
|
def test_monospace_replacement(self, klass, monkeypatch):
|
||||||
|
monkeypatch.setattr(configtypes.Font, 'monospace_fonts', 'Terminus')
|
||||||
|
if klass is configtypes.Font:
|
||||||
|
expected = '10pt Terminus'
|
||||||
|
elif klass is configtypes.QtFont:
|
||||||
|
desc = FontDesc(QFont.StyleNormal, QFont.Normal, 10, None,
|
||||||
|
'Terminus'),
|
||||||
|
expected = Font.fromdesc(*desc)
|
||||||
|
assert klass().to_py('10pt monospace') == expected
|
||||||
|
|
||||||
|
|
||||||
class TestFontFamily:
|
class TestFontFamily:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user