Advertisement
here2share

# list_sort_from_clipboard.py

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