]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/tools/img2img.py
Added wx/pickerbase.h so it will get installed.
[wxWidgets.git] / wxPython / wx / tools / img2img.py
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 #----------------------------------------------------------------------
11 # 12/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
12 #
13 # o V2.5 compatability update
14 #
15
16 import getopt
17 import glob
18 import os
19 import sys
20
21 import wx
22
23 def convert(file, maskClr, outputDir, outputName, outType, outExt):
24 if os.path.splitext(file)[1].lower() == ".ico":
25 icon = wx.Icon(file, wx.BITMAP_TYPE_ICO)
26 img = wx.BitmapFromIcon(icon)
27 else:
28 img = wx.Bitmap(file, wx.BITMAP_TYPE_ANY)
29
30 if not img.Ok():
31 return 0, file + " failed to load!"
32 else:
33 if maskClr:
34 om = img.GetMask()
35 mask = wx.Mask(img, maskClr)
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:
47 img = wx.ImageFromBitmap(img)
48 if img.SaveFile(newname, outType):
49 return 1, "ok"
50 else:
51 return 0, file + " failed to save!"
52
53
54
55
56 def 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