Add "lite" Machine class

Contributes to CL-1331
This commit is contained in:
Ian Paschal 2019-05-13 14:45:02 +02:00
parent 8b25816b1b
commit 177e031f4f

View file

@ -18,7 +18,18 @@ i18n_catalog = i18nCatalog("cura")
# api = CuraAPI() # api = CuraAPI()
# api.machines.addOutputDeviceToCurrentMachine() # api.machines.addOutputDeviceToCurrentMachine()
# ``` # ```
#
## Since Cura doesn't have a machine class, we're going to make a fake one to make our lives a
# little bit easier.
class Machine():
def __init__(self) -> None:
self.hostname = "" # type: str
self.group_id = "" # type: str
self.group_name = "" # type: str
self.um_network_key = "" # type: str
self.configuration = {} # type: Dict
self.connection_types = [] # type: List
class Machines(QObject): class Machines(QObject):
def __init__(self, application: "CuraApplication", parent = None) -> None: def __init__(self, application: "CuraApplication", parent = None) -> None:
@ -27,27 +38,18 @@ class Machines(QObject):
@pyqtSlot(result="QVariantMap") @pyqtSlot(result="QVariantMap")
def getCurrentMachine(self) -> "QVariantMap": def getCurrentMachine(self) -> "QVariantMap":
# Since Cura doesn't have a machine class, we're going to make a fake one to make our fake_machine = Machine() # type: Machine
# lives a little bit easier.
fake_machine = {
"hostname": "",
"group_id": "",
"group_name": "",
"um_network_key": "",
"configuration": {},
"connection_types": []
}
global_stack = self._application.getGlobalContainerStack() global_stack = self._application.getGlobalContainerStack()
if global_stack: if global_stack:
metadata = global_stack.getMetaData() metadata = global_stack.getMetaData()
if "group_id" in metadata: if "group_id" in metadata:
fake_machine["group_id"] = global_stack.getMetaDataEntry("group_id") fake_machine.group_id = global_stack.getMetaDataEntry("group_id")
if "group_name" in metadata: if "group_name" in metadata:
fake_machine["group_name"] = global_stack.getMetaDataEntry("group_name") fake_machine.group_name = global_stack.getMetaDataEntry("group_name")
if "um_network_key" in metadata: if "um_network_key" in metadata:
fake_machine["um_network_key"] = global_stack.getMetaDataEntry("um_network_key") fake_machine.um_network_key = global_stack.getMetaDataEntry("um_network_key")
fake_machine["connection_types"] = global_stack.configuredConnectionTypes fake_machine.connection_types = global_stack.configuredConnectionTypes
return fake_machine return fake_machine