"bracket"-ify fills bar + labels and try to evenly space the pane sections
parent
637364d1c3
commit
4974579e73
|
@ -155,6 +155,10 @@ class FontScaledDelegate(QStyledItemDelegate):
|
||||||
|
|
||||||
class FieldsForm(QWidget):
|
class FieldsForm(QWidget):
|
||||||
|
|
||||||
|
godwidget: 'GodWidget' # noqa
|
||||||
|
vbox: QVBoxLayout
|
||||||
|
form: QFormLayout
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
||||||
|
@ -172,41 +176,46 @@ class FieldsForm(QWidget):
|
||||||
QSizePolicy.Expanding,
|
QSizePolicy.Expanding,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# XXX: not sure why we have to create this here exactly
|
||||||
|
# (instead of in the pane creation routine) but it's
|
||||||
|
# here and is managed by downstream layout routines.
|
||||||
|
# best guess is that you have to create layouts in order
|
||||||
|
# of hierarchy in order for things to display correctly?
|
||||||
|
# TODO: we may want to hand this *down* from some "pane manager"
|
||||||
|
# thing eventually?
|
||||||
self.vbox = QVBoxLayout(self)
|
self.vbox = QVBoxLayout(self)
|
||||||
self.vbox.setAlignment(Qt.AlignTop)
|
self.vbox.setAlignment(Qt.AlignVCenter)
|
||||||
self.vbox.setContentsMargins(0, 4, 4, 4)
|
self.vbox.setContentsMargins(0, 4, 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)
|
self.form = QFormLayout(self)
|
||||||
self.form.setAlignment(Qt.AlignCenter | Qt.AlignLeft)
|
self.form.setAlignment(Qt.AlignTop | Qt.AlignLeft)
|
||||||
self.form.setContentsMargins(0, 0, 0, 0)
|
self.form.setContentsMargins(0, 0, 0, 0)
|
||||||
self.form.setSpacing(4)
|
self.form.setSpacing(3)
|
||||||
self.form.setHorizontalSpacing(0)
|
self.form.setHorizontalSpacing(0)
|
||||||
# self.vbox.addStretch()
|
|
||||||
|
|
||||||
self.vbox.addLayout(self.form, stretch=3/8)
|
self.vbox.addLayout(self.form, stretch=1/3)
|
||||||
|
|
||||||
self.labels: dict[str, QLabel] = {}
|
self.labels: dict[str, QLabel] = {}
|
||||||
self.fields: dict[str, QWidget] = {}
|
self.fields: dict[str, QWidget] = {}
|
||||||
|
|
||||||
self._font_size = _font_small.px_size - 2
|
self._font_size = _font_small.px_size - 2
|
||||||
self.vbox.addSpacing(0.375 * self._font_size)
|
|
||||||
self._max_item_width: (float, float) = 0, 0
|
self._max_item_width: (float, float) = 0, 0
|
||||||
|
|
||||||
def add_field_label(
|
def add_field_label(
|
||||||
self,
|
self,
|
||||||
|
|
||||||
name: str,
|
name: str,
|
||||||
|
|
||||||
font_size: Optional[int] = None,
|
font_size: Optional[int] = None,
|
||||||
font_color: str = 'default_lightest',
|
font_color: str = 'default_lightest',
|
||||||
|
|
||||||
**vbox_kwargs,
|
|
||||||
|
|
||||||
) -> QtGui.QLabel:
|
) -> QtGui.QLabel:
|
||||||
|
|
||||||
# add label to left of search bar
|
# add label to left of search bar
|
||||||
self.label = label = QtGui.QLabel()
|
self.label = label = QtGui.QLabel()
|
||||||
font_size = font_size or self._font_size - 3
|
font_size = font_size or self._font_size - 2
|
||||||
label.setStyleSheet(
|
label.setStyleSheet(
|
||||||
f"""QLabel {{
|
f"""QLabel {{
|
||||||
color : {hcolor(font_color)};
|
color : {hcolor(font_color)};
|
||||||
|
@ -338,7 +347,7 @@ async def handle_field_input(
|
||||||
Qt.Key_Space, # i feel like this is the "native" one
|
Qt.Key_Space, # i feel like this is the "native" one
|
||||||
Qt.Key_Alt,
|
Qt.Key_Alt,
|
||||||
}:
|
}:
|
||||||
fields.godwidget.setFocus() #linkedsplits.chart._vb.setFocus()
|
fields.godwidget.setFocus() # linkedsplits.chart._vb.setFocus()
|
||||||
fields.godwidget.linkedsplits.focus()
|
fields.godwidget.linkedsplits.focus()
|
||||||
|
|
||||||
widget.clearFocus()
|
widget.clearFocus()
|
||||||
|
@ -395,39 +404,47 @@ async def open_form(
|
||||||
def mk_health_bar(
|
def mk_health_bar(
|
||||||
|
|
||||||
fields: FieldsForm,
|
fields: FieldsForm,
|
||||||
h: int = 200,
|
pane_vbox: QVBoxLayout,
|
||||||
|
bar_h: int = 250,
|
||||||
|
|
||||||
) -> (QHBoxLayout, QProgressBar):
|
) -> (QHBoxLayout, QProgressBar):
|
||||||
|
|
||||||
w = fields.width()
|
w = fields.width()
|
||||||
# indent = 18
|
# indent = 18
|
||||||
bracket_val = 0.375 * w
|
# bracket_val = 0.375 * 0.666 * w
|
||||||
indent = bracket_val / 1.625
|
# indent = bracket_val / (1 + 5/8)
|
||||||
|
|
||||||
# title label
|
# TODO: once things are sized to screen
|
||||||
pps_label = fields.add_field_label(
|
label_font = DpiAwareFont()
|
||||||
'pps',
|
label_font._set_qfont_px_size(_font.px_size - 6)
|
||||||
font_size=_font_small.px_size,
|
br = label_font.boundingRect(f'{3.32:.1f}% port')
|
||||||
|
w, h = br.width(), br.height()
|
||||||
|
bar_h = 8/3 * w
|
||||||
|
|
||||||
|
# PnL on lhs
|
||||||
|
bar_labels_lhs = QVBoxLayout(fields)
|
||||||
|
left_label = fields.add_field_label(
|
||||||
|
dedent(f"""
|
||||||
|
-{30}% PnL
|
||||||
|
"""),
|
||||||
|
font_size=_font.px_size - 6,
|
||||||
|
font_color='gunmetal',
|
||||||
)
|
)
|
||||||
|
|
||||||
section_hbox = QHBoxLayout(fields)
|
bar_labels_lhs.addSpacing(5/8 * bar_h)
|
||||||
section_hbox.addSpacing(indent - 2) # pair with bar indent
|
bar_labels_lhs.addWidget(
|
||||||
section_hbox.addWidget(
|
left_label,
|
||||||
pps_label,
|
|
||||||
alignment=Qt.AlignLeft | Qt.AlignTop,
|
alignment=Qt.AlignLeft | Qt.AlignTop,
|
||||||
)
|
)
|
||||||
|
|
||||||
fields.vbox.addLayout(section_hbox)
|
|
||||||
|
|
||||||
# TODO: spec this based on remaining space?
|
|
||||||
fields.vbox.addSpacing(6)
|
|
||||||
|
|
||||||
hbox = QHBoxLayout(fields)
|
hbox = QHBoxLayout(fields)
|
||||||
|
|
||||||
hbox.addSpacing(indent) # push to right a bit
|
hbox.addLayout(bar_labels_lhs)
|
||||||
|
# hbox.addSpacing(indent) # push to right a bit
|
||||||
|
|
||||||
# config
|
# config
|
||||||
hbox.setSpacing(indent * 0.375)
|
# hbox.setSpacing(indent * 0.375)
|
||||||
|
hbox.setSpacing(0)
|
||||||
hbox.setAlignment(Qt.AlignTop | Qt.AlignLeft)
|
hbox.setAlignment(Qt.AlignTop | Qt.AlignLeft)
|
||||||
hbox.setContentsMargins(0, 0, 0, 0)
|
hbox.setContentsMargins(0, 0, 0, 0)
|
||||||
|
|
||||||
|
@ -438,14 +455,18 @@ def mk_health_bar(
|
||||||
dedent(f"""
|
dedent(f"""
|
||||||
{3.32:.1f}% port
|
{3.32:.1f}% port
|
||||||
"""),
|
"""),
|
||||||
font_size=_font.px_size - 5,
|
font_size=_font.px_size - 6,
|
||||||
|
# font_color='default_spotlight',
|
||||||
|
font_color='gunmetal',
|
||||||
)
|
)
|
||||||
|
|
||||||
bottom_label = fields.add_field_label(
|
bottom_label = fields.add_field_label(
|
||||||
dedent(f"""
|
dedent(f"""
|
||||||
{5e3/4/1e3:.1f}k step\n
|
{5e3/4/1e3:.2f}k $fill\n
|
||||||
"""),
|
"""),
|
||||||
font_size=_font.px_size - 5,
|
font_size=_font.px_size - 6,
|
||||||
|
# font_color='default_spotlight',
|
||||||
|
font_color='gunmetal',
|
||||||
)
|
)
|
||||||
|
|
||||||
bar = QProgressBar(fields)
|
bar = QProgressBar(fields)
|
||||||
|
@ -470,9 +491,8 @@ def mk_health_bar(
|
||||||
slot_margin_px = 2
|
slot_margin_px = 2
|
||||||
|
|
||||||
# TODO: compute "used height" thus far and mostly fill the rest
|
# TODO: compute "used height" thus far and mostly fill the rest
|
||||||
h = 200
|
|
||||||
slot_height_px = math.floor(
|
slot_height_px = math.floor(
|
||||||
(h - 2*border_size_px)/slots
|
(bar_h - 2*border_size_px)/slots
|
||||||
) - slot_margin_px*1
|
) - slot_margin_px*1
|
||||||
|
|
||||||
bar.setOrientation(Qt.Vertical)
|
bar.setOrientation(Qt.Vertical)
|
||||||
|
@ -493,7 +513,7 @@ def mk_health_bar(
|
||||||
|
|
||||||
QProgressBar::chunk {{
|
QProgressBar::chunk {{
|
||||||
|
|
||||||
background-color: {hcolor('default_lightest')};
|
background-color: {hcolor('default_spotlight')};
|
||||||
color: {hcolor('papas_special')};
|
color: {hcolor('papas_special')};
|
||||||
|
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
@ -511,12 +531,12 @@ def mk_health_bar(
|
||||||
# width: 10px;
|
# width: 10px;
|
||||||
|
|
||||||
bar.setRange(0, slots)
|
bar.setRange(0, slots)
|
||||||
bar.setValue(slots)
|
bar.setValue(1)
|
||||||
bar.setFormat('')
|
bar.setFormat('')
|
||||||
bar.setMinimumHeight(h)
|
bar.setMinimumHeight(bar_h)
|
||||||
bar.setMaximumHeight(h + slots*slot_margin_px)
|
bar.setMaximumHeight(bar_h + slots*slot_margin_px)
|
||||||
bar.setMinimumWidth(bracket_val)
|
bar.setMinimumWidth(h * 1.375)
|
||||||
bar.setMaximumWidth(bracket_val)
|
bar.setMaximumWidth(h * 1.375)
|
||||||
|
|
||||||
return hbox, bar
|
return hbox, bar
|
||||||
|
|
||||||
|
@ -524,28 +544,27 @@ def mk_health_bar(
|
||||||
def mk_order_pane_layout(
|
def mk_order_pane_layout(
|
||||||
|
|
||||||
fields: FieldsForm,
|
fields: FieldsForm,
|
||||||
|
font_size: int = _font_small.px_size - 2
|
||||||
|
|
||||||
) -> FieldsForm:
|
) -> FieldsForm:
|
||||||
|
|
||||||
# fh = form.form.sizeHint().height()
|
# TODO: maybe just allocate the whole fields form here
|
||||||
|
# and expect an async ctx entry?
|
||||||
|
|
||||||
w, h = fields.width(), fields.height()
|
fields._font_size = font_size
|
||||||
print(f'w, h: {w, h}')
|
|
||||||
|
|
||||||
# TODO: spec this based on remaining space?
|
# top level pane layout
|
||||||
# fields.vbox.addSpacing(36)
|
# XXX: see ``FieldsForm.__init__()`` for why we can't do basic
|
||||||
fields.vbox.addSpacing((5/8) * h)
|
# config of the vbox here
|
||||||
|
vbox = fields.vbox
|
||||||
|
|
||||||
# info label on RHS
|
# _, h = fields.width(), fields.height()
|
||||||
# {30}% PnL\n
|
# print(f'w, h: {w, h}')
|
||||||
|
|
||||||
hbox, bar = mk_health_bar(fields)
|
hbox, bar = mk_health_bar(fields, pane_vbox=vbox)
|
||||||
|
|
||||||
# TODO: move the ``.vbox`` from fields obj to top of routine
|
|
||||||
|
|
||||||
# add pp fill bar + spacing
|
# add pp fill bar + spacing
|
||||||
fields.vbox.addLayout(hbox, stretch=5/8)
|
vbox.addLayout(hbox, stretch=1/3)
|
||||||
fields.vbox.addSpacing(36)
|
|
||||||
|
|
||||||
feed_label = fields.add_field_label(
|
feed_label = fields.add_field_label(
|
||||||
dedent("""
|
dedent("""
|
||||||
|
@ -557,13 +576,16 @@ def mk_order_pane_layout(
|
||||||
font_size=_font.px_size - 5,
|
font_size=_font.px_size - 5,
|
||||||
)
|
)
|
||||||
|
|
||||||
feed_label.setMaximumHeight(feed_label.height())
|
|
||||||
fields.vbox.addSpacing(3/8 * h)
|
|
||||||
|
|
||||||
# add feed info label
|
# add feed info label
|
||||||
fields.vbox.addWidget(
|
vbox.addWidget(
|
||||||
feed_label,
|
feed_label,
|
||||||
alignment=Qt.AlignBottom, # | Qt.AlignVCenter,
|
alignment=Qt.AlignBottom,
|
||||||
|
stretch=1/3,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: handle resize events and appropriately scale this
|
||||||
|
# to the sidepane height?
|
||||||
|
# https://doc.qt.io/qt-5/layout.html#adding-widgets-to-a-layout
|
||||||
|
vbox.setSpacing(36)
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
|
|
Loading…
Reference in New Issue