magicclass.widgets.pywidgets package¶
Submodules¶
magicclass.widgets.pywidgets.dict module¶
- class magicclass.widgets.pywidgets.dict.DictItemView(widget: magicclass.widgets.pywidgets.dict.PyTableWidget)[source]¶
Bases:
object
- class magicclass.widgets.pywidgets.dict.DictValueView(widget: magicclass.widgets.pywidgets.dict.PyTableWidget)[source]¶
Bases:
object
- class magicclass.widgets.pywidgets.dict.DictWidget(value=None, **kwargs)[source]¶
Bases:
magicclass.widgets.pywidgets.object.BaseWidget
,MutableMapping
- items() magicclass.widgets.pywidgets.dict.DictItemView [source]¶
Return the view of dictionary keys and values as strings and Python objects.
- 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.pywidgets.dict.PyTableWidget(parent: None)[source]¶
Bases:
magicclass.widgets.pywidgets.object.ContextMenuMixin
,PyQt5.QtWidgets.QTableWidget
- PyTableWidget.item(self, int, int) -> QTableWidgetItem[source]
- class magicclass.widgets.pywidgets.dict.PyTableWidgetItem(obj=None, name=None)[source]¶
Bases:
magicclass.widgets.pywidgets.object.PyObjectBound
,PyQt5.QtWidgets.QTableWidgetItem
magicclass.widgets.pywidgets.list module¶
- class magicclass.widgets.pywidgets.list.ListWidget(value: Optional[Iterable[Any]] = None, dragdrop: bool = True, **kwargs)[source]¶
Bases:
magicclass.widgets.pywidgets.object.BaseWidget
,MutableSequence
- 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.
- 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.pywidgets.list.PyListWidget(parent: None)[source]¶
Bases:
magicclass.widgets.pywidgets.object.ContextMenuMixin
,PyQt5.QtWidgets.QListWidget
- class magicclass.widgets.pywidgets.list.PyListWidgetItem(parent: Optional[PyQt5.QtWidgets.QListWidget] = None, obj=None, name=None)[source]¶
Bases:
magicclass.widgets.pywidgets.object.PyObjectBound
,PyQt5.QtWidgets.QListWidgetItem
magicclass.widgets.pywidgets.object module¶
- class magicclass.widgets.pywidgets.object.BaseWidget(**kwargs)[source]¶
Bases:
magicclass.widgets.utils.FreeWidget
- register_callback(type_: type)[source]¶
Register a double-click callback function for items of certain type.
Register a custom context menu for 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.
- setParentWidget(widget: magicclass.widgets.pywidgets.object.BaseWidget) None [source]¶
magicclass.widgets.pywidgets.tree module¶
- class magicclass.widgets.pywidgets.tree.DictTreeWidget(value=None, **kwargs)[source]¶
Bases:
magicclass.widgets.pywidgets.object.BaseWidget
,MutableMapping
- property value: dict[str, typing.Any]¶
- values() magicclass.widgets.pywidgets.tree.DictValueView [source]¶
Return the view of dictionary values as Python objects.
- class magicclass.widgets.pywidgets.tree.DictValueView(widget: magicclass.widgets.pywidgets.tree.PyTreeWidget)[source]¶
Bases:
object
- class magicclass.widgets.pywidgets.tree.PyTreeWidget(parent: None)[source]¶
Bases:
magicclass.widgets.pywidgets.object.ContextMenuMixin
,PyQt5.QtWidgets.QTreeWidget
- item(row: int, column: int) magicclass.widgets.pywidgets.tree.PyTreeWidgetItem [source]¶
- class magicclass.widgets.pywidgets.tree.PyTreeWidgetItem(obj=None, name=None)[source]¶
Bases:
magicclass.widgets.pywidgets.object.PyObjectBound
,PyQt5.QtWidgets.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:
magicclass.widgets.pywidgets.object.BaseWidget
,MutableMapping
- items() magicclass.widgets.pywidgets.dict.DictItemView [source]¶
Return the view of dictionary keys and values as strings and Python objects.
- values() magicclass.widgets.pywidgets.dict.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:
magicclass.widgets.pywidgets.object.BaseWidget
,MutableSequence
- 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.