From f27db80bf4a0afce7c5b315d75235fa534f7e7e0 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 25 Jul 2021 20:32:29 -0400 Subject: [PATCH] Start using a small schema for generating forms --- piker/ui/_forms.py | 16 ++++++++++++---- piker/ui/order_mode.py | 32 ++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/piker/ui/_forms.py b/piker/ui/_forms.py index 9e03a809..ab155394 100644 --- a/piker/ui/_forms.py +++ b/piker/ui/_forms.py @@ -309,7 +309,7 @@ async def handle_field_input( @asynccontextmanager -async def mk_form( +async def open_form( parent: QWidget, fields: dict, @@ -319,10 +319,18 @@ async def mk_form( form = FieldsForm(parent) - for name, value in fields.items(): - form.add_edit_field(name, value) + for name, config in fields.items(): + wtype = config['type'] + key = str(config['key']) - form.add_select_field('policy:', ['uniform']) + # plain (line) edit field + if wtype == 'edit': + form.add_edit_field(key, config['default_value']) + + # drop-down selection + elif wtype == 'select': + values = list(config['default_value']) + form.add_select_field(key, values) form.add_field_label('fills:') fill_bar = QProgressBar(form) diff --git a/piker/ui/order_mode.py b/piker/ui/order_mode.py index e255148e..30229b82 100644 --- a/piker/ui/order_mode.py +++ b/piker/ui/order_mode.py @@ -35,7 +35,7 @@ from ._editors import LineEditor, ArrowEditor from ._lines import LevelLine from ._position import PositionTracker from ._window import MultiStatus -from ._forms import FieldsForm, mk_form +from ._forms import FieldsForm, open_form log = get_logger(__name__) @@ -378,6 +378,27 @@ async def run_order_mode( positions ), + open_form( + parent=chart.linked.godwidget, + fields={ + 'dollar_size': { + 'key': '**$size**:', + 'type': 'edit', + 'default_value': 5000, + }, + 'slots': { + 'key': '**slots**:', + 'type': 'edit', + 'default_value': 4, + }, + 'disti_policy': { + 'key': '**policy**:', + 'type': 'select', + 'default_value': ['uniform'], + }, + }, + ) as pp_config, + ): view = chart._vb lines = LineEditor(chart=chart) @@ -389,15 +410,6 @@ async def run_order_mode( pp.hide() # insert order mode config to left of mode label - pp_config = mk_form( - parent=chart.linked.godwidget, - fields={ - '**$size**:': 5000, - '**slots**:': 4, - # '**policy**:': 'uniform', - # '**type**:': 'live-buy', - }, - ) sb = chart.window().statusBar() sb.insertPermanentWidget(0, pp_config) pp_config.hide()