00001
00002
00003 import sys
00004 import os
00005 from optparse import OptionParser
00006 from subprocess import check_call, CalledProcessError
00007
00008 def GIMPCreateDialog(name, pngName, width, height):
00009 try:
00010 check_call(["gimp", "--no-interface", "--batch",
00011 "(python-fu-mythvideo-popup RUN-NONINTERACTIVE %d %d "
00012 "\"%s\" \"%s\" TRUE FALSE) (gimp-quit 1)" %
00013 (width, height, name, pngName)])
00014 except CalledProcessError, cpe:
00015 print("Error code %d returned when attemptin to create %s" %
00016 (cpe.returncode, name))
00017
00018 class DirError(Exception):
00019 def __init__(self, name):
00020 self.name = name
00021
00022 def __str__(self):
00023 return self.name
00024
00025 def main():
00026 parser = OptionParser()
00027 defaultThemeDir = os.path.normpath(os.path.join(os.getcwd(), "..", "theme"))
00028 parser.add_option("--theme-directory", dest="themedir",
00029 default=defaultThemeDir)
00030
00031 (options, args) = parser.parse_args()
00032
00033 smallSave = os.path.join(options.themedir, "default", "images")
00034 wideSave = os.path.join(options.themedir, "default-wide", "images")
00035 try:
00036 checkdirs = [ options.themedir, smallSave, wideSave ]
00037
00038 for dir in checkdirs:
00039 if not (os.path.exists(dir) and os.path.isdir(dir)):
00040 raise DirError(dir)
00041 except DirError, e:
00042 print(e.name)
00043 print("Error: missing theme directory \"%s\"" % (str(e),))
00044 sys.exit(1)
00045
00046 images = [
00047 {
00048 "name" : ("MythVideo-SearchSelect", "mv_results_popup.png"),
00049 "Small" : (387, 400),
00050 "Wide" : (592, 400),
00051 },
00052 {
00053 "name" : ("MythVideo-ItemDetailPopup",
00054 "mv_itemdetail_popup.png"),
00055 "Small" : (720, 540),
00056 "Wide" : (1152, 648),
00057 },
00058 ]
00059
00060 savepath = { "Small" : smallSave, "Wide" : wideSave, }
00061
00062 for image in images:
00063 for size in [ "Small", "Wide" ]:
00064 name = "%s-%s" % (image['name'][0], size)
00065 xcfname = os.path.join(os.getcwd(), name)
00066 pngname = os.path.join(savepath[size], image['name'][1])
00067 GIMPCreateDialog(xcfname, pngname,
00068 image[size][0], image[size][1])
00069
00070 if __name__ == '__main__':
00071 main()