From 2cf174299936468b7f13ba2f13032cd6de0d182c Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 21 Sep 2022 15:42:29 -0400 Subject: [PATCH] Always apply at least the pos size as the limit --- piker/clearing/_allocate.py | 3 +++ piker/ui/_position.py | 23 ++++++++++++++++------- piker/ui/order_mode.py | 6 +++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/piker/clearing/_allocate.py b/piker/clearing/_allocate.py index 9529991a..34f59571 100644 --- a/piker/clearing/_allocate.py +++ b/piker/clearing/_allocate.py @@ -93,6 +93,9 @@ class Allocator(Struct): else: return self.units_limit + def limit_info(self) -> tuple[str, float]: + return self.size_unit, self.limit() + def next_order_info( self, diff --git a/piker/ui/_position.py b/piker/ui/_position.py index 2b914c6e..c986022a 100644 --- a/piker/ui/_position.py +++ b/piker/ui/_position.py @@ -184,7 +184,7 @@ class SettingsPane: ''' self.apply_setting(key, value) - self.update_status_ui(pp=self.order_mode.current_pp) + self.update_status_ui(self.order_mode.current_pp) def apply_setting( self, @@ -262,6 +262,8 @@ class SettingsPane: log.error( f'limit must > then current pp: {dsize}' ) + # reset position size value + alloc.currency_limit = dsize return False alloc.currency_limit = value @@ -299,22 +301,29 @@ class SettingsPane: def update_status_ui( self, - pp: PositionTracker, + tracker: PositionTracker, ) -> None: - alloc = pp.alloc + alloc = tracker.alloc slots = alloc.slots - used = alloc.slots_used(pp.live_pp) + used = alloc.slots_used(tracker.live_pp) + size = tracker.live_pp.size + dsize = tracker.live_pp.dsize # READ out settings and update the status UI / settings widgets suffix = {'currency': ' $', 'units': ' u'}[alloc.size_unit] - limit = alloc.limit() + size_unit, limit = alloc.limit_info() step_size, currency_per_slot = alloc.step_sizes() if alloc.size_unit == 'currency': step_size = currency_per_slot + if dsize >= limit: + self.apply_setting('limit', limit) + + elif size >= limit: + self.apply_setting('limit', limit) self.step_label.format( step_size=str(humanize(step_size)) + suffix @@ -331,7 +340,7 @@ class SettingsPane: self.form.fields['limit'].setText(str(limit)) # update of level marker size label based on any new settings - pp.update_from_pp() + tracker.update_from_pp() # calculate proportion of position size limit # that exists and display in fill bar @@ -343,7 +352,7 @@ class SettingsPane: # min(round(prop * slots), slots) min(used, slots) ) - self.update_account_icons({alloc.account: pp.live_pp}) + self.update_account_icons({alloc.account: tracker.live_pp}) def update_account_icons( self, diff --git a/piker/ui/order_mode.py b/piker/ui/order_mode.py index 73c54ba3..72571d90 100644 --- a/piker/ui/order_mode.py +++ b/piker/ui/order_mode.py @@ -491,7 +491,8 @@ class OrderMode: ''' dialog = self.dialogs[uuid] lines = dialog.lines - assert len(lines) == 2 + # XXX: seems to fail on certain types of races? + # assert len(lines) == 2 if lines: _, _, ratio = self.feed.get_ds_info() for i, chart in [ @@ -843,8 +844,7 @@ async def open_order_mode( ) # make fill bar and positioning snapshot - order_pane.on_ui_settings_change('limit', tracker.alloc.limit()) - order_pane.update_status_ui(pp=tracker) + order_pane.update_status_ui(tracker) # TODO: create a mode "manager" of sorts? # -> probably just call it "UxModes" err sumthin?