Ejemplo n.º 1
0
    def background_process(self, cmd, stdout=False, stderr=False, env=None):
        '''Add a new background process and begin running it.'''

        process = KProcess()
        #if env:
        #    process.setEnv()
        process.setNextOpenMode(QIODevice.ReadOnly|QIODevice.Text)
        if stdout and stderr:
            process.setOutputChannelMode(KProcess.MergedChannels)
        else:
            if stdout:
                process.setOutputChannelMode(KProcess.OnlyStdoutChannel)
            elif stderr:
                process.setOutputChannelMode(KProcess.OnlyStderrChannel)
        process.setProgram(cmd)
        process.start()

        self.__process = process
Ejemplo n.º 2
0
    def init(self):
        #There is no configuration dialogue for this applet
        self.setHasConfigurationInterface(False)
        
        #This applet will always retain its Initial aspect ratio
        self.setAspectRatioMode(Plasma.KeepAspectRatio)
        
        #Get the current theme and use the default background ("widgets/background") and background hints 
        self.theme = Plasma.Svg(self)
        self.theme.setImagePath("widgets/background")
        self.setBackgroundHints(Plasma.Applet.DefaultBackground)
 
        #The applet layout is horizontal
        self.layout = QGraphicsLinearLayout(Qt.Vertical, self.applet)
        #Create a new label
        self.label = Plasma.Label(self.applet)
        
        # Add the label to the layout so it will be displayed 
        self.layout.addItem(self.label)
        self.setLayout(self.layout)

        # setup the process
        self.process=KProcess(self)
        self.process.setShellCommand(self.fortunecommand + " " + self.fortunecookies)
        self.process.setOutputChannelMode(KProcess.MergedChannels)
        # When the command outputs something , get it 
        QObject.connect( self.process, SIGNAL("readyReadStandardOutput()"), self.gotsomeoutput );
    
        #setup timer
        self.mytimer=QTimer(self)
        # We don't want this to timeout all by itself..
        self.mytimer.setSingleShot(True)

        # When the timer times out, execute this
        QObject.connect(self.mytimer,SIGNAL("timeout()"), self.TimeOut)

        # start the timer
        self.process.start()
        self.mytimer.start(self.mytimeout)
        # Set the default applet size
        self.resize(180,130)