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
Editor class has methods to work with editor. Global objects of Editor exist:
- ed: refers to currently focused editor (for any tab)
- ed_bro: refers to brother of current editor. If tab is splitted, 2 editors shown: 1st/2nd. 1st is "brother" for 2nd, 2nd is brother for 1st.
Carets
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.
get_filename
get_filename()
Gets str: filename for the editor. Empty if tab is untitled.
get_tabcolor
get_tabcolor()
Gets color (int) of tab for the editor. It's COLOR_NONE if color is not set.
set_tabcolor
set_tabcolor(value)
Sets color (int) for editor tab. Pass COLOR_NONE to remove custom color.
get_enc
get_enc()
Gets encoding name for editor. It's one of the strings which are visible in the encodings menu of statusbar: "UTF-8", "ANSI" etc.
set_enc
set_enc(value)
Sets encoding name for editor.
get_top
get_top()
Gets index of top visible line in editor.
set_top
set_top(num)
Sets index of top visible line in editor.
get_split
get_split()
Gets props of tab splitting (each tab can be splitted to main/second editors), 2-tuple:
- int: kind of splitting, one of values TAB_SPLIT_NO, TAB_SLIT_HORZ, TAB_SPLIT_VERT.
- float: percent of splitting, it's 0.5 if tab splitted 50/50.
set_split
set_split(state, value)
Sets props of tab splitting:
- state: int: one of values TAB_SPLIT_nnn.
- value: float: percent of splitting, e.g. 0.5 for splitting 50/50.