dmg-builder 26.0.16 → 26.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,37 +1,61 @@
1
- # -*- coding: utf-8 -*-
2
- from __future__ import unicode_literals
3
-
4
- from Quartz import *
5
1
  import math
6
2
 
7
- _REMOVABLE_DISK_PATH = '/System/Library/Extensions/IOStorageFamily.kext/Contents/Resources/Removable.icns'
3
+ from Quartz import (
4
+ CFURLCreateWithFileSystemPath,
5
+ CGBitmapContextCreate,
6
+ CGBitmapContextCreateImage,
7
+ CGColorSpaceCreateWithName,
8
+ CGImageDestinationAddImage,
9
+ CGImageDestinationCreateWithURL,
10
+ CGImageDestinationFinalize,
11
+ CGImageSourceCopyPropertiesAtIndex,
12
+ CGImageSourceCreateImageAtIndex,
13
+ CGImageSourceCreateWithURL,
14
+ CGImageSourceGetCount,
15
+ CIContext,
16
+ CIFilter,
17
+ CIImage,
18
+ CIVector,
19
+ NSAffineTransform,
20
+ kCFURLPOSIXPathStyle,
21
+ kCGColorSpaceGenericRGB,
22
+ kCGImageAlphaPremultipliedLast,
23
+ kCIInputAspectRatioKey,
24
+ kCIInputBackgroundImageKey,
25
+ kCIInputImageKey,
26
+ kCIInputScaleKey,
27
+ kCIOutputImageKey,
28
+ )
29
+
30
+ _REMOVABLE_DISK_PATH = (
31
+ "/System/Library/Extensions/IOStorageFamily.kext/Contents/Resources/Removable.icns"
32
+ )
33
+
8
34
 
9
35
  def badge_disk_icon(badge_file, output_file):
10
36
  # Load the Removable disk icon
11
- url = CFURLCreateWithFileSystemPath(None, _REMOVABLE_DISK_PATH,
12
- kCFURLPOSIXPathStyle, False)
37
+ url = CFURLCreateWithFileSystemPath(
38
+ None, _REMOVABLE_DISK_PATH, kCFURLPOSIXPathStyle, False
39
+ )
13
40
  backdrop = CGImageSourceCreateWithURL(url, None)
14
41
  backdropCount = CGImageSourceGetCount(backdrop)
15
-
42
+
16
43
  # Load the badge
17
- url = CFURLCreateWithFileSystemPath(None, badge_file,
18
- kCFURLPOSIXPathStyle, False)
44
+ url = CFURLCreateWithFileSystemPath(None, badge_file, kCFURLPOSIXPathStyle, False)
19
45
  badge = CGImageSourceCreateWithURL(url, None)
20
- assert badge is not None, 'Unable to process image file: %s' % badge_file
46
+ assert badge is not None, "Unable to process image file: %s" % badge_file
21
47
  badgeCount = CGImageSourceGetCount(badge)
22
-
48
+
23
49
  # Set up a destination for our target
24
- url = CFURLCreateWithFileSystemPath(None, output_file,
25
- kCFURLPOSIXPathStyle, False)
26
- target = CGImageDestinationCreateWithURL(url, 'com.apple.icns',
27
- backdropCount, None)
50
+ url = CFURLCreateWithFileSystemPath(None, output_file, kCFURLPOSIXPathStyle, False)
51
+ target = CGImageDestinationCreateWithURL(url, "com.apple.icns", backdropCount, None)
28
52
 
29
53
  # Get the RGB colorspace
30
54
  rgbColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)
31
55
 
32
56
  # Scale
33
57
  scale = 1.0
34
-
58
+
35
59
  # Perspective transform
36
60
  corners = ((0.2, 0.95), (0.8, 0.95), (0.85, 0.35), (0.15, 0.35))
37
61
 
@@ -40,104 +64,106 @@ def badge_disk_icon(badge_file, output_file):
40
64
 
41
65
  for n in range(backdropCount):
42
66
  props = CGImageSourceCopyPropertiesAtIndex(backdrop, n, None)
