More stringent settings pane input handling
If a setting fails to apply try to log an error msg and revert to the previous setting by not applying the UI read-update until after the new `SettingsPane.apply_setting()` call. This prevents crashes when the user tries to give bad inputs on editable allocator fields.size_in_shm_token
parent
980815d075
commit
8792c97de6
|
@ -166,6 +166,21 @@ class SettingsPane:
|
||||||
key: str,
|
key: str,
|
||||||
value: str,
|
value: str,
|
||||||
|
|
||||||
|
) -> None:
|
||||||
|
'''
|
||||||
|
Try to apply some input setting (by the user), revert to previous setting if it fails
|
||||||
|
display new value if applied.
|
||||||
|
|
||||||
|
'''
|
||||||
|
self.apply_setting(key, value)
|
||||||
|
self.update_status_ui(pp=self.order_mode.current_pp)
|
||||||
|
|
||||||
|
def apply_setting(
|
||||||
|
self,
|
||||||
|
|
||||||
|
key: str,
|
||||||
|
value: str,
|
||||||
|
|
||||||
) -> bool:
|
) -> bool:
|
||||||
'''
|
'''
|
||||||
Called on any order pane edit field value change.
|
Called on any order pane edit field value change.
|
||||||
|
@ -217,8 +232,17 @@ class SettingsPane:
|
||||||
alloc.size_unit = value
|
alloc.size_unit = value
|
||||||
|
|
||||||
elif key != 'account': # numeric fields entry
|
elif key != 'account': # numeric fields entry
|
||||||
value = puterize(value)
|
try:
|
||||||
|
value = puterize(value)
|
||||||
|
except ValueError as err:
|
||||||
|
log.error(err.args[0])
|
||||||
|
return False
|
||||||
|
|
||||||
if key == 'limit':
|
if key == 'limit':
|
||||||
|
if value <= 0:
|
||||||
|
log.error('limit must be > 0')
|
||||||
|
return False
|
||||||
|
|
||||||
pp = mode.current_pp.live_pp
|
pp = mode.current_pp.live_pp
|
||||||
|
|
||||||
if alloc.size_unit == 'currency':
|
if alloc.size_unit == 'currency':
|
||||||
|
@ -243,7 +267,10 @@ class SettingsPane:
|
||||||
|
|
||||||
elif key == 'slots':
|
elif key == 'slots':
|
||||||
if value <= 0:
|
if value <= 0:
|
||||||
raise ValueError('slots must be > 0')
|
# raise ValueError('slots must be > 0')
|
||||||
|
log.error('limit must be > 0')
|
||||||
|
return False
|
||||||
|
|
||||||
alloc.slots = int(value)
|
alloc.slots = int(value)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -254,14 +281,25 @@ class SettingsPane:
|
||||||
# on every mouse interaction.
|
# on every mouse interaction.
|
||||||
log.info(f'settings change: {key}: {value}')
|
log.info(f'settings change: {key}: {value}')
|
||||||
|
|
||||||
|
# TODO: maybe return a diff of settings so if we can an error we
|
||||||
|
# can have general input handling code to report it through the
|
||||||
|
# UI in some way?
|
||||||
|
return True
|
||||||
|
|
||||||
|
def update_status_ui(
|
||||||
|
self,
|
||||||
|
pp: PositionTracker,
|
||||||
|
|
||||||
|
) -> None:
|
||||||
|
|
||||||
|
alloc = pp.alloc
|
||||||
|
slots = alloc.slots
|
||||||
|
used = alloc.slots_used(pp.live_pp)
|
||||||
|
|
||||||
# READ out settings and update the status UI / settings widgets
|
# READ out settings and update the status UI / settings widgets
|
||||||
suffix = {'currency': ' $', 'units': ' u'}[alloc.size_unit]
|
suffix = {'currency': ' $', 'units': ' u'}[alloc.size_unit]
|
||||||
limit = alloc.limit()
|
limit = alloc.limit()
|
||||||
|
|
||||||
# TODO: a reverse look up from the position to the equivalent
|
|
||||||
# account(s), if none then look to user config for default?
|
|
||||||
self.update_status_ui(pp=tracker)
|
|
||||||
|
|
||||||
step_size, currency_per_slot = alloc.step_sizes()
|
step_size, currency_per_slot = alloc.step_sizes()
|
||||||
|
|
||||||
if alloc.size_unit == 'currency':
|
if alloc.size_unit == 'currency':
|
||||||
|
@ -282,23 +320,7 @@ class SettingsPane:
|
||||||
self.form.fields['limit'].setText(str(limit))
|
self.form.fields['limit'].setText(str(limit))
|
||||||
|
|
||||||
# update of level marker size label based on any new settings
|
# update of level marker size label based on any new settings
|
||||||
tracker.update_from_pp()
|
pp.update_from_pp()
|
||||||
|
|
||||||
# TODO: maybe return a diff of settings so if we can an error we
|
|
||||||
# can have general input handling code to report it through the
|
|
||||||
# UI in some way?
|
|
||||||
return True
|
|
||||||
|
|
||||||
def update_status_ui(
|
|
||||||
self,
|
|
||||||
|
|
||||||
pp: PositionTracker,
|
|
||||||
|
|
||||||
) -> None:
|
|
||||||
|
|
||||||
alloc = pp.alloc
|
|
||||||
slots = alloc.slots
|
|
||||||
used = alloc.slots_used(pp.live_pp)
|
|
||||||
|
|
||||||
# calculate proportion of position size limit
|
# calculate proportion of position size limit
|
||||||
# that exists and display in fill bar
|
# that exists and display in fill bar
|
||||||
|
|
Loading…
Reference in New Issue