makeIco.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. #
  3. # Make a DWIN .ico file from a directory of JPEG icon files.
  4. #
  5. # Copyright (c) 2020 Brent Burton
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. #----------------------------------------------------------------
  20. import os.path, argparse, DWIN_ICO
  21. version = '2.0.7'
  22. #----------------
  23. if __name__ == '__main__':
  24. try:
  25. parser = argparse.ArgumentParser(description='Make .ico from JPEG files')
  26. parser.add_argument('iconDir', type=str, nargs=1,
  27. help='name of directory containing icon JPGs')
  28. parser.add_argument('filename', type=str, nargs=1,
  29. help='name of new .ico file to create')
  30. args = parser.parse_args()
  31. filename = args.filename[0]
  32. iconDir = args.iconDir[0]
  33. if os.path.isfile(filename):
  34. raise RuntimeError("ICO file '%s' already exists." % (filename))
  35. if not os.path.exists(iconDir):
  36. raise RuntimeError("Icon directory '%s' doesn't exist." % (iconDir))
  37. print("Making .ico file '%s' from contents of '%s'" % (filename, iconDir))
  38. ico = DWIN_ICO.DWIN_ICO_File()
  39. ico.createFile(iconDir, filename)
  40. except Exception as e:
  41. print('Error: ', e)