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 """Manages icons and artworks"""
29
30 import os
31 import logging
32 logger = logging.getLogger('camelot.view.art')
33
34 from camelot.view.model_thread import gui_function
35
36 from PyQt4 import QtGui
42
44 """Load pixmaps from the camelot art library"""
45
47 """:param path: the path of the pixmap relative to the art directory, use
48 '/' as a path separator
49 :param module: the module that contains the art directory, if None is given
50 this will be camelot"""
51 self._path = path
52 self._cached_pixmap = None
53 if not module:
54 import camelot
55 self._module_name = camelot.__name__
56 else:
57 self._module_name = module.__name__
58
61
63 return self.__class__.__name__ + "('" + self._path + "')"
64
66 """Obsolete : avoid this method, since it will copy the resource file
67 from its package and copy it to a temp folder if the resource is
68 packaged."""
69 from camelot.core.resources import resource_filename
70 pth = resource_filename(self._module_name, 'art/%s'%(self._path), 'CAMELOT_MAIN_DIRECTORY')
71 if os.path.exists(pth):
72 return pth
73 else:
74 return ''
75
76 @gui_function
78 """QPixmaps can only be used in the gui thread"""
79 if self._cached_pixmap:
80 return self._cached_pixmap
81 from camelot.core.resources import resource_string
82 from PyQt4.QtGui import QPixmap
83 qpm = QPixmap()
84 success = qpm.loadFromData(resource_string(self._module_name,
85 'art/%s'%(self._path),
86 'CAMELOT_MAIN_DIRECTORY'))
87 if not success:
88 msg = u'Could not load pixmap %s from camelot art library'
89 logger.warn(msg % self._path)
90 self._cached_pixmap = qpm
91 return qpm
92
94 """Manages paths to the icons images"""
95
96 @gui_function
98 """QPixmaps can only be used in the gui thread"""
99 from PyQt4.QtGui import QIcon
100 return QIcon(self.getQPixmap())
101
103 """The default color scheme for camelot, based on the Tango icon set
104 see http://tango.freedesktop.org/Generic_Icon_Theme_Guidelines
105 """
106 yellow = QtGui.QColor('#ffff00')
107 yellow_0 = yellow
108 yellow_1 = QtGui.QColor('#fce94f')
109 yellow_2 = QtGui.QColor('#edd400')
110 yellow_3 = QtGui.QColor('#c4a000')
111 orange_1 = QtGui.QColor('#fcaf3e')
112 orange_2 = QtGui.QColor('#f57900')
113 orange_3 = QtGui.QColor('#cd5c00')
114 brown_1 = QtGui.QColor('#e9b96e')
115 brown_2 = QtGui.QColor('#c17d11')
116 brown_3 = QtGui.QColor('#8f5902')
117 red = QtGui.QColor('#ff0000')
118 red_0 = red
119 red_1 = QtGui.QColor('#ef2929')
120 red_2 = QtGui.QColor('#cc0000')
121 red_3 = QtGui.QColor('#a40000')
122 blue = QtGui.QColor('#0000ff')
123 blue_0 = blue
124 blue_1 = QtGui.QColor('#000080')
125 green = QtGui.QColor('#00ff00')
126 green_0 = green
127 cyan = QtGui.QColor('#00ffff')
128 cyan_0 = cyan
129 cyan_1 = QtGui.QColor('#008080')
130 magenta = QtGui.QColor('#ff00ff')
131 magenta_0 = magenta
132 magenta_1 = QtGui.QColor('#800080')
133 pink_1 = QtGui.QColor('#f16c6c')
134 pink_2 = QtGui.QColor('#f13c3c')
135 aluminium_0 = QtGui.QColor('#eeeeec')
136 aluminium_1 = QtGui.QColor('#d3d7cf')
137 aluminium_2 = QtGui.QColor('#babdb6')
138 aluminium = aluminium_0
139 grey_0 = QtGui.QColor('#eeeeee')
140 grey_1 = QtGui.QColor('#cccccc')
141 grey_2 = QtGui.QColor('#333333')
142 grey_3 = QtGui.QColor('#666666')
143 grey_4 = QtGui.QColor('#999999')
144 grey = grey_0
145
146 VALIDATION_ERROR = red_1
147 """
148 for consistency with QT:
149 Qt::white 3 White (#ffffff)
150 Qt::black 2 Black (#000000)
151 Qt::red 7 Red (#ff0000)
152 Qt::darkRed 13 Dark red (#800000)
153 Qt::green 8 Green (#00ff00)
154 Qt::darkGreen 14 Dark green (#008000)
155 Qt::blue 9 Blue (#0000ff)
156 Qt::darkBlue 15 Dark blue ()
157 Qt::cyan 10 Cyan (#00ffff)
158 Qt::darkCyan 16 Dark cyan (#008080)
159 Qt::magenta 11 Magenta (#ff00ff)
160 Qt::darkMagenta 17 Dark magenta (#800080)
161 Qt::yellow 12 Yellow (#ffff00)
162 Qt::darkYellow 18 Dark yellow (#808000)
163 Qt::gray 5 Gray (#a0a0a4)
164 Qt::darkGray 4 Dark gray (#808080)
165 Qt::lightGray 6 Light gray (#c0c0c0)
166 Qt::transparent 19 a transparent black value (i.e., QColor(0, 0, 0, 0))
167 Qt::color0 0 0 pixel value (for bitmaps)
168 Qt::color1 1 1 pixel value (for bitmaps)
169 """
170