Merged the wxPy_newswig branch into the HEAD branch (main trunk)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24541 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,8 +1,84 @@
|
||||
#----------------------------------------------------------------------
|
||||
# Name: wxPython.tools.img2img
|
||||
# Purpose: Common routines for the image converter utilities.
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
# RCS-ID: $Id$
|
||||
# Copyright: (c) 2002 by Total Control Software
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
"""Renamer stub: provides a way to drop the wx prefix from wxPython objects."""
|
||||
|
||||
from wx import _rename
|
||||
from wxPython.tools import img2img
|
||||
_rename(globals(), img2img.__dict__, modulename='tools.img2img')
|
||||
del img2img
|
||||
del _rename
|
||||
import sys, os, glob, getopt
|
||||
from wxPython.wx import *
|
||||
|
||||
|
||||
def convert(file, maskClr, outputDir, outputName, outType, outExt):
|
||||
if os.path.splitext(file)[1].lower() == ".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]) + outExt)
|
||||
if img.SaveFile(newname, outType):
|
||||
return 1, file + " converted to " + newname
|
||||
else:
|
||||
img = wxImageFromBitmap(img)
|
||||
if img.SaveFile(newname, outType):
|
||||
return 1, "ok"
|
||||
else:
|
||||
return 0, file + " failed to save!"
|
||||
|
||||
|
||||
|
||||
|
||||
def main(args, outType, outExt, doc):
|
||||
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,
|
||||
outType, outExt)
|
||||
print msg
|
||||
|
||||
|
Reference in New Issue
Block a user