Advertisement
ijontichy

tmp.py

Jan 17th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. # !/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Doc Holliday's Specialized medical bag
  5. # what I'm trying to do is make a multi application launcher
  6. # to help neaten up my desktop.
  7.  
  8. import subprocess, sys
  9. from tkinter import *
  10.  
  11. PROGRAMS = (
  12.             (r"C:\eclipse\eclipse.exe", "Eclipse (Java)"),    # ... is for fussies
  13.             (r"C:\Program Files (x86)\Lua\5.1\lua.exe", "Lua"),
  14.             (r"C:\Program Files (x86)\Notepad++\notepad++.exe", "Notepad++"),
  15.             (r"C:\Program Files (x86)\Filezilla\filezilla.exe", "Filezilla"),
  16.             (r"C:\Program Files (x86)\Lua\5.1\SciTE\SciTE.exe", "Scintilla"),
  17.             (r"C:\Users\Bryan\Documents\My Games\metapad36\metapad.exe", "Metapad"),
  18.             (r"C:\Dev-Cpp\devcpp.exe", "Dev-C++"),
  19.            )
  20.  
  21.  
  22. class AppLauncher(Frame):    
  23.  
  24.     def __init__(self, parent):
  25.         Frame.__init__(self, parent)
  26.         self.parent = parent
  27.         self.initialize()
  28.  
  29.     def initialize(self):
  30.         # Don't do this - grid doesn't play well with pack, and we don't want
  31.         # to assume
  32.         #~ self.grid()
  33.        
  34.         for i, progPair in enumerate(PROGRAMS):
  35.             program, name = progPair
  36.             tmpBtn = Button(self, text=name, border=4, command=(lambda prog=program: self.openProg(prog) ) )
  37.             tmpBtn.grid(row=i//3, column=i%3, padx=1, pady=1, sticky="NSEW")
  38.        
  39.     def openProg(self, prog):
  40.         print("Opening \"{}\"".format(prog))
  41.        
  42.         try:
  43.             subprocess.call([prog])
  44.        
  45.         except OSError as e:
  46.             reason = e.args[1]
  47.  
  48.             if "No such" in reason:
  49.                 print("ERROR: \"{}\" doesn't exist".format(prog), file=sys.stderr)
  50.  
  51.  
  52. if __name__ == "__main__":
  53.     root = Tk()
  54.     root.title("Doc Holliday's Medical Bag")
  55.     root.resizable(False, False)
  56.  
  57.     app = AppLauncher(root)
  58.     app.grid(sticky="NSEW")
  59.  
  60.     root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement