Advertisement
Guest User

Untitled

a guest
May 13th, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. try:
  2.     import Tkinter as tk
  3.     from pathlib import Path, WindowsPath
  4.     import string
  5.     import os, sys
  6.     from copy import copy
  7.  
  8. except ImportError:
  9.     Import()
  10.  
  11. def Import():
  12.     try:
  13.         import Tkinter as tk
  14.         from pathlib import Path, WindowsPath, PurePath
  15.         import string
  16.         import os, sys
  17.         from copy import copy
  18.  
  19.     except ImportError as e:
  20.         e = str(e).split()
  21.         print e
  22.         import pip
  23.         print 'Missing: ' + e[len(e)-1]
  24.         pip.main(['install', e[len(e)-1]])
  25.         pause = raw_input('Press Enter to continue')
  26.         del pause
  27.         Import()
  28.  
  29. class MainApp(tk.Frame):
  30.     def __init__(self,parent,*args,**kwargs):
  31.         tk.Frame.__init__(self,parent,*args,**kwargs)
  32.         self.parent = parent
  33.         self.entrys = []
  34.         self.height, self.width = k + 1, len(pL)
  35.         print self.height, self.width
  36.         a = 0
  37.         self.parent.title('Version Manager')
  38.         for j in range(self.width): #Columns
  39.             for i in range(self.height): #Rows
  40.                 exec('sv{} = tk.StringVar()'.format(a))
  41.                 exec('sv{}.trace("w",changeDir)'.format(a))
  42.                 self.grid_rowconfigure(i,weight=1); self.grid_columnconfigure(j,weight=1)
  43.                 exec('self.entrys.append(tk.Entry(self, text="",justify=tk.CENTER,textvariable={}))'.format(a))
  44.                 self.entrys[a].grid(row=i, column=j, sticky='NWSE')
  45.                 if i == 0:
  46.                     p = pL[j]
  47.                     self.entrys[a].insert(0,p)
  48.                 else:
  49.                     try:
  50.                         self.entrys[a].insert(0,projects[p][i-1])
  51.                     except:
  52.                         pass
  53.                 a += 1
  54.  
  55. class Script(object):
  56.     def __init__(self,path,project='Unsorted'):
  57.         if not path == WindowsPath or not path == PurePath:
  58.             path = Path(path)
  59.         self.path = path
  60.         self.project = project
  61.     def __repr__(self):
  62.         return str(self.path.name)
  63.  
  64. def changeDir(name):
  65.     sys.stdout.write(name)
  66.  
  67. def updateProj():
  68.     global projects, pL, k; k = 1
  69.     projects = {}
  70.     pL = []
  71.     for i in scripts:
  72.         if not i.project in pL:
  73.             pL.append(i.project)
  74.             d = 0
  75.         try:
  76.             projects[i.project].append(str(i))
  77.             d += 1
  78.         except:
  79.             projects[i.project] = [str(i)]
  80.             d += 1
  81.         if d >= k:
  82.             k = copy(d)
  83.     print projects
  84.  
  85. def getProj(path,project='Unsorted',inst=0):
  86.     p = Path(path)
  87.     for i in p.iterdir():
  88.         if str(i) == os.path.basename(__file__):
  89.             pass
  90.         elif str(i).endswith(".py"):
  91.             scripts.append(Script(i,project))
  92.         elif i.is_dir():
  93.             if inst != 1:
  94.                 getProj(i,project=str(i),inst=1)
  95.  
  96. if __name__ == '__main__':
  97.     global scripts
  98.     scripts = []
  99.     path = "./"
  100.     getProj(path)
  101.     updateProj()
  102.     root = tk.Tk()
  103.     MainApp(root).pack(side="top", fill="both", expand=True)
  104.     root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement