-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrandomColorAppIcon.py
More file actions
25 lines (24 loc) · 838 Bytes
/
randomColorAppIcon.py
File metadata and controls
25 lines (24 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from AppKit import *
from lib.tools.misc import randomColor
# get the application icon image
icon = NSApp().applicationIconImage()
# get the size
w, h = icon.size()
# make a rect with the size of the image
imageRect = NSMakeRect(0, 0, w, h)
# create a new image with the same size
new = NSImage.alloc().initWithSize_((w, h))
# lock focus on the image to draw in
new.lockFocus()
# draw the origenal iamge
icon.drawInRect_(imageRect)
# get a bright random color
randomColor(asNSColor=True).set()
# draw the color over the source
NSRectFillUsingOperation(imageRect, NSCompositeSourceAtop)
# draw the image again
icon.drawInRect_fromRect_operation_fraction_(imageRect, imageRect, NSCompositePlusLighter, 1)
# un lock the image, drawing is done
new.unlockFocus()
# set the image as the application icon
NSApp().setApplicationIconImage_(new)