himena.plugins
register_hidden_function = partial(register_function, menus=[], palette=False)
module-attribute
A shorthand for register_function(menus=[], palette=False)
.
AppActionRegistry
Source code in src\himena\plugins\actions.py
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 |
|
installed_plugins
property
List of modules or python paths that are installed as plugins.
add_action(action, is_dynamic=False)
Add an action to the registry.
Source code in src\himena\plugins\actions.py
144 145 146 147 148 149 150 151 |
|
install_to(app, actions=None)
Install actions to the application.
This method automatically adds submenus if they are not already exists, and returns the list of added root menu IDs. Note that this does NOT updates the GUI menubar and toolbar.
Source code in src\himena\plugins\actions.py
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 |
|
instance()
classmethod
Get the global instance of the registry.
Source code in src\himena\plugins\actions.py
115 116 117 118 119 120 |
|
pick_a_tip()
Pick a random tip.
Source code in src\himena\plugins\actions.py
137 138 139 140 141 142 |
|
submenu_group(id)
Get the group of a submenu.
Source code in src\himena\plugins\actions.py
169 170 171 |
|
submenu_title(id)
Get the title of a submenu.
Source code in src\himena\plugins\actions.py
163 164 165 166 167 |
|
ReaderPlugin
Source code in src\himena\plugins\io.py
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 |
|
define_matcher(matcher)
Mark a function as a matcher.
The matcher function should return a type string if the reader can read the
file, or None otherwise. If the reader function is annotated with Path
, only
single Path input is forwarded to the matcher function, otherwise both Path
and list[Path]
will be considered.
Examples:
A reader plugin that reads only text files:
@my_reader.define_matcher
def _(path: Path):
if path.suffix == ".txt":
return "text"
return None
Source code in src\himena\plugins\io.py
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 |
|
match_model_type(path)
True if the reader can read the file.
Source code in src\himena\plugins\io.py
107 108 109 110 111 112 113 114 115 116 |
|
read(path)
Read file(s) and return a data model.
Source code in src\himena\plugins\io.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
read_and_update_source(source)
Update workflow to a local-reader method if it is not set.
Source code in src\himena\plugins\io.py
146 147 148 149 150 151 |
|
ReproduceArgs
dataclass
Command and its arguments to reproduce a user modification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command_id
|
str
|
|
required |
Source code in src\himena\plugins\actions.py
79 80 81 82 83 84 85 86 |
|
WriterPlugin
Source code in src\himena\plugins\io.py
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 |
|
define_matcher(matcher)
Define how to match the input data model and the save path to this writer.
Examples:
```python @my_writer.define_matcher def _(model: WidgetDataModel, path: Path) -> bool: return path.suffix == ".txt" and model.type == "text"
Source code in src\himena\plugins\io.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
add_default_status_tip(short, long)
Add a status tip that will be randomly shown in the status bar.
Source code in src\himena\plugins\actions.py
610 611 612 613 614 615 616 |
|
config_field(default=MISSING, *, default_factory=MISSING, tooltip=None, label=None, choices=None, widget_type=None, enabled=None, visible=None, **kwargs)
Field used for plugin config dataclass.
@dataclass
class MyPluginConfig:
my_field: str = config_field("abc", tooltip="how to use this")
Source code in src\himena\plugins\config.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
configure_gui(f=None, *, title=None, preview=False, auto_close=True, show_parameter_labels=True, gui_options=None, result_as='window', **kwargs)
configure_gui(f: _F, *, title: str | None = None, preview: bool = False, auto_close: bool = True, show_parameter_labels: bool = True, gui_options: dict[str, Any] | None = None, result_as: Literal['window', 'below', 'right'] = 'window', **kwargs) -> _F
configure_gui(*, title: str | None = None, preview: bool = False, auto_close: bool = True, show_parameter_labels: bool = True, gui_options: dict[str, Any] | None = None, result_as: Literal['window', 'below', 'right'] = 'window', **kwargs) -> Callable[[_F], _F]
Configure the parametric GUI.
This decorator sets the configuration options for the parametric GUI window.
@configure_gui(a={"label": "A", "widget_type": "FloatSlider"})
def my_func(a: float):
pass
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
The title of the parametric GUI window. If not provided, this title will be determined by the action title where this function is returned. |
None
|
preview
|
bool
|
If true, a preview toggle switch will be added to the GUI window. When the
switch is on, the function will be called and the result will be displayed. Note
that |
False
|
auto_close
|
bool
|
If true, the parametric GUI window will be closed automatically after the function is executed. |
True
|
show_parameter_labels
|
bool
|
If true, the parameter names will be shown in the GUI window. |
True
|
gui_options
|
dict
|
Additional GUI options to be passed to the |
None
|
Source code in src\himena\plugins\_signature.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 |
|
configure_submenu(submenu_id, title=None, *, group=None)
Register a configuration for submenu(s).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
submenu_id
|
str or iterable of str
|
Submenu ID(s) to configure. |
required |
title
|
str
|
Specify the title of the submenu. |
None
|
group
|
str
|
Specify the group ID of the submenu. |
None
|
Source code in src\himena\plugins\actions.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
install_plugins(app, plugins)
Install plugins to the application.
Source code in src\himena\plugins\install.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
override_keybindings(app, prof)
Override keybindings in the application.
Source code in src\himena\plugins\install.py
84 85 86 87 88 89 90 91 92 |
|
register_conversion_rule(*args, **kwargs)
register_conversion_rule(func: _F, type_from: str, type_to: str, *, keybindings: KeyBindingsType | None = None, command_id: str | None = None) -> _F
register_conversion_rule(type_from: str, type_to: str, *, keybindings: KeyBindingsType | None = None, command_id: str | None = None) -> Callable[[_F], _F]
Register a function as a conversion rule.
A conversion rule will be added to the model menu under "Convert > ..." submenu.
Essentially, this method does nothing more than register_function
, but using this
registration method is recommended for the sake of clarity and following the
conventions.
from himena.plugins import register_conversion_rule
@register_conversion_rule("text", "table")
def convert_text_to_table(model: WidgetDataModel) -> WidgetDataModel:
... # convert the data type
Source code in src\himena\plugins\actions.py
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 |
|
register_dock_widget_action(widget_factory=None, *, menus=None, title=None, area=DockArea.RIGHT, allowed_areas=None, keybindings=None, singleton=False, plugin_configs=None, command_id=None, icon=None)
register_dock_widget_action(widget_factory: _F, *, menus: str | Sequence[str] | None = None, title: str | None = None, area: DockArea | DockAreaString = DockArea.RIGHT, allowed_areas: Sequence[DockArea | DockAreaString] | None = None, keybindings: KeyBindingsType | None = None, singleton: bool = False, plugin_configs: PluginConfigType | None = None, command_id: str | None = None, icon: str | None = None) -> _F
register_dock_widget_action(widget_factory: None = None, *, menus: str | Sequence[str] | None = None, title: str | None = None, area: DockArea | DockAreaString = DockArea.RIGHT, allowed_areas: Sequence[DockArea | DockAreaString] | None = None, keybindings: KeyBindingsType | None = None, singleton: bool = False, plugin_configs: PluginConfigType | None = None, command_id: str | None = None, icon: str | None = None) -> Callable[[_F], _F]
Register a widget factory as a dock widget function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget_factory
|
callable
|
Class of dock widget, or a factory function for the dock widget. |
None
|
menus
|
str or sequence of str
|
Menu ID or list of menu IDs where the action will be added. |
None
|
title
|
str
|
Title of the dock widget. |
None
|
area
|
DockArea or DockAreaString
|
Initial area of the dock widget. |
RIGHT
|
allowed_areas
|
sequence of DockArea or DockAreaString
|
List of areas that is allowed for the dock widget. |
None
|
keybindings
|
sequence of keybinding rule
|
Keybindings to trigger the dock widget. |
None
|
singleton
|
bool
|
If true, the registered dock widget will constructed only once. |
False
|
plugin_configs
|
(dict, dataclass or BaseModel)
|
Default configuration for the plugin. This config will be saved in the
application profile and will be used to update the dock widget via the method
where only "value" is required. If a dataclass or pydantic.BaseModel, field objects will be used instead of the dict.
|
None
|
command_id
|
str
|
Command ID. If not given, the function name will be used. |
None
|
icon
|
str
|
Iconify icon key. |
None
|
Source code in src\himena\plugins\widget_plugins.py
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 |
|
register_function(func=None, *, menus='plugins', title=None, types=None, enablement=None, keybindings=None, run_async=False, command_id=None, icon=None, palette=True)
register_function(*, menus: str | Sequence[str] = 'plugins', title: str | None = None, types: str | Sequence[str] | None = None, enablement: BoolOp | None = None, keybindings: Sequence[KeyBindingRule] | None = None, run_async: bool = False, command_id: str | None = None, icon: str | None = None, palette: bool = True) -> None
register_function(func: _F, *, menus: str | Sequence[str] = 'plugins', title: str | None = None, types: str | Sequence[str] | None = None, enablement: BoolOp | None = None, keybindings: Sequence[KeyBindingRule] | None = None, run_async: bool = False, command_id: str | None = None, icon: str | None = None, palette: bool = True) -> _F
Register a function as a callback of a plugin action.
This function can be used either as a decorator or a simple function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
callable
|
Function to register as an action. |
None
|
menus
|
str or sequence of str
|
Menu(s) to add the action. Submenus are separated by |
"plugins"
|
title
|
str
|
Title of the action. Name of the function will be used if not given. |
None
|
types
|
The |
None
|
|
enablement
|
Expression that describes when the action will be enabled. As this argument
is a generalized version of |
None
|
|
run_async
|
bool
|
If true, the function will be executed asynchronously. Note that if the function updates the GUI, running it asynchronously may cause issues. |
False
|
command_id
|
str
|
Command ID. If not given, the function qualname will be used. |
None
|
icon
|
str
|
Iconify icon key to use for the action. |
None
|
palette
|
bool
|
If true, the action will be added to the command palette. |
True
|
Source code in src\himena\plugins\actions.py
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 |
|
register_modification_tracker(type)
Register a modification tracker.
Source code in src\himena\plugins\actions.py
595 596 597 598 599 600 601 602 603 604 605 606 607 |
|
register_previewer_class(type_, widget_class)
Register a widget class for previewing the given model type.
Source code in src\himena\plugins\widget_class.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
register_reader_plugin(reader=None, *, priority=100)
register_reader_plugin(reader: Callable[[Path | list[Path]], WidgetDataModel], *, priority: int = 100) -> ReaderPlugin
register_reader_plugin(*, priority: int = 100) -> Callable[[Callable[[Path | list[Path]], WidgetDataModel]], ReaderPlugin]
Register a reader plugin function.
Decorate a function to register it as a reader plugin. The function should take a
Path
or a list of Path
s as input and return a WidgetDataModel.
from himena.plugins import register_reader_plugin
@register_reader_plugin
def my_reader(path) -> WidgetDataModel:
... # read file and return a WidgetDataModel
You will need to define a matcher function to tell whether this function can read
a path using define_matcher
method.
from himena import StandardType
@my_reader.define_matcher
def _(path: Path):
if path.suffix == ".txt":
return StandardType.TEXT # StandardType.TEXT == "text"
return None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
priority
|
int
|
Priority of choosing this reader when multiple readers are available. The default value 100 is higher than the himena builtin readers, so that your reader will prioritized over the default ones. If priority is less than 0, it will not be used unless users intentionally choose this plugin. |
100
|
Source code in src\himena\plugins\io.py
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 |
|
register_widget_class(type_, widget_class=None, priority=100, plugin_configs=None)
register_widget_class(type_: str, widget_class: _T, priority: int = 100, plugin_configs: PluginConfigType | None = None) -> _T
register_widget_class(type_: str, widget_class: None, priority: int = 100, plugin_configs: PluginConfigType | None = None) -> Callable[[_T], _T]
Register a frontend widget class for the given model type.
The __init__
method of the registered class must not take any argument. The class
must implement update_model
method to update the widget state from a
WidgetDataModel.
@register_widget("text")
class MyTextEdit(QtW.QPlainTextEdit):
def update_model(self, model: WidgetDataModel):
self.setPlainText(model.value)
There are other method names that can be implemented to make the widget more functional.
to_model(self) -> WidgetDataModel
:model_type(self) -> str
:control_widget(self) -> <widget>
:is_modified(self) -> bool
:set_modified(self, modified: bool)
:size_hint(self) -> tuple[int, int]
:is_editable(self) -> bool
:set_editable(self, editable: bool)
:dropped_callback(self, other: WidgetDataModel)
:allowed_drop_types(self) -> list[str]
:display_name(cls) -> str
:theme_changed_callback(self, theme: Theme)
:widget_activated_callback(self)
:widget_closed_callback(self)
:widget_resized_callback(self, size_old, size_new)
:
Source code in src\himena\plugins\widget_class.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 |
|
register_writer_plugin(writer=None, *, priority=100)
register_writer_plugin(writer: Callable[[WidgetDataModel, Path], Any], *, priority: int = 100) -> WriterPlugin
register_writer_plugin(*, priority: int = 100) -> Callable[[Callable[[WidgetDataModel, Path], Any]], WriterPlugin]
Register a writer plugin function.
Decorate a function to register it as a writer plugin. The function should take a
Path
as a save path and a WidgetDataModel
.
from himena.plugins import register_writer_plugin
@register_writer_plugin
def my_writer(path, model) -> None:
... # read file and return a WidgetDataModel
You will need to define a matcher function to tell whether this function can write
a data model to the specified path using define_matcher
method. Unlike reader
plugins, matchers should return bool.
from himena import StandardType, WidgetDataModel
@my_writer.define_matcher
def _(path: Path, model: WidgetDataModel):
if path.suffix == ".txt":
return True
return False
Parameters:
Name | Type | Description | Default |
---|---|---|---|
priority
|
int
|
Priority of choosing this writer when multiple writers are available. The default value 100 is higher than the himena builtin writers, so that your writer will prioritized over the default ones. If priority is less than 0, it will not be used unless users intentionally choose this plugin. |
100
|
Source code in src\himena\plugins\io.py
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 |
|
update_config_context(config_class, plugin_id=None, *, update_widget=False)
update_config_context(plugin_id: str, *, update_widget: bool = False) -> Iterator[PluginConfigType]
update_config_context(config_class: type[_C], plugin_id: str | None = None, *, update_widget: bool = False) -> Iterator[_C]
Context manager for updating plugin config.
Source code in src\himena\plugins\widget_plugins.py
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 |
|
validate_protocol(f)
Check if the method is allowed as a himena protocol.
Source code in src\himena\plugins\_checker.py
36 37 38 39 40 |
|
widget_classes()
Get the mapping of widget ID to widget class.
Source code in src\himena\plugins\widget_class.py
119 120 121 122 123 124 125 126 127 |
|