Show a save dialog when the save button is clicked in Printer

This commit is contained in:
Arjen Hiemstra 2015-01-28 18:00:52 +01:00
parent ff850c5bec
commit 8e1e37e2eb
2 changed files with 33 additions and 1 deletions

View file

@ -1,9 +1,29 @@
import QtQuick 2.1 import QtQuick 2.1
import QtQuick.Controls 1.1 import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.1
import UM 1.0 as UM import UM 1.0 as UM
UM.DefaultWindow { UM.DefaultWindow {
title: "Cura" title: "Cura"
function saveClicked() {
saveDialog.open();
}
FileDialog {
id: saveDialog
title: "Choose Filename"
modality: Qt.NonModal;
selectExisting: false;
onAccepted:
{
Printer.saveGCode(fileUrl)
}
}
} }

View file

@ -12,6 +12,8 @@ from UM.Scene.Selection import Selection
from PlatformPhysics import PlatformPhysics from PlatformPhysics import PlatformPhysics
from BuildVolume import BuildVolume from BuildVolume import BuildVolume
from PyQt5.QtCore import pyqtSlot, QUrl
import os.path import os.path
class PrinterApplication(QtApplication): class PrinterApplication(QtApplication):
@ -104,7 +106,7 @@ class PrinterApplication(QtApplication):
self.getMachineSettings().saveValuesToFile(Resources.getStoragePath(Resources.SettingsLocation, 'ultimaker2.cfg')) self.getMachineSettings().saveValuesToFile(Resources.getStoragePath(Resources.SettingsLocation, 'ultimaker2.cfg'))
def registerObjects(self, engine): def registerObjects(self, engine):
pass engine.rootContext().setContextProperty('Printer', self)
def onSelectionChanged(self): def onSelectionChanged(self):
if Selection.getCount() > 0: if Selection.getCount() > 0:
@ -115,3 +117,13 @@ class PrinterApplication(QtApplication):
else: else:
if self.getController().getActiveTool() and self.getController().getActiveTool().getName() == 'TranslateTool': if self.getController().getActiveTool() and self.getController().getActiveTool().getName() == 'TranslateTool':
self.getController().setActiveTool(None) 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)