Compare commits
2 Commits
858cfce958
...
3a515afccd
| Author | SHA1 | Date |
|---|---|---|
|
|
3a515afccd | |
|
|
88732a67d5 |
|
|
@ -30,7 +30,7 @@ import tractor
|
||||||
|
|
||||||
from piker.data._formatters import BGM
|
from piker.data._formatters import BGM
|
||||||
from piker.storage import log
|
from piker.storage import log
|
||||||
# from piker.ui._style import _font
|
from piker.ui._style import get_fonts
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from piker.ui._remote_ctl import AnnotCtl
|
from piker.ui._remote_ctl import AnnotCtl
|
||||||
|
|
@ -88,6 +88,10 @@ async def markup_gaps(
|
||||||
wdts: pl.DataFrame,
|
wdts: pl.DataFrame,
|
||||||
gaps: pl.DataFrame,
|
gaps: pl.DataFrame,
|
||||||
|
|
||||||
|
# XXX, switch on to see txt showing a "humanized" label of each
|
||||||
|
# gap's duration.
|
||||||
|
show_txt: bool = False,
|
||||||
|
|
||||||
) -> dict[int, dict]:
|
) -> dict[int, dict]:
|
||||||
'''
|
'''
|
||||||
Remote annotate time-gaps in a dt-fielded ts (normally OHLC)
|
Remote annotate time-gaps in a dt-fielded ts (normally OHLC)
|
||||||
|
|
@ -202,6 +206,10 @@ async def markup_gaps(
|
||||||
|
|
||||||
diff: float = cls - opn
|
diff: float = cls - opn
|
||||||
sgn: float = copysign(1, diff)
|
sgn: float = copysign(1, diff)
|
||||||
|
up_gap: bool = sgn == -1
|
||||||
|
down_gap: bool = sgn == 1
|
||||||
|
flat: bool = sgn == 0
|
||||||
|
|
||||||
color: str = 'dad_blue'
|
color: str = 'dad_blue'
|
||||||
# TODO? mks more sense to have up/down coloring?
|
# TODO? mks more sense to have up/down coloring?
|
||||||
# color: str = {
|
# color: str = {
|
||||||
|
|
@ -233,7 +241,7 @@ async def markup_gaps(
|
||||||
assert aid
|
assert aid
|
||||||
aids[aid] = rect_kwargs
|
aids[aid] = rect_kwargs
|
||||||
direction: str = (
|
direction: str = (
|
||||||
'down' if sgn == 1
|
'down' if down_gap
|
||||||
else 'up'
|
else 'up'
|
||||||
)
|
)
|
||||||
# TODO! mk this a `msgspec.Struct` which we deserialize
|
# TODO! mk this a `msgspec.Struct` which we deserialize
|
||||||
|
|
@ -261,31 +269,33 @@ async def markup_gaps(
|
||||||
)
|
)
|
||||||
|
|
||||||
# add duration label to RHS of arrow
|
# add duration label to RHS of arrow
|
||||||
if sgn == -1: # up-gap
|
if up_gap:
|
||||||
anchor = (0, 0) # XXX, i dun get dese dims.. XD
|
anchor = (0, 0)
|
||||||
else: # down-gap
|
# ^XXX? i dun get dese dims.. XD
|
||||||
|
elif down_gap:
|
||||||
anchor = (0, 1) # XXX y, x?
|
anchor = (0, 1) # XXX y, x?
|
||||||
|
else: # no-gap?
|
||||||
|
assert flat
|
||||||
|
anchor = (0, 0) # up from bottom
|
||||||
|
|
||||||
# ?TODO? why returning -1 !?
|
# use a slightly smaller font for gap label txt.
|
||||||
# [ ] use conf.toml value instead!
|
font, small_font = get_fonts()
|
||||||
#
|
font_size: int = small_font.px_size - 1
|
||||||
# font_size: int = _font.font.pixelSize() - 10
|
assert isinstance(font_size, int)
|
||||||
# await tractor.pause()
|
|
||||||
# assert isinstance(font_size, int)
|
|
||||||
font_size = None
|
|
||||||
|
|
||||||
text_aid: int = await actl.add_text(
|
if show_txt:
|
||||||
fqme=fqme,
|
text_aid: int = await actl.add_text(
|
||||||
timeframe=timeframe,
|
fqme=fqme,
|
||||||
text=gap_label,
|
timeframe=timeframe,
|
||||||
x=iend + 1, # fallback if timestamp lookup fails
|
text=gap_label,
|
||||||
y=cls,
|
x=iend + 1, # fallback if timestamp lookup fails
|
||||||
time=gap_time, # server-side index lookup
|
y=cls,
|
||||||
color=color,
|
time=gap_time, # server-side index lookup
|
||||||
anchor=anchor,
|
color=color,
|
||||||
font_size=font_size,
|
anchor=anchor,
|
||||||
)
|
font_size=font_size,
|
||||||
aids[text_aid] = {'text': gap_label}
|
)
|
||||||
|
aids[text_aid] = {'text': gap_label}
|
||||||
|
|
||||||
# tell chart to redraw all its
|
# tell chart to redraw all its
|
||||||
# graphics view layers Bo
|
# graphics view layers Bo
|
||||||
|
|
|
||||||
|
|
@ -407,8 +407,9 @@ async def serve_rc_annots(
|
||||||
# apply font size (default to DpiAwareFont if not
|
# apply font size (default to DpiAwareFont if not
|
||||||
# provided)
|
# provided)
|
||||||
if font_size is None:
|
if font_size is None:
|
||||||
from ._style import _font
|
from ._style import get_fonts
|
||||||
font_size = _font.font.pixelSize() - 3
|
font, font_small = get_fonts()
|
||||||
|
font_size = font_small.px_size - 1
|
||||||
|
|
||||||
qfont: QFont = text_item.textItem.font()
|
qfont: QFont = text_item.textItem.font()
|
||||||
qfont.setPixelSize(font_size)
|
qfont.setPixelSize(font_size)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class DpiAwareFont:
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
self._font_size_calc_key: str = _font_size_key
|
self._font_size_calc_key: str = _font_size_key
|
||||||
self._font_size: int | None = None
|
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)
|
||||||
|
|
@ -107,7 +107,22 @@ class DpiAwareFont:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def px_size(self) -> int:
|
def px_size(self) -> int:
|
||||||
return self._qfont.pixelSize()
|
size: int = self._qfont.pixelSize()
|
||||||
|
|
||||||
|
# XXX, when no Qt app has been spawned this will always be
|
||||||
|
# invalid..
|
||||||
|
# SO, just return any conf.toml value.
|
||||||
|
if size == -1:
|
||||||
|
if (conf_size := self._font_size) is None:
|
||||||
|
raise ValueError(
|
||||||
|
f'No valid `{type(_font).__name__}.px_size` set?\n'
|
||||||
|
f'\n'
|
||||||
|
f'-> `ui.font_size` is NOT set in `conf.toml`\n'
|
||||||
|
f'-> no Qt app is active ??\n'
|
||||||
|
)
|
||||||
|
return conf_size
|
||||||
|
|
||||||
|
return size
|
||||||
|
|
||||||
def configure_to_dpi(self, screen: QtGui.QScreen | None = None):
|
def configure_to_dpi(self, screen: QtGui.QScreen | None = None):
|
||||||
'''
|
'''
|
||||||
|
|
@ -221,6 +236,20 @@ def _config_fonts_to_screen() -> None:
|
||||||
_font_small.configure_to_dpi()
|
_font_small.configure_to_dpi()
|
||||||
|
|
||||||
|
|
||||||
|
def get_fonts() -> tuple[
|
||||||
|
DpiAwareFont,
|
||||||
|
DpiAwareFont,
|
||||||
|
]:
|
||||||
|
'''
|
||||||
|
Get the singleton font pair (of instances) from which all other
|
||||||
|
UI/UX should be "scaled around".
|
||||||
|
|
||||||
|
See `DpiAwareFont` for (internal) deats.
|
||||||
|
|
||||||
|
'''
|
||||||
|
return _font, _font_small
|
||||||
|
|
||||||
|
|
||||||
# TODO: re-compute font size when main widget switches screens?
|
# TODO: re-compute font size when main widget switches screens?
|
||||||
# https://forum.qt.io/topic/54136/how-do-i-get-the-qscreen-my-widget-is-on-qapplication-desktop-screen-returns-a-qwidget-and-qobject_cast-qscreen-returns-null/3
|
# https://forum.qt.io/topic/54136/how-do-i-get-the-qscreen-my-widget-is-on-qapplication-desktop-screen-returns-a-qwidget-and-qobject_cast-qscreen-returns-null/3
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue