File: css.py

package info (click to toggle)
iso-flags-svg 1.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 15,652 kB
  • sloc: perl: 590; makefile: 160; sh: 70; python: 59
file content (70 lines) | stat: -rwxr-xr-x 2,249 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python

from os.path import basename, splitext
from optparse import OptionParser

parser = OptionParser()
parser.add_option("--cmd", dest="cmd",
                  help="command", metavar="COMMAND")
parser.add_option("--tile", dest="tile",
                  type=int, default=10,
                  help="number of horizontal tiles")
parser.add_option("--resx", dest="resx",
                  type=int, default=40,
                  help="horizontal flag size in pixel")
parser.add_option("--resy", dest="resy",
                  type=int, default=30,
                  help="vertical flag size in pixel")
parser.add_option("--image", dest="image",
                  default="flags.png",
                  help="image file with the flags")
parser.add_option("--css", dest="css",
                  default="flags.css",
                  help="css file with for flags")

(options, args) = parser.parse_args()

if options.cmd == "css":

    background_position_fmt = 'background-position: -%dpx -%dpx;'
    flag_styles = []
    i = 0
    for f in args:
        name, _ = splitext(basename(f))
        x = (i % options.tile) * options.resx
        y = (i / options.tile) * options.resy
        flag_styles.append((name, x, y))
        if name=='zz': # unknown
            default_background_position = background_position_fmt % (x, y)

        i = i+1

    print ('''.flag {
    height: %(height)dpx;
    width: %(width)dpx;
    background-image: url("%(image)s");
    background-repeat: no-repeat;
    display: block;
    overflow: hidden;
    text-indent: -99999px;
    %(background-position)s
}
''' % {
        'height': options.resy, 
        'width': options.resx, 
        'image': options.image,
        'background-position': default_background_position
        })

    for (name, x, y) in flag_styles:
        print (".flag-%s { background-position: -%dpx -%dpx; }" % (name, x, y))

elif options.cmd == "html":
    print ('<link rel="stylesheet" type="text/css" href="%s">' % options.css)
    for f in args:
        name, _ = splitext(basename(f))
        print ('<p>%(name)s <span class="flag flag-%(name)s"></span></p>' % {'name': name})
    print ('<p>empty <span class="flag"></span></p>')

else:
    print ("unknown command")