import os, sys from Tkinter import * # Configure ------------------------------------------------------------ CONFIGFILE = '~/.ZopeEditDirectories' # /Configure ----------------------------------------------------------- CONFIGFILE = os.path.expanduser(CONFIGFILE) # read the file if os.path.isfile(CONFIGFILE): DIRS = [x.strip() for x in file(CONFIGFILE).readlines()] else: DIRS = [] _base = os.path.expanduser('~/zope') for d in os.listdir(_base): print d, os.path.isdir(d), d.find('zope') if os.path.isdir(os.path.join(_base, d)) and d.find('zope') >-1: DIRS.append(os.path.join(_base, d)) #------------------------------------------------------------------------------ class App: def __init__(self, master): frame = Frame(master) frame.pack() c =0 for path in DIRS: _callback = eval ("lambda: remember_path(%r)" % path) b = Button(frame, text=path.split('/')[-1], command=_callback) setattr(self, 'btn_%s'%c, b) #self.btn = b #self.btn.pack(side=TOP) getattr(self, 'btn_%s'%c).pack(side=TOP) c += 1 self.button = Button(frame, text="QUIT", fg="red", command=frame.quit) self.button.pack(side=BOTTOM) def moveUpListelement(element, xlist): """ move an element in a _mutable_ list up one position if possible. If the element is a list, then the function is self recursivly called for each subelement. """ assert type(xlist)==type([]), "List to change not of list type "\ "(%r)"%type(xlist) if type(element)==type([]): for subelement in element: moveUpListelement(subelement, xlist) if element==xlist[0]: pass elif element in xlist: i=xlist.index(element) xlist[i], xlist[i-1] = xlist[i-1], xlist[i] def remember_path(desired_path): # puts it up one position: moveUpListelement(desired_path, DIRS) #DIRS.remove(desired_path) #DIRS.insert(0, desired_path) as_string = '\n'.join(DIRS) w=file(CONFIGFILE, 'w').write(as_string) print desired_path sys.exit(0) root = Tk() app = App(root) root.mainloop()