def __kdeGetSaveFileName(parent = None, caption = QString(), dir_ = QString(),
                          filter = QString(), selectedFilter = None, 
                          options = QFileDialog.Options()):
     """
     Module function to get the name of a file for saving it.
     
     @param parent parent widget of the dialog (QWidget)
     @param caption window title of the dialog (QString)
     @param dir_ working directory of the dialog (QString)
     @param filter filter string for the dialog (QString)
     @param selectedFilter selected filter for the dialog (QString)
     @param options various options for the dialog (QFileDialog.Options)
     @return name of file to be saved (QString)
     """
     if not QString(filter).isEmpty():
         filter = __convertFilter(filter, selectedFilter)
     wdir = __workingDirectory(dir_)
     dlg = KFileDialog(KUrl.fromPath(wdir), filter, parent)
     if wdir != dir_:
         dlg.setSelection(dir_)
     dlg.setOperationMode(KFileDialog.Saving)
     dlg.setMode(KFile.Modes(KFile.File) | KFile.Modes(KFile.LocalOnly))
     dlg.setWindowTitle(caption.isEmpty() and \
         QApplication.translate('KFileDialog', 'Save As') or caption)
     
     dlg.exec_()
     
     if selectedFilter is not None:
         flt = dlg.currentFilter()
         flt.prepend("(").append(")")
         selectedFilter.replace(0, selectedFilter.length(), flt)
     
     return dlg.selectedFile()
Exemplo n.º 2
0
    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())
 def __kdeGetExistingDirectory(parent = None, caption = QString(), 
                         dir_ = QString(), 
                         options = QFileDialog.Options(QFileDialog.ShowDirsOnly)):
     """
     Module function to get the name of a directory.
     
     @param parent parent widget of the dialog (QWidget)
     @param caption window title of the dialog (QString)
     @param dir_ working directory of the dialog (QString)
     @param options various options for the dialog (QFileDialog.Options)
     @return name of selected directory (QString)
     """
     wdir = __workingDirectory(dir_)
     dlg = KFileDialog(KUrl.fromPath(wdir), QString(), parent)
     dlg.setOperationMode(KFileDialog.Opening)
     dlg.setMode(KFile.Modes(KFile.Directory) | KFile.Modes(KFile.LocalOnly) | \
                 KFile.Modes(KFile.ExistingOnly))
     dlg.setWindowTitle(caption.isEmpty() and \
         QApplication.translate('KFileDialog', 'Select Directory') or caption)
     
     dlg.exec_()
     
     return dlg.selectedFile()
Exemplo n.º 4
0
 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()