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.


(Virtual) Formats value to put into text.

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


(Virtual) Parses text to put into value.

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


(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.


(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).


Triggers a view refresh().


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.


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.


Refreshes the contents of the input widget.

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