Skip to content

Commit 9e6ddb1

Browse files
committed
Add customization for welcome and header image texts
1 parent a7c9de2 commit 9e6ddb1

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

CONSTRUCT.md

+12
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,15 @@ The color of the default images (when not providing explicit image files)
132132
used on Windows. Possible values are `red`, `green`, `blue`, `yellow`.
133133
The default is `blue`.
134134

135+
136+
`welcome_image_text`:
137+
----------------
138+
If `welcome_image` is not provided, use this text when generating the image
139+
(Windows only). Defaults to `name`.
140+
141+
142+
`header_image_text`:
143+
----------------
144+
If `header_image` is not provided, use this text when generating the image
145+
(Windows only). Defaults to `name`.
146+

constructor/construct.py

+10
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@
130130
The color of the default images (when not providing explicit image files)
131131
used on Windows. Possible values are `red`, `green`, `blue`, `yellow`.
132132
The default is `blue`.
133+
'''),
134+
135+
('welcome_image_text', False, str, '''
136+
If `welcome_image` is not provided, use this text when generating the image
137+
(Windows only). Defaults to `name`.
138+
'''),
139+
140+
('header_image_text', False, str, '''
141+
If `header_image` is not provided, use this text when generating the image
142+
(Windows only). Defaults to `name`.
133143
'''),
134144
]
135145

constructor/imaging.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,33 @@ def new_background(size, color, bs=20, boxes=50):
2929
return im
3030

3131

32+
def add_text(im, xy, text, min_lines, line_height, font, color):
33+
x, y = xy
34+
d = ImageDraw.Draw(im)
35+
lines = text.splitlines()
36+
text_height = len(lines) * line_height
37+
min_text_height = min_lines * line_height
38+
y = int(y * (im.height - text_height) / (im.height - min_text_height))
39+
for line in text.splitlines():
40+
d.text((x, y), line, fill=color, font=font)
41+
y += line_height
42+
return d
43+
44+
3245
def mk_welcome_image(info):
3346
font = ImageFont.truetype(ttf_path, 20)
3447
im = new_background(welcome_size, info['_color'])
35-
d = ImageDraw.Draw(im)
36-
d.text((20, 100), info['name'], fill=white, font=font)
37-
d.text((20, 130), info['version'], fill=white, font=font)
48+
text = '\n'.join([info['welcome_image_text'], info['version']])
49+
add_text(im, (20, 100), text, 2, 30, font, white)
3850
return im
3951

4052

4153
def mk_header_image(info):
4254
font = ImageFont.truetype(ttf_path, 20)
4355
im = Image.new('RGB', header_size, color=white)
44-
d = ImageDraw.Draw(im)
45-
d.text((20, 15), info['name'], fill=info['_color'], font=font)
56+
text = info['header_image_text']
57+
color = info['_color']
58+
add_text(im, (20, 15), text, 1, 20, font, color)
4659
return im
4760

4861

constructor/main.py

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def main_build(dir_path, output_dir='.', platform=cc_platform,
6565
if verbose:
6666
print('conda packages download: %s' % info['_download_dir'])
6767

68+
for key in ('welcome_image_text', 'header_image_text'):
69+
if key not in info:
70+
info[key] = info['name']
71+
6872
for key in ('license_file', 'welcome_image', 'header_image', 'icon_image',
6973
'pre_install', 'post_install'):
7074
if key in info:

examples/grin/construct.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,12 @@ license_file: eula.txt
4747

4848
# default install prefix
4949
#default_prefix: /opt/example
50+
51+
# If `welcome_image` or `header_image` are not provided, their texts
52+
# default to `name`, which may be overridden by the following keys
53+
#welcome_image_text: |-
54+
# multi-line
55+
# welcome-text
56+
#header_image_text: |-
57+
# multi-line
58+
# header-text

0 commit comments

Comments
 (0)