Add `font_size` param to `AnnotCtl.add_text()` API

Expose font sizing control for `pg.TextItem` annotations thru the
annot-ctl API. Default to `_font.font.pixelSize() - 3` when no
size provided.

Also,
- thread `font_size` param thru IPC handler in `serve_rc_annots()`
- apply font via `QFont.setPixelSize()` on text item creation
- add `?TODO` note in `markup_gaps()` re using `conf.toml` value
- update `add_text()` docstring with font_size param desc

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
multiaddrs
Gud Boi 2026-01-27 20:53:10 -05:00
parent de5b1737b4
commit 1fb0fe3a04
2 changed files with 30 additions and 1 deletions

View File

@ -30,6 +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
if TYPE_CHECKING: if TYPE_CHECKING:
from piker.ui._remote_ctl import AnnotCtl from piker.ui._remote_ctl import AnnotCtl
@ -236,6 +237,14 @@ async def markup_gaps(
else: # down-gap else: # down-gap
anchor = (0, 1) # XXX y, x? anchor = (0, 1) # XXX y, x?
# ?TODO? why returning -1 !?
# [ ] use conf.toml value instead!
#
# font_size: int = _font.font.pixelSize() - 10
# await tractor.pause()
# assert isinstance(font_size, int)
font_size = None
text_aid: int = await actl.add_text( text_aid: int = await actl.add_text(
fqme=fqme, fqme=fqme,
timeframe=timeframe, timeframe=timeframe,
@ -244,6 +253,7 @@ async def markup_gaps(
y=cls, y=cls,
color=color, color=color,
anchor=anchor, anchor=anchor,
font_size=font_size,
) )
aids[text_aid] = {'text': gap_label} aids[text_aid] = {'text': gap_label}

View File

@ -48,8 +48,8 @@ from piker.service import find_service
from piker.brokers import SymbolNotFound from piker.brokers import SymbolNotFound
from piker.ui.qt import ( from piker.ui.qt import (
QGraphicsItem, QGraphicsItem,
QColor,
) )
from PyQt6.QtGui import QFont
from ._display import DisplayState from ._display import DisplayState
from ._interaction import ChartView from ._interaction import ChartView
from ._editors import ( from ._editors import (
@ -248,6 +248,7 @@ async def serve_rc_annots(
'y': int()|float() as y, 'y': int()|float() as y,
'color': color, 'color': color,
'anchor': list(anchor), 'anchor': list(anchor),
'font_size': int()|None as font_size,
}, },
}: }:
ds: DisplayState = _dss[fqme] ds: DisplayState = _dss[fqme]
@ -264,7 +265,22 @@ async def serve_rc_annots(
text=text, text=text,
color=color_hex, color=color_hex,
anchor=anchor, anchor=anchor,
# ?TODO, pin to github:main for this?
# legacy, can have scaling ish?
# ensureInBounds=True,
) )
# apply font size (default to DpiAwareFont if not
# provided)
if font_size is None:
from ._style import _font
font_size = _font.font.pixelSize() - 3
qfont: QFont = text_item.textItem.font()
qfont.setPixelSize(font_size)
text_item.setFont(qfont)
text_item.setPos(x, y) text_item.setPos(x, y)
chart.plotItem.addItem(text_item) chart.plotItem.addItem(text_item)
@ -547,6 +563,7 @@ class AnnotCtl(Struct):
y: float, y: float,
color: str|tuple = 'dad_blue', color: str|tuple = 'dad_blue',
anchor: tuple[float, float] = (0, 1), anchor: tuple[float, float] = (0, 1),
font_size: int|None = None,
from_acm: bool = False, from_acm: bool = False,
@ -555,6 +572,7 @@ class AnnotCtl(Struct):
Add a `pg.TextItem` annotation to the target view. Add a `pg.TextItem` annotation to the target view.
anchor: (x, y) where (0,0) is upper-left, (1,1) is lower-right anchor: (x, y) where (0,0) is upper-left, (1,1) is lower-right
font_size: pixel size for font, defaults to `_font.font.pixelSize()`
''' '''
ipc: MsgStream = self._get_ipc(fqme) ipc: MsgStream = self._get_ipc(fqme)
@ -568,6 +586,7 @@ class AnnotCtl(Struct):
'y': float(y), 'y': float(y),
'color': color, 'color': color,
'anchor': tuple(anchor), 'anchor': tuple(anchor),
'font_size': font_size,
}, },
}) })
aid: int = await ipc.receive() aid: int = await ipc.receive()