magicclass.core
Parameters
Source code in magicclass\core.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
|
as_dict()
Convert parameter fields into a dictionary.
class params(Parameters): i = 1 j = 2
p = params() p.as_dict() # {"i": 1, "j": 2}
Source code in magicclass\core.py
641 642 643 644 645 646 647 648 649 650 651 652 653 |
|
build_help(ui, parent=None)
Build a widget for user guide. Once it is built, widget will be cached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ui |
MagicTemplate
|
Magic class UI object. |
required |
Returns:
Type | Description |
---|---|
HelpWidget
|
Help of the input UI. |
Source code in magicclass\core.py
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 |
|
get_button(ui, name=None, *, cache=False)
Get the button/action object for the given method.
This function is a helper function for magicclass. Using this method is
always safer than directly accessing it by ui["method"]
.
Either of following expression is allowed.
get_button(ui, "method") get_button(ui.method)
Source code in magicclass\core.py
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 |
|
get_function_gui(ui, name=None)
Get the FunctionGui object hidden beneath push button or menu action.
This function is a helper function for magicclass. Using this method is
always safer than directly accessing it by ui["method"].mgui
.
Either of following expression is allowed.
get_function_gui(ui, "method") get_function_gui(ui.method)
Source code in magicclass\core.py
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 |
|
magicclass(class_=None, *, layout='vertical', labels=True, name=None, visible=None, close_on_run=None, popup_mode=None, error_mode=None, widget_type=WidgetType.none, icon=None, stylesheet=None, properties=None, use_native_menubar=True, record=True, symbol='ui')
Decorator that can convert a Python class into a widget.
@magicclass class C: ... ui = C() ui.show() # open GUI
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_ |
type
|
Class to be decorated. |
None
|
layout |
(str, 'vertical' or 'horizontal')
|
Layout of the main widget. |
"vertical"
|
labels |
bool
|
If true, magicgui labels are shown. |
True
|
name |
str
|
Name of GUI. |
None
|
visible |
bool
|
Initial visibility of GUI. Useful when magic class is nested. |
None
|
close_on_run |
bool
|
If True, magicgui created by every method will be deleted after the method is completed without exceptions, i.e. magicgui is more like a dialog. |
True
|
popup_mode |
str or PopUpMode
|
Option of how to popup FunctionGui widget when a button is clicked. |
PopUpMode.popup
|
error_mode |
str or ErrorMode
|
Option of how to raise errors during function calls. |
ErrorMode.msgbox
|
widget_type |
WidgetType or str
|
Widget type of container. |
none
|
icon |
Any
|
Path to the icon image or any object that can be converted into an icon. |
None
|
stylesheet |
str or StyleSheet object
|
Set stylesheet to the widget if given. |
None
|
properties |
dict
|
Set properties to the widget if given. This argument is useful when you want to set width, height or margin without defining post_init. |
None
|
use_native_menubar |
bool
|
If True, native menubar will be used in such as macOS. |
True
|
record |
bool
|
If True, macro recording is enabled. |
True
|
symbol |
str
|
The identifier used in macro to represent this widget. |
"ui"
|
Returns:
Type | Description |
---|---|
Decorated class or decorator.
|
|
Source code in magicclass\core.py
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 |
|
magiccontext(class_=None, *, into=None, close_on_run=None, popup_mode=None, error_mode=None, labels=True, name=None, icon=None, record=True)
Decorator that converts a Python class into a context menu.
Source code in magicclass\core.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
magicmenu(class_=None, *, close_on_run=None, popup_mode=None, error_mode=None, labels=True, name=None, icon=None, record=True)
Decorator that converts a Python class into a menu bar.
Source code in magicclass\core.py
240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
magictoolbar(class_=None, *, close_on_run=None, popup_mode=None, error_mode=None, labels=True, name=None, icon=None, record=True)
Decorator that converts a Python class into a menu bar.
Source code in magicclass\core.py
271 272 273 274 275 276 277 278 279 280 281 282 283 |
|
repeat(ui, index=-1)
Repeat last operation on GUI using recorded macro.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ui |
MagicTemplate
|
Target magic-class widget. |
required |
index |
int
|
Which execution will be repeated. Any object that support list slicing can be used. By default the last operation will be repeated. |
-1
|
Source code in magicclass\core.py
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 |
|
update_widget_state(ui, macro=None)
Update widget values based on a macro.
This helper function works similar to the update_widget
method of FunctionGui
.
In most cases, this function will be used for restoring a state from a macro
recorded before. Value changed signal will not be emitted within this operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ui |
MagicTemplate
|
Magic class instance. |
required |
macro |
Macro or str
|
An executable macro or string that dictates how GUI will be updated. |
None
|
Source code in magicclass\core.py
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 |
|