Beispiel #1
0
 def saveFileAs(self):
     fileFormats = OrderedDict([
         (self.tr("UFO Font version 3 {}").format("(*.ufo)"), 3),
         (self.tr("UFO Font version 2 {}").format("(*.ufo)"), 2),
     ])
     state = settings.saveFileDialogState()
     path = self._font.path or self._font.binaryPath
     if path:
         directory = os.path.dirname(path)
     else:
         directory = (None if state else QStandardPaths.standardLocations(
             QStandardPaths.DocumentsLocation)[0])
     # TODO: switch to directory dlg on platforms that need it
     dialog = QFileDialog(self, self.tr("Save File"), directory,
                          ";;".join(fileFormats.keys()))
     if state:
         dialog.restoreState(state)
     dialog.setAcceptMode(QFileDialog.AcceptSave)
     if directory:
         dialog.setDirectory(directory)
     ok = dialog.exec_()
     settings.setSaveFileDialogState(dialog.saveState())
     if ok:
         nameFilter = dialog.selectedNameFilter()
         path = dialog.selectedFiles()[0]
         if not os.path.basename(path).endswith(".ufo"):
             path += ".ufo"
         self.saveFile(path, fileFormats[nameFilter])
         app = QApplication.instance()
         app.setCurrentFile(self._font.path)
         self.setWindowTitle(self.fontTitle())
Beispiel #2
0
 def saveFileAs(self):
     fileFormats = OrderedDict([
         (self.tr("UFO Font version 3 {}").format("(*.ufo)"), 3),
         (self.tr("UFO Font version 2 {}").format("(*.ufo)"), 2),
     ])
     state = settings.saveFileDialogState()
     path = self._font.path or self._font.binaryPath
     if path:
         directory = os.path.dirname(path)
     else:
         directory = None if state else QStandardPaths.standardLocations(
             QStandardPaths.DocumentsLocation)[0]
     # TODO: switch to directory dlg on platforms that need it
     dialog = QFileDialog(
         self, self.tr("Save File"), directory,
         ";;".join(fileFormats.keys()))
     if state:
         dialog.restoreState(state)
     dialog.setAcceptMode(QFileDialog.AcceptSave)
     if directory:
         dialog.setDirectory(directory)
     ok = dialog.exec_()
     settings.setSaveFileDialogState(dialog.saveState())
     if ok:
         nameFilter = dialog.selectedNameFilter()
         path = dialog.selectedFiles()[0]
         self.saveFile(path, fileFormats[nameFilter])
         self.setWindowTitle(self.fontTitle())