-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get font style from main config #523
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,11 @@ | |
tsdb.backend = 'marketstore' | ||
tsdb.host = 'localhost' | ||
tsdb.grpc_port = 5995 | ||
|
||
[ui] | ||
# set custom font + size which will scale entire UI | ||
# font_size = 16 | ||
# font_name = 'Monospaced' | ||
|
||
# colorscheme = 'default' # UNUSED | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are just "wishlist" stuff rn since nothing implemented but figured i might as well toss em in for a keen piker to take a swing at 😉 |
||
# graphics.update_throttle = 60 # Hz # TODO |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
|
||
from ..log import get_logger | ||
|
||
from .. import config | ||
|
||
log = get_logger(__name__) | ||
|
||
_magic_inches = 0.0666 * (1 + 6/16) | ||
|
@@ -49,15 +51,27 @@ class DpiAwareFont: | |
|
||
def __init__( | ||
self, | ||
# TODO: move to config | ||
name: str = 'Hack', | ||
font_size: str = 'default', | ||
_font_size_key: str = 'default', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. main init change was this, anyway, changed all dep code as well so should be fine to land without regression. |
||
|
||
) -> None: | ||
|
||
self._font_size_calc_key: str = _font_size_key | ||
self._font_size: int | None = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this now gets cached (after first calc) if not defined in the user config TODO: ideally in the future we can actually build an entire "dynamic resizing system" + controls so that a user can do the classic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm maybe i'll make a follow up task-issue for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, another thing was checking out that https://github.com/samuelcolvin/watchfiles lib to see if we could also get a "changes-in- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mentioned in #221 since we're more or less officially exposing a top level config now. |
||
|
||
# Read preferred font size from main config file if it exists | ||
conf, path = config.load('conf', touch_if_dne=True) | ||
if ui_section := conf.get('ui'): | ||
if font_size := ui_section.get('font_size'): | ||
self._font_size = int(font_size) | ||
|
||
if not (name := ui_section.get('font_name')): | ||
name: str = 'Hack' | ||
|
||
self.name = name | ||
self._qfont = QtGui.QFont(name) | ||
self._font_size: str = font_size | ||
self._qfm = QtGui.QFontMetrics(self._qfont) | ||
|
||
self._font_inches: float = None | ||
self._screen = None | ||
|
||
|
@@ -99,6 +113,14 @@ def configure_to_dpi(self, screen: QtGui.QScreen | None = None): | |
listed in the script in ``snippets/qt_screen_info.py``. | ||
|
||
''' | ||
if self._font_size is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm maybe it's handy to eventually add a (will stick in follow up issue as per above comments) |
||
self._set_qfont_px_size(self._font_size) | ||
return | ||
|
||
# NOTE: if no font size set either in the [ui] section of the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe document this impl detail: the dynamic size calculating by DPI, in the class doc string? |
||
# config or not yet computed from our magic scaling calcs, | ||
# then attempt to caculate it here! | ||
|
||
if screen is None: | ||
screen = self.screen | ||
|
||
|
@@ -116,10 +138,10 @@ def configure_to_dpi(self, screen: QtGui.QScreen | None = None): | |
scale = round(ldpi/pdpi, ndigits=2) | ||
|
||
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 | ||
inches = _font_sizes['hi'][self._font_size] | ||
inches = _font_sizes['hi'][self._font_size_calc_key] | ||
|
||
dpi = mn_dpi | ||
|
||
|
@@ -128,7 +150,7 @@ def configure_to_dpi(self, screen: QtGui.QScreen | None = None): | |
# No implicit DPI scaling was done by the DE so let's engage | ||
# some hackery ad-hoc scaling shiat. | ||
# 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 | ||
if 1.2 <= scale: | ||
|
@@ -184,7 +206,7 @@ def boundingRect(self, value: str) -> QtCore.QRectF: | |
|
||
# use inches size to be cross-resolution compatible? | ||
_font = DpiAwareFont() | ||
_font_small = DpiAwareFont(font_size='small') | ||
_font_small = DpiAwareFont(_font_size_key='small') | ||
|
||
|
||
def _config_fonts_to_screen() -> None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ebisu4 tellin me there's issues getting this to work on windows @sirdinkus, so if you could test it a bit it'd be handy 😉