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
,collections.abc.MutableMapping
- pop(k[, d]) v, remove specified key and return the corresponding value. [source]¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- update([E, ]**F) None. Update D from mapping/iterable E and F. [source]¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- property value: list[typing.Any]¶
- 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
,collections.abc.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]¶
Module contents¶
This widget submodule contains "visible PyObject" widgets, which has similar API as PyObject to
operate items. They can be considered as a simpler form of Table
widget in magicgui
.
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
,collections.abc.MutableMapping
- pop(k[, d]) v, remove specified key and return the corresponding value. [source]¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- class magicclass.widgets.pywidgets.ListWidget(value: Optional[Iterable[Any]] = None, dragdrop: bool = True, **kwargs)[source]¶
Bases:
magicclass.widgets.pywidgets.object.BaseWidget
,collections.abc.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.