Cowsay Fortune!

Hey drop us a line about the show. Feel free to ask questions, provide feedback and criticism, or just ramble on about anything your little heart desires.

Moderators: snarkout, Patrick, dann

Post Reply
User avatar
CptnObvious999
Posts: 798
Joined: Fri Jun 03, 2005 7:54 pm
Location: Maryland
Contact:

Cowsay Fortune!

Post by CptnObvious999 » Thu Dec 08, 2005 9:41 pm

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:

User avatar
snarkout
Site Admin
Posts: 1342
Joined: Tue Aug 16, 2005 9:35 pm

Post by snarkout » Thu Dec 08, 2005 11:14 pm

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.
Shared pain is lessened, shared joy is increased; thus do we refute entropy.
--Spider Robinson

User avatar
CptnObvious999
Posts: 798
Joined: Fri Jun 03, 2005 7:54 pm
Location: Maryland
Contact:

Post by CptnObvious999 » Fri Dec 09, 2005 1:28 pm

Ok thanks so its not that Im a complete noob :wink: Ill see if I can write one up in python

User avatar
CptnObvious999
Posts: 798
Joined: Fri Jun 03, 2005 7:54 pm
Location: Maryland
Contact:

Post by CptnObvious999 » Fri Dec 09, 2005 10:19 pm

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:

User avatar
snarkout
Site Admin
Posts: 1342
Joined: Tue Aug 16, 2005 9:35 pm

Post by snarkout » Fri Dec 09, 2005 11:18 pm

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.
Shared pain is lessened, shared joy is increased; thus do we refute entropy.
--Spider Robinson

User avatar
CptnObvious999
Posts: 798
Joined: Fri Jun 03, 2005 7:54 pm
Location: Maryland
Contact:

Post by CptnObvious999 » Fri Dec 09, 2005 11:31 pm

Yeah it turned out to be more than a simple 1 minute program ;-)

Post Reply