Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_multi_clipboard.py ZZZ tabspaces oddly disappears from listbox
- import os
- import time
- import string
- import subprocess
- from Tkinter import *
- root=Tk()
- root.title('Multi-Clipboard')
- class Cv: 0
- cv=Cv()
- def yview(*args):
- if len(args) is 1:
- args="scroll", args, "units"
- select1.yview(*args)
- multi.yview(*args)
- 0
- def OnMouseWheel(event): # ZZZ ?
- d=-0.2
- if event.delta < 1:
- d=0.2
- # to sync listboxes
- d+=cv.yDuoScroll
- cv.yDuoScroll=min(1,max(0,d))
- select1.yview('moveto', str(d))
- multi.yview('moveto', str(d))
- return 'break'
- 0
- data=['' for z in range(100)]
- def add_row(): # ZZZ Save To Primary
- if len(data) < 99:
- data.insert(20, select2.get(1.0, END))
- renew_listbox()
- else:
- print "Copy Not Saved To Primary. List Is Full"
- 0
- def delete_row(): # ZZZ
- pass
- 0
- def edit_pro():
- if cv.file.closed:
- root.attributes('-disabled',0)
- return
- print '???'
- root.after(3000, edit_pro)
- 0
- def edit(): # ZZZ
- root.attributes('-disabled',1)
- for z in root.attributes(): print z
- try:
- sss=files[data[cv.ddd]]
- except:
- sss=dir+'\\'+str(time.clock())[4:-4]+'__temp.txt'
- file=open(sss, 'w')
- file.write(data[cv.ddd])
- file.close()
- subprocess.Popen(['notepad++.exe', sss])
- cv.file = open(sss)
- edit_pro()
- 0
- topframe=Frame(root)
- topframe.grid()
- b3=Button(topframe , text='Main Text Editor', bg='yellow', command=edit)
- b3.grid(column=0, row=0)
- Label(topframe , text=' '*4).grid(column=1, row=0)
- b1=Button(topframe , text='Add Row', bg='yellow', command=add_row)
- b1.grid(column=2, row=0)
- b2=Button(topframe , text='Delete Selected', bg='yellow', command=delete_row)
- b2.grid(column=3, row=0)
- frame=Frame(root)
- frame.grid()
- scroll=Scrollbar(frame, orient=VERTICAL, command=yview)
- select1=Listbox(frame, height=30, width=40, selectmode=SINGLE, selectbackground='purple') # ZZZ selectmode=MULTIPLE
- # + exportselection=False
- select1.config(yscrollcommand=scroll.set)
- select1.grid(column=1, row=1, sticky='ns')
- multi=Listbox(frame, height=30, width=2, selectmode=MULTIPLE, selectbackground='red')
- multi.config(yscrollcommand=scroll.set)
- multi.grid(column=0, row=1, sticky='ns')
- for z in range(100):
- multi.insert(END,'')
- cbg='white'
- if z % 2: cbg='#CCCCFF'
- multi.itemconfigure(z, fg='black', bg=cbg)
- 0
- scroll.grid(column=2, row=1, sticky='ns')
- label=Label(root)
- label.grid(column=3, row=1)
- select2=Text(label, height=30, width=120)
- scroll2=Scrollbar(root, orient=VERTICAL, command=yview)
- select2.config(yscrollcommand=scroll2.set)
- select2.grid(sticky='news')
- scroll2.grid(column=4, row=1, sticky='ns')
- cv.ddd=0
- cv.prev=''
- cv.tab=0
- cv.yDuoScroll=0
- cv.active='textbox'
- files={}
- dir=os.path.join(os.path.expanduser('~'))+'\\Documents\\MultiClip'
- print dir
- def select_data(): # ZZZ
- global data
- if not os.path.exists(dir):
- print "Path: " , dir , " Not Found"
- ans=raw_input("Create That Directory? (y/n) ")
- if 'y' in ans.lower():
- try:
- os.mkdir(dir)
- print "Directory ", dir ," Created "
- except:
- print "Unable To Create Directory ", dir
- return
- byDate=[]
- for z,f in enumerate(os.listdir(dir)[:80]):
- f=dir+'\\'+f
- byDate.append([os.path.getmtime(f),f])
- byDate.sort(reverse=True)
- for z,f in enumerate(byDate):
- file=open(f[-1], 'r')
- s=file.read()
- data[z+20]=s
- files.update({s: f[-1]})
- 0
- def renew_listbox():
- select1.delete(0, END)
- for z,content in enumerate(data):
- if not content.strip():
- content=''
- n=str(z+1).zfill(3)+':'
- if z < 20:
- n+=u" \u25BC" # '\u25B2' is upward
- select1.insert(END,'%s %s' % (n, content.lstrip()))
- cbg='white'
- if z % 2: cbg='#CCCCFF'
- select1.itemconfigure(z, fg='black', bg=cbg)
- select1.itemconfigure(cv.ddd, fg='white', bg='purple')
- select1.activate(cv.ddd)
- 0
- def diff(x,y): # because ACTIVE and ANCHOR failed in multiple mode
- z=max([tuple(set(x).difference(set(y))) for x,y in [(x,y),(y,x)]])
- if z:
- return z[-1]
- return cv.ddd
- 0
- def OnSelect(e):
- z=cv.ddd
- w=e.widget
- try: cv.ddd=w.curselection()[-1]
- except: 0
- n=cv.ddd
- cbg='white'
- if z % 2: cbg='#CCCCFF'
- select1.itemconfigure(z, fg='black', bg=cbg)
- sss=data[n]
- setClipboardData()
- select2.delete(1.0, END)
- select2.insert(END, sss)
- 0
- def OnChange(e):
- n=cv.ddd
- sss=data[n]
- s=e.char
- try:
- c=ord(s)
- except:
- return
- if c == 8: sss=sss[:-1]
- elif c == 13: sss+='\n'
- elif c == 9: sss+='\t' # ZZZ ?????
- else: sss+=s
- #sss=''.join(s for s in sss if s in string.printable)
- try:
- files[sss]=files.pop(data[n])
- except:
- 0
- data[n]=sss
- OnSelect(e)
- renew_listbox()
- 0
- def getClipboardData():
- try:
- z=root.clipboard_get()
- return z
- except:
- return ''
- 0
- def setClipboardData():
- root.clipboard_clear()
- root.clipboard_append(data[cv.ddd])
- 0
- def loop_check():
- sss=getClipboardData()
- if sss:
- if sss not in data: # ZZZ
- data.insert(0,sss)
- data.pop(20)
- select2.delete(1.0, END)
- select2.insert(END, sss)
- cv.ddd=0
- renew_listbox()
- root.after(5000, loop_check)
- 0
- select1.bind('<<ListboxSelect>>', OnSelect)
- root.bind('<Key>', OnChange)
- scroll.bind_all('<MouseWheel>', OnMouseWheel)
- select_data()
- renew_listbox()
- loop_check()
- root.mainloop()
Add Comment
Please, Sign In to add comment