diff --git a/Printer.qml b/Printer.qml index 4212d0ff37..9db3eb3b21 100644 --- a/Printer.qml +++ b/Printer.qml @@ -1,9 +1,29 @@ import QtQuick 2.1 import QtQuick.Controls 1.1 import QtQuick.Layouts 1.1 +import QtQuick.Dialogs 1.1 import UM 1.0 as UM UM.DefaultWindow { title: "Cura" + + function saveClicked() { + saveDialog.open(); + } + + FileDialog { + id: saveDialog + + title: "Choose Filename" + + modality: Qt.NonModal; + + selectExisting: false; + + onAccepted: + { + Printer.saveGCode(fileUrl) + } + } } diff --git a/PrinterApplication.py b/PrinterApplication.py index 33941f3f4f..d8225710aa 100644 --- a/PrinterApplication.py +++ b/PrinterApplication.py @@ -12,6 +12,8 @@ from UM.Scene.Selection import Selection from PlatformPhysics import PlatformPhysics from BuildVolume import BuildVolume +from PyQt5.QtCore import pyqtSlot, QUrl + import os.path class PrinterApplication(QtApplication): @@ -104,7 +106,7 @@ class PrinterApplication(QtApplication): self.getMachineSettings().saveValuesToFile(Resources.getStoragePath(Resources.SettingsLocation, 'ultimaker2.cfg')) def registerObjects(self, engine): - pass + engine.rootContext().setContextProperty('Printer', self) def onSelectionChanged(self): if Selection.getCount() > 0: @@ -115,3 +117,13 @@ class PrinterApplication(QtApplication): else: if self.getController().getActiveTool() and self.getController().getActiveTool().getName() == 'TranslateTool': self.getController().setActiveTool(None) + + @pyqtSlot(QUrl) + def saveGCode(self, file): + try: + gcode = self.getController().getScene().gcode + except AttributeError: + return + + with open(file.toLocalFile(), 'w') as f: + f.write(gcode)