Build out feed status label, add to top of sidepane

fsp_feeds
Tyler Goodlet 2021-09-16 09:19:02 -04:00
parent bc42d625fc
commit 3e25be6321
2 changed files with 66 additions and 34 deletions

View File

@ -21,7 +21,6 @@ Text entry "forms" widgets (mostly for configuration and UI user input).
from __future__ import annotations from __future__ import annotations
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from functools import partial from functools import partial
from textwrap import dedent
from typing import ( from typing import (
Optional, Any, Callable, Awaitable Optional, Any, Callable, Awaitable
) )
@ -320,14 +319,14 @@ class FieldsForm(QWidget):
self.vbox = QVBoxLayout(self) self.vbox = QVBoxLayout(self)
# self.vbox.setAlignment(Qt.AlignVCenter) # self.vbox.setAlignment(Qt.AlignVCenter)
self.vbox.setAlignment(Qt.AlignBottom) self.vbox.setAlignment(Qt.AlignBottom)
self.vbox.setContentsMargins(0, 4, 3, 6) self.vbox.setContentsMargins(3, 6, 3, 6)
self.vbox.setSpacing(0) self.vbox.setSpacing(0)
# split layout for the (<label>: |<widget>|) parameters entry # split layout for the (<label>: |<widget>|) parameters entry
self.form = QFormLayout() self.form = QFormLayout()
self.form.setAlignment(Qt.AlignTop | Qt.AlignLeft) self.form.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.form.setContentsMargins(0, 0, 0, 0) self.form.setContentsMargins(0, 0, 3, 0)
self.form.setSpacing(3) self.form.setSpacing(0)
self.form.setHorizontalSpacing(0) self.form.setHorizontalSpacing(0)
self.vbox.addLayout(self.form, stretch=1/3) self.vbox.addLayout(self.form, stretch=1/3)
@ -645,9 +644,7 @@ def mk_fill_status_bar(
# PnL on lhs # PnL on lhs
bar_labels_lhs = QVBoxLayout() bar_labels_lhs = QVBoxLayout()
left_label = form.add_field_label( left_label = form.add_field_label(
dedent(""" '{pnl:>+.2%} pnl',
{pnl:>+.2%} pnl
"""),
font_size=bar_label_font_size, font_size=bar_label_font_size,
font_color='gunmetal', font_color='gunmetal',
) )
@ -674,18 +671,13 @@ def mk_fill_status_bar(
# https://docs.python.org/3/library/string.html#grammar-token-precision # https://docs.python.org/3/library/string.html#grammar-token-precision
top_label = form.add_field_label( top_label = form.add_field_label(
# {limit:.1f} limit '{limit}',
dedent("""
{limit}
"""),
font_size=bar_label_font_size, font_size=bar_label_font_size,
font_color='gunmetal', font_color='gunmetal',
) )
bottom_label = form.add_field_label( bottom_label = form.add_field_label(
dedent(""" 'x: {step_size}',
x: {step_size}\n
"""),
font_size=bar_label_font_size, font_size=bar_label_font_size,
font_color='gunmetal', font_color='gunmetal',
) )
@ -788,29 +780,10 @@ def mk_order_pane_layout(
# add pp fill bar + spacing # add pp fill bar + spacing
vbox.addLayout(hbox, stretch=1/3) vbox.addLayout(hbox, stretch=1/3)
# TODO: status labels for brokerd real-time info
# feed_label = form.add_field_label(
# dedent("""
# brokerd.ib\n
# |_@{host}:{port}\n
# |_consumers: {cons}\n
# |_streams: {streams}\n
# |_shms: {streams}\n
# """),
# font_size=_font_small.px_size,
# )
# # add feed info label
# vbox.addWidget(
# feed_label,
# alignment=Qt.AlignBottom,
# # stretch=1/3,
# )
# TODO: handle resize events and appropriately scale this # TODO: handle resize events and appropriately scale this
# to the sidepane height? # to the sidepane height?
# https://doc.qt.io/qt-5/layout.html#adding-widgets-to-a-layout # https://doc.qt.io/qt-5/layout.html#adding-widgets-to-a-layout
vbox.setSpacing(_font.px_size * 1.375) # vbox.setSpacing(_font.px_size * 1.375)
form.show() form.show()
return form return form

View File

@ -45,6 +45,7 @@ from ._position import (
PositionTracker, PositionTracker,
SettingsPane, SettingsPane,
) )
from ._label import FormatLabel
from ._window import MultiStatus from ._window import MultiStatus
from ..clearing._messages import Order from ..clearing._messages import Order
from ._forms import open_form_input_handling from ._forms import open_form_input_handling
@ -623,6 +624,64 @@ async def open_order_mode(
# setup order mode sidepane widgets # setup order mode sidepane widgets
form = chart.sidepane 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 - 1,
font_color='default_lightest',
)
form.feed_label = feed_label
# add feed info label
# vbox.addWidget(
vbox.insertWidget(
0,
feed_label,
alignment=Qt.AlignBottom,
# stretch=1/3,
)
# vbox.setAlignment(feed_label, Qt.AlignBottom)
# vbox.setAlignment(Qt.AlignBottom)
blank_h = chart.height() - (
form.height() +
form.fill_bar.height()
# feed_label.height()
)
# await tractor.breakpoint()
# vbox.setSpacing(round(blank_h / 3) - 2*_font.px_size)
vbox.setSpacing((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,
)
order_pane = SettingsPane( order_pane = SettingsPane(
form=form, form=form,