earwax.editor module¶
Provides the Editor class.
-
class
earwax.editor.
Editor
(game: Game, dismissible: bool = True, text: str = '', cursor_position: Optional[int] = None, vertical_position: Optional[int] = None)¶ Bases:
earwax.level.Level
,earwax.mixins.DismissibleMixin
A basic text editor.
By default, the enter key dispatches the
on_submit
event, with the contents ofearwax.Editor.text
.Below is an example of how to use this class:
e: Editor = Editor(game) @e.event def on_submit(text: str) -> None: # Do something with text... game.push_level(e)
Variables: - func – The function which should be called when pressing enter in an edit field.
- text – The text which can be edited by this object.
- cursor_position – The position of the cursor.
- vertical_position – The position in the alphabet of the hat.
-
beginning_of_line
() → None¶ Move to the start of the current line.
By default, this method is called when the home key is pressed.
-
clear
() → None¶ Clear this editor.
By default, this method is called when control + u is pressed.
-
copy
() → None¶ Copy the contents of this editor to the clipboard.
-
cut
() → None¶ Cut the contents of this editor to the clipboard.
-
do_delete
() → None¶ Perform a forward delete.
Used by
motion_delete()
, as well as the vertical hat movement methods.
-
echo
(text: str) → None¶ Speak the provided text.
Parameters: text – The text to speak, using tts.speak
.
-
echo_current_character
() → None¶ Echo the current character.
Used when moving through the text.
-
end_of_line
() → None¶ Move to the end of the line.
By default, this method is called when the end key is pressed.
-
hat_down
() → None¶ Move down through the list of letters.
-
hat_up
() → None¶ Change the current letter to the previous one in the configured alphabet.
If the cursor is at the end of the line, moving up will select a “save” button.
If the cursor is not at the end of the line, moving up will select a “delete” button.
-
insert_text
(text: str) → None¶ Insert
text
at the current cursor position.
-
motion_backspace
() → None¶ Delete the previous character.
This will do nothing if the cursor is at the beginning of the line, or there is no text to delete.
-
motion_delete
() → None¶ Delete the character under the cursor.
Nothing will happen if we are at the end of the line (or there is no text, which will amount to the same thing).
-
motion_down
() → None¶ Arrow down.
Since we’re not bothering with multiline text fields at this stage, just move the cursor to the end of the line, and read the whole thing.
By default, this method is called when the down arrow key is pressed.
-
motion_left
() → None¶ Move left in the editor.
By default, this method is called when the left arrow key is pressed.
-
motion_right
() → None¶ Move right in the editor.
By default, this method is called when the right arrow key is pressed.
-
motion_up
() → None¶ Arrow up.
Since we’re not bothering with multiline text fields at this stage, just move the cursor to the start of the line, and read the whole thing.
By default, this method is called when the up arrow key is pressed.
-
on_submit
(text: str) → None¶ Code to be run when this editor is submitted.
The event which is dispatched if the enter key is pressed.
Parameters: text – The contents of self.text
.
-
on_text
(text: str) → None¶ Text has been entered.
If the cursor is at the end of the line, append the text. Otherwise, insert it.
Parameters: text – The text that has been entered.
-
paste
() → None¶ Paste the contents of the clipboard into this editor.
-
set_cursor_position
(pos: Optional[int]) → None¶ Set the cursor position within
text
.If
pos
isNone
, then the cursor will be at the end of the line. Otherwise,pos
should be an integer between 0 andlen(self.text) - 1
.Parameters: pos – The new cursor position.
-
submit
() → None¶ Submit
self.text
.Dispatch the
on_submit
event with the contents ofself.text
.By default, this method is called when the enter key is pressed.