# Source editor¶

This module contains source code editing classes for Myokit’s IDE.

## Implementation¶

class myokit.gui.source.Editor(parent=None)

Source code editor used in Myokit.

Provides the signal find_action(str) which is fired everything a find action occurred with a description that can be used in an application’s status bar.

activate_find_dialog()

Activates the find/replace dialog for this editor: Shows the dialog if hidden, sets the focus to the query field and copies any current selection into the query field.

cursor_changed()

Slot: Called when the cursor position is changed

cursor_position()

Returns a tuple (line, char) with the current cursor position. If a selection is made only the left position is used.

Line and char counts both start at zero.

get_text()

Returns the text in this editor.

hide_find_dialog()

Hides the find/replace dialog for this editor.

jump_to(line, char)

Jumps to the given line and row.

keyPressEvent(event)

Qt event: A key was pressed.

load_config(config, section)

Loads this editor’s configuration using the given ConfigParser config. Loads all settings from the section section.

paintEvent(e)

Paints this editor.

replace(text)

Replaces the current text with the given text, in a single operation that does not reset undo/redo.

resizeEvent(event)

Qt event: Editor is resized.

save_config(config, section)

Saves this editor’s configuration using the given ConfigParser config. Stores all settings in the section section.

set_cursor(pos)

Changes the current cursor to the given position and scrolls so that its visible.

set_text(text)

Replaces the text in this editor.

show_find_dialog()

Displays a find/replace dialog for this editor.

toggle_comment()

trim_trailing_whitespace()

Trims all trailing whitespace from this document.

class myokit.gui.source.LineNumberArea(editor)

Line number area widget for the editor. All real actions are delegated to the text area class.

The line number is drawn in the left margin of the Editor widget, the space to do so is created by setting the editor’s viewport margins.

paintEvent(event)

Qt event: Paint this area.

sizeHint()

Qt event: Suggest a size for this area.

update_contents(rect, scroll)

Slot: Invoked when the text editor view has changed and the line numbers need to be redrawn.

update_width(count)

Slot: Invoked when the number of lines in the text area changed, which might change the size of the number area.

### Find dialog¶

class myokit.gui.source.FindDialog(editor)

Find/replace dialog for Editor.

action_close()

Qt slot: Close this window.

action_find()

Qt slot: Find (next) item.

action_replace()

Qt slot: Replace found item with replacement.

action_replace_all()

Qt slot: Replace all found items with replacement

activate()

Activates this dialog.

case_sensitive()

Returns True if this dialog is set for case-sensitive searching.

keyPressEvent(event)

Qt event: A key-press reaches the dialog.

set_case_sensitive(case_sensitive)

Sets/unsets the case-sensitive option.

set_whole_word(whole_word)

Sets/unsets the whole-word option.

whole_word()

Returns True if this dialog is set for whole-word searching.

### Syntax highlighting¶

class myokit.gui.source.ModelHighlighter(document)

Syntax highlighter for mmt model definitions.

highlightBlock(text)

Qt: Called whenever a block should be highlighted.

class myokit.gui.source.ProtocolHighlighter(document)

Syntax highlighter for mmt protocol definitions.

highlightBlock(text)

Qt: Called whenever a block should be highlighted.

class myokit.gui.source.ScriptHighlighter(document)

Syntax highlighter for mmt script files.

highlightBlock(text)

Qt: Called whenever a block should be highlighted.