def importIndex(self): filename = str(KFileDialog.getOpenFileName(KUrl("pisi-installed"), "*.xml", self, i18n("Import index file"))) if filename: self.switchSession(SessionManager.OFFLINE) self.emit(SIGNAL("importIndex(str)"), filename) self.emit(SIGNAL("packagesChanged()"))
def openDataFile(self): print "Sorry, this does not work currently." return self.verifyDataSaved() f = KFileDialog.getOpenFileName() s = str(f).split('/') self.clearData() self.dataAccessMutex.lock() try: with open(f) as fileptr: data = fileptr.readlines() self.data = [float(item.split('\t')[1]) for item in data] if len(self.data) == 0: raise IOError("No valid data points found, probably the file is empty") self.ui.record_url.setText('/'.join(s[:-1])) self.ui.record_prefix.setText(s[-1].replace('result', '') + "_cont_") self.ui.record_startstop.setChecked(False) self.updateRecordingState() self.ui.statusbar.message("Successfully loaded %s data points from %s." % (len(data), str(f))) except Exception as e: print e try: self.ui.statusbar.message("Could not load file %s: %s" % (f, str(e))) except: self.ui.statusbar.message("Could not load file %s: invalid characters" % f) finally: if len(self.data) > 0: self.addDataPoint(self.data) self.redrawPlot() self.dataAccessMutex.unlock()
def openSession(self): filename = str( KFileDialog.getOpenFileName(KUrl("pisi-archive"), "*.offline", self, i18n("Open offline session")) ) if filename: self.emit(SIGNAL("openSession(str)"), filename)
def batch_download(self, ok): "Download images in batch." selected_items = self.thumbnailarea.selected_images() if not selected_items: return start_url = KUrl("kfiledialog:///danbooru") caption = i18n("Select a directory to save the images to") directory = KFileDialog.getExistingDirectoryUrl( start_url, self, caption) if directory.isEmpty(): return for item in selected_items: file_url = item.url_label.url() tags = item.data.tags # Make a local copy to append paths as addPath works in-place destination = KUrl(directory) file_name = KUrl(file_url).fileName() destination.addPath(file_name) job = KIO.file_copy(KUrl(file_url), destination, -1) job.setProperty("tags", QVariant(tags)) job.result.connect(self.batch_download_slot)
def saveAllData(self): f = KFileDialog.getSaveFileName() try: writeArrayToDatafile(self.rawDataBackupCopy, f) self.ui.statusbar.message("Successfully saved %s values to %s." % (str(len(self.data)), f)) except Exception as e: self.ui.statusbar.message("Failed to save data to %s: %s" % (f, str(e)))
def batch_download(self, ok): "Download images in batch." selected_items = self.thumbnailarea.selected_images() if not selected_items: return start_url = KUrl("kfiledialog:///danbooru") caption = i18n("Select a directory to save the images to") directory = KFileDialog.getExistingDirectoryUrl(start_url, self, caption) if directory.isEmpty(): return for item in selected_items: file_url = item.url_label.url() tags = item.data.tags # Make a local copy to append paths as addPath works in-place destination = KUrl(directory) file_name = KUrl(file_url).fileName() destination.addPath(file_name) job = KIO.file_copy(KUrl(file_url), destination, -1) job.setProperty("tags", QVariant(tags)) job.result.connect(self.batch_download_slot)
def saveSession(self): filename = str( KFileDialog.getSaveFileName(KUrl("pisi-archive"), "*.offline", self, i18n("Save offline session")) ) if filename: self.emit(SIGNAL("saveSession(str)"), filename) self.switchSession(SessionManager.NORMAL)
def save_file(self): """ Save the current document. """ tabwidget = self.window.tabWidget document = tabwidget.currentWidget() if(document is not None): filename = KFileDialog.getSaveFileName(KUrl(), "*.xoj | *.xoj - Xournal File") xournal = Xournal() xournal.save(filename, document)
def addDir(self): path = KFileDialog.getExistingDirectory( KUrl('') , self , i18nc('@title:window', 'Select a Directory with CMake Modules') ) kate.kDebug('CMakeCC: got path={}'.format(path)) self.moduleDirs.addItem(str(path))
def add_file_source_dialog(self): filename = '' filter = QString('*.iso|' + _('ISO Files') + '\n*.img|' + _('IMG Files')) # FIXME: should set the default path KUrl to users home dir... # This is all screwy as its run as root under kdesudo... Home = root and not user.. blarg! # Need to convert to plain string for backend to work filename = str(KFileDialog.getOpenFileName(KUrl(),filter)) if not filename: return self.__backend.add_file_source(filename)
def export_to_file(self): filename = KFileDialog.getSaveFileName(KUrl("~"), "Text (*.txt)", self, "Select file to save launcher data") fh = open(filename, 'w') for rownum in range(self.tableWidget.rowCount()): icon = self.tableWidget.cellWidget(rownum, 0) and unicode(self.tableWidget.cellWidget(rownum, 0).icon()) or "" button_text = self.tableWidget.item(rownum, 1) and unicode(self.tableWidget.item(rownum, 1).text()) media_url = self.tableWidget.item(rownum, 2) and unicode(self.tableWidget.item(rownum, 2).text()) tooltip_text = (self.tableWidget.item(rownum, 3) and unicode(self.tableWidget.item(rownum, 3).text())) or "" if button_text and media_url: fh.write("\t".join([icon, button_text, media_url, tooltip_text]) + "\n") fh.close()
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()
def slotFileDialog(self): """ Get file name from file dialog """ if ctx.Pds.session == ctx.pds.Kde4: from PyKDE4.kio import KFileDialog from PyKDE4.kdecore import KUrl url=KUrl.fromPath("/boot/") filename=unicode(KFileDialog.getOpenFileName(url, "", self, i18n("File System"))) else: filename=unicode(QtGui.QFileDialog.getOpenFileName(self, i18n("File System"), "/boot/")) if filename: self.setFile(filename)
def open_file(self): """ Open a dialog to let the user choose pdf files and open them in tabs. """ #TODO: Move filter to a better place :D files = KFileDialog.getOpenFileNames(KUrl(), "*.pdf| PDF files") if not files: return QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) for file in files: filename = os.path.basename(str(file)) self.open_document(PynalDocument(file), filename) QtGui.QApplication.restoreOverrideCursor()
def add_key_clicked(self): """Provide a file chooser that allows to add the gnupg of a trusted software vendor""" home = QDir.homePath() if "SUDO_USER" in os.environ: home = os.path.expanduser("~%s" % os.environ["SUDO_USER"]) url = KUrl.fromPath(home) filename = KFileDialog.getOpenFileName(url, 'application/pgp-keys', self.userinterface, utf8(_("Import key"))) if filename: if not self.add_key(filename): title = _("Error importing selected file") text = _("The selected file may not be a GPG key file " \ "or it might be corrupt.") KMessageBox.sorry(self.userinterface, utf8(text), utf8(title)) self.show_keys()
def open_file(self): """ Open a dialog to let the user choose pdf files and open them in tabs. """ files = KFileDialog.getOpenFileNames(KUrl(), "*.pyn | *.pyn - Pynal File\n *.xoj | *.xoj - Xournal File\n *.pdf| *.pdf - PDF files\n * | All Files") if not files: return QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) for file in files: filename = os.path.basename(str(file)) (shortname, extension) = os.path.splitext(filename) if (extension == ".pdf"): self.open_document(PynalDocument(file), filename) elif (extension == ".xoj"): document = PynalDocument() self.open_document(document, shortname) xournal = Xournal() xournal.load(file, document) QtGui.QApplication.restoreOverrideCursor()
def on_browseButton_pressed(self): path = KFileDialog.getExistingDirectory(self.parentWidget(), i18n("Choose Directory")) if path != '':
def on_browseButton_pressed(self): path = KFileDialog.getExistingDirectory(self.parentWidget(), i18n("Choose Directory")) if path != '': self.path = path self.folderLabel.setText(self.path)
def saveSession(self): filename = str(KFileDialog.getSaveFileName(KUrl("pisi-archive"), "*.offline", self, i18n("Save offline session"))) if filename: self.emit(SIGNAL("saveSession(str)"), filename) self.switchSession(SessionManager.NORMAL)
def openSession(self): filename = str(KFileDialog.getOpenFileName(KUrl("pisi-archive"), "*.offline", self, i18n("Open offline session"))) if filename: self.emit(SIGNAL("openSession(str)"), filename)
def exportIndex(self): filename = str(KFileDialog.getSaveFileName(KUrl("pisi-installed"), "*.xml", self, i18n("Export index file"))) if filename: self.emit(SIGNAL("exportIndex(str)"), filename)
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()
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())