mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 15:44:04 -06:00
Remove the output_device related stuff from CuraApplication and fix the qml
This is now properly handled by the Output Device API in Uranium
This commit is contained in:
parent
baf4ea9523
commit
c2e672591c
3 changed files with 31 additions and 148 deletions
|
@ -111,15 +111,6 @@ class CuraApplication(QtApplication):
|
||||||
def run(self):
|
def run(self):
|
||||||
self._i18n_catalog = i18nCatalog("cura");
|
self._i18n_catalog = i18nCatalog("cura");
|
||||||
|
|
||||||
self.addOutputDevice("local_file", {
|
|
||||||
"id": "local_file",
|
|
||||||
"function": self._writeToLocalFile,
|
|
||||||
"description": self._i18n_catalog.i18nc("Save button tooltip", "Save to Disk"),
|
|
||||||
"shortDescription": self._i18n_catalog.i18nc("Save button tooltip", "Save to Disk"),
|
|
||||||
"icon": "save",
|
|
||||||
"priority": 0
|
|
||||||
})
|
|
||||||
|
|
||||||
self.showSplashMessage(self._i18n_catalog.i18nc("Splash screen message", "Setting up scene..."))
|
self.showSplashMessage(self._i18n_catalog.i18nc("Splash screen message", "Setting up scene..."))
|
||||||
|
|
||||||
controller = self.getController()
|
controller = self.getController()
|
||||||
|
@ -159,8 +150,6 @@ class CuraApplication(QtApplication):
|
||||||
self.setMainQml(Resources.getPath(Resources.QmlFilesLocation, "Cura.qml"))
|
self.setMainQml(Resources.getPath(Resources.QmlFilesLocation, "Cura.qml"))
|
||||||
self.initializeEngine()
|
self.initializeEngine()
|
||||||
|
|
||||||
self.getStorageDevice("LocalFileStorage").removableDrivesChanged.connect(self._removableDrivesChanged)
|
|
||||||
|
|
||||||
if self.getMachines():
|
if self.getMachines():
|
||||||
active_machine_pref = Preferences.getInstance().getValue("cura/active_machine")
|
active_machine_pref = Preferences.getInstance().getValue("cura/active_machine")
|
||||||
if active_machine_pref:
|
if active_machine_pref:
|
||||||
|
@ -173,7 +162,6 @@ class CuraApplication(QtApplication):
|
||||||
else:
|
else:
|
||||||
self.requestAddPrinter.emit()
|
self.requestAddPrinter.emit()
|
||||||
|
|
||||||
self._removableDrivesChanged()
|
|
||||||
if self._engine.rootObjects:
|
if self._engine.rootObjects:
|
||||||
self.closeSplash()
|
self.closeSplash()
|
||||||
|
|
||||||
|
@ -360,16 +348,6 @@ class CuraApplication(QtApplication):
|
||||||
def expandedCategories(self):
|
def expandedCategories(self):
|
||||||
return Preferences.getInstance().getValue("cura/categories_expanded").split(";")
|
return Preferences.getInstance().getValue("cura/categories_expanded").split(";")
|
||||||
|
|
||||||
outputDevicesChanged = pyqtSignal()
|
|
||||||
|
|
||||||
@pyqtProperty("QVariantMap", notify = outputDevicesChanged)
|
|
||||||
def outputDevices(self):
|
|
||||||
return self._output_devices
|
|
||||||
|
|
||||||
@pyqtProperty("QStringList", notify = outputDevicesChanged)
|
|
||||||
def outputDeviceNames(self):
|
|
||||||
return self._output_devices.keys()
|
|
||||||
|
|
||||||
@pyqtSlot(str, result = "QVariant")
|
@pyqtSlot(str, result = "QVariant")
|
||||||
def getSettingValue(self, key):
|
def getSettingValue(self, key):
|
||||||
if not self.getActiveMachine():
|
if not self.getActiveMachine():
|
||||||
|
@ -385,82 +363,6 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
self.getActiveMachine().setSettingValueByKey(key, value)
|
self.getActiveMachine().setSettingValueByKey(key, value)
|
||||||
|
|
||||||
## Add an output device that can be written to.
|
|
||||||
#
|
|
||||||
# \param id \type{string} The identifier used to identify the device.
|
|
||||||
# \param device \type{StorageDevice} A dictionary of device information.
|
|
||||||
# It should contains the following:
|
|
||||||
# - function: A function to be called when trying to write to the device. Will be passed the device id as first parameter.
|
|
||||||
# - description: A translated string containing a description of what happens when writing to the device.
|
|
||||||
# - icon: The icon to use to represent the device.
|
|
||||||
# - priority: The priority of the device. The device with the highest priority will be used as the default device.
|
|
||||||
def addOutputDevice(self, id, device):
|
|
||||||
self._output_devices[id] = device
|
|
||||||
self.outputDevicesChanged.emit()
|
|
||||||
|
|
||||||
## Remove output device
|
|
||||||
# \param id \type{string} The identifier used to identify the device.
|
|
||||||
# \sa PrinterApplication::addOutputDevice()
|
|
||||||
def removeOutputDevice(self, id):
|
|
||||||
if id in self._output_devices:
|
|
||||||
del self._output_devices[id]
|
|
||||||
self.outputDevicesChanged.emit()
|
|
||||||
|
|
||||||
@pyqtSlot(str)
|
|
||||||
def writeToOutputDevice(self, device):
|
|
||||||
self._output_devices[device]["function"](device)
|
|
||||||
|
|
||||||
writeToLocalFileRequested = pyqtSignal()
|
|
||||||
|
|
||||||
def _writeToLocalFile(self, device):
|
|
||||||
self.writeToLocalFileRequested.emit()
|
|
||||||
|
|
||||||
def _writeToSD(self, device):
|
|
||||||
for node in DepthFirstIterator(self.getController().getScene().getRoot()):
|
|
||||||
if type(node) is not SceneNode or not node.getMeshData():
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
path = self.getStorageDevice("LocalFileStorage").getRemovableDrives()[device]
|
|
||||||
except KeyError:
|
|
||||||
Logger.log("e", "Tried to write to unknown SD card %s", device)
|
|
||||||
return
|
|
||||||
|
|
||||||
filename = os.path.join(path, node.getName()[0:node.getName().rfind(".")] + ".gcode")
|
|
||||||
|
|
||||||
message = Message(self._output_devices[device]["description"], 0, False, -1)
|
|
||||||
message.show()
|
|
||||||
|
|
||||||
job = WriteMeshJob(filename, node.getMeshData())
|
|
||||||
job._sdcard = device
|
|
||||||
job._message = message
|
|
||||||
job.start()
|
|
||||||
job.finished.connect(self._onWriteToSDFinished)
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def _removableDrivesChanged(self):
|
|
||||||
drives = self.getStorageDevice("LocalFileStorage").getRemovableDrives()
|
|
||||||
for drive in drives:
|
|
||||||
if drive not in self._output_devices:
|
|
||||||
self.addOutputDevice(drive, {
|
|
||||||
"id": drive,
|
|
||||||
"function": self._writeToSD,
|
|
||||||
"description": self._i18n_catalog.i18nc("Save button tooltip. {0} is sd card name", "Save to SD Card {0}").format(drive),
|
|
||||||
"shortDescription": self._i18n_catalog.i18nc("Save button tooltip. {0} is sd card name", "Save to SD Card {0}").format(""),
|
|
||||||
"icon": "save_sd",
|
|
||||||
"priority": 1
|
|
||||||
})
|
|
||||||
|
|
||||||
drives_to_remove = []
|
|
||||||
for device in self._output_devices:
|
|
||||||
if device not in drives:
|
|
||||||
if self._output_devices[device]["function"] == self._writeToSD:
|
|
||||||
drives_to_remove.append(device)
|
|
||||||
|
|
||||||
for drive in drives_to_remove:
|
|
||||||
self.removeOutputDevice(drive)
|
|
||||||
|
|
||||||
def _onActiveMachineChanged(self):
|
def _onActiveMachineChanged(self):
|
||||||
machine = self.getActiveMachine()
|
machine = self.getActiveMachine()
|
||||||
if machine:
|
if machine:
|
||||||
|
@ -486,25 +388,6 @@ class CuraApplication(QtApplication):
|
||||||
else:
|
else:
|
||||||
self._platform.setPosition(Vector(0.0, 0.0, 0.0))
|
self._platform.setPosition(Vector(0.0, 0.0, 0.0))
|
||||||
|
|
||||||
def _onWriteToSDFinished(self, job):
|
|
||||||
message = Message(self._i18n_catalog.i18nc("Saved to SD message, {0} is sdcard, {1} is filename", "Saved to SD Card {0} as {1}").format(job._sdcard, job.getFileName()))
|
|
||||||
message.addAction(
|
|
||||||
"eject",
|
|
||||||
self._i18n_catalog.i18nc("Message action", "Eject"),
|
|
||||||
"eject",
|
|
||||||
self._i18n_catalog.i18nc("Message action tooltip, {0} is sdcard", "Eject SD Card {0}").format(job._sdcard)
|
|
||||||
)
|
|
||||||
|
|
||||||
job._message.hide()
|
|
||||||
|
|
||||||
message._sdcard = job._sdcard
|
|
||||||
message.actionTriggered.connect(self._onMessageActionTriggered)
|
|
||||||
message.show()
|
|
||||||
|
|
||||||
def _onMessageActionTriggered(self, message, action):
|
|
||||||
if action == "eject":
|
|
||||||
self.getStorageDevice("LocalFileStorage").ejectRemovableDrive(message._sdcard)
|
|
||||||
|
|
||||||
def _onFileLoaded(self, job):
|
def _onFileLoaded(self, job):
|
||||||
mesh = job.getResult()
|
mesh = job.getResult()
|
||||||
if mesh != None:
|
if mesh != None:
|
||||||
|
|
|
@ -7,7 +7,7 @@ import QtQuick.Controls.Styles 1.1
|
||||||
import QtQuick.Layouts 1.1
|
import QtQuick.Layouts 1.1
|
||||||
import QtQuick.Dialogs 1.1
|
import QtQuick.Dialogs 1.1
|
||||||
|
|
||||||
import UM 1.0 as UM
|
import UM 1.1 as UM
|
||||||
|
|
||||||
UM.MainWindow {
|
UM.MainWindow {
|
||||||
id: base
|
id: base
|
||||||
|
@ -30,21 +30,40 @@ UM.MainWindow {
|
||||||
title: qsTr("&File");
|
title: qsTr("&File");
|
||||||
|
|
||||||
MenuItem { action: actions.open; }
|
MenuItem { action: actions.open; }
|
||||||
MenuItem { action: actions.save; }
|
|
||||||
|
|
||||||
MenuSeparator { }
|
Menu {
|
||||||
|
id: recentFilesMenu;
|
||||||
|
title: "Open Recent"
|
||||||
|
|
||||||
Instantiator {
|
Instantiator {
|
||||||
model: Printer.recentFiles
|
model: Printer.recentFiles
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: {
|
text: {
|
||||||
var path = modelData.toString()
|
var path = modelData.toString()
|
||||||
return (index + 1) + ". " + path.slice(path.lastIndexOf("/") + 1);
|
return (index + 1) + ". " + path.slice(path.lastIndexOf("/") + 1);
|
||||||
|
}
|
||||||
|
onTriggered: UM.MeshFileHandler.readLocalFile(modelData);
|
||||||
}
|
}
|
||||||
onTriggered: UM.MeshFileHandler.readLocalFile(modelData);
|
onObjectAdded: recentFilesMenu.insertItem(index, object)
|
||||||
|
onObjectRemoved: recentFilesMenu.removeItem(object)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItem { text: "Save Selection" }
|
||||||
|
Menu {
|
||||||
|
id: saveAllMenu
|
||||||
|
title: "Save All"
|
||||||
|
|
||||||
|
Instantiator {
|
||||||
|
model: UM.OutputDevicesModel { }
|
||||||
|
|
||||||
|
MenuItem {
|
||||||
|
text: model.description
|
||||||
|
onTriggered: model.requestWriteToCurrentDevice();
|
||||||
|
}
|
||||||
|
onObjectAdded: saveAllMenu.insertItem(index, object)
|
||||||
|
onObjectRemoved: saveAllMenu.removeItem(object)
|
||||||
}
|
}
|
||||||
onObjectAdded: fileMenu.insertItem(index, object)
|
|
||||||
onObjectRemoved: fileMenu.removeItem(object)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuSeparator { }
|
MenuSeparator { }
|
||||||
|
@ -278,7 +297,6 @@ UM.MainWindow {
|
||||||
|
|
||||||
addMachineAction: actions.addMachine;
|
addMachineAction: actions.addMachine;
|
||||||
configureMachinesAction: actions.configureMachines;
|
configureMachinesAction: actions.configureMachines;
|
||||||
saveAction: actions.save;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
@ -411,22 +429,6 @@ UM.MainWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDialog {
|
|
||||||
id: saveDialog;
|
|
||||||
//: File save dialog title
|
|
||||||
title: qsTr("Save File");
|
|
||||||
selectExisting: false;
|
|
||||||
|
|
||||||
modality: UM.Application.platform == "linux" ? Qt.NonModal : Qt.WindowModal;
|
|
||||||
|
|
||||||
nameFilters: UM.MeshFileHandler.supportedWriteFileTypes
|
|
||||||
|
|
||||||
onAccepted:
|
|
||||||
{
|
|
||||||
UM.MeshFileHandler.writeLocalFile(fileUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EngineLog {
|
EngineLog {
|
||||||
id: engineLog;
|
id: engineLog;
|
||||||
}
|
}
|
||||||
|
@ -442,7 +444,6 @@ UM.MainWindow {
|
||||||
Connections {
|
Connections {
|
||||||
target: Printer
|
target: Printer
|
||||||
onRequestAddPrinter: addMachine.visible = true;
|
onRequestAddPrinter: addMachine.visible = true;
|
||||||
onWriteToLocalFileRequested: saveDialog.open();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: UM.Theme.load(UM.Resources.getPath(UM.Resources.ThemesLocation, "cura"))
|
Component.onCompleted: UM.Theme.load(UM.Resources.getPath(UM.Resources.ThemesLocation, "cura"))
|
||||||
|
|
|
@ -13,7 +13,6 @@ Rectangle {
|
||||||
|
|
||||||
property Action addMachineAction;
|
property Action addMachineAction;
|
||||||
property Action configureMachinesAction;
|
property Action configureMachinesAction;
|
||||||
property alias saveAction: saveButton.saveAction;
|
|
||||||
|
|
||||||
color: UM.Theme.colors.sidebar;
|
color: UM.Theme.colors.sidebar;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue