From 1e81feee46377c6c56163f973fca5a4a5f786a6e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 8 Sep 2022 22:48:34 -0400 Subject: [PATCH] Finally get chart startup view-state kinda correct It ended up being what'd you expect, races on the accessing shm buffer data by the UI during the whole "mega-async-startup-everything" phase XD So we add the following list of ad-hoc startup steps: - do `.default_view()` on the slow chart after the fast chart is mostly fully spawned with the intention being to capture the state where the historical buffer is mostly loaded before sizing the view to the graphical form of the data. - resize slow chart sidepanes from the fast chart just before sleeping forever (and after order mode has booted). --- piker/ui/_display.py | 35 +++++++++++++++++++++++------------ piker/ui/_interaction.py | 7 +++---- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/piker/ui/_display.py b/piker/ui/_display.py index f2d015f1..27bb466b 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -851,13 +851,6 @@ async def display_symbol_data( rt_linked = godwidget.rt_linked rt_linked._symbol = symbol - # generate order mode side-pane UI - # A ``FieldsForm`` form to configure order entry - pp_pane: FieldsForm = mk_order_pane_layout(godwidget) - - # add as next-to-y-axis singleton pane - godwidget.pp_pane = pp_pane - # create top history view chart above the "main rt chart". hist_linked = godwidget.hist_linked hist_linked._symbol = symbol @@ -872,10 +865,11 @@ async def display_symbol_data( # don't show when not focussed hist_linked.cursor.always_show_xlabel = False - hist_chart.default_view( - bars_from_y=int(len(hist_ohlcv.array)), # size to data - y_offset=6116*2, # push it a little away from the y-axis - ) + # generate order mode side-pane UI + # A ``FieldsForm`` form to configure order entry + # and add as next-to-y-axis singleton pane + pp_pane: FieldsForm = mk_order_pane_layout(godwidget) + godwidget.pp_pane = pp_pane # create main OHLC chart chart = rt_linked.plot_ohlc_main( @@ -1020,6 +1014,15 @@ async def display_symbol_data( # size view to data prior to order mode init chart.default_view() + rt_linked.graphics_cycle() + await trio.sleep(0) + + hist_chart.default_view( + bars_from_y=int(len(hist_ohlcv.array)), # size to data + y_offset=6116*2, # push it a little away from the y-axis + ) + hist_linked.graphics_cycle() + await trio.sleep(0) async with ( open_order_mode( @@ -1040,6 +1043,8 @@ async def display_symbol_data( rt_linked.set_split_sizes() hist_linked.resize_sidepanes(from_linked=rt_linked) + # TODO: look into this because not sure why it was + # commented out / we ever needed it XD # NOTE: we pop the volume chart from the subplots set so # that it isn't double rendered in the display loop # above since we do a maxmin calc on the volume data to @@ -1050,6 +1055,12 @@ async def display_symbol_data( # close group status sbar._status_groups[loading_sym_key][1]() + hist_linked.graphics_cycle() + await trio.sleep(0) + hist_chart.default_view( + bars_from_y=int(len(hist_ohlcv.array)), # size to data + y_offset=6116*2, # push it a little away from the y-axis + ) + # let the app run.. bby - # rt_linked.graphics_cycle() await trio.sleep_forever() diff --git a/piker/ui/_interaction.py b/piker/ui/_interaction.py index 796ed07d..9b7eba6d 100644 --- a/piker/ui/_interaction.py +++ b/piker/ui/_interaction.py @@ -142,8 +142,8 @@ async def handle_viewmode_kb_inputs( } ): godw = view._chart.linked.godwidget + godw.hist_linked.resize_sidepanes(from_linked=godw.rt_linked) godw.search.focus() - # godw.hist_linked.resize_sidepanes(from_linked=godw.rt_linked) # esc and ctrl-c if key == Qt.Key_Escape or (ctrl and key == Qt.Key_C): @@ -181,7 +181,8 @@ async def handle_viewmode_kb_inputs( if key in pressed: pressed.remove(key) - # QUERY/QUOTE MODE # + # QUERY/QUOTE MODE + # ---------------- if {Qt.Key_Q}.intersection(pressed): view.linked.cursor.in_query_mode = True @@ -191,7 +192,6 @@ async def handle_viewmode_kb_inputs( # SELECTION MODE # -------------- - if shift: if view.state['mouseMode'] == ViewBox.PanMode: view.setMouseMode(ViewBox.RectMode) @@ -212,7 +212,6 @@ async def handle_viewmode_kb_inputs( # ORDER MODE # ---------- - # live vs. dark trigger + an action {buy, sell, alert} order_keys_pressed = ORDER_MODE.intersection(pressed)