Skip to content

Commit

Permalink
adding the pyxie script and some support for the pyxie script
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoiron committed Apr 13, 2010
1 parent 56dbc6d commit 6012ee3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
52 changes: 52 additions & 0 deletions bin/pyxie
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""pyxie command line tool"""

import sys
import glob
import os
import optparse
from pyxie import sprite

white, black, red, green, yellow, blue, purple = range(89, 96)
def color(string, color=green, bold=True):
return '\033[%s%sm' % ('01;' if bold else '', color) + str(string) + '\033[0m'

def err(string):
sys.stderr.write(color("Error:", red) + str(string))
sys.exit(-1)

def main():
opts, args = parse_args()
spritepath, paths = args[0], args[1:]
s = sprite.sprite_from_paths(*paths)
s.write(spritepath)
if opts.css:
open(opts.css, 'w').write(s.css())
else:
print s.css()
if opts.html:
open(opts.html, 'w').write(s.html())
return 0

def parse_args():
parser = optparse.OptionParser(version='0.1', usage='%prog [opts] spritefile <images>')
parser.set_conflict_handler("resolve")
parser.add_option('-c', '--css', help='css output file (default stdout)')
parser.add_option('', '--sprite-url', help='url to the sprite')
parser.add_option('-h', '--html', help='html output file (default none)')
# parser.add_option('', '--class-prefix', help='css class prefix')
opts, args = parser.parse_args()
if not args:
err("You must provide a path for the sprite-file")
if len(args) < 2:
err("You can't make a sprite without images")
return opts, args

if __name__ == '__main__':
try:
sys.exit(main())
except KeyboardInterrupt:
pass

5 changes: 4 additions & 1 deletion pyxie/sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def sprite_from_glob(*glob_exprs):
filenames = []
for expr in glob_exprs:
filenames += glob.glob(expr)
images = [Image.open(f) for f in filenames]
return sprite_from_paths(*filenames)

def sprite_from_paths(*paths):
images = [Image.open(f) for f in paths]
field = autopack(*images)
return Sprite(field)

0 comments on commit 6012ee3

Please sign in to comment.