source: src/python/bin/gnuboat-splashscreen@ 9f28f0a

debian/bullseye
Last change on this file since 9f28f0a was b45e75d, checked in by Joachim Langenbach <joachim.langenbach@…>, 9 years ago
  • Changed all % string formattings into string.format
  • Changed all print "" calls into print() calls
  • Property mode set to 100755
File size: 2.2 KB
Line 
1#!/usr/bin/python
2'''
3 Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17'''
18
19import sys
20import os
21import getopt
22try:
23 from PIL import Image
24 from PIL import ImageOps
25 from EPD import EPD
26 epdEnabled = True
27except:
28 epdEnabled = False
29
30
31def displayImage(epd, imageFilePath):
32 image = Image.open(imageFilePath)
33 image = ImageOps.grayscale(image)
34 imageResized = image.resize((epd.width, epd.height))
35 imageBlackWhite = imageResized.convert("1", dither=Image.FLOYDSTEINBERG)
36 epd.display(imageBlackWhite)
37 epd.update()
38
39
40def usage():
41 print("Usage of gnuboat-splashscreen:")
42 print(" gnuboat-splashscreen [-h] -i PATH_TO_IMAGE_TO_DISPLAY")
43 print("")
44 print(" -h --help Print this help")
45 print(" -i --image Path to the image, which should be displayed")
46 sys.exit()
47
48
49def main(argv):
50 image = ""
51 try:
52 opts, args = getopt.getopt(argv, "hi:", ["help", "image="])
53 except getopt.GetoptError:
54 usage()
55 sys.exit(2)
56
57 for option, argument in opts:
58 if option == ("-h", "--help"):
59 usage()
60 sys.exit()
61 elif option in ("-i", "--image"):
62 image = argument
63 else:
64 assert False, "unhandled option"
65
66 if not os.path.exists(image):
67 print("Image {} not found".format(image))
68 usage()
69 sys.exit(2)
70
71 if not epdEnabled:
72 print("Could not initialize EPD or PIL python packages")
73 sys.exit(2)
74
75 epd = EPD()
76 epd.clear()
77 displayImage(epd, image)
78
79if __name__ == "__main__":
80 main(sys.argv[1:])
Note: See TracBrowser for help on using the repository browser.