magicclass.widgets.pywidgets package

Submodules

magicclass.widgets.pywidgets.dict module

class magicclass.widgets.pywidgets.dict.DictItemView(widget: PyTableWidget)[source]

Bases: object

class magicclass.widgets.pywidgets.dict.DictValueView(widget: PyTableWidget)[source]

Bases: object

class magicclass.widgets.pywidgets.dict.DictWidget(value=None, **kwargs)[source]

Bases: 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() 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, Any])[source]

Update the dictionary contents.

property value: dict[str, Any]
values() DictValueView[source]

Return the view of dictionary values as Python objects.

class magicclass.widgets.pywidgets.dict.PyTableWidget(parent: None)[source]

Bases: ContextMenuMixin, QTableWidget

PyTableWidget.item(self, int, int) -> QTableWidgetItem[source]
itemAt(self, QPoint) QTableWidgetItem[source]
PyTableWidget.itemAt(self, int, int) -> QTableWidgetItem
class magicclass.widgets.pywidgets.dict.PyTableWidgetItem(obj=None, name=None)[source]

Bases: PyObjectBound, QTableWidgetItem

magicclass.widgets.pywidgets.list module

class magicclass.widgets.pywidgets.list.ListWidget(value: Optional[Iterable[Any]] = None, dragdrop: bool = True, **kwargs)[source]

Bases: 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[Any]

Get all the contents as a Python list.

Returns

Contents of the list widget.

Return type

list

class magicclass.widgets.pywidgets.list.PyListWidget(parent: None)[source]

Bases: ContextMenuMixin, QListWidget

item(self, int) QListWidgetItem[source]
itemAt(self, QPoint) QListWidgetItem[source]
PyListWidget.itemAt(self, int, int) -> QListWidgetItem
class magicclass.widgets.pywidgets.list.PyListWidgetItem(parent: Optional[QListWidget] = None, obj=None, name=None)[source]

Bases: PyObjectBound, QListWidgetItem

magicclass.widgets.pywidgets.object module

class magicclass.widgets.pywidgets.object.BaseWidget(**kwargs)[source]

Bases: FreeWidget

register_callback(type_: type)[source]

Register a double-click callback function for items of certain type.

register_contextmenu(type_: type)[source]

Register a custom context menu for items of certain type.

register_delegate(type_: type)[source]

Register a custom display.

register_tooltip(type_: type)[source]

Register a custom tooltipfor items of certain type.

property title: str
property value
class magicclass.widgets.pywidgets.object.ContextMenuMixin[source]

Bases: object

This class defines custom contextmenu with type dispatching.

contextMenu(point)[source]
setContextMenu()[source]
setParentWidget(widget: BaseWidget) None[source]
class magicclass.widgets.pywidgets.object.PyObjectBound[source]

Bases: object

setObject(obj=None, name=None)[source]
magicclass.widgets.pywidgets.object.partial_event(f, *args)[source]

magicclass.widgets.pywidgets.tree module

class magicclass.widgets.pywidgets.tree.DictTreeWidget(value=None, **kwargs)[source]

Bases: BaseWidget, MutableMapping

clear() None[source]

Clear dictionary contents.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.[source]
keys()[source]

Return the view of dictionary keys.

pop(k: str)[source]

Pop a dictionary content.

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

Update the dictionary contents.

property value: dict[str, Any]
values() DictValueView[source]

Return the view of dictionary values as Python objects.

class magicclass.widgets.pywidgets.tree.DictValueView(widget: PyTreeWidget)[source]

Bases: object

class magicclass.widgets.pywidgets.tree.PyTreeWidget(parent: None)[source]

Bases: ContextMenuMixin, QTreeWidget

item(row: int, column: int) PyTreeWidgetItem[source]
itemAt(self, QPoint) QTreeWidgetItem[source]
PyTreeWidget.itemAt(self, int, int) -> QTreeWidgetItem
class magicclass.widgets.pywidgets.tree.PyTreeWidgetItem(obj=None, name=None)[source]

Bases: PyObjectBound, QTreeWidgetItem

Module contents

This widget submodule contains "visible PyObject" widgets, which has similar API as PyObject to operate items. They are also equipped with custom delegate, contextmenu and double-click callbacks.

ListWidget

ListWidget is a QListWidget wrapper class. This widget can contain any Python objects as list items.

from magicclass.widgets import ListWidget

listwidget = ListWidget()

# You can add any objects
listwidget.append("abc")
listwidget.append(np.arange(5))

You can dispatch double click callbacks depending on the type of contents.

@listwidget.register_callback(str)
def _(item, i):
    # This function will be called when the item "abc" is double-clicked.
    print(item)

@listwidget.register_callback(np.ndarray)
def _(item, i):
    # This function will be called when the item np.arange(5) is double-clicked.
    print(item.tolist())

In a similar way, you can dispatch display method and context menu.

@listwidget.register_delegate(np.ndarray)
def _(item):
    # This function should return how ndarray will be displayed.
    return f"Array with shape {item.shape}"

@listwidget.register_contextmenu(np.ndarray)
def Plot(item, i):
    '''Function documentation will be the tooltip.'''
    plt.plot(item)
    plt.show()

DictWidget

DictWidget is a single column QTableWidget. This widget can contain any Python objects as table items and keys as row names..

from magicclass.widgets import DictWidget

dictwidget = DictWidget()

# You can add any objects
dictwidget["name-1"] = 10
dictwidget["data"] = np.arange(5)

The dispatching feature is shared with ListWidget.

class magicclass.widgets.pywidgets.DictWidget(value=None, **kwargs)[source]

Bases: 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() 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, Any])[source]

Update the dictionary contents.

property value: dict[str, Any]
values() DictValueView[source]

Return the view of dictionary values as Python objects.

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

Bases: 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[Any]

Get all the contents as a Python list.

Returns

Contents of the list widget.

Return type

list