magicclass.widgets package

Subpackages

Submodules

magicclass.widgets.console module

Jupyter QtConsole widget with callback signals.

You can embed a console widget in a magic class.

from magicclass import magicclass
from magicclass.widgets import QtConsole

class Main:
    console = QtConsole()

ui = Main()
ui.show()

There are some additional methods that would be very useful for developing a Python script executable GUI.

# programmatically add code to console.
ui.console.value = "a = 1"

# callback when code is executed.
@console.executed.connect
def _():
    print("executed!")

# programmatically execute code.
ui.console.execute()
class magicclass.widgets.console.QtConsole(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

execute()[source]

Execute current code block

executed
property value: str

Get current code block

magicclass.widgets.containers module

magicclass.widgets.containers.wrap_container(cls: type[C] = None, base: type = None) Callable | type[C][source]

Provide a wrapper for a new container widget with a new protocol.

magicclass.widgets.misc module

class magicclass.widgets.misc.CheckButton(text: str | None = None, **kwargs)[source]

Bases: magicgui.widgets.PushButton

A checkable button.

class magicclass.widgets.misc.ConsoleTextEdit(*args, **kwargs)[source]

Bases: magicgui.widgets.TextEdit

A text edit with console-like setting.

append(text: str)[source]
erase_last()[source]
property tab_size
class magicclass.widgets.misc.Figure(nrows: int = 1, ncols: int = 1, figsize: tuple[int, int] = (4, 3), style=None, **kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

A matplotlib figure canvas.

property ax
property axes
draw()[source]

magicclass.widgets.separator module

class magicclass.widgets.separator.Separator(orientation: str = 'horizontal', text: str = '', name: str = '', button: bool = False)[source]

Bases: magicclass.widgets.utils.FreeWidget

A Separator widget that can be used in both widgets and menus.

btn_clicked
property btn_text

magicclass.widgets.sequence module

class magicclass.widgets.sequence.ListDataView(widget: magicclass.widgets.sequence.ListEdit)[source]

Bases: object

class magicclass.widgets.sequence.ListEdit(value: Iterable[magicclass.widgets.sequence._V] = UNSET, annotation: Optional[type] = None, layout: str = 'horizontal', options: Optional[dict] = None, **kwargs)[source]

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

append_new(value=UNSET)[source]
delete_last()[source]
property value
class magicclass.widgets.sequence.TupleEdit(value: Iterable[Any] = UNSET, annotation: Optional[type] = None, layout: str = 'horizontal', options: Optional[dict] = None, **kwargs)[source]

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

property value

magicclass.widgets.threading module

class magicclass.widgets.threading.ProgressWidget(text: Optional[str] = None, visible: bool = False)[source]

Bases: magicclass.widgets.utils.FreeWidget

range(n: int)[source]
run() magicclass.widgets.threading.progress[source]

Build a context that progress bar will be displayed.

Returns

Context manager for progress bar.

Return type

progress

show_progress(f: Optional[Callable] = None) Callable[source]
property text: str
property value: int
class magicclass.widgets.threading.progress(obj: Optional[Callable] = None, *, progress: Optional[magicclass.widgets.threading.ProgressWidget] = None)[source]

Bases: object

property function

magicclass.widgets.utils module

class magicclass.widgets.utils.FreeWidget(layout='vertical', **kwargs)[source]

Bases: magicgui.widgets._bases.widget.Widget

A Widget class with any QWidget as a child.

set_widget(widget: PyQt5.QtWidgets.QWidget, *args)[source]
magicclass.widgets.utils.magicwidget(qcls: type[PyQt5.QtWidgets.QWidget])[source]

Module contents

Advanced widgets for magic class GUI. These widgets are all compatible with the append method of Container widgets.

class magicclass.widgets.ButtonContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A Container Widget hidden in a button.

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

property btn_text
class magicclass.widgets.CheckButton(text: str | None = None, **kwargs)[source]

Bases: magicgui.widgets.PushButton

A checkable button.

class magicclass.widgets.CollapsibleContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A collapsible Container Widget.

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

property btn_text
class magicclass.widgets.ConsoleTextEdit(*args, **kwargs)[source]

Bases: magicgui.widgets.TextEdit

A text edit with console-like setting.

append(text: str)[source]
erase_last()[source]
property tab_size
class magicclass.widgets.DictWidget(value=None, **kwargs)[source]

Bases: magicclass.widgets.pywidgets.object.BaseWidget, MutableMapping

clear() None[source]

Clear dictionary contents.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.[source]
items() magicclass.widgets.pywidgets.dict.DictItemView[source]

Return the view of dictionary keys and values as strings and Python objects.

keys()[source]

Return the view of dictionary keys.

pop(k: str)[source]

Pop a dictionary content.

update(d: dict[str, typing.Any])[source]

Update the dictionary contents.

property value: dict[str, typing.Any]
values() magicclass.widgets.pywidgets.dict.DictValueView[source]

Return the view of dictionary values as Python objects.

class magicclass.widgets.DraggableContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A draggable Container Widget.

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

class magicclass.widgets.Figure(nrows: int = 1, ncols: int = 1, figsize: tuple[int, int] = (4, 3), style=None, **kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

A matplotlib figure canvas.

property ax
property axes
draw()[source]
class magicclass.widgets.FreeWidget(layout='vertical', **kwargs)[source]

Bases: magicgui.widgets._bases.widget.Widget

A Widget class with any QWidget as a child.

set_widget(widget: PyQt5.QtWidgets.QWidget, *args)[source]
class magicclass.widgets.GroupBoxContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A QGroupBox like container

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

property name
class magicclass.widgets.HCollapsibleContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A collapsible Container Widget.

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

property btn_text
class magicclass.widgets.ListContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A Container Widget that support drag and drop.

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

property current_index
class magicclass.widgets.ListEdit(value: Iterable[magicclass.widgets.sequence._V] = UNSET, annotation: Optional[type] = None, layout: str = 'horizontal', options: Optional[dict] = None, **kwargs)[source]

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

append_new(value=UNSET)[source]
delete_last()[source]
property value
class magicclass.widgets.ListWidget(value: Optional[Iterable[Any]] = None, dragdrop: bool = True, **kwargs)[source]

Bases: magicclass.widgets.pywidgets.object.BaseWidget, MutableSequence

clear()[source]

Clear all the items.

index(obj: Any, start: int = 0, stop: Optional[int] = None) int[source]

Find object or list widget item from the list widget.

Parameters
  • obj (Any) -- Object to find. If a PyListWidgetItem is given, the index of the item (not the tagged object) is searched for.

  • start (int, optional) -- Starting index, by default 0

  • stop (int, optional) -- Index to stop searching.

Returns

Index of object.

Return type

int

Raises

ValueError -- If object was not found.

insert(i: int, obj: Any)[source]

Insert object of any type to the list.

property value: list[typing.Any]

Get all the contents as a Python list.

Returns

Contents of the list widget.

Return type

list

class magicclass.widgets.NapariCanvas(ndisplay=2, order=(), axis_labels=(), **kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

class magicclass.widgets.ProgressWidget(text: Optional[str] = None, visible: bool = False)[source]

Bases: magicclass.widgets.utils.FreeWidget

range(n: int)[source]
run() magicclass.widgets.threading.progress[source]

Build a context that progress bar will be displayed.

Returns

Context manager for progress bar.

Return type

progress

show_progress(f: Optional[Callable] = None) Callable[source]
property text: str
property value: int
class magicclass.widgets.Qt2YPlotCanvas(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

updateViews()[source]
class magicclass.widgets.QtConsole(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget

execute()[source]

Execute current code block

executed
name: str
property value: str

Get current code block

class magicclass.widgets.QtImageCanvas(lock_contrast_limits: bool = False, **kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget, magicclass.widgets.qtgraph.qt_graph.ImageItem

class magicclass.widgets.QtMultiImageCanvas(nrows: int = 0, ncols: int = 0, sharex: bool = False, sharey: bool = False, **kwargs)[source]

Bases: magicclass.widgets.qtgraph.qt_graph._MultiPlot[magicclass.widgets.qtgraph.qt_graph.ImageItem]

A pyqtgraph-based canvas with multiple images.

class magicclass.widgets.QtMultiPlotCanvas(nrows: int = 0, ncols: int = 0, sharex: bool = False, sharey: bool = False, **kwargs)[source]

Bases: magicclass.widgets.qtgraph.qt_graph._MultiPlot[magicclass.widgets.qtgraph.qt_graph.PlotItem]

A pyqtgraph-based canvas with multiple plot.

class magicclass.widgets.QtPlotCanvas(**kwargs)[source]

Bases: magicclass.widgets.utils.FreeWidget, magicclass.widgets.qtgraph.qt_graph.PlotItem

A 1-D data viewer that have similar API as napari Viewer.

class magicclass.widgets.ScrollableContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A scrollable Container Widget.

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

class magicclass.widgets.Separator(orientation: str = 'horizontal', text: str = '', name: str = '', button: bool = False)[source]

Bases: magicclass.widgets.utils.FreeWidget

A Separator widget that can be used in both widgets and menus.

btn_clicked
property btn_text
name: str
class magicclass.widgets.SplitterContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A Container equipped with splitter

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

class magicclass.widgets.StackedContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A stacked Container Widget

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

property current_index
class magicclass.widgets.SubWindowsContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A window-in-window container

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

class magicclass.widgets.TabbedContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A tab categorized Container Widget.

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

property current_index
class magicclass.widgets.ToolBoxContainer(name: str = '', annotation: Any = None, label: str = None, tooltip: str | None = None, visible: bool | None = None, enabled: bool = True, gui_only=False, backend_kwargs={}, layout: str = 'vertical', widgets: Sequence[Widget] = (), labels=True)

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

A Tool box Widget.

Parameters
  • name (str) -- The name of the parameter represented by this widget. by default ""

  • annotation (Any) -- The type annotation for the parameter represented by the widget, by default None

  • label (str) -- A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str) -- A tooltip to display when hovering over the widget.

  • visible (bool) -- Whether the widget is visible, by default True.

  • backend_kwargs (dict) -- keyword argument to pass to the backend widget constructor.

property current_index
class magicclass.widgets.TupleEdit(value: Iterable[Any] = UNSET, annotation: Optional[type] = None, layout: str = 'horizontal', options: Optional[dict] = None, **kwargs)[source]

Bases: magicgui.widgets._bases.widget.Widget, magicgui.widgets._bases.mixins._OrientationMixin, MutableSequence[magicgui.widgets._bases.widget.Widget]

property value
class magicclass.widgets.progress(obj: Optional[Callable] = None, *, progress: Optional[magicclass.widgets.threading.ProgressWidget] = None)[source]

Bases: object

property function