Page 1 of 1

Cowsay Fortune!

Posted: Thu Dec 08, 2005 9:41 pm
by CptnObvious999
Hey this seemed like it would be a 1 minute program however it has not turned out to be so. I wanted to combine 2 programs and put the output into kdialog then create a KDE shortcut to it because I was bored and needed to refresh my BASH skills (or lack there of). I just want kdialog to show a messagebox that has a cow saying the fortune using cowsay and fortune. The command to use the CLI is

Code: Select all

cowsay `fortune`
however I need to put that command in kdialog and somehow keep it in the same format. Im a BASH noob :roll:

Posted: Thu Dec 08, 2005 11:14 pm
by snarkout
Well, there are a few different ways to do it, but they all look like crap since kdialog doesn't seem to honor the --font option even though it's a listed qt option. Kdialoq seems extremely inflexible.

Posted: Fri Dec 09, 2005 1:28 pm
by CptnObvious999
Ok thanks so its not that Im a complete noob :wink: Ill see if I can write one up in python

Posted: Fri Dec 09, 2005 10:19 pm
by CptnObvious999
Heres the program:

Code: Select all

#!/usr/bin/env python

import sys, os
from qt import *

class CowFortune(QApplication):
    
    def __init__(self, args):
        """ In the constructor we're doing everything to get our application
            started, which is basically constructing a basic QApplication by 
            its __init__ method, then adding our widgets and finally starting 
            the exec_loop."""
        self.getFortune()
        QApplication.__init__(self, args)
        self.addWidgets()
        self.exec_loop()        
        
    def addWidgets(self):
        """ In this method, we're adding widgets and connecting signals from 
            these widgets to methods of our class, the so-called "slots" 
        """
        self.text = QLabel(self.output,None)
        self.text.setFont(QFont("Fixed",12))
        self.setMainWidget(self.text)
        self.text.show()

    def getFortune(self):
        os.system("rm -f /tmp/cowsay") # delete the file if it exists for any reason
        os.system("cowsay `fortune` >> /tmp/cowsay") # execute the command
        tmp = open("/tmp/cowsay","r")
        self.output = tmp.read()
        tmp.close()
        os.system("rm -f /tmp/cowsay")


if __name__ == "__main__":
    app = CowFortune(sys.argv)
it needs PyQt and python (obviously). Enjoy :wink:

Posted: Fri Dec 09, 2005 11:18 pm
by snarkout
That's certainly more hardcore than my solution of:

xterm -hold -e cowsay $(fortune)

After I got the idea from you, I added that to my KDE startup stuff.

Posted: Fri Dec 09, 2005 11:31 pm
by CptnObvious999
Yeah it turned out to be more than a simple 1 minute program ;-)