Move feed status label generation into a new module
parent
78b9333bcd
commit
488506d8b8
|
@ -0,0 +1,91 @@
|
|||
# piker: trading gear for hackers
|
||||
# Copyright (C) Tyler Goodlet (in stewardship for piker0)
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Feed status and controls widget(s) for embedding in a UI-pane.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
from textwrap import dedent
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
# from PyQt5.QtCore import Qt
|
||||
|
||||
from ._style import _font, _font_small
|
||||
from ..calc import humanize
|
||||
from ._label import FormatLabel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._chart import ChartPlotWidget
|
||||
from ..data.feed import Feed
|
||||
from ._forms import FieldsForm
|
||||
|
||||
|
||||
def mk_feed_label(
|
||||
form: FieldsForm,
|
||||
feed: Feed,
|
||||
chart: ChartPlotWidget,
|
||||
|
||||
) -> FormatLabel:
|
||||
'''
|
||||
Generate a label from feed meta-data to be displayed
|
||||
in a UI sidepane.
|
||||
|
||||
TODO: eventually buttons for changing settings over
|
||||
a feed control protocol.
|
||||
|
||||
'''
|
||||
msg = """
|
||||
actor: **{actor_name}**\n
|
||||
|_ @**{host}:{port}**\n
|
||||
|_ throttle_hz: **{throttle_rate}**\n
|
||||
|_ shm: **{shm}**\n
|
||||
"""
|
||||
|
||||
feed_label = FormatLabel(
|
||||
fmt_str=dedent(msg),
|
||||
# |_ streams: **{symbols}**\n
|
||||
font=_font.font,
|
||||
font_size=_font_small.px_size,
|
||||
font_color='default_lightest',
|
||||
)
|
||||
|
||||
# form.vbox.setAlignment(feed_label, Qt.AlignBottom)
|
||||
# form.vbox.setAlignment(Qt.AlignBottom)
|
||||
_ = chart.height() - (
|
||||
form.height() +
|
||||
form.fill_bar.height()
|
||||
# feed_label.height()
|
||||
)
|
||||
|
||||
# fill in brokerd feed info
|
||||
host, port = feed.portal.channel.raddr
|
||||
if host == '127.0.0.1':
|
||||
host = 'localhost'
|
||||
mpshm = feed.shm._shm
|
||||
shmstr = f'{humanize(mpshm.size)}'
|
||||
|
||||
feed_label.format(
|
||||
actor_name=feed.portal.channel.uid[0],
|
||||
host=host,
|
||||
port=port,
|
||||
# symbols=len(feed.symbols),
|
||||
shm=shmstr,
|
||||
throttle_rate=feed.throttle_rate,
|
||||
)
|
||||
|
||||
return feed_label
|
|
@ -750,12 +750,12 @@ def mk_order_pane_layout(
|
|||
parent=parent,
|
||||
fields_schema={
|
||||
'account': {
|
||||
'label': '**account**:',
|
||||
'label': '**accnt**:',
|
||||
'type': 'select',
|
||||
'default_value': ['paper'],
|
||||
},
|
||||
'size_unit': {
|
||||
'label': '**allocate**:',
|
||||
'label': '**alloc**:',
|
||||
'type': 'select',
|
||||
'default_value': [
|
||||
'$ size',
|
||||
|
|
|
@ -30,6 +30,7 @@ import uuid
|
|||
from pydantic import BaseModel
|
||||
import tractor
|
||||
import trio
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
from .. import config
|
||||
from ..clearing._client import open_ems, OrderBook
|
||||
|
@ -37,6 +38,7 @@ from ..clearing._allocate import (
|
|||
mk_allocator,
|
||||
Position,
|
||||
)
|
||||
from ._style import _font
|
||||
from ..data._source import Symbol
|
||||
from ..data.feed import Feed
|
||||
from ..log import get_logger
|
||||
|
@ -46,7 +48,8 @@ from ._position import (
|
|||
PositionTracker,
|
||||
SettingsPane,
|
||||
)
|
||||
from ._label import FormatLabel
|
||||
from ._forms import FieldsForm
|
||||
# from ._label import FormatLabel
|
||||
from ._window import MultiStatus
|
||||
from ..clearing._messages import Order, BrokerdPosition
|
||||
from ._forms import open_form_input_handling
|
||||
|
@ -639,63 +642,21 @@ async def open_order_mode(
|
|||
pp_tracker.hide_info()
|
||||
|
||||
# setup order mode sidepane widgets
|
||||
form = chart.sidepane
|
||||
vbox = form.vbox
|
||||
|
||||
from textwrap import dedent
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
from ._style import _font, _font_small
|
||||
from ..calc import humanize
|
||||
|
||||
feed_label = FormatLabel(
|
||||
fmt_str=dedent("""
|
||||
actor: **{actor_name}**\n
|
||||
|_ @**{host}:{port}**\n
|
||||
|_ throttle_hz: **{throttle_rate}**\n
|
||||
|_ streams: **{symbols}**\n
|
||||
|_ shm: **{shm}**\n
|
||||
"""),
|
||||
font=_font.font,
|
||||
font_size=_font_small.px_size,
|
||||
font_color='default_lightest',
|
||||
)
|
||||
|
||||
form.feed_label = feed_label
|
||||
|
||||
# add feed info label to top
|
||||
vbox.insertWidget(
|
||||
0,
|
||||
feed_label,
|
||||
alignment=Qt.AlignBottom,
|
||||
)
|
||||
# vbox.setAlignment(feed_label, Qt.AlignBottom)
|
||||
# vbox.setAlignment(Qt.AlignBottom)
|
||||
_ = chart.height() - (
|
||||
form.height() +
|
||||
form.fill_bar.height()
|
||||
# feed_label.height()
|
||||
)
|
||||
vbox.setSpacing(
|
||||
form: FieldsForm = chart.sidepane
|
||||
form.vbox.setSpacing(
|
||||
int((1 + 5/8)*_font.px_size)
|
||||
)
|
||||
|
||||
# fill in brokerd feed info
|
||||
host, port = feed.portal.channel.raddr
|
||||
if host == '127.0.0.1':
|
||||
host = 'localhost'
|
||||
mpshm = feed.shm._shm
|
||||
shmstr = f'{humanize(mpshm.size)}'
|
||||
form.feed_label.format(
|
||||
actor_name=feed.portal.channel.uid[0],
|
||||
host=host,
|
||||
port=port,
|
||||
symbols=len(feed.symbols),
|
||||
shm=shmstr,
|
||||
throttle_rate=feed.throttle_rate,
|
||||
from ._feedstatus import mk_feed_label
|
||||
|
||||
feed_label = mk_feed_label(
|
||||
form,
|
||||
feed,
|
||||
chart,
|
||||
)
|
||||
|
||||
# XXX: we set this because?
|
||||
form.feed_label = feed_label
|
||||
order_pane = SettingsPane(
|
||||
form=form,
|
||||
# XXX: ugh, so hideous...
|
||||
|
@ -706,6 +667,11 @@ async def open_order_mode(
|
|||
)
|
||||
order_pane.set_accounts(list(trackers.keys()))
|
||||
|
||||
form.vbox.addWidget(
|
||||
feed_label,
|
||||
alignment=Qt.AlignBottom,
|
||||
)
|
||||
|
||||
# update pp icons
|
||||
for name, tracker in trackers.items():
|
||||
order_pane.update_account_icons({name: tracker.live_pp})
|
||||
|
|
Loading…
Reference in New Issue