CudaText API
Intro
This is API for CudaText in Python.
- Main Py module is cudatext. Main module has constants, funcs, class Editor, objects of class Editor.
- Additional module: cudatext_cmd has constants for command runner func.
Global funcs
msg_box
Editor class
get_caret
get_caret()
Returns 4-tuple: info about top visible caret: (PosX, PosY, EndX, EndY). PosY is line index (0-base), PosX is column (0-base), EndY/EndX are position of selection end for this caret or both -1 if no selection.
get_carets
get_carets()
Returns list of 4-tuples. Each list item is info about each caret, see get_caret.
set_caret
set_caret(posx, posy, endx=-1, endy=-1)
Sets single caret with given info (4 integers, see get_caret). Multi-carets 're removed.
add_caret
add_caret(posx, posy, endx=-1, endy=-1)
Adds caret with given info (4 integers, see get_caret). If called with posx<0, then all carets deleted.
Text read/write
get_text_all
get_text_all()
Returns str: entire text in editor.
set_text_all
set_text_all(text)
Sets entire text in editor from str.
get_text_line
get_text_line(num)
Gets str: line with given index (w/o CR LF). Gets None if index incorrect.
set_text_line
set_text_line(num, text)
Sets line with given index to given text. Text should be w/o CR LF.
get_text_substr
get_text_substr(x1, y1, x2, y2)
Gets substring: from caret position (x1, y1) to caret position (x2, y2). Second position must be higher.
delete
delete(x1, y1, x2, y2)
Deletes range from position (x1, y1) to higher position (x2, y2). (Too big x-coord is allowed).
insert
insert(x1, y1, text)
Inserts given string, it can be multi-line with CR LF, into given position (x1, y1).
Selection
get_text_sel
get_text_sel()
Returns str: selected text for 1st caret (empty, if no selection).
get_sel_mode
get_sel_mode()
Gets kind of selection: normal or column selection, values: SEL_NORMAL, SEL_COLUMN.
get_sel_lines
get_sel_lines()
Gets 2-tuple, indexes of 1st and last lines affected by 1st caret selection. Both -1 if no selection.
get_sel_rect
get_sel_rect()
Gets 4-tuple: coords of column selection, (x1, y1, x2, y2). All 0 if no column selection.
set_sel_rect
set_sel_rect(x1, y1, x2, y2)
Sets column selection (removes previous carets) to given coords.
Properties
get_line_count
get_line_count()
Gets number of lines.
get_line_prop
get_line_prop(num)
Gets properties if line with given index (0-base), 2-tuple.
- 1st value: length of line.
- 2nd: line state, one if values LINESTATE_nnn. Line state changes from "normal" to "changed" if line modifies, set to "new" for inserted lines, set from "changed/new" to "saved" after file is saved.
Gets None for incorrect index.