def __init__(self, dialog): BlankPaperJob.__init__(self, dialog) self.sourcePDF = None self.targetPDF = None dlg = KFileDialog(KUrl(), '*.pdf|{0}\n*|{1}'.format( i18n("PDF Files"), i18n("All Files")), dialog) dlg.setOperationMode(KFileDialog.Saving) dlg.setCaption(i18n("Save PDF")) dlg.setConfirmOverwrite(True) dlg.setSelection('staffpaper.pdf') if dlg.exec_(): self.targetPDF = dlg.selectedUrl() self.savePDF() else: self.cleanup()
def doExport(self, exporter): filePath = exporter.getFilePath() if filePath != None: # if a path is set, than it is configurable fileTypes = exporter.getFileTypes() if fileTypes: filterStr = ' '.join(fileTypes) else: filterStr = '' # TODO make remote url work fileDialog = KFileDialog(KUrl(filePath), filterStr, self) fileDialog.setSelection(os.path.basename(filePath)) fileDialog.setCaption(i18n('Export Vocabulary')) #fileDialog.setConfirmOverwrite(True) fileDialog.setOperationMode(KFileDialog.Saving) if fileDialog.exec_() != KFileDialog.Accepted: return filePath = unicode(fileDialog.selectedFile()) # TODO setConfirmOverwrite() doesn't work right now, so... while filePath and os.path.exists(filePath) \ and KMessageBox.warningYesNo(self, i18n('The given file "%1" already exists. Overwrite?', os.path.basename(filePath))) == KMessageBox.No: fileDialog.setSelection(os.path.basename(filePath)) if fileDialog.exec_() != KFileDialog.Accepted: return filePath = unicode(fileDialog.selectedFile()) if not filePath: return exporter.setFilePath(unicode(filePath)) exporter.setEntries(self.vocabularyModel.getVocabulary()) try: if not exporter.write(): KMessageBox.error(self, i18n('Error saving file')) except Exception, e: KMessageBox.error(self, i18n('Error saving file: %1', unicode(e))) print unicode(e).encode(locale.getpreferredencoding())