hscommon.gui.text_field

TextField() Cross-toolkit text field.
TextFieldView Expected interface for TextField’s view.
class hscommon.gui.text_field.TextField

Cross-toolkit text field.

Represents a UI element allowing the user to input a text value. Its main attribute is text which acts as the store of the said value.

When our model value isn’t a string, we have a built-in parsing/formatting mechanism allowing us to directly retrieve/set our non-string value through value.

Subclasses GUIObject. Expected view: TextFieldView.

_format(value)

(Virtual) Formats value to put into text.

Returns the formatted version of value. Called whenever value changes.

_parse(text)

(Virtual) Parses text to put into value.

Returns the parsed version of text. Called whenever text changes.

_update(newvalue)

(Virtual) Called whenever we have a new value.

Whenever our text/value store changes to a new value (different from the old one), this method is called. By default, it does nothing but you can override it if you want.

_view_updated()

(Virtual) Called after view has been set.

Doing nothing by default, this method is called after view has been set (it isn’t called when it’s unset, however). Use this for initialization code that requires a view (which is often the whole of the initialization code).

refresh()

Triggers a view refresh().

text

The text that is currently displayed in the widget.

str. get/set.

This property can be set. When it is, refresh() is called and the view is synced with our value. Always in sync with value.

value

The “parsed” representation of text.

arbitrary type. get/set.

By default, it’s a mirror of text, but a subclass can override _parse() and _format() to have anything else. Always in sync with text.

class hscommon.gui.text_field.TextFieldView

Expected interface for TextField’s view.

Not actually used in the code. For documentation purposes only.

Our view is expected to sync with TextField.text “both ways”, that is, update the model’s text when the user types something, but also update the text field when refresh() is called.

refresh()

Refreshes the contents of the input widget.

Ensures that the contents of the input widget is actually TextField.text.