]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/tools/img2img.py
Clean up comments a bit
[wxWidgets.git] / wxPython / wx / tools / img2img.py
CommitLineData
d14a1e28
RD
1#----------------------------------------------------------------------
2# Name: wxPython.tools.img2img
3# Purpose: Common routines for the image converter utilities.
4#
5# Author: Robin Dunn
6#
7# RCS-ID: $Id$
8# Copyright: (c) 2002 by Total Control Software
9# Licence: wxWindows license
10#----------------------------------------------------------------------
d4b73b1b
RD
11# 12/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
12#
13# o V2.5 compatability update
14#
1fded56b 15
d4b73b1b
RD
16import getopt
17import glob
18import os
19import sys
1fded56b 20
d4b73b1b 21import wx
d14a1e28
RD
22
23def convert(file, maskClr, outputDir, outputName, outType, outExt):
24 if os.path.splitext(file)[1].lower() == ".ico":
d4b73b1b
RD
25 icon = wx.Icon(file, wx.BITMAP_TYPE_ICO)
26 img = wx.BitmapFromIcon(icon)
d14a1e28 27 else:
d4b73b1b 28 img = wx.Bitmap(file, wx.BITMAP_TYPE_ANY)
d14a1e28
RD
29
30 if not img.Ok():
31 return 0, file + " failed to load!"
32 else:
33 if maskClr:
34 om = img.GetMask()
241af5cf 35 mask = wx.Mask(img, maskClr)
d14a1e28
RD
36 img.SetMask(mask)
37 if om is not None:
38 om.Destroy()
39 if outputName:
40 newname = outputName
41 else:
42 newname = os.path.join(outputDir,
43 os.path.basename(os.path.splitext(file)[0]) + outExt)
44 if img.SaveFile(newname, outType):
45 return 1, file + " converted to " + newname
46 else:
d4b73b1b 47 img = wx.ImageFromBitmap(img)
d14a1e28
RD
48 if img.SaveFile(newname, outType):
49 return 1, "ok"
50 else:
51 return 0, file + " failed to save!"
52
53
54
55
56def main(args, outType, outExt, doc):
57 if not args or ("-h" in args):
58 print doc
59 return
60
61 outputDir = ""
62 maskClr = None
63 outputName = None
64
65 try:
66 opts, fileArgs = getopt.getopt(args, "m:n:o:")
67 except getopt.GetoptError:
68 print __doc__
69 return
70
71 for opt, val in opts:
72 if opt == "-m":
73 maskClr = val
74 elif opt == "-n":
75 outputName = val
76 elif opt == "-o":
77 outputDir = val
78
79 if not fileArgs:
80 print doc
81 return
82
83 for arg in fileArgs:
84 for file in glob.glob(arg):
85 if not os.path.isfile(file):
86 continue
87 ok, msg = convert(file, maskClr, outputDir, outputName,
88 outType, outExt)
89 print msg
90