Talk:CudaText API

From Lazarus wiki
Revision as of 23:29, 15 April 2017 by Alextp (talk | contribs) (→‎Actions)
Jump to navigationJump to search
(no text)

Dlg_proc (temp text)

dlg_proc

dlg_proc(id_dialog, id_action, prop="", index=-1, index2=-1)

Advanced work with dialogs (forms). More advanced than dlg_custom(), e.g. dialogs can show as modal/nonmodal. Dialogs use on_dlg event, it's described in events section.

Form properties

  • "cap": str: Caption of form.
  • "x", "y": int: Position (screen coordinates), left/top.
  • "w", "h": int: Size, width/height.
  • "w_min", "w_max": int: Constraints for width, min/max value.
  • "h_min", "h_max": int: Constraints for height, min/max value.
  • "resize": bool: Allows form to resize.

Control properties

  • "name": str: Optional word-like string, name of control, to find control later by name.
  • "cap": str: Caption.
  • "x", "y": int: Position (coordinates relative to dialog), left/top.
  • "w", "h": int: Size, width/height.
  • "en": bool: Enabled state.
  • "vis": bool: Visible state.
  • "color": int: Color.
  • "font_name": str: Font name.
  • "font_size": int: Font size.
  • "font_color": int: Font color.
  • "hint": str: Hint (tooltip) for mouse-over. Newlines must be "\r".
  • "act": bool: Active state. For active control, change of value calls the event (on_dlg or custom callback). Buttons are active by default.
  • "props": str: Advanced control-specific props. Described in dlg_custom.
  • "items": str: Usually tab-separated items. Described in dlg_custom.
  • "val": str: Value of control. Described in dlg_custom.
  • "tag": str: Any string, set by plugin.
  • "callback": str: If not empty, active control calls this callback instead of on_dlg event. Has one of forms:
    • "module=mmm;cmd=nnn;" - to call method nnn (in class Command) in plugin mmm (mmm is usually subfolder in the "cudatext/py", but can be any module name)
    • "mmm.nnn" - the same, to call method, short form
    • "module=mmm;func=nnn;" - to call function nnn in root of module mmm

Actions

Param prop: it can be of any simple type (str, int, bool), also tuple/list (of any simple type), also dict (keys: str, values: simple type or tuple/list). Most used is dict. Example of control props: prop={"cap": "...", "x": 10, "y": 10, "w": 600, "en": False}.

Param id_dialog: int, form handle. Ignored only for DLG_CREATE (pass 0).

Possible values of id_action:

  • DLG_CREATE: Creates new form, gets form handle.
  • DLG_HIDE: Hides from.
  • DLG_FREE: Hides and deletes form.
  • DLG_SHOW_MODAL: Shows form in modal mode (blocks input to other forms).
  • DLG_SHOW_NONMODAL: Shows form in non-modal mode.
  • DLG_FOCUS: Focuses form (in non-modal mode).
  • DLG_PROP_GET: Gets form props, as dict.
  • DLG_PROP_SET: Sets from props. Param "prop" is dict with props. See example above, see list of possible form props.
  • DLG_CTL_COUNT: Gets count of controls on form.
  • DLG_CTL_ADD: Adds new control to form, gets its index, or None if cannot add. Param "prop" is type of control. See description in dlg_custom.
  • DLG_CTL_PROP_GET: Gets control props, as dict. Param "index" is index of control.
  • DLG_CTL_PROP_SET: Sets control props. Param "index" is index of control. Param "prop" is dict with props.
  • DLG_CTL_FOCUS: Focuses control. Param "index" is index of control.
  • DLG_CTL_DELETE: Deletes control. Param "index" is index of control. Controls are stored in list, so after a control deleted, indexes of next controls shift by -1. So don't use fixed indexes if you delete some, use DLG_CTL_FIND.
  • DLG_CTL_DELETE_ALL: Deletes all controls.
  • DLG_CTL_FIND: Gets index of control by name, or -1 if cannot find. Param "prop" is name.
  • DLG_COORD_LOCAL_TO_SCREEN: Converts x/y coordinates from form-related, to screen-related. Param "index" is x, "index2" is y. Gets tuple (x,y).
  • DLG_COORD_SCREEN_TO_LOCAL: Converts x/y coordinates from screen-related, to form-related. Param "index" is x, "index2" is y. Gets tuple (x,y).

Example

Detailed demo plugin exists, it shows many dlg_proc actions, shows modal/nonmodal forms, uses callbacks, moves control by button click, moves control on form resize. It is in the CudaText repo with name "cuda_testing_dlg_proc".