def textctrl(element, instance: wx.TextCtrl): props = {**element['props']} value = props.get('value') try: del props['value'] except KeyError: pass set_basic_props(instance, props) if 'editable' in props: instance.SetEditable(props['editable']) if value is not None: instance.ChangeValue(value) instance.Unbind(wx.EVT_TEXT) if 'on_change' in props: instance.Bind(wx.EVT_TEXT, props['on_change']) return instance
def _ChangePairValue(self, ctrl: wx.TextCtrl, new_val: Vec2, prec: int): """Helper for updating the value of a paired number TextCtrl. The TextCtrl accepts text in the format "X, Y" where X and Y are floats. The control is not updated if the new and old values are identical (considering precision). Args: ctrl: The TextCtrl widget. new_val: The new pair of floats to update the control with. prec: The precision of the numbers. The new value is rounded to this precision. """ old_text = ctrl.GetValue() old_val = Vec2(parse_num_pair(old_text)) # round old_val to desired precision. We don't want to refresh value when user is typing, # even if their value exceeded our precision if old_val != new_val: if ctrl.HasFocus(): orig_insertion = ctrl.GetInsertionPoint() wx.CallAfter(lambda: self._SetBestInsertion( ctrl, old_text, orig_insertion)) ctrl.ChangeValue('{} , {}'.format(no_rzeros(new_val.x, prec), no_rzeros(new_val.y, prec)))