Base & Interfaces
karcytics_sdk.plugin.base
Base plugin class for Karcytics SDK.
Provides the main PluginBase class that all plugins should inherit from, with integrated state management and undo/redo support.
PluginBase
Bases: QWidget
Abstract base class for all Karcytics plugins.
This class implements the KarcyticsPlugin Protocol.
Source code in src/karcytics_sdk/plugin/base.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
history
property
writable
Lazy-loaded HistoryManager to avoid circular dependencies.
__getattr__(name)
Proxy signal access to self.signals for convenience.
Allows using self.state_changed.emit() instead of
self.signals.state_changed.emit().
Source code in src/karcytics_sdk/plugin/base.py
__init__(plugin_id, parent=None)
Initialize the plugin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin_id
|
str
|
Unique identifier for this plugin |
required |
parent
|
Parent QWidget (usually None for top-level plugins) |
None
|
Source code in src/karcytics_sdk/plugin/base.py
begin_async_init()
Override to implement the two-phase loading protocol.
Called by PluginLoaderManager immediately after the skeleton panel
is added to the layout. The default no-op preserves backward compatibility
for panels that do not need the protocol.
Subclasses that override this method MUST also declare:
- panel_ready = pyqtSignal() on the class
- Optionally: data_ready = pyqtSignal() for async data gating
See the class-level docstring above for full protocol details.
Source code in src/karcytics_sdk/plugin/base.py
can_redo()
Check if redo is available.
Returns:
| Type | Description |
|---|---|
bool
|
True if there are states to redo to |
can_undo()
Check if undo is available.
Returns:
| Type | Description |
|---|---|
bool
|
True if there are states to undo to |
check_for_updates(repo_url, current_version=None, display_name=None)
Check GitHub for a newer release of this plugin and toast the user with the result.
Opt-in: call this yourself (e.g. from begin_async_init) if you
want it — nothing runs it automatically. The check happens on a
background thread and never blocks or raises. A toast always appears
once it completes — either "an update is available" or a welcome
toast confirming the installed version is already current — except
when the check itself couldn't be completed (no network, GitHub
unreachable, ...), in which case nothing is shown rather than
guessing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_url
|
str
|
This plugin's GitHub repository URL (its manifest's |
required |
current_version
|
str | None
|
The installed version to compare against.
Defaults to |
None
|
display_name
|
str | None
|
The human-readable name to show in the
toast (e.g. |
None
|
Source code in src/karcytics_sdk/plugin/base.py
cleanup()
Automatic Resource Cleansing.
Uses ResourceInspector to break references to heavy objects in both the plugin instance and its state. This helps the GC reclaim memory immediately when a tab is closed.
Source code in src/karcytics_sdk/plugin/base.py
closeEvent(event)
create_render_pipeline(compute_stage, rasterize_stage, target_factory, raster_lock=None, task_scheduler=None)
Build a RenderPipelineController pairing compute_stage with rasterize_stage.
For plugins that want the async-compute/locked-rasterize split
(see rendering.pipeline) without adopting
rendering.LayeredMatplotlibCanvas wholesale — e.g. a one-off
"export image" action. target_factory builds the object
rasterize_stage.rasterize() draws onto (e.g. a fresh matplotlib
Axes) each time a request completes. task_scheduler defaults to
the process-wide runtime_services.task_scheduler singleton but is
overridable — e.g. with a synchronous fake in tests — mirroring
rendering.LayeredMatplotlibCanvas's own constructor for the same
reason.
Source code in src/karcytics_sdk/plugin/base.py
create_worker(analyzer, state=None)
Build an AnalysisWorker wrapping analyzer, ready for start_worker() dispatch.
Kept as a separate call from start_worker() specifically so
callers can connect to the worker's signals (progress, finished,
error, cancelled) before the analyzer starts running on another
thread — connecting after start_worker() risks missing an
emission that fires before the connection is made.
Source code in src/karcytics_sdk/plugin/base.py
get_panel_class()
classmethod
get_state()
abstractmethod
Return the current analysis state.
Must be implemented by subclasses. Called by Karcytics core to capture plugin state for undo/redo and workflow persistence.
Returns:
| Type | Description |
|---|---|
PluginState
|
Current PluginState instance |
Source code in src/karcytics_sdk/plugin/base.py
populate_preferences(dialog)
Default preferences-page contribution: adds the "Workspace"
autosave page if setup_workflow_autosave() was called, otherwise
does nothing.
Called by the isolated-plugin daemon runtime's Preferences dialog
(see ui_daemon_runtime._open_preferences). Subclasses that need
their own additional pages should override this and call
super().populate_preferences(dialog) to keep this behavior.
Source code in src/karcytics_sdk/plugin/base.py
publish_event(topic, data=None)
push_state()
Save current state to undo history.
Call this whenever the user makes a destructive edit (e.g., changing a parameter, drawing on an image). Karcytics will emit state_changed signal and automatically capture this state for undo/redo.
Source code in src/karcytics_sdk/plugin/base.py
redo()
Redo to next state.
Source code in src/karcytics_sdk/plugin/base.py
set_state(state)
abstractmethod
Set the plugin state and update UI accordingly.
Must be implemented by subclasses. Called by Karcytics core to restore plugin state during undo/redo and workflow loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
PluginState
|
PluginState instance to restore |
required |
Source code in src/karcytics_sdk/plugin/base.py
setup_workflow_autosave(has_saved_once, save, *, interval_ms=None)
Opt this plugin into the SDK's shared workflow-autosave loop.
has_saved_once should report whether the current workspace has
already been saved manually at least once (autosave only ever
applies after that — it's what gives a workflow a name). save
should perform a quiet save (no blocking dialogs — the controller
shows its own toast) and call the callback it's given with whether
that save succeeded.
Building the WorkflowAutosaveController here — rather than each
plugin constructing one itself — is what makes populate_preferences
below able to add its "Workspace" preferences page automatically for
any plugin that calls this, with no further wiring on the plugin's
part.
Source code in src/karcytics_sdk/plugin/base.py
show_toast(message, icon='ℹ️', color='#5C9EE5', duration_ms=4000)
Show a non-intrusive toast notification anchored to this plugin's window.
Uses the same bottom-right, auto-fading popup the Hub uses for its
own system warnings (see karcytics_sdk.plugin.toast). Works
identically whether this plugin runs in-process or isolated, since
each owns its own QApplication.
Source code in src/karcytics_sdk/plugin/base.py
shutdown()
start_worker(worker)
Dispatch a worker built by create_worker() onto the shared QThreadPool.
Uses AnalysisRunnable directly — the same QThreadPool adapter
runtime_services.LocalTaskScheduler.submit() uses internally —
rather than routing through a task scheduler's submit(analyzer,
state), because that call always builds its own fresh
AnalysisWorker from an analyzer/state pair and has no way to
accept an already-constructed worker. The whole point of the
create_worker()/start_worker() split is that callers connect
signals on the exact worker instance create_worker() returned
before dispatch, so that same instance must be the one that runs.
Source code in src/karcytics_sdk/plugin/base.py
subscribe_event(topic, callback)
undo()
Undo to previous state.
Source code in src/karcytics_sdk/plugin/base.py
karcytics_sdk.plugin.interfaces
Karcytics Plugin Interfaces.
Defines the formal structural requirements for Karcytics analysis modules using PEP 544 Protocols.
KarcyticsPlugin
Bases: Protocol
Structural protocol for a valid Karcytics Plugin module.
Any Python module or class that implements this protocol can be loaded as a Karcytics plugin.
Source code in src/karcytics_sdk/plugin/interfaces.py
__plugin_id__
property
The unique identifier for the plugin (matches manifest.json id).
__version__
property
The version string of the plugin (e.g. '1.2.3').
cleanup()
Release instance-specific resources (e.g. caches, local memory).
Called when a specific instance of the plugin panel is closed.
get_panel_class()
shutdown()
Release global/module resources (e.g. GPU models, open files).
Called when the application exists or the module is unloaded.