BasePlugin¶
- class forkbit_sdk.BasePlugin[source]¶
Bases:
objectBase class for all ForkBit plugins.
Subclass this and override
on_ready()to build your plugin UI. The app creates an instance, injects context (project, settings, git), and callson_ready()when everything is wired up.Example:
from forkbit_sdk import BasePlugin from PySide6.QtWidgets import QLabel, QVBoxLayout class MyPlugin(BasePlugin): def on_ready(self): layout = QVBoxLayout(self.container) layout.addWidget(QLabel("Hello!"))
- container¶
The root widget for your plugin UI. Build your layout inside this.
- property plugin_icon_colors: tuple[str, str]¶
Gradient colors
(start, end)for the plugin icon background.
- property data_dir: Path¶
Per-instance directory for plugin file storage.
Created automatically by the app before
on_ready()is called. Useread_json()andwrite_json()for convenient access.- Raises:
RuntimeError – If accessed before
on_ready().
- write_json(filename, data)[source]¶
Atomic-write a JSON file to
data_dir.Writes to a temporary file first, then renames — safe against crashes.
- secret_file_stream(field_id)[source]¶
Return a file-like
BytesIOfor asecret_filesettings field.Useful when a library expects a file object instead of raw bytes.
- on_ready()[source]¶
Called when the plugin is fully initialized.
Override this to build your UI inside
containerand set up initial state. All context properties (settings,data_dir,git, etc.) are available at this point.- Return type:
None
- on_settings_changed(settings)[source]¶
Called when the user saves plugin settings.
Override this to react to settings changes at runtime (e.g. refresh data with a new API key). The base implementation updates
settings— callsuper()if you override.- Parameters:
settings (dict) – The full updated settings dict.
- Return type:
None
- property status_chip: QWidget | None¶
Optional status chip widget in the plugin header.
Injected by the app —
Noneuntilon_ready()runs.
- set_subtitle(text)[source]¶
Update the subtitle shown in the plugin header.
- Parameters:
text (str) – New subtitle text (e.g.
"v1.2.0 — 3 locales").- Return type:
None
- translate(text, source_lang, target_lang, on_done=None, on_error=None)[source]¶
Request an asynchronous translation via the app’s translation service.
The translation runs in a background thread. Results arrive via callbacks.
- Parameters:
text (str) – The text to translate.
source_lang (str) – Source language code (e.g.
"en").target_lang (str) – Target language code (e.g.
"de").on_done (Callable[[str], None] | None) – Callback receiving the translated text.
on_error (Callable[[str], None] | None) – Callback receiving an error message.
- Returns:
A request ID for tracking.
- Raises:
RuntimeError – If no translation service is configured.
- Return type: