Merge pull request #1 from pikers/fix_custom_font_settings
Fix reading font size from user config on linuxmaster
commit
949fa9fbb9
|
@ -2,3 +2,11 @@
|
||||||
tsdb.backend = 'marketstore'
|
tsdb.backend = 'marketstore'
|
||||||
tsdb.host = 'localhost'
|
tsdb.host = 'localhost'
|
||||||
tsdb.grpc_port = 5995
|
tsdb.grpc_port = 5995
|
||||||
|
|
||||||
|
[ui]
|
||||||
|
# set custom font + size which will scale entire UI
|
||||||
|
# font_size = 16
|
||||||
|
# font_name = 'Monospaced'
|
||||||
|
|
||||||
|
# colorscheme = 'default' # UNUSED
|
||||||
|
# graphics.update_throttle = 60 # Hz # TODO
|
||||||
|
|
|
@ -418,7 +418,7 @@ class AxisLabel(pg.GraphicsObject):
|
||||||
|
|
||||||
self._txt_br: QtCore.QRect = None
|
self._txt_br: QtCore.QRect = None
|
||||||
|
|
||||||
self._dpifont = DpiAwareFont(font_size=font_size)
|
self._dpifont = DpiAwareFont(_font_size_key=font_size)
|
||||||
self._dpifont.configure_to_dpi()
|
self._dpifont.configure_to_dpi()
|
||||||
|
|
||||||
self.bg_color = pg.mkColor(hcolor(bg_color))
|
self.bg_color = pg.mkColor(hcolor(bg_color))
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Label:
|
||||||
|
|
||||||
# configure font size based on DPI
|
# configure font size based on DPI
|
||||||
dpi_font = DpiAwareFont(
|
dpi_font = DpiAwareFont(
|
||||||
font_size=font_size,
|
_font_size_key=font_size,
|
||||||
)
|
)
|
||||||
dpi_font.configure_to_dpi()
|
dpi_font.configure_to_dpi()
|
||||||
txt.setFont(dpi_font.font)
|
txt.setFont(dpi_font.font)
|
||||||
|
|
|
@ -52,28 +52,26 @@ class DpiAwareFont:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name: str = 'Hack',
|
name: str = 'Hack',
|
||||||
font_size: str = 'default',
|
_font_size_key: str = 'default',
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self._custom_ui = False
|
|
||||||
|
self._font_size_calc_key: str = _font_size_key
|
||||||
|
self._font_size: int | None = None
|
||||||
|
|
||||||
# Read preferred font size from main config file if it exists
|
# Read preferred font size from main config file if it exists
|
||||||
conf, path = config.load('conf', touch_if_dne=True)
|
conf, path = config.load('conf', touch_if_dne=True)
|
||||||
ui_section = conf.get('ui')
|
if ui_section := conf.get('ui'):
|
||||||
if ui_section:
|
if font_size := ui_section.get('font_size'):
|
||||||
self._custom_ui = True
|
self._font_size = int(font_size)
|
||||||
|
|
||||||
font_size = ui_section.get('font_size')
|
if not (name := ui_section.get('font_name')):
|
||||||
if not font_size:
|
name: str = 'Hack'
|
||||||
font_size = 'default'
|
|
||||||
|
|
||||||
name = ui_section.get('name')
|
|
||||||
if not name:
|
|
||||||
name = 'Hack'
|
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self._qfont = QtGui.QFont(name)
|
self._qfont = QtGui.QFont(name)
|
||||||
self._font_size: str = font_size
|
|
||||||
self._qfm = QtGui.QFontMetrics(self._qfont)
|
self._qfm = QtGui.QFontMetrics(self._qfont)
|
||||||
|
|
||||||
self._font_inches: float = None
|
self._font_inches: float = None
|
||||||
self._screen = None
|
self._screen = None
|
||||||
|
|
||||||
|
@ -115,10 +113,14 @@ class DpiAwareFont:
|
||||||
listed in the script in ``snippets/qt_screen_info.py``.
|
listed in the script in ``snippets/qt_screen_info.py``.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
if self._custom_ui:
|
if self._font_size is not None:
|
||||||
self._set_qfont_px_size(self._font_size)
|
self._set_qfont_px_size(self._font_size)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# NOTE: if no font size set either in the [ui] section of the
|
||||||
|
# config or not yet computed from our magic scaling calcs,
|
||||||
|
# then attempt to caculate it here!
|
||||||
|
|
||||||
if screen is None:
|
if screen is None:
|
||||||
screen = self.screen
|
screen = self.screen
|
||||||
|
|
||||||
|
@ -136,10 +138,10 @@ class DpiAwareFont:
|
||||||
scale = round(ldpi/pdpi, ndigits=2)
|
scale = round(ldpi/pdpi, ndigits=2)
|
||||||
|
|
||||||
if mx_dpi <= 97: # for low dpi use larger font sizes
|
if mx_dpi <= 97: # for low dpi use larger font sizes
|
||||||
inches = _font_sizes['lo'][self._font_size]
|
inches = _font_sizes['lo'][self._font_size_calc_key]
|
||||||
|
|
||||||
else: # hidpi use smaller font sizes
|
else: # hidpi use smaller font sizes
|
||||||
inches = _font_sizes['hi'][self._font_size]
|
inches = _font_sizes['hi'][self._font_size_calc_key]
|
||||||
|
|
||||||
dpi = mn_dpi
|
dpi = mn_dpi
|
||||||
|
|
||||||
|
@ -148,7 +150,7 @@ class DpiAwareFont:
|
||||||
# No implicit DPI scaling was done by the DE so let's engage
|
# No implicit DPI scaling was done by the DE so let's engage
|
||||||
# some hackery ad-hoc scaling shiat.
|
# some hackery ad-hoc scaling shiat.
|
||||||
# dpi is likely somewhat scaled down so use slightly larger font size
|
# dpi is likely somewhat scaled down so use slightly larger font size
|
||||||
if scale >= 1.1 and self._font_size:
|
if scale >= 1.1 and self._font_size_calc_key:
|
||||||
|
|
||||||
# no idea why
|
# no idea why
|
||||||
if 1.2 <= scale:
|
if 1.2 <= scale:
|
||||||
|
@ -204,7 +206,7 @@ class DpiAwareFont:
|
||||||
|
|
||||||
# use inches size to be cross-resolution compatible?
|
# use inches size to be cross-resolution compatible?
|
||||||
_font = DpiAwareFont()
|
_font = DpiAwareFont()
|
||||||
_font_small = DpiAwareFont(font_size='small')
|
_font_small = DpiAwareFont(_font_size_key='small')
|
||||||
|
|
||||||
|
|
||||||
def _config_fonts_to_screen() -> None:
|
def _config_fonts_to_screen() -> None:
|
||||||
|
|
Loading…
Reference in New Issue