def openFile(self): sub_extensions = self.__getAllSubExtensions() str_sub_exts = ' '.join(['*.%s' % ext for ext in sub_extensions[1:]]) fileDialog = FileDialog( parent = self, caption = _("Open file"), directory = self._settings.getLatestDirectory(), filter = _("Subtitles (%s);;All files (*)") % str_sub_exts ) fileDialog.addEncodings(True) fileDialog.setFileMode(QFileDialog.ExistingFiles) if fileDialog.exec(): filenames = fileDialog.selectedFiles() encoding = fileDialog.getEncoding() self._settings.setLatestDirectory(os.path.dirname(filenames[0])) self._openFiles(filenames, encoding)
def saveFileAs(self): fileDialog = FileDialog( parent = self, caption = _('Save as...'), directory = self._settings.getLatestDirectory() ) currentTab = self._tabs.currentPage() fileDialog.addFormats(self._subtitleData.supportedFormats) fileDialog.setSubFormat(currentTab.outputFormat) fileDialog.addEncodings(False) fileDialog.setEncoding(currentTab.outputEncoding) fileDialog.setAcceptMode(QFileDialog.AcceptSave) fileDialog.setFileMode(QFileDialog.AnyFile) if fileDialog.exec(): newFilePath = fileDialog.selectedFiles()[0] data = currentTab.data outputFormat = fileDialog.getSubFormat() outputEncoding = fileDialog.getEncoding() # user can overwrite previous output encoding if data.outputFormat != outputFormat or data.outputEncoding != outputEncoding: # save user changes data.outputFormat = outputFormat data.outputEncoding = outputEncoding if self._subtitleData.fileExists(newFilePath): command = ChangeData(newFilePath, data, _("Overwritten by %s") % currentTab.name) else: command = CreateSubtitlesFromData(newFilePath, data) self._subtitleData.execute(command) self._tabs.openTab(newFilePath) self.saveFile(newFilePath) self._settings.setLatestDirectory(os.path.dirname(newFilePath))