Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/python/bin/gnuboat-splashscreen

    r6f09609 rcfdd201  
    2121import getopt
    2222try:
    23     from PIL import Image
    24     from PIL import ImageOps
    25     from EPD import EPD
    26     epdEnabled = True
     23  from PIL import Image
     24  from PIL import ImageOps
     25  from EPD import EPD
     26  epdEnabled = True
    2727except:
    28     epdEnabled = False
    29 
     28  epdEnabled = False
    3029
    3130def 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 
     31  image = Image.open(imageFilePath)
     32  image = ImageOps.grayscale(image)
     33  imageResized = image.resize((epd.width, epd.height))
     34  imageBlackWhite = imageResized.convert("1", dither=Image.FLOYDSTEINBERG)
     35  epd.display(imageBlackWhite)
     36  epd.update()
    3937
    4038def usage():
    41     print "Usage of gnuboat-splashscreen:"
    42     print "  gnuboat-splashscreen [-h] -i PATH_TO_IMAGE_TO_DISPLAY"
     39  print "Usage of gnuboat-splashscreen:"
     40  print "  gnuboat-splashscreen [-h] -i PATH_TO_IMAGE_TO_DISPLAY"
     41  print ""
     42  print "  -h --help    Print this help"
     43  print "  -i --image   Path to the image, which should be displayed"
     44  sys.exit()
     45
     46def main(argv):                     
     47  image = ""                 
     48  try:                               
     49    opts, args = getopt.getopt(argv, "hi:", ["help", "image="])
     50  except getopt.GetoptError:           
     51    usage()                         
     52    sys.exit(2)
     53
     54  for option, argument in opts:
     55    if option == ("-h", "--help"):
     56      usage()
     57      sys.exit()
     58    elif option in ("-i", "--image"):
     59       image = argument
     60    else:
     61      assert False, "unhandled option"
     62
     63  if not os.path.exists(image):
     64    print "Image %s not found" % image
    4365    print ""
    44     print "  -h --help    Print this help"
    45     print "  -i --image   Path to the image, which should be displayed"
    46     sys.exit()
     66    usage()
     67    sys.exit(2)
    4768
     69  if not epdEnabled:
     70    print "Could not initialize EPD or PIL python packages"
     71    sys.exit(2)
    4872
    49 def 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 %s not found" % image
    68         print ""
    69         usage()
    70         sys.exit(2)
    71 
    72     if not epdEnabled:
    73         print "Could not initialize EPD or PIL python packages"
    74         sys.exit(2)
    75 
    76     epd = EPD()
    77     epd.clear()
    78     displayImage(epd, image)
     73  epd = EPD()
     74  epd.clear()
     75  displayImage(epd, image)
    7976
    8077if __name__ == "__main__":
    81     main(sys.argv[1:])
     78  main(sys.argv[1:])
Note: See TracChangeset for help on using the changeset viewer.