Skip to content

PluginAPI

maxhatei2 edited this page Nov 1, 2025 · 1 revision

PluginAPI

PluginAPI is a class of commands used to configure kPad or to add widgets which are based on Tkinter.

How to interact

Interacting is easy: use the editor variable alongside the command you would like to use, like editor.get_text_from_box(). That automatically uses the PluginAPI command to interact with kPad.

Available commands

There are currently 25 commands for plugins to use:

Editing

  • get_text_from_box():
    • Get text from the edit box, returned as a string.
  • get_specific_text_from_box(start, end):
    • Get some specific text from the edit box, where start is the position start, and end is the position end. Returned as a string.
  • clear_text_from_box():
    • Clear text from the edit box.
  • insert_text_to_start_of_box(text):
    • Inserts text to the start of the box, where text is a string or integer to insert.
  • insert_text_to_end_of_box(text):
    • Same as insert_text_to_start_of_box(text), but more like an append.
  • get_selected_text():
    • Gets the current selected text. If there is none, it returns an empty string.
  • get_selected_text_indexes():
    • Gets the current selected text indexes in a tuple. If there isn't anything selected, it returns a None object.

Paths

  • get_plugin_path(plugin_name):
    • Gets the current plugin location path.
  • get_current_file_path():
    • Gets the currently opened file path in kPad. Returns None if new file.

Appearance

  • get_current_theme_mode():
    • Gets the current theme mode: dark or light.
  • set_current_theme_mode(mode):
    • Sets the current theme mode. Accepts dark or light.
  • set_theme_mode(json_path):
    • Sets a theme based on a JSON file. Refer to CustomTkinter documentation.

Communication

  • showinfo(text):
    • Shows a message in a messagebox, where text is the text to show.
  • showerror(text):
    • Shows an error message in a messagebox, where text is the text to show.
  • log(text):
    • Shows a log in the terminal, without disturbing the user.

Widgets

  • Widget_Frame(parent, **kwargs):
    • Creates a frame to use for widgets, where parent can be the editor appinstance (you can define it with editor._appinstance) and **kwargs can be other arguments that the CTkFrame support.
  • Widget_Label(parent, text, font=('', 13), **kwargs):
    • Creates a label to use inside a parent or a frame, where parent can be the editor appinstance (you can define it with editor._appinstance) and **kwargs can be other arguments that the CTkLabel support, text is the text that the label will contain, font is a tuple where '' is the font family, and the integer is the font size.
  • Widget_Button(parent, text, cmd, font=('', 13))
    • Creates a button; everything is provided in the upper widget descriptions.
  • Widget_Other(self, parent, widget, **kwargs):
    • Creates a widget which is based on Tcl/Tk roots and supports **kwargs, where parent can be the editor appinstance (you can define it with editor._appinstance) and **kwargs can be other arguments that the widget supports. widget can be the chosen widget (e.g. tkwebview.HtmlLabel).

Text tags

  • add_text_tag(tag_name, **options):

    • Adds (or updates) a text tag (fg, bg, font, etc.)
  • tag_text(tag_name, start, end):

    • Apply a tag to a range of text.
  • remove_tag(tag_name, start="1.0", end="end"):

    • Remove a tag from a range.
  • clear_all_tags():

    • Remove all tags from the edit box.

Misc

  • bind(sequence, callback):
  • Binds a key or a specific shortcut (sequence) to a function (callback). The function must be into the action function and should have a parameter (event=None). Refer to this page to see using sequences.
  • run_async(cmd, withdaemon):
    • Runs a command which could take some time in a separate thread to not freeze the UI. cmd is the function to run, and withdaemon is a boolean for to use or not a daemon.
  • prepare_for_external_libs():
    • Use this when external libraries (needed to be installed) are required to use. This activates the created env.

Clone this wiki locally