Example #1
0
 def start(self):
     """
     Starts the process. If successful, show the button pressed.
     """
     # Call this to perform setup right before start
     self.onStart()
     # Now start...
     p = KProcess()
     cmd = self.command
     if isinstance(cmd, basestring):
         cmd = splitcommandline(cmd)
     if self.pty:
         # p.setUsePty does currently not work on Gentoo
         if hasattr(p, "setUsePty"):
             p.setUsePty(KProcess.Stdin, False)
         else:
             # Hack to let a process think it reads from a terminal
             cmd[0:0] = ["python", os.path.join(appdir, "runpty.py")]
     p.setExecutable(cmd[0])
     p.setArguments(cmd[1:])
     # Setup the signals
     if self.comm & KProcess.Stdin:
         self.pending = []
         p.connect(p, SIGNAL("wroteStdin(KProcess*)"), self.wroteStdin)
     if self.comm & KProcess.Stdout:
         p.connect(p, SIGNAL("receivedStdout(KProcess*, char*, int)"),
             self.receivedStdout)
     if self.comm & KProcess.Stderr:
         p.connect(p, SIGNAL("receivedStderr(KProcess*, char*, int)"),
             self.receivedStderr)
     p.connect(p, SIGNAL("processExited(KProcess*)"), self.processExited)
     if p.start(KProcess.NotifyOnExit, self.comm):
         self._p = p
         self.setDown(True)
         self.started()
     else:
         self._p = None
         self.failed()
Example #2
0
def runAction(url):
    """
    Runs an URL with KRun. If url starts with "email=" or "emailpreview=",
    it is converted to a mailto: link with the url attached, and opened in
    the default KDE mailer.
    If url starts with "print=", the file is directly printed with lpr.
    If url starts with "embed=", a subroutine in pdftk is called to embed
    LilyPond documents in the output PDF.
    """
    # hack: prevent QTextView recognizing mailto: urls cos it can't handle
    # query string
    url = unicode(url)        # url could be a QString
    m = re.match("([a-z]+)=(.*)", url)
    if not m:
        return krun(url)
    command, url = m.groups()
    if command == 'print':
        path = unicode(KURL(url).path())
        cmd = splitcommandline(config("commands").get("lpr", "lpr"))
        cmd.append(path)
        p = Popen(cmd, stderr=PIPE)
        if p.wait() != 0:
            error(_("Printing failed: %s") % p.stderr.read())
        else:
            info(_("The document has been sent to the printer."))
    elif command in ('email', 'emailpreview'):
        if command == "email" or warncontinue(_(
            "This PDF has been created with point-and-click urls (preview "
            "mode), which increases the file size dramatically. It's better "
            "to email documents without point-and-click urls (publish mode), "
            "because they are much smaller. Continue anyway?")):
            KApplication.kApplication().invokeMailer(
                KURL(u"mailto:?attach=%s" % url), "", True)
    elif command == 'embed':
        ly = unicode(KURL(url).path())
        from lilykde import pdftk
        pdftk.attach_files(ly)