You are not logged in.
Pages: 1
I'm sure it's not anything some of you vets can't do with both eyes closed and one hand tied behind your back... but it's my first and I'm proud
I wrote this so I'd have access to the "Terminal Apps" portion of the #! menu from the terminal, because sometimes I'm running x-less and wondering what programs I've got available to me there.
#!/usr/bin/python import subprocess import sys running = True while running: subprocess.call( ["clear"] ) print("Terminal-based applications menu") print(" 1. Text editor.") print(" 2. File Manager.") print(" 3. Bit Torrent Client.") print(" 4. Music Player.") print(" 5. Feed Reader.") print(" 6. Web Browser.") print(" 7. Email Client.") print(" 8. IRC Client.") print(" 9. Instant Messaging.") print("10. System Monitor.") print(" 0. Quit") try: x = int(raw_input("Enter the number of your choice: ")) if x == 0: sys.exit() if x == 1: subprocess.call( ["vim"] ) sys.exit() if x == 2: subprocess.call( ["mc"] ) sys.exit() if x == 3: subprocess.call( ["rtorrent"] ) sys.exit() if x == 4: subprocess.call( ["mocp"] ) sys.exit() if x == 5: subprocess.call( ["newsbeuter", "-r"] ) sys.exit() if x == 6: subprocess.call( ["elinks"] ) sys.exit() if x == 7: subprocess.call( ["mutt"] ) sys.exit() if x == 8: subprocess.call( ["irssi"] ) sys.exit() if x == 9: subprocess.call( ["naim"] ) sys.exit() if x == 10: subprocess.call( ["htop"] ) sys.exit() if x != range(0, 10): print("Please type the number corresponding to your menu choice.") raw_input("Press Enter to try again.") except ValueError: raw_input("Numbers only, please. Press Enter to try again.")I'm sure it's useless to most of us considering we all know how to type 'htop' (LOL), but I had a lot of fun making it and wanted to share it
I'll appreciate any free advice you want to throw my way!
Good work, seems very handy. I would like to offer a suggestion which will help get rid of all of those if statements.
Because subprocess.call() takes a string as its argument you can use a list containing the commands, much like this.
commands = ["vim", "mc", "rtorrent", "mocp", "newsbeuter -r", "elinks", "mutt", "irssi", "naim", "htop"]Now, in a list we start counting from 0. So although we have 10 entries, the last entry will be number 9. First lets make the first entry sys.exit() so that it fits with your numbering scheme. Then, we take input from the user, convert to an integer and use this to run the specified command like so.
commands = ["sys.exit()", "vim", "mc", "rtorrent", "mocp", "newsbeuter -r", "elinks", "mutt", "irssi", "naim", "htop"]
choice = int(raw_input("Enter the number of your choice: "))
if choice < len(commands) - 1:
subprocess.call(commands[choice])
else:
print "Invalid input."We have to use -1 after the len() function because len() returns the number of entries starting at 1. meaning it returns 11 when, as far as python is concerned, we have 10. If we did not do this then if you tried to use htop you would receive an index error.
Anyway, I hope this helps, if you need a hand with anything just gimme a shout.
Kind regards,
Bodsda
Thanks for the warm welcome guys 
I'm gonna have to have a play with conky tomorrow night. Anyone got a link to a guide starter guide on it?
Love some of the examples in this thread, great work everyone 
Glad you made your way to #! and hope you enjoy your stay
Thanks, I am sure I will 
Hi guys,
My name is Bodsda.
I recently had a mishap with my computer... Turning off temperature checking is a *bad* idea. So I had to borrow a laptop that I could not install Linux on. Not to be deterred I went out and bought a 4GB USB drive, then I continued to struggle for a few days to get Ubuntu to install on the darn thing. After the 5th failure I got annoyed and starting reading my LXF magazine, which happened to have #! on it.
After slipping that in the drive and booting I was pleasantly surprised. None of this Gnome/KDE bloat, no horrible theme, no 30 step install procedure and no lack of gstreamer preinstalled packages. Although flash was not installed, but thats hardly worth complaining about.
Anywhooo, Hi!
Pages: 1
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.