mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-11 00:37:50 -06:00
Expose machines API to QML
Contributes to CL-1331
This commit is contained in:
parent
03fd9da417
commit
b3276777b7
4 changed files with 31 additions and 25 deletions
|
@ -25,8 +25,8 @@ class Machines(QObject):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._application = application
|
self._application = application
|
||||||
|
|
||||||
@pyqtSlot(result=dict)
|
@pyqtSlot(result="QVariantMap")
|
||||||
def getCurrentMachine(self) -> dict:
|
def getCurrentMachine(self) -> "QVariantMap":
|
||||||
# Since Cura doesn't have a machine class, we're going to make a fake one to make our
|
# Since Cura doesn't have a machine class, we're going to make a fake one to make our
|
||||||
# lives a little bit easier.
|
# lives a little bit easier.
|
||||||
fake_machine = {
|
fake_machine = {
|
||||||
|
|
|
@ -62,7 +62,7 @@ class CuraAPI(QObject):
|
||||||
def backups(self) -> "Backups":
|
def backups(self) -> "Backups":
|
||||||
return self._backups
|
return self._backups
|
||||||
|
|
||||||
@property
|
@pyqtProperty(QObject)
|
||||||
def machines(self) -> "Machines":
|
def machines(self) -> "Machines":
|
||||||
return self._machines
|
return self._machines
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,14 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
var printerKey = base.selectedDevice.key
|
var printerKey = base.selectedDevice.key
|
||||||
var printerName = base.selectedDevice.name // TODO To change when the groups have a name
|
var printerName = base.selectedDevice.name // TODO To change when the groups have a name
|
||||||
if (manager.getStoredKey() != printerKey)
|
if (Cura.API.machines.getCurrentMachine()["um_network_key"] != printerKey)
|
||||||
{
|
{
|
||||||
// Check if there is another instance with the same key
|
// Check if there is another instance with the same key
|
||||||
if (!manager.existsKey(printerKey))
|
if (!manager.existsKey(printerKey))
|
||||||
{
|
{
|
||||||
manager.associateActiveMachineWithPrinterDevice(base.selectedDevice)
|
Cura.API.machines.addOutputDeviceToCurrentMachine(base.selectedDevice)
|
||||||
manager.setGroupName(printerName) // TODO To change when the groups have a name
|
Cura.API.machines.setCurrentMachineGroupName(printerName) // TODO To change when the groups have a name
|
||||||
|
manager.refreshConnections()
|
||||||
completed()
|
completed()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -156,7 +157,7 @@ Cura.MachineAction
|
||||||
var selectedKey = manager.getLastManualEntryKey()
|
var selectedKey = manager.getLastManualEntryKey()
|
||||||
// If there is no last manual entry key, then we select the stored key (if any)
|
// If there is no last manual entry key, then we select the stored key (if any)
|
||||||
if (selectedKey == "")
|
if (selectedKey == "")
|
||||||
selectedKey = manager.getStoredKey()
|
selectedKey = Cura.API.machines.getCurrentMachine()["um_network_key"]
|
||||||
for(var i = 0; i < model.length; i++) {
|
for(var i = 0; i < model.length; i++) {
|
||||||
if(model[i].key == selectedKey)
|
if(model[i].key == selectedKey)
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,27 +108,32 @@ class DiscoverUM3Action(MachineAction):
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# TODO: Should be able to just access the API from QML.
|
# # TODO: Should be able to just access the API from QML.
|
||||||
@pyqtSlot(str)
|
# @pyqtSlot(str)
|
||||||
def setGroupName(self, group_name: str) -> None:
|
# def setGroupName(self, group_name: str) -> None:
|
||||||
self._api.machines.setCurrentMachineGroupName(group_name)
|
# self._api.machines.setCurrentMachineGroupName(group_name)
|
||||||
|
# if self._network_plugin:
|
||||||
|
# self._network_plugin.refreshConnections()
|
||||||
|
|
||||||
|
# # TODO: Should be able to just access the API from QML.
|
||||||
|
# @pyqtSlot(QObject)
|
||||||
|
# def associateActiveMachineWithPrinterDevice(self, output_device: Optional["PrinterOutputDevice"]) -> None:
|
||||||
|
# self._api.machines.addOutputDeviceToCurrentMachine(output_device)
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def refreshConnections(self) -> None:
|
||||||
if self._network_plugin:
|
if self._network_plugin:
|
||||||
self._network_plugin.refreshConnections()
|
self._network_plugin.refreshConnections()
|
||||||
|
|
||||||
# TODO: Should be able to just access the API from QML.
|
# # TODO: Better naming needed. Stored where? This is current machine's key.
|
||||||
@pyqtSlot(QObject)
|
# # TODO: CHANGE TO HOSTNAME
|
||||||
def associateActiveMachineWithPrinterDevice(self, output_device: Optional["PrinterOutputDevice"]) -> None:
|
# # TODO: Should be able to just access the API from QML.
|
||||||
self._api.machines.addOutputDeviceToCurrentMachine(output_device)
|
# @pyqtSlot(result = str)
|
||||||
if self._network_plugin:
|
# def getStoredKey(self) -> str:
|
||||||
self._network_plugin.refreshConnections()
|
# current_machine = self._api.machines.getCurrentMachine()
|
||||||
|
# if current_machine:
|
||||||
# TODO: Better naming needed. Stored where? This is current machine's key.
|
# return current_machine["um_network_key"]
|
||||||
# TODO: CHANGE TO HOSTNAME
|
# return ""
|
||||||
# TODO: Should be able to just access the API from QML.
|
|
||||||
@pyqtSlot(result = str)
|
|
||||||
def getStoredKey(self) -> str:
|
|
||||||
current_machine = self._api.machines.getCurrentMachine()
|
|
||||||
return current_machine["um_network_key"]
|
|
||||||
|
|
||||||
# TODO: CHANGE TO HOSTNAME
|
# TODO: CHANGE TO HOSTNAME
|
||||||
@pyqtSlot(result = str)
|
@pyqtSlot(result = str)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue