File: styledeclaration.py

package info (click to toggle)
cssutils 0.9.10-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 1,991
  • sloc: python: 19,781; sh: 102; makefile: 79
file content (52 lines) | stat: -rw-r--r-- 1,321 bytes parent folder | download | duplicates (6)
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
import cssutils

def show(style):
    print "style.length ==", style.length
    print "style.item(0) ==", style.item(0)
    print "style.item(1) ==", style.item(1)
    print "style.getProperties('color', all=True) == ["
    for x in style.getProperties('color', all=True):
        print "\t", x.cssText
    print "\t]"
    print "style.getPropertyValue('color') ==", style.getPropertyValue('color'), '\n'


styledeclaration = '''
x:1;
color: yellow;
color: red;
c\olor: green !important;
c\olor: blue;
FONT-FAMILY: serif;
'''
print "\nGiven styledeclaration:"
print styledeclaration
print "------------"

print "setting cssText"
style = cssutils.css.CSSStyleDeclaration(cssText=styledeclaration)
show(style)

print "------------"

# overwrite in any case
print "style.setProperty('color', 'yellow','!important')"
style.setProperty('color', 'yellow','!important')
show(style)

# overwrite in any case, even !important
print "style.setProperty('color', 'red')"
style.setProperty('color', 'red')
show(style)

print "------------"

# overwrite in any case, even !important
print "style.setProperty('color', 'green', '!important')"
style.setProperty('color', 'green', '!important')
show(style)

# overwrite in any case, even !important
print "style.setProperty('color', 'blue')"
style.setProperty('color', 'blue')
show(style)