43
- width = props['PixelWidth']
44
- height = props['PixelHeight']
45
- dpi = props['DPIWidth']
46
- depth = props['Depth']
47
-
67
+ width = props["PixelWidth"]
68
+ height = props["PixelHeight"]
69
+ dpi = props["DPIWidth"]
70
+ depth = props["Depth"]
71
+
48
72
  # Choose the best sized badge image
49
73
  bestWidth = None
50
- bestHeight = None
74
+ # ?? bestHeight = None
51
75
  bestBadge = None
52
76
  bestDepth = None
53
- bestDPI = None
77
+ # ?? bestDPI = None
54
78
  for m in range(badgeCount):
55
79
  badgeProps = CGImageSourceCopyPropertiesAtIndex(badge, m, None)
56
- badgeWidth = badgeProps['PixelWidth']
57
- badgeHeight = badgeProps['PixelHeight']
58
- badgeDPI = badgeProps['DPIWidth']
59
- badgeDepth = badgeProps['Depth']
60
-
61
- if bestBadge is None or (badgeWidth <= width
62
- and (bestWidth > width
63
- or badgeWidth > bestWidth
64
- or (badgeWidth == bestWidth
65
- and badgeDPI == dpi
66
- and badgeDepth <= depth
67
- and (bestDepth is None
68
- or badgeDepth > bestDepth)))):
80
+ badgeWidth = badgeProps["PixelWidth"]
81
+ # ?? badgeHeight = badgeProps['PixelHeight']
82
+ badgeDPI = badgeProps["DPIWidth"]
83
+ badgeDepth = badgeProps["Depth"]
84
+
85
+ if bestBadge is None or (
86
+ badgeWidth <= width
87
+ and (
88
+ bestWidth > width
89
+ or badgeWidth > bestWidth
90
+ or (
91
+ badgeWidth == bestWidth
92
+ and badgeDPI == dpi
93
+ and badgeDepth <= depth
94
+ and (bestDepth is None or badgeDepth > bestDepth)
95
+ )
96
+ )
97
+ ):
69
98
  bestBadge = m
70
99
  bestWidth = badgeWidth
71
- bestHeight = badgeHeight
72
- bestDPI = badgeDPI
100
+ # ?? bestHeight = badgeHeight
101
+ # ?? bestDPI = badgeDPI
73
102
  bestDepth = badgeDepth
74
103
 
75
104
  badgeImage = CGImageSourceCreateImageAtIndex(badge, bestBadge, None)
76
105
  badgeCI = CIImage.imageWithCGImage_(badgeImage)
77
-
106
+
78
107
  backgroundImage = CGImageSourceCreateImageAtIndex(backdrop, n, None)
79
108
  backgroundCI = CIImage.imageWithCGImage_(backgroundImage)
80
-
81
- compositor = CIFilter.filterWithName_('CISourceOverCompositing')
82
- lanczos = CIFilter.filterWithName_('CILanczosScaleTransform')
83
- perspective = CIFilter.filterWithName_('CIPerspectiveTransform')
84
- transform = CIFilter.filterWithName_('CIAffineTransform')
85
-
109
+
110
+ compositor = CIFilter.filterWithName_("CISourceOverCompositing")
111
+ lanczos = CIFilter.filterWithName_("CILanczosScaleTransform")
112
+ perspective = CIFilter.filterWithName_("CIPerspectiveTransform")
113
+ transform = CIFilter.filterWithName_("CIAffineTransform")
114
+
86
115
  lanczos.setValue_forKey_(badgeCI, kCIInputImageKey)
87
- lanczos.setValue_forKey_(scale * float(width)/bestWidth, kCIInputScaleKey)
116
+ lanczos.setValue_forKey_(scale * float(width) / bestWidth, kCIInputScaleKey)
88
117
  lanczos.setValue_forKey_(1.0, kCIInputAspectRatioKey)
89
118
 
