Example #1
0
 def saveLogAs(self):
     startDir, fileName = os.path.split(self.doc.localPath())
     fileName = (os.path.splitext(fileName)[0] or "lilypond") + ".log"
     dlg = KEncodingFileDialog(startDir, 'utf-8', '',
         i18n("Save LilyPond Log as"),
         KEncodingFileDialog.Saving, self)
     dlg.setSelection(fileName)
     dlg.setConfirmOverwrite(True)
     if not dlg.exec_():
         return # Cancelled
     encoding = dlg.selectedEncoding()
     fileName = dlg.selectedFile()
     text = (self.textCursor().selection().toPlainText()
             or self.toPlainText())
     try:
         with open(fileName, 'w') as f:
             f.write(text.encode(encoding, 'replace'))
             f.write('\n')
     except (OSError, IOError) as e:
         KMessageBox.error(self,
             i18n("Could not save LilyPond log:\n\n%1", unicode(e)))
Example #2
0
 def saveAs(self):
     """Saves the document, always asking for a file name.
     
     Returns True if saving succeeded, otherwise False.
     
     """
     if self.doc:
         dlg = KEncodingFileDialog(
             self.app.mainwin.sessionManager().basedir() or
             self.app.defaultDirectory(),
             self.doc.encoding(),
             '\n'.join(self.app.fileTypes + ["*|" + i18n("All Files")]),
             i18n("Save File"),
             KEncodingFileDialog.Saving,
             self.app.mainwin)
         dlg.setSelection(self.url().url())
         dlg.setConfirmOverwrite(True)
         if not dlg.exec_():
             return False # Cancelled
         self.doc.setEncoding(dlg.selectedEncoding())
         return self.doc.saveAs(dlg.selectedUrl())
     return True