#!/bin/env python ## echo_icon_theme - builds icon theme from echo_art dir ## where echo_art dir is populated using ## J5's script ## AUTHOR: Leon ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import commands import os from xml.sax import handler, make_parser import pprint import shutil icon_src_dir = os.path.realpath(".") + '/echo_art' icon_dest_dir = os.path.realpath(".") + '/Echo' icon_map_exec = commands.getoutput("pkg-config \ --variable=program_path icon-naming-utils") + "/icon-name-mapping" icon_mapping_xml = \ "/usr/share/icon-naming-utils/legacy-icon-mapping.xml" class IconMappingHandler(handler.ContentHandler): def __init__(self): self.inIcon = 0 self.mapping = {} def startElement(self, name, attributes): if name == "context": self.IconList = [] self.Context = attributes["dir"] elif name == "icon": self.inIcon = 1 self.IconName = attributes["name"] def endElement(self, name): if name == "icon": self.inIcon = 0 self.IconList.append(self.IconName) if name == "context": self.mapping[self.Context] = self.IconList def create16x16(mapping): os.makedirs(icon_dest_dir + "/16x16", 0755) for context in mapping.keys(): contextdir=icon_dest_dir + "/16x16/" + context os.mkdir(contextdir) for icon in mapping[context]: srcicon1 = icon_src_dir + '/' + icon + '16.png' srcicon2 = icon_src_dir + '/' + icon + 'S.png' if os.path.exists(srcicon1): shutil.copyfile(srcicon1, contextdir + '/' + icon + '.png') elif os.path.exists(srcicon2): shutil.copyfile(srcicon2, contextdir + '/' + icon + '.png') os.system("(cd %s; %s -c %s)" % (contextdir, icon_map_exec, context)) def create24x24(mapping): os.makedirs(icon_dest_dir + "/24x24", 0755) for context in mapping.keys(): contextdir=icon_dest_dir + "/24x24/" + context os.mkdir(contextdir) for icon in mapping[context]: srcicon1 = icon_src_dir + '/' + icon + '24.png' if os.path.exists(srcicon1): shutil.copyfile(srcicon1, contextdir + '/' + icon + '.png') os.system("(cd %s; %s -c %s)" % (contextdir, icon_map_exec, context)) def createLarge(mapping): for s in [32, 48, 64, 96, 128]: size = "%sx%s" % (s, s) os.makedirs("%s/%s" % (icon_dest_dir, size), 0755) for context in mapping.keys(): contextdir=icon_dest_dir + '/' + size + '/' + context os.mkdir(contextdir) for icon in mapping[context]: srcicon = icon_src_dir + '/' + icon + 'L.svg' if os.path.exists(srcicon): desticon = contextdir + '/' + icon + '.png' os.system("convert -background none -resize %s %s %s" % (size, srcicon, desticon)) os.system("(cd %s; %s -c %s)" % (contextdir, icon_map_exec, context)) def BuildIconTheme(): parser = make_parser() handler = IconMappingHandler() parser.setContentHandler(handler) parser.parse(icon_mapping_xml) #pprint.pprint(handler.mapping) create16x16(handler.mapping) create24x24(handler.mapping) createLarge(handler.mapping) if __name__ == "__main__": BuildIconTheme()