def saveProject(self): """ Save all variables to file """ prj_filename = self.showSaveDialog( self.tr('Save project to file'), "Project files (*%s)" % c.PROJECT_EXTENSION) save_prj_filename = qstr_encode(prj_filename[0]) # If Cancel was pressed if not save_prj_filename: return (beg, ende) = os.path.split(save_prj_filename) (fileBaseName, fileExtension) = os.path.splitext(ende) if fileExtension != c.PROJECT_EXTENSION: if not QtCore.QFile.exists(save_prj_filename): save_prj_filename += c.PROJECT_EXTENSION pyCode = self.d2g.export() try: # File open and write f = open(save_prj_filename, "w") f.write(str_encode(pyCode)) f.close() logger.info(self.tr("Save project to FILE was successful")) except IOError: QMessageBox.warning(g.window, self.tr("Warning during Save Project As"), self.tr("Cannot Save the File"))
def OpenFileDialog(self, title): self.filename, _ = getOpenFileName( self, title, g.config.vars.Paths['import_dir'], self.tr("All supported files (*.dxf *.ps *.pdf *%s);;" "DXF files (*.dxf);;" "PS files (*.ps);;" "PDF files (*.pdf);;" "Project files (*%s);;" "All types (*.*)") % (c.PROJECT_EXTENSION, c.PROJECT_EXTENSION)) # If there is something to load then call the load function callback if self.filename: self.filename = qstr_encode(self.filename) logger.info(self.tr("File: %s selected") % self.filename)
def exportShapes(self, status=False, saveas=None): """ This function is called by the menu "Export/Export Shapes". It may open a Save Dialog if used without LinuxCNC integration. Otherwise it's possible to select multiple postprocessor files, which are located in the folder. """ self.setCursor(QtCore.Qt.WaitCursor) self.app.processEvents() logger.debug(self.tr('Export the enabled shapes')) # Get the export order from the QTreeView self.TreeHandler.updateExportOrder() self.updateExportRoute() logger.debug(self.tr("Sorted layers:")) for i, layer in enumerate(self.layerContents.non_break_layer_iter()): logger.debug("LayerContents[%i] = %s" % (i, layer)) if not g.config.vars.General['write_to_stdout']: # Get the name of the File to export if not saveas: MyFormats = "" for i in range(len(self.MyPostProcessor.output_format)): name = "%s " % (self.MyPostProcessor.output_text[i]) format_ = "(*%s);;" % ( self.MyPostProcessor.output_format[i]) MyFormats = MyFormats + name + format_ filename = self.showSaveDialog(self.tr('Export to file'), MyFormats) save_filename = qstr_encode(filename[0]) else: filename = [None, None] save_filename = saveas # If Cancel was pressed if not save_filename: self.unsetCursor() return (beg, ende) = os.path.split(save_filename) (fileBaseName, fileExtension) = os.path.splitext(ende) pp_file_nr = 0 for i in range(len(self.MyPostProcessor.output_format)): name = "%s " % (self.MyPostProcessor.output_text[i]) format_ = "(*%s)" % (self.MyPostProcessor.output_format[i]) MyFormats = name + format_ if filename[1] == MyFormats: pp_file_nr = i if fileExtension != self.MyPostProcessor.output_format[pp_file_nr]: if not QtCore.QFile.exists(save_filename): save_filename += self.MyPostProcessor.output_format[ pp_file_nr] self.MyPostProcessor.getPostProVars(pp_file_nr) else: save_filename = "" self.MyPostProcessor.getPostProVars(0) """ Export will be performed according to LayerContents and their order is given in this variable too. """ self.MyPostProcessor.exportGCode(self.filename, save_filename, self.layerContents, self.valuesDXF.entities.geo) self.unsetCursor() if g.config.vars.General['write_to_stdout']: self.close()