class FortuneCookie(plasmascript.Applet): # The all important label : This is the only control in our plasmoid label = Plasma.Label mytimer = QTimer process = KProcess fortunecommand="fortune" fortunecookies="fortune-ml" offensive="-o" #Every half an hour mytimeout = 1800000 #process = def __init__(self,parent,args=None): plasmascript.Applet.__init__(self,parent) 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) def gotsomeoutput(self): outputstring = str(self.process.readAllStandardOutput()) self.label.setText(unicode(outputstring,"utf-8")) self.mytimer.start(self.mytimeout) def TimeOut(self): # execute the fortune command and get its output if self.process.state() == QProcess.NotRunning: self.process.start() else: return # On mouse click , change the quote def mousePressEvent(self, event): print "Test" self.mytimer.start(0)