Skip to content

Commit 87ea89e

Browse files
committed
move icon addition into mkshim400.py
1 parent ddf3a59 commit 87ea89e

File tree

3 files changed

+84
-72
lines changed

3 files changed

+84
-72
lines changed

make.py

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -185,72 +185,6 @@ def build_nsis(srcname, dstname, data):
185185
print("Execution failed:", e, file=sys.stderr)
186186
os.remove(dstname)
187187

188-
def checkPath(path, mode):
189-
""" from https://gist.github.com/flyx/2965682 """
190-
import os, os.path
191-
if not os.path.exists(path) or not os.path.isfile(path):
192-
raise ValueError("{0} does not exist or isn't a file.".format(path))
193-
if not os.access(path, mode):
194-
raise ValueError("Insufficient permissions: {0}".format(path))
195-
196-
def updateExecutableIcon(executablePath, iconPath):
197-
""" from https://gist.github.com/flyx/2965682 """
198-
import win32api, win32con
199-
import struct
200-
import math
201-
"""
202-
Updates the icon of a Windows executable file.
203-
"""
204-
205-
checkPath(executablePath, os.W_OK)
206-
checkPath(iconPath, os.R_OK)
207-
208-
handle = win32api.BeginUpdateResource(executablePath, False)
209-
210-
icon = open(iconPath, "rb")
211-
212-
fileheader = icon.read(6)
213-
214-
# Read icon data
215-
image_type, image_count = struct.unpack("xxHH", fileheader)
216-
print ("Icon file has type {0} and contains {1} images.".format(image_type, image_count))
217-
218-
icon_group_desc = struct.pack("<HHH", 0, image_type, image_count)
219-
icon_sizes = []
220-
icon_offsets = []
221-
222-
# Read data of all included icons
223-
for i in range(1, image_count + 1):
224-
imageheader = icon.read(16)
225-
width, height, colors, panes, bits_per_pixel, image_size, offset =\
226-
struct.unpack("BBBxHHLL", imageheader)
227-
print ("Image is {0}x{1}, has {2} colors in the palette, {3} planes, {4} bits per pixel.".format(
228-
width, height, colors, panes, bits_per_pixel));
229-
print ("Image size is {0}, the image content has an offset of {1}".format(image_size, offset));
230-
231-
icon_group_desc = icon_group_desc + struct.pack("<BBBBHHIH",
232-
width, # Icon width
233-
height, # Icon height
234-
colors, # Colors (0 for 256 colors)
235-
0, # Reserved2 (must be 0)
236-
panes, # Color planes
237-
bits_per_pixel, # Bits per pixel
238-
image_size, # ImageSize
239-
i # Resource ID
240-
)
241-
icon_sizes.append(image_size)
242-
icon_offsets.append(offset)
243-
244-
# Read icon content and write it to executable file
245-
for i in range(1, image_count + 1):
246-
icon_content = icon.read(icon_sizes[i - 1])
247-
print ("Read {0} bytes for image #{1}".format(len(icon_content), i))
248-
win32api.UpdateResource(handle, win32con.RT_ICON, i, icon_content)
249-
250-
win32api.UpdateResource(handle, win32con.RT_GROUP_ICON, "MAINICON", icon_group_desc)
251-
252-
win32api.EndUpdateResource(handle, False)
253-
254188

255189
def build_shimmy_launcher(launcher_name, command, icon_path, mkshim_program='mkshim400.py', workdir=''):
256190
"""Build .exe launcher with mkshim_program and pywin32"""
@@ -263,12 +197,12 @@ def build_shimmy_launcher(launcher_name, command, icon_path, mkshim_program='mks
263197
mkshim_command = f'{python_program} "{mkshim_program}" -f "{launcher_name}" -c "{command}"'
264198
if workdir !='': # V03 of shim: we can handle an optional sub-directory
265199
mkshim_command += f' --subdir "{workdir}"'
200+
# Embed the icon, if provided
201+
if Path(icon_path).is_file():
202+
mkshim_command += f' --i "{icon_path}"'
266203
print(f"Building .exe launcher with {mkshim_program}:", mkshim_command)
267204
subprocess.run(mkshim_command, shell=True)
268205

269-
# Embed the icon with pywin32, if provided
270-
if Path(icon_path).is_file():
271-
updateExecutableIcon(launcher_name, icon_path)
272206

273207
def build_iss(srcname, dstname, data):
274208
"""Build Inno Setup Script"""

mkshim400.py

Lines changed: 80 additions & 2 deletions
Large diffs are not rendered by default.

winpython/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
OTHER DEALINGS IN THE SOFTWARE.
2929
"""
3030

31-
__version__ = '10.4.20240904'
31+
__version__ = '10.5.20240905'
3232
__license__ = __doc__
3333
__project_url__ = 'http://winpython.github.io/'

0 commit comments

Comments
 (0)