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-codemultiaddrs
parent
de5b1737b4
commit
1fb0fe3a04
|
|
@ -30,6 +30,7 @@ import tractor
|
|||
|
||||
from piker.data._formatters import BGM
|
||||
from piker.storage import log
|
||||
# from piker.ui._style import _font
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from piker.ui._remote_ctl import AnnotCtl
|
||||
|
|
@ -236,6 +237,14 @@ async def markup_gaps(
|
|||
else: # down-gap
|
||||
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(
|
||||
fqme=fqme,
|
||||
timeframe=timeframe,
|
||||
|
|
@ -244,6 +253,7 @@ async def markup_gaps(
|
|||
y=cls,
|
||||
color=color,
|
||||
anchor=anchor,
|
||||
font_size=font_size,
|
||||
)
|
||||
aids[text_aid] = {'text': gap_label}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ from piker.service import find_service
|
|||
from piker.brokers import SymbolNotFound
|
||||
from piker.ui.qt import (
|
||||
QGraphicsItem,
|
||||
QColor,
|
||||
)
|
||||
from PyQt6.QtGui import QFont
|
||||
from ._display import DisplayState
|
||||
from ._interaction import ChartView
|
||||
from ._editors import (
|
||||
|
|
@ -248,6 +248,7 @@ async def serve_rc_annots(
|
|||
'y': int()|float() as y,
|
||||
'color': color,
|
||||
'anchor': list(anchor),
|
||||
'font_size': int()|None as font_size,
|
||||
},
|
||||
}:
|
||||
ds: DisplayState = _dss[fqme]
|
||||
|
|
@ -264,7 +265,22 @@ async def serve_rc_annots(
|
|||
text=text,
|
||||
color=color_hex,
|
||||
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)
|
||||
chart.plotItem.addItem(text_item)
|
||||
|
||||
|
|
@ -547,6 +563,7 @@ class AnnotCtl(Struct):
|
|||
y: float,
|
||||
color: str|tuple = 'dad_blue',
|
||||
anchor: tuple[float, float] = (0, 1),
|
||||
font_size: int|None = None,
|
||||
|
||||
from_acm: bool = False,
|
||||
|
||||
|
|
@ -555,6 +572,7 @@ class AnnotCtl(Struct):
|
|||
Add a `pg.TextItem` annotation to the target view.
|
||||
|
||||
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)
|
||||
|
|
@ -568,6 +586,7 @@ class AnnotCtl(Struct):
|
|||
'y': float(y),
|
||||
'color': color,
|
||||
'anchor': tuple(anchor),
|
||||
'font_size': font_size,
|
||||
},
|
||||
})
|
||||
aid: int = await ipc.receive()
|
||||
|
|
|
|||
Loading…
Reference in New Issue