def format_input(self, spin, new_value_pointer): text = spin.get_text() if text: value = user_locale_format.str2float(text) value_location = ctypes.c_double.from_address(hash(new_value_pointer)) value_location.value = float(value) return True return False
def text_to_float(self, text): try: if text and ':' in text: return round(int(text.split(':')[0]) + int(text.split(':')[1]) / 60.0,4) else: return user_locale_format.str2float(text) except: pass return 0.0
def _on_insert_text(self, editable, value, length, position): text = self.widget.get_text() if value: current_pos = self.widget.get_position() new_text = text[:current_pos] + value + text[current_pos:] digits = self.widget.get_digits() try: spin_value = user_locale_format.str2float(new_text) new_spin_value = user_locale_format.format("%." + str(digits) + "f", spin_value) except: self.widget.set_text(text) self.widget.stop_emission("insert-text") self.widget.show() return
def _on_insert_text(self, editable, value, length, position): text = self.widget.get_text() if value: current_pos = self.widget.get_position() new_text = text[:current_pos] + value + text[current_pos:] digits = self.widget.get_digits() try: spin_value = user_locale_format.str2float(new_text) new_spin_value = user_locale_format.format( '%.' + str(digits) + 'f', spin_value) except: self.widget.set_text(text) self.widget.stop_emission('insert-text') self.widget.show() return
def _on_insert_text(self, editable, value, length, position): text = self.widget.get_text() if value: current_pos = self.widget.get_position() new_text = text[:current_pos] + value + text[current_pos:] digits = self.widget.get_digits() try: spin_value = user_locale_format.str2float(new_text) new_spin_value = user_locale_format.format('%.' + str(digits) + 'f', spin_value) except: self.widget.set_text(text) #allow entering -ve sign if new_text != '-': self.widget.stop_emission('insert-text') self.widget.show() return
def value_from_text(self, model, text): return user_locale_format.str2float(text)