mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 02:37:49 -06:00
Added extra SettingsModel for a QML
This commit is contained in:
parent
0906e3f1e7
commit
f577789859
1 changed files with 32 additions and 0 deletions
32
cura/Settings/SidebarCustomMenuItemsModel.py
Normal file
32
cura/Settings/SidebarCustomMenuItemsModel.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
from UM.Qt.ListModel import ListModel
|
||||||
|
from PyQt5.QtCore import pyqtSlot, Qt
|
||||||
|
|
||||||
|
class SidebarCustomMenuItemsModel(ListModel):
|
||||||
|
NameRole = Qt.UserRole + 1
|
||||||
|
ActionsRole = Qt.UserRole + 2
|
||||||
|
MenuItemRole = Qt.UserRole + 3
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.addRoleName(self.NameRole, "name")
|
||||||
|
self.addRoleName(self.ActionsRole, "actions")
|
||||||
|
self.addRoleName(self.MenuItemRole, "menu_item")
|
||||||
|
self._updateExtensionList()
|
||||||
|
|
||||||
|
def _updateExtensionList(self)-> None:
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
|
for menu_item in CuraApplication.getInstance().getSidebarCustomMenuItems():
|
||||||
|
|
||||||
|
self.appendItem({
|
||||||
|
"name": menu_item["name"],
|
||||||
|
"actions": menu_item["actions"],
|
||||||
|
"menu_item": menu_item["menu_item"]
|
||||||
|
})
|
||||||
|
|
||||||
|
@pyqtSlot(str, "QVariantList")
|
||||||
|
def callMenuItemMethod(self, menu_item_name: str, menu_item_actions: list)-> None:
|
||||||
|
for item in self._items:
|
||||||
|
if menu_item_name == item["name"]:
|
||||||
|
for method in menu_item_actions:
|
||||||
|
getattr(item["menu_item"], method)()
|
||||||
|
break
|
Loading…
Add table
Add a link
Reference in a new issue