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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
#!/usr/bin/env python
#Copyright 2008-2010 David D Lowe
#released under the GPLv3
"""pigment is a module containing the parent classes for all pigment objects"""
from pigment import PigmentType, Pigment
import sys, os
from glob import glob
import subprocess
import gtk
if __name__ == "__main__" or 'pychecker' in sys.argv[0]:
sys.path.append("..")
from shell import SubprocessShell
import handy
import ep_exceptions
import managepigments
import const
from const import PIGMENT_TYPES, MY_DATA_HOME, SHARED_PIGMENT_DIR
from gettext import gettext as _
TEMP_DIR = "TEMP"
class SkinType(PigmentType):
humanName = {"en":"Skin"}
humanPluralName = {"en":"Skins"}
codeName = "skin"
abbreviation = "sk"
directoryName = "skins"
canGeneratePreview = True
attachmentTypeHelp = _("The skin pigment does not have a theme file")
@staticmethod
def get_Pigment():
return Skin
class Skin(Pigment):
"""A Skin is a Pigment that links to other pigments (no more than one
of every type), but does not contain them. This is the mechanism by which
you can change every aspect of the appearance of your desktop at once."""
type = SkinType
def __init__(self):
Pigment.__init__(self)
self.linkedPigments = {} # a dictionary of the linked Pigments.
# example: {"wallpaper":<wallpaper object>, ...}
self.primaryColours = []
self.secondaryColours = []
self.keyWords = {} # note different languages
self.version = ""
self.webPage = ""
def get_words(self, words, lang="en"):
"""Return a string with the items in either words seperated by commas
Keyword arguments:
words -- can be self.keyWords, self.primaryColours,
self.secondaryColours
lang -- if self.keyWords is passed, a language should
be specified
"""
out = ""
if isinstance(words, list):
for word in words:
out = out + word + ", "
out = out[:-2]
return out
elif isinstance(words, dict):
if not words.has_key(lang) and words.has_key(""):
lang = ""
for word in words[lang]:
out = out + word + ", "
out = out[:-2]
return out
raise(Exception("words not dictionary nor list"))
def add_attachment(self, attachmentPath):
raise(ep_exceptions.TooManyAttachmentsException(len(self.attachments) + 1))
def set_linked_pigment(self, pigmentObject):
self.linkedPigments[pigmentObject.type.codeName] = pigmentObject
def install(self, installationDirectory, progressCallback=None, shell=None):
"""Note: doesn't install linked pigments of course"""
Pigment.install(self, installationDirectory, progressCallback, shell)
def remove(self, progressCallback=None, shell=None):
"""Note: doesn't remove linked pigments of course"""
Pigment.remove(self, progressCallback, shell)
def activate(self, progressCallback=None, shell=None):
"""Activate Skin, including all linked Pigments"""
if progressCallback is None: progressCallback = lambda(a1): False
if progressCallback(0.0): return
progress = 0
for pigm in self.linkedPigments.values():
if ((not const.USE_XSPLASH) and pigm.type.codeName == "xsplashHack") or \
(const.USE_XSPLASH and pigm.type.codeName == "gdm") or (const.USE_GRUB and pigm.type.codeName == "grub"):
pass
else:
pigm.activate(shell=shell)
progress = progress + 1
if progressCallback(progress / (len(self.linkedPigments) + 1)): return
progressCallback(1.0)
def load_with_pigments(self, filePath, pigments):
"""Similar to load, but accepting a list of Pigment objects which will
take priority in the search for linked pigments over (other) installed
pigments
"""
dir = self._extract_in_temp(filePath)
self.read_with_pigments(os.path.join(dir, "pigment.xml"), pigments)
self._rearrange_temp(dir)
def read_with_pigments(self, filePath, pigments):
"""Similar to read, but will look for linked pigments in the pigments
argument, before looking for installed pigments
Keyword arguments:
filePath -- the path of the xml file to read
pigments -- a list of Pigment objects from which to search for
linked pigments"""
Pigment.read(self, filePath)
from xml.dom import minidom
doc = minidom.parse(filePath)
root = doc.getElementsByTagName("pigment")[0]
self.primaryColours, self.secondaryColours = ([], [])
for xmlName, alist in (("primaryColors", "primaryColours"), \
("secondaryColors", "secondaryColours")):
xmlBit = doc.getElementsByTagName(xmlName)[0]
for bit in xmlBit.getElementsByTagName("color"):
getattr(self,alist).append(self.__get_first_text(bit))
self.keyWords = {}
for keyXml in root.getElementsByTagName("keyWords")[0].getElementsByTagName("keyWord"):
lang = keyXml.getAttribute("lang")
text = self.__get_first_text(keyXml)
if self.keyWords.has_key(lang):
self.keyWords[lang].append(text)
else:
self.keyWords[lang] = [text]
try:
self.version = self.__get_first_text(root.getElementsByTagName("version")[0])
except ep_exceptions.NoFirstTextError:
self.version = ""
try:
self.webPage = self.__get_first_text(root.getElementsByTagName("webPage")[0])
except ep_exceptions.NoFirstTextError:
self.webPage = ""
self.linkedPigments = {}
for link in root.getElementsByTagName("link"):
pt = link.getElementsByTagName("codename")[0].getAttribute("type")
text = self.__get_first_text(link.getElementsByTagName("codename")[0])
# look for pigment in Pigments
foundP = None
for pigm in pigments:
if pigm.codeName == text and pigm.type.codeName == pt:
foundP = pigm
break
if foundP is None and pt in const.PIGMENT_TYPES[1:]:
foundP = managepigments.load_pigment(text, pt)
if pt in const.PIGMENT_TYPES[1:]:
self.linkedPigments[pt] = foundP
def read(self, filePath):
return self.read_with_pigments(filePath, [])
def information_xml(self):
"""Returns the XML document describing the pigment"""
doc = Pigment.information_xml(self)
root = doc.getElementsByTagName("pigment")[0]
for xmlName, alist in (("primaryColors",self.primaryColours), \
("secondaryColors", self.secondaryColours)):
xmlBit = doc.createElement(xmlName)
for bit in alist:
subXmlBit = doc.createElement("color")
tn = doc.createTextNode(bit)
subXmlBit.appendChild(tn)
xmlBit.appendChild(subXmlBit)
root.appendChild(xmlBit)
keyXml = doc.createElement("keyWords")
for lang in self.keyWords:
for word in self.keyWords[lang]:
xmlBit = doc.createElement("keyWord")
xmlBit.setAttribute("lang", lang)
tn = doc.createTextNode(word)
xmlBit.appendChild(tn)
keyXml.appendChild(xmlBit)
root.appendChild(keyXml)
for xmlName, bit in (("version", self.version), ("webPage", self.webPage)):
xmlBit = doc.createElement(xmlName)
tn = doc.createTextNode(bit)
xmlBit.appendChild(tn)
root.appendChild(xmlBit)
for pt in self.linkedPigments.keys():
xmlBit = doc.createElement("link")
xmlBit2 = doc.createElement("codename")
xmlBit2.setAttribute("type", pt)
tn = doc.createTextNode(self.linkedPigments[pt].codeName)
xmlBit2.appendChild(tn)
xmlBit.appendChild(xmlBit2)
root.appendChild(xmlBit)
return doc
def is_activated(self):
for pt in PIGMENT_TYPES:
if self.linkedPigments.has_key(pt):
if not self.linkedPigments[pt].is_activated():
return False
return True
def convert_from_meat(self, meat, progressCallback=None):
progressCallback(1.0)
def is_meat_installed(self):
return True
def generate_preview(self):
if self.linkedPigments.has_key("metacity") or self.linkedPigments.has_key("gtk") \
or self.linkedPigments.has_key("icons"):
dir = os.path.dirname(os.path.abspath(__file__))
themeScript = os.path.join(dir,"theme_preview.py")
subprocess.call(["mkdir", "-p", "/tmp/epidermis"])
subprocess.call(["rm","-f", "/tmp/epidermis/skin-preview.png"])
env = os.environ
if self.linkedPigments.has_key("gtk"):
env["GTK2_RC_FILES"] = os.path.join(self.linkedPigments["gtk"].attPath, "gtk-2.0", "gtkrc")
command = ["python",themeScript,"multiple","/tmp/epidermis/skin-preview.png"]
for bit in ("metacity","icons","wallpaper"):
if self.linkedPigments.has_key(bit):
command.extend([bit,self.linkedPigments[bit].attPath])
subprocess.call(command, env=env)
try:
pb = gtk.gdk.pixbuf_new_from_file("/tmp/epidermis/skin-preview.png")
except Exception, ee:
import traceback
traceback.print_exc()
return None
if not pb is None:
self.preview = pb
return pb
else:
return None
elif self.linkedPigments.has_key("wallpaper"):
# preview is just the wallpaper
pb = gtk.gdk.pixbuf_new_from_file_at_size(self.linkedPigments["wallpaper"].attPath,150,150)
if not pb is None:
self.preview = pb
return pb
else:
return None
else:
return None
def is_meat_activated(self):
return True
def does_activation_require_root(self):
for pigm in self.linkedPigments.values():
if pigm.does_activation_require_root():
return True
return False
def match_filter(self, matchString, lang="en"):
for ii in (self.get_human_name(lang), self.get_description(lang)):
if matchString.lower() in ii.lower():
return True
for alist in (self.keyWords[lang], self.primaryColours, self.secondaryColours):
for item in alist:
if matchString.lower() in item.lower():
return True
return False
def __get_first_text(self, thexml):
import xml.dom
for el in thexml.childNodes:
if el.nodeType == xml.dom.Node.TEXT_NODE:
return el.data
raise(ep_exceptions.NoFirstTextError())
|