90
- topLeft = (width * scale * corners[0][0],
91
- width * scale * corners[0][1])
92
- topRight = (width * scale * corners[1][0],
93
- width * scale * corners[1][1])
94
- bottomRight = (width * scale * corners[2][0],
95
- width * scale * corners[2][1])
96
- bottomLeft = (width * scale * corners[3][0],
97
- width * scale * corners[3][1])
119
+ topLeft = (width * scale * corners[0][0], width * scale * corners[0][1])
120
+ topRight = (width * scale * corners[1][0], width * scale * corners[1][1])
121
+ bottomRight = (width * scale * corners[2][0], width * scale * corners[2][1])
122
+ bottomLeft = (width * scale * corners[3][0], width * scale * corners[3][1])
98
123
 
99
124
  out = lanczos.valueForKey_(kCIOutputImageKey)
100
125
  if width >= 16:
101
126
  perspective.setValue_forKey_(out, kCIInputImageKey)
102
- perspective.setValue_forKey_(CIVector.vectorWithX_Y_(*topLeft),
103
- 'inputTopLeft')
104
- perspective.setValue_forKey_(CIVector.vectorWithX_Y_(*topRight),
105
- 'inputTopRight')
106
- perspective.setValue_forKey_(CIVector.vectorWithX_Y_(*bottomRight),
107
- 'inputBottomRight')
108
- perspective.setValue_forKey_(CIVector.vectorWithX_Y_(*bottomLeft),
109
- 'inputBottomLeft')
127
+ perspective.setValue_forKey_(
128
+ CIVector.vectorWithX_Y_(*topLeft), "inputTopLeft"
129
+ )
130
+ perspective.setValue_forKey_(
131
+ CIVector.vectorWithX_Y_(*topRight), "inputTopRight"
132
+ )
133
+ perspective.setValue_forKey_(
134
+ CIVector.vectorWithX_Y_(*bottomRight), "inputBottomRight"
135
+ )
136
+ perspective.setValue_forKey_(
137
+ CIVector.vectorWithX_Y_(*bottomLeft), "inputBottomLeft"
138
+ )
110
139
  out = perspective.valueForKey_(kCIOutputImageKey)
111
140
 
112
141
  tfm = NSAffineTransform.transform()
113
- tfm.translateXBy_yBy_(math.floor((position[0] - 0.5 * scale) * width),
114
- math.floor((position[1] - 0.5 * scale) * height))
142
+ tfm.translateXBy_yBy_(
143
+ math.floor((position[0] - 0.5 * scale) * width),
144
+ math.floor((position[1] - 0.5 * scale) * height),
145
+ )
115
146
 
116
147
  transform.setValue_forKey_(out, kCIInputImageKey)
117
- transform.setValue_forKey_(tfm, 'inputTransform')
148
+ transform.setValue_forKey_(tfm, "inputTransform")
118
149
  out = transform.valueForKey_(kCIOutputImageKey)
119
-
150
+
120
151
  compositor.setValue_forKey_(out, kCIInputImageKey)
121
152
  compositor.setValue_forKey_(backgroundCI, kCIInputBackgroundImageKey)
122
153
 
123
154
  result = compositor.valueForKey_(kCIOutputImageKey)
124
155
 
125
- cgContext = CGBitmapContextCreate(None,
126
- width,
127
- height,
128
- 8,
129
- 0,
130
- rgbColorSpace,
131
- kCGImageAlphaPremultipliedLast)
156
+ cgContext = CGBitmapContextCreate(
157
+ None, width, height, 8, 0, rgbColorSpace, kCGImageAlphaPremultipliedLast
158
+ )
132
159
  context = CIContext.contextWithCGContext_options_(cgContext, None)
133
160
 
134
- context.drawImage_inRect_fromRect_(result,
135
- ((0, 0), (width, height)),
136
- ((0, 0), (width, height)))
161
+ context.drawImage_inRect_fromRect_(
162
+ result, ((0, 0), (width, height)), ((0, 0), (width, height))
163
+ )
137
164
 
138
165
  image = CGBitmapContextCreateImage(cgContext)
139
166
 
140
167
  CGImageDestinationAddImage(target, image, props)
141
168
 
142
169
  CGImageDestinationFinalize(target)
143
-