-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
genmakefile: Generate combined screenshots
It automatically detects `src/webview.png` file and creates screenshots in the `screenshots` directory. Issue: #5
- Loading branch information
1 parent
ba6c9fb
commit adda4bd
Showing
10 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
""" | ||
Copyright 2016 Jiří Janoušek <[email protected]> | ||
Copyright 2016-2018 Jiří Janoušek <[email protected]> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
@@ -35,6 +35,7 @@ | |
import nuvolasdk.datadir | ||
import nuvolasdk.appdata | ||
import nuvolasdk.addondata | ||
import nuvolasdk.createscreenshots | ||
|
||
def print_help(prog): | ||
print('Help') | ||
|
@@ -59,6 +60,9 @@ def print_help(prog): | |
print('\nCreate addon data XML') | ||
print('====================\n') | ||
nuvolasdk.addondata.create_arg_parser(prog + " create-addondata").print_help() | ||
print('\nCreate combined screenshots') | ||
print('===========================\n') | ||
nuvolasdk.createscreenshots.create_arg_parser(prog + " create-screenshots").print_help() | ||
|
||
def run(wd, argv): | ||
prog = os.path.basename(argv[0]) | ||
|
@@ -79,6 +83,8 @@ def run(wd, argv): | |
return nuvolasdk.appdata.run(wd, prog + " " + cmd, argv[2:]) or 0 | ||
if cmd == "create-addondata": | ||
return nuvolasdk.addondata.run(wd, prog + " " + cmd, argv[2:]) or 0 | ||
if cmd == "create-screenshots": | ||
return nuvolasdk.createscreenshots.run(wd, prog + " " + cmd, argv[2:]) or 0 | ||
if cmd == "data-dir": | ||
return nuvolasdk.datadir.run(wd, prog + " " + cmd, argv[2:]) or 0 | ||
if cmd in ('-h', '--help', 'help'): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Copyright 2014-2018 Jiří Janoušek <[email protected]> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
""" | ||
|
||
import argparse | ||
import datetime | ||
|
||
from nuvolasdk.shkit import * | ||
from nuvolasdk import defaults | ||
from nuvolasdk import imaging | ||
from nuvolasdk import screenshots | ||
from nuvolasdk import utils | ||
|
||
def create_arg_parser(prog): | ||
parser = argparse.ArgumentParser( | ||
prog = prog, | ||
description = 'Creates combined screenshots.' | ||
) | ||
parser.add_argument("--kind", help='The kind the app belongs to (e.g. audio, video, other).', type=str) | ||
parser.add_argument("--fill", help='The fill color for areas not covered by the web view snapshot."', type=str) | ||
parser.add_argument('-o', "--output-dir", help='The output directory to place screenshots to.', type=str) | ||
parser.add_argument('-i', "--input", help='The input web view screenshot.', type=str, required=True) | ||
return parser | ||
|
||
def run(directory, prog, argv): | ||
args = create_arg_parser(prog).parse_args(argv) | ||
output_dir = abspath(args.output_dir or directory) | ||
kind = args.kind or 'other' | ||
web_view_screenshot = abspath(args.input) | ||
screenshots_dir = utils.get_sdk_data_dir('screenshots') | ||
mkdirs(output_dir) | ||
for base, bounds, fill in screenshots.BASE_SCREENSHOTS[kind]: | ||
input_path = joinpath(screenshots_dir, base) | ||
output_path = joinpath(output_dir, base) | ||
print("'%s' → '%s'" % (input_path, output_path)) | ||
img = imaging.combine_images(input_path, web_view_screenshot, bounds, args.fill or fill) | ||
img.save(output_path, 'PNG', optimize=True) | ||
|
||
path = joinpath(output_dir, defaults.SCREENSHOTS_DIR_TIMESTAMP) | ||
print("Timestamp file: '%s'" % path) | ||
fwrite(path, datetime.datetime.now().isoformat()) | ||
return 0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
""" | ||
Copyright 2014-2016 Jiří Janoušek <[email protected]> | ||
Copyright 2014-2018 Jiří Janoušek <[email protected]> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
@@ -37,7 +37,7 @@ | |
] | ||
} | ||
|
||
GITIGNORE = "Makefile\nmetadata.json\nicons\n" | ||
GITIGNORE = "Makefile\nmetadata.json\nicons\n/screenshots/\n" | ||
|
||
METADATA_IN_JSON = OrderedDict(( | ||
("id", "happy_songs"), | ||
|
@@ -56,3 +56,7 @@ | |
)) | ||
|
||
CONFIGURE_SCRIPT = "#!/usr/bin/env python3\nimport nuvolasdk\nnuvolasdk.gen_makefile(\"%s\")\n" % VERSION | ||
|
||
WEB_VIEW_IMAGE = 'src/webview.png' | ||
|
||
SCREENSHOTS_DIR_TIMESTAMP = 'timestamp.txt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Copyright 2018 Jiří Janoušek <[email protected]> | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
""" | ||
|
||
try: | ||
from PIL import Image | ||
except ImportError as e: | ||
Image = e | ||
|
||
def combine_images(outer, inner, bounds, fill=None): | ||
if isinstance(Image, ImportError): | ||
raise Image | ||
if not isinstance(outer, Image.Image): | ||
outer = Image.open(outer) | ||
if not isinstance(inner, Image.Image): | ||
inner = Image.open(inner) | ||
if isinstance(bounds, str): | ||
bounds = tuple(int(i) for i in bounds.replace('+', ',').split(',')) | ||
result = Image.new('RGB', outer.size, fill) | ||
x, y, width, height = bounds | ||
x_offset = int((width - inner.size[0]) / 2) | ||
y_offset = int((height - inner.size[1]) / 2) | ||
result.paste(inner, (x + x_offset, y + y_offset), inner if inner.mode == 'RGBA' else None) | ||
result.paste(outer, (0, 0), outer if outer.mode == 'RGBA' else None) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.