Bases: PyQt5.QtWidgets.QPlainTextEdit
Qutepart is based on QPlainTextEdit, and you can use QPlainTextEdit methods, if you don’t see some functionality here.
Text
text attribute holds current text. It may be read and written.:
qpart.text = readFile()
saveFile(qpart.text)
This attribute always returns text, separated with \n. Use textForSaving() for get original text.
It is recommended to use lines attribute whenever possible, because access to text might require long time on big files. Attribute is cached, only first read access after text has been changed in slow.
Selected text
selectedText attribute holds selected text. It may be read and written. Write operation replaces selection with new text. If nothing is selected - just inserts text:
print qpart.selectedText # print selection
qpart.selectedText = 'new text' # replace selection
Text lines
lines attribute, which represents text as list-of-strings like object and allows to modify it. Examples:
qpart.lines[0] # get the first line of the text
qpart.lines[-1] # get the last line of the text
qpart.lines[2] = 'new text' # replace 3rd line value with 'new text'
qpart.lines[1:4] # get 3 lines of text starting from the second line as list of strings
qpart.lines[1:4] = ['new line 2', 'new line3', 'new line 4'] # replace value of 3 lines
del qpart.lines[3] # delete 4th line
del qpart.lines[3:5] # delete lines 4, 5, 6
len(qpart.lines) # get line count
qpart.lines.append('new line') # append new line to the end
qpart.lines.insert(1, 'new line') # insert new line before line 1
print qpart.lines # print all text as list of strings
# iterate over lines.
for lineText in qpart.lines:
doSomething(lineText)
qpart.lines = ['one', 'thow', 'three'] # replace whole text
Position and selection
Rectangular selection is not available via API currently.
EOL, indentation, edge
Visible white spaces
Autocompletion
Qutepart supports autocompletion, based on document contents. It is enabled, if completionEnabled is True. completionThreshold is count of typed symbols, after which completion is shown.
Linters support
Vim mode
vimModeEnabled - read-write property switches Vim mode. See also vimModeEnabledChanged. vimModeIndication - An application shall display a label, which shows current Vim mode. This read-only property contains (QColor, str) to be displayed on the label. See also vimModeIndicationChanged.
Actions
Component contains list of actions (QAction instances). Actions can be insered to some menu, a shortcut and an icon can be configured.
Bookmarks:
Scroll:
Indentation:
Lines:
Other: * undoAction - Undo * redoAction - Redo * invokeCompletionAction - Invoke completion * printAction - Print file
Text modification and Undo/Redo
Sometimes, it is required to make few text modifications, which are Undo-Redoble as atomic operation. i.e. you want to indent (insert indentation) few lines of text, but user shall be able to Undo it in one step. In this case, you can use Qutepart as a context manager.:
with qpart:
qpart.modifySomeText()
qpart.modifyOtherText()
Nested atomic operations are joined in one operation
Signals
Public methods
Terminate Qutepart instance. This method MUST be called before application stop to avoid crashes and some other interesting effects Call it on close to free memory and stop background highlighting
Get text with correct EOL symbols. Use this method for saving a file to storage
Replace length symbols from pos with new text.
If pos is an integer, it is interpreted as absolute position, if a tuple - as (line, column)
Insert text at position
If pos is an integer, it is interpreted as absolute position, if a tuple - as (line, column)
Get syntax by next parameters (fill as many, as known):
- name of XML file with syntax definition
- MIME type of source file
- Programming language name
- Source file path
- First line of source file
First parameter in the list has the hightest priority. Old syntax is always cleared, even if failed to detect new.
Method returns True, if syntax is detected, and False otherwise
Clear syntax. Disables syntax highlighting
This method might take long time, if document is big. Don’t call it if you don’t have to (i.e. in destructor)
Check if text at given position is a code.
If language is not known, or text is not parsed yet, True is returned
Check if text at given position is a comment. Including block comments and here documents.
If language is not known, or text is not parsed yet, False is returned
Check if text at given position is a block comment.
If language is not known, or text is not parsed yet, False is returned
Check if text at given position is a here document.
If language is not known, or text is not parsed yet, False is returned
Package logs it’s debug information to qutepart logger. By default logger prints messages to stderr with qutepart: prefix. For performance reasons, parser in C:
- checks, if DEBUG logs are enabled only when created
- always prints logs to stderr
- always prints ERROR logs
- always uses qutepart: prefix
Logging handler is available as consoleHandler attribute of the package
API version is available as qutepart.VERSION. It is a tuple (major, minor, patch)
Qutepart has 2 text parsers - slower in Python, and quicker in C. If C parser has been successfully loaded, qutepart.binaryParserAvailable is True