Advertisement
here2share

# list_sort_from_clipboard.py

Nov 5th, 2018 (edited)
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. # list_sort_from_clipboard.py
  2.  
  3. from tkinter import *
  4. import re
  5. import string
  6. import webbrowser
  7. import tempfile
  8. import random
  9.  
  10. srcfilename=tempfile.mktemp(".html", "demo_")
  11.  
  12. web="""<!DOCTYPE html><b>@"""
  13.  
  14. root = Tk('200X200+1+1')
  15.    
  16. def clipb():
  17.     t = root.clipboard_get()
  18.     L=[]
  19.     if '#' in t:
  20.         a,b = [z.splitlines() for z in t.split('#')]
  21.         a.sort()
  22.         random.shuffle(b)
  23.         t = a+['#']+b
  24.     else:
  25.         t = t.splitlines()
  26.     for z in t:
  27.         z = z.strip()
  28.         if z and z not in L:
  29.             L+=[z]
  30.         else:
  31.             if z:
  32.                 print( '*** removed', z)
  33.     print()
  34.     print()
  35.     r = []
  36.     for z in L:
  37.         try:
  38.             r.append(z)
  39.         except:
  40.             s=''
  41.             for char in z:
  42.                 if char in string.letters+' ': s+=char
  43.                 else: s+='_'
  44.             r.append(s)
  45.  
  46.     r='<br>'.join(r)
  47.     r = r.replace('#','#'+'<br>'*20)
  48.     temp=open(srcfilename, 'w')
  49.     temp.write(web.replace('@',r))
  50.     temp.close()
  51.     webbrowser.open_new_tab(srcfilename)
  52.    
  53.  
  54. Frame=LabelFrame(root,height=200,width=200,borderwidth=0,bg="light blue") # note: width=200 minimal
  55. Frame.pack(fill=X)
  56. Frame.pack_propagate(False)
  57.  
  58. Label(Frame,text="Fix Lists Onto Browser",bg="light blue").pack(anchor=NW)
  59.  
  60. cpb=Button(Frame,text="Copy From Clipboard",command=clipb)
  61. cpb.pack()
  62.  
  63.  
  64. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement