Skip to content
Newer
Older
100644 34 lines (27 sloc) 985 Bytes
26d729b @agateau Introduce CssColor class
authored Jan 13, 2012
1 # -*- coding: UTF-8 -*-
0f40b83 @agateau Nicer, more-generic way to expose the system palette
authored Jan 13, 2012
2 from PyQt4.QtGui import *
3
4 class CssPalette(object):
c60fb9d @agateau doc++
authored Jan 17, 2012
5 """
6 Expose a Qt palette to Jinja. If one exposes an object name "palette" in
7 Jinja, then it is possible to access the palette as: {{ palette.window }}
8 the part after "palette." can be any Qt color role.
9 """
0f40b83 @agateau Nicer, more-generic way to expose the system palette
authored Jan 13, 2012
10 def __init__(self, qpalette):
11 self.qpalette = qpalette
12
13 def __getattr__(self, name):
3167ae8 @agateau Nicer implementation
authored Jan 13, 2012
14 try:
15 getter = getattr(self.qpalette, name)
16 except AttributeError:
17 print "No such color role '%s'" % name
18 return CssColor(QColor("purple"))
19 brush = getter()
20 return CssColor(brush.color())
0f40b83 @agateau Nicer, more-generic way to expose the system palette
authored Jan 13, 2012
21
26d729b @agateau Introduce CssColor class
authored Jan 13, 2012
22 class CssColor(object):
23 def __init__(self, qcolor):
24 self.qcolor = qcolor
25
26 def darker(self, percent):
27 return CssColor(self.qcolor.darker(percent))
28
29 def lighter(self, percent):
30 return CssColor(self.qcolor.lighter(percent))
31
32 def __str__(self):
33 return unicode(self.qcolor.name())
Something went wrong with that request. Please try again.