SHARE
TWEET

Untitled

a guest May 23rd, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Tkinter as tk, os, StringIO
  2. from PIL import Image, ImageTk
  3.  
  4. ##################################
  5. # To use:
  6. # pip install Pillow
  7. # pip install Tkinter
  8. #
  9. ##################################
  10.  
  11. #size of window
  12. windowsize = "430x430"
  13. #xy location of window
  14. #windowloc = "85+97"
  15. windowloc = "74+88"
  16. #string to initiate window
  17. geo = windowsize + "+" + windowloc
  18. #size of art, we set it to same size as window here
  19. size = map(int, (windowsize.split("x")))
  20. #music folder
  21. music_dir = "/Volumes/ext/flac/"
  22. #delay before checking for updates
  23. delay = 1000
  24. #color for idle/stopped art
  25. color = "#0A0A0A"
  26.  
  27. #gets cover.jpg of song that is playing
  28. def GetCover():
  29.     #make string where we find the alb art
  30.     current = os.popen("mpc current -f '%file%'").read()
  31.     if len(current) > 1:
  32.         song = current.split("/")
  33.         np = music_dir + song[0] + "/" + song[1] + "/" + "cover.jpg"
  34.     else:
  35.         np = Stoped(color)
  36.     return np
  37.  
  38. #Creates single color img for stopped/idle mpc
  39. def Stoped(color):
  40.     img = Image.new("RGB", [1,1], color)
  41.     cover = StringIO.StringIO()
  42.     img.save(cover, format="JPEG")
  43.     return cover
  44.  
  45. #returns image of the art we just got resized to our window size
  46. def GetArt():
  47.     art = Image.open(GetCover()).resize((size[0], size[1]), Image.ANTIALIAS)
  48.     return art
  49.  
  50. #initiate window class
  51. root = tk.Tk()
  52. root.geometry(geo)
  53. # eliminate the titlebar
  54. root.overrideredirect(1)
  55.  
  56. panel = tk.Label(root)
  57. panel.pack(side="bottom", fill="both", expand="yes")
  58. img = None
  59.  
  60. #loop that displays art and updates every second
  61. def UpdateLoop():
  62.     img = ImageTk.PhotoImage(GetArt())
  63.     panel.config(image=img)
  64.     panel.img = img
  65.     root.update_idletasks()
  66.     root.after(delay,UpdateLoop)
  67.  
  68. UpdateLoop()
  69. root.mainloop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top