X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7905ec5558bb5fe7bcaab231503112a6bf815580..3f4f90c2a0c1f274d1918b320132ed0ca2922fe5:/wxPython/tools/img2xpm.py
diff --git a/wxPython/tools/img2xpm.py b/wxPython/tools/img2xpm.py
index 4acc0d6b50..e6da69e8d8 100644
--- a/wxPython/tools/img2xpm.py
+++ b/wxPython/tools/img2xpm.py
@@ -8,7 +8,7 @@ Usage:
Options:
- -o
The directory to place the .xmp file(s), defaults to
+ -o The directory to place the .xpm file(s), defaults to
the current directory.
-m <#rrggbb> If the original image has a mask or transparency defined
@@ -22,83 +22,10 @@ Options:
"""
-import sys, os, glob, getopt, string
-from wxPython.wx import *
+import sys
+import img2img
+from wxPython import wx
-wxInitAllImageHandlers()
-app = wxPySimpleApp() # just to let global initialization to take place...
-
-def convert(file, maskClr, outputDir, outputName):
- if string.lower(os.path.splitext(file)[1]) == ".ico":
- icon = wxIcon(file, wxBITMAP_TYPE_ICO)
- img = wxBitmapFromIcon(icon)
- else:
- img = wxBitmap(file, wxBITMAP_TYPE_ANY)
-
- if not img.Ok():
- return 0, file + " failed to load!"
- else:
- if maskClr:
- om = img.GetMask()
- mask = wxMaskColour(img, maskClr)
- img.SetMask(mask)
- if om is not None:
- om.Destroy()
- if outputName:
- newname = outputName
- else:
- newname = os.path.join(outputDir, os.path.basename(os.path.splitext(file)[0]) + ".xpm")
- if img.SaveFile(newname, wxBITMAP_TYPE_XPM):
- return 1, file + " converted to " + newname
- else:
- img = wxImageFromBitmap(img)
- if img.SaveFile(newname, wxBITMAP_TYPE_XPM):
- return 1, "ok"
- else:
- return 0, file + " failed to save!"
-
-
-
-def main(args):
- if not args or ("-h" in args):
- print __doc__
- return
-
- outputDir = ""
- maskClr = None
- outputName = None
-
- try:
- opts, fileArgs = getopt.getopt(args, "m:n:o:")
- except getopt.GetoptError:
- print __doc__
- return
-
- for opt, val in opts:
- if opt == "-m":
- maskClr = val
- elif opt == "-n":
- outputName = val
- elif opt == "-o":
- outputDir = val
-
- if not fileArgs:
- print __doc__
- return
-
- for arg in fileArgs:
- for file in glob.glob(arg):
- if not os.path.isfile(file):
- continue
- ok, msg = convert(file, maskClr, outputDir, outputName)
- print msg
-
-
-
-if __name__ == "__main__":
- if wxPlatform == "__WXGTK__":
- app = wxPySimpleApp() # Blech! the GUI needs initialized before
- # bitmaps can be created...
- main(sys.argv[1:])
+img2img.main(sys.argv[1:], wx.wxBITMAP_TYPE_XPM, ".xpm", __doc__)