Example #1
0
    def run(self):
        """Runs convert-ly (again)."""
        fromVersion = self.fromVersion.text()
        toVersion = self.toVersion.text()
        if not fromVersion or not toVersion:
            self.messages.setPlainText(
                _("Both 'from' and 'to' versions need to be set."))
            return
        info = self._info
        command = info.toolcommand(info.ly_tool('convert-ly'))
        command += ['-f', fromVersion, '-t', toVersion, '-']

        # if the user wants english messages, do it also here: LANGUAGE=C
        env = None
        if os.name == "nt":
            # Python 2.7 subprocess on Windows chokes on unicode in env
            env = util.bytes_environ()
        else:
            env = dict(os.environ)
        if sys.platform.startswith('darwin'):
            try:
                del env['PYTHONHOME']
            except KeyError:
                pass
            try:
                del env['PYTHONPATH']
            except KeyError:
                pass
        if QSettings().value("lilypond_settings/no_translation", False, bool):
            if os.name == "nt":
                # Python 2.7 subprocess on Windows chokes on unicode in env
                env[b'LANGUAGE'] = b'C'
            else:
                env['LANGUAGE'] = 'C'

        with qutil.busyCursor():
            try:
                proc = subprocess.Popen(command,
                                        env=env,
                                        stdin=subprocess.PIPE,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
                out, err = proc.communicate(
                    util.platform_newlines(self._text).encode(self._encoding))
            except OSError as e:
                self.messages.setPlainText(
                    _("Could not start {convert_ly}:\n\n"
                      "{message}\n").format(convert_ly=command[0], message=e))
                return
            out = util.universal_newlines(out.decode('UTF-8'))
            err = util.universal_newlines(err.decode('UTF-8'))
            self.messages.setPlainText(err)
            self.setConvertedText(out)
            self.setDiffText(out)
            if not out or self._convertedtext == self._text:
                self.messages.append('\n' +
                                     _("The document has not been changed."))
Example #2
0
 def run(self):
     """Runs convert-ly (again)."""
     fromVersion = self.fromVersion.text()
     toVersion = self.toVersion.text()
     if not fromVersion or not toVersion:
         self.messages.setPlainText(_(
             "Both 'from' and 'to' versions need to be set."))
         return
     info = self._info
     command = info.toolcommand(info.ly_tool('convert-ly'))
     command += ['-f', fromVersion, '-t', toVersion, '-']
     
     # if the user wants english messages, do it also here: LANGUAGE=C
     env = None
     if os.name == "nt":
         # Python 2.7 subprocess on Windows chokes on unicode in env
         env = util.bytes_environ()
     else:
         env = dict(os.environ)
     if sys.platform.startswith('darwin'):
         try:
             del env['PYTHONHOME']
         except KeyError:
             pass
         try:
             del env['PYTHONPATH']
         except KeyError:
             pass
     if QSettings().value("lilypond_settings/no_translation", False, bool):
         if os.name == "nt":
             # Python 2.7 subprocess on Windows chokes on unicode in env
             env[b'LANGUAGE'] = b'C'
         else:
             env['LANGUAGE'] = 'C'
     
     with qutil.busyCursor():
         try:
             proc = subprocess.Popen(command,
                 env = env,
                 stdin = subprocess.PIPE,
                 stdout = subprocess.PIPE,
                 stderr = subprocess.PIPE)
             out, err = proc.communicate(util.platform_newlines(self._text).encode(self._encoding))
         except OSError as e:
             self.messages.setPlainText(_(
                 "Could not start {convert_ly}:\n\n"
                 "{message}\n").format(convert_ly = command[0], message = e))
             return
         out = util.universal_newlines(out.decode('UTF-8'))
         err = util.universal_newlines(err.decode('UTF-8'))
         self.messages.setPlainText(err)
         self.setConvertedText(out)
         self.setDiffText(out)
         if not out or self._convertedtext == self._text:
             self.messages.append('\n' + _("The document has not been changed."))
Example #3
0
 def insertFromFile(self):
     ext = os.path.splitext(self.currentDocument().url().path())[1]
     filetypes = app.filetypes(ext)
     caption = app.caption(_("dialog title", "Insert From File"))
     directory = os.path.dirname(self.currentDocument().url().toLocalFile()) or app.basedir()
     filename = QFileDialog.getOpenFileName(self, caption, directory, filetypes)[0]
     if filename:
         try:
             with open(filename, 'rb') as f:
                 data = f.read()
         except IOError as e:
             msg = _("{message}\n\n{strerror} ({errno})").format(
                 message = _("Could not read from: {url}").format(url=filename),
                 strerror = e.strerror,
                 errno = e.errno)
             QMessageBox.critical(self, app.caption(_("Error")), msg)
         else:
             text = util.universal_newlines(util.decode(data))
             self.currentView().textCursor().insertText(text)
Example #4
0
 def insertFromFile(self):
     ext = os.path.splitext(self.currentDocument().url().path())[1]
     filetypes = app.filetypes(ext)
     caption = app.caption(_("dialog title", "Insert From File"))
     directory = os.path.dirname(self.currentDocument().url().toLocalFile()) or app.basedir()
     filename = QFileDialog.getOpenFileName(self, caption, directory, filetypes)
     if filename:
         try:
             with open(filename, 'rb') as f:
                 data = f.read()
         except IOError as e:
             msg = _("{message}\n\n{strerror} ({errno})").format(
                 message = _("Could not read from: {url}").format(url=filename),
                 strerror = e.strerror,
                 errno = e.errno)
             QMessageBox.critical(self, app.caption(_("Error")), msg)
         else:
             text = util.universal_newlines(util.decode(data))
             self.currentView().textCursor().insertText(text)
Example #5
0
    def load_data(cls, url, encoding=None):
        """Class method to load document contents from an url.

        This is intended to open a document without instantiating one
        if loading the contents fails.

        This method returns the text contents of the url as decoded text,
        thus a unicode string.

        The line separator is always '\\n'.

        """
        filename = url.toLocalFile()

        # currently, we do not support non-local files
        if not filename:
            raise IOError("not a local file")
        with open(filename, 'rb') as f:
            data = f.read()
        text = util.decode(data, encoding)
        return util.universal_newlines(text)
Example #6
0
 def load_data(cls, url, encoding=None):
     """Class method to load document contents from an url.
     
     This is intended to open a document without instantiating one
     if loading the contents fails.
     
     This method returns the text contents of the url as decoded text,
     thus a unicode string.
     
     The line separator is always '\\n'.
     
     """
     filename = url.toLocalFile()
     
     # currently, we do not support non-local files
     if not filename:
         raise IOError("not a local file")
     with open(filename, 'rb') as f:
         data = f.read()
     text = util.decode(data, encoding)
     return util.universal_newlines(text)