PageRenderTime 71ms CodeModel.GetById 53ms RepoModel.GetById 0ms app.codeStats 0ms

/original/base.app/Contents/Resources/magnetizer.py

https://github.com/aleray/datateb
Python | 95 lines | 37 code | 9 blank | 49 comment | 3 complexity | 044617a67748ec182f0956d83bd4b3d4 MD5 | raw file
Possible License(s): GPL-3.0
  1. #!/usr/local/bin/python
  2. # -*- coding: utf-8 -*-
  3. from AppKit import NSSound
  4. from appscript import *
  5. # from mactypes import Alias
  6. # import osax
  7. # import sys
  8. import time
  9. import os, sys
  10. # import os, sys
  11. # import EasyDialogs
  12. # Play a sound
  13. snd = "electricity.wav"
  14. sound = NSSound.alloc()
  15. sound.initWithContentsOfFile_byReference_('/Users/aleray/Desktop/Magnetize.app/Contents/Resources/electricity.wav', True)
  16. #sound.Loops(100)
  17. sound.play()
  18. fi = app('Finder')
  19. droplet = fi.desktop.items[its.name=='Magnetize.app'].get()[0]
  20. dropletX, dropletY = droplet.desktop_position.get()
  21. items = fi.desktop.items[its.name_extension=='doc'].get()
  22. items += fi.desktop.items[its.name_extension=='ppt'].get()
  23. items += fi.desktop.items[its.name_extension=='dwf'].get()
  24. items += fi.desktop.items[its.name_extension=='xls'].get()
  25. # for i in range(100):
  26. # for item in items:
  27. # itemX, itemY = item.desktop_position.get()
  28. # newX = itemX+((dropletX-itemX)*30/100)
  29. # print newX
  30. # newY = itemY+((dropletY-itemY)*30/100)
  31. # print newY
  32. # item.desktop_position.set([newX, newY])
  33. # time.sleep(0.01)
  34. friction = 1.1
  35. i = 3000
  36. def move(items):
  37. global i
  38. global friction
  39. global sound
  40. for item in items:
  41. itemX, itemY = item.desktop_position.get()
  42. itemX += (dropletX-itemX)/i
  43. itemX = round(itemX)
  44. itemY += (dropletY-itemY)/i
  45. itemY = round(itemY)
  46. item.desktop_position.set([itemX, itemY])
  47. if itemX==dropletX:
  48. items.remove(item)
  49. print item, "removed"
  50. item.delete()
  51. time.sleep(0.01)
  52. if len(items)>=1:
  53. i = i/friction
  54. move(items)
  55. # else:
  56. # sound.stop()
  57. move(items)
  58. #
  59. # while len(items)>=1:
  60. # for item in items:
  61. # itemX, itemY = item.desktop_position.get()
  62. # if abs(itemX)<=dropletX+3:
  63. # items.remove(item)
  64. # print item, "removed"
  65. # itemX += (dropletX-itemX)/i
  66. # itemX = round(itemX)
  67. # itemY += (dropletY-itemY)/i
  68. # itemY = round(itemY)
  69. # print itemX
  70. # item.desktop_position.set([itemX, itemY])
  71. # time.sleep(0.1)
  72. # i = i/friction
  73. # while len(items)>=1:
  74. # print "1"
  75. # for item in items:
  76. # itemX, itemY = item.desktop_position.get()
  77. # if itemX==dropletX:
  78. # items.remove(item)
  79. # print item, "removed"
  80. # item.delete()
  81. # newX = itemX+((dropletX-itemX)/10)
  82. # newY = itemY+((dropletY-itemY)/10)
  83. # item.desktop_position.set([newX, newY])
  84. # time.sleep(0.1)
  85. #
  86. # os.system("killall mplayer")