Difference between revisions of "CudaText API"

From Free Pascal wiki
Jump to navigationJump to search
Line 197: Line 197:
 
===bookmark===
 
===bookmark===
  
  bookmark(self, id, nline, nkind=1, ncolor=-1, icon='')
+
  bookmark(id, nline, nkind=1, ncolor=-1, icon='')
  
 
Controls bookmarks. Values of id:
 
Controls bookmarks. Values of id:

Revision as of 20:48, 23 September 2015

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 ed. If tab is splitted, 2 editors are shown: 1st/2nd. 1st and 2nd are "brother" editors.

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.

bookmark

bookmark(id, nline, nkind=1, ncolor=-1, icon=)

Controls bookmarks. Values of id:

  • BOOKMARK_GET: Gets kind of bookmark at line=nline.
  • BOOKMARK_SET: Sets bookmark with kind=nkind at line=nline. 1 means usual bookmark with usual color and icon. Other kind values mean custom bookmark, which must be setup via BOOKMARK_SETUP.
  • BOOKMARK_CLEAR: Removes bookmark from line=nline.
  • BOOKMARK_CLEAR_ALL: Removes all bookmarks.
  • BOOKMARK_SETUP: Setup custom bookmarks with kind=nkind. Setup is:
    • ncolor: color if bookmarked line,
    • icon: path to icon file, .bmp file of size 16x16.
  • BOOKMARK_GET_LIST: Gets list of line indexes with bookmarks.

Note: nkind must be 1..255.

Misc

cmd

cmd(code)

Command runner, it runs any command of editor by its int code. See codes in module cudatext_cmd.

focus

focus()

Activates editor's tab and focuses editor itself. It's needed when you want to activate non-visible tab.

lock/unlock

lock()
unlock()

These lock, then unlock editor. Locked editor is not painted and shows text label "Wait...".