1 """This is an internal module. Do not use it. GTK 2.4 will contain functions
2 that replace those defined here."""
8 theme_dirs
= [os
.path
.join(os
.environ
.get('HOME', '/'), '.icons')] + \
9 list(basedir
.load_data_paths('icons'))
12 def __init__(self
, dir):
14 sections
= file(os
.path
.join(dir, "index.theme")).read().split('\n[')
18 sname
= lines
[0].strip('[] \t')
19 section
= self
.sections
[sname
] = {}
20 for line
in lines
[1:]:
21 if not line
.strip(): continue
22 if line
.startswith('#'): continue
23 key
, value
= map(str.strip
, line
.split('=', 1))
26 self
.subdirs
= [SubDir(self
, d
) for
27 d
in self
.get('Icon Theme', 'Directories').split(';')]
29 def get(self
, section
, key
):
31 return self
.sections
.get(section
, {}).get(key
, None)
34 def __init__(self
, index
, subdir
):
35 type = index
.get(subdir
, 'Type')
37 self
.size
= int(index
.get(subdir
, 'Size'))
39 self
.min_size
= self
.max_size
= self
.size
40 elif type == "Threshold":
41 threshold
= int(index
.get(subdir
, 'Threshold'))
42 self
.min_size
= self
.size
- threshold
43 self
.max_size
= self
.size
+ threshold
44 elif type == "Scaled":
45 self
.min_size
= int(index
.get(subdir
, 'MinSize'))
46 self
.max_size
= int(index
.get(subdir
, 'MaxSize'))
48 self
.min_size
= self
.max_size
= 100000
51 def __init__(self
, name
):
55 for dir in theme_dirs
:
56 theme_dir
= os
.path
.join(dir, name
)
57 index_file
= os
.path
.join(theme_dir
, 'index.theme')
58 if os
.path
.exists(os
.path
.join(index_file
)):
60 self
.indexes
.append(Index(theme_dir
))
64 def lookup_icon(self
, iconname
, size
):
65 icon
= self
._lookup
_this
_theme
(iconname
, size
)
69 def _lookup_this_theme(self
, iconname
, size
):
71 for i
in self
.indexes
:
74 diff
= d
.min_size
- size
75 elif size
> d
.max_size
:
76 diff
= size
- d
.max_size
79 dirs
.append((diff
, os
.path
.join(i
.dir, d
.name
)))
81 # Sort by closeness of size
84 minimal_size
= 1000000
85 for _
, subdir
in dirs
:
86 for extension
in ("png", "svg"):
87 filename
= os
.path
.join(subdir
,
88 iconname
+ '.' + extension
)
89 if os
.path
.exists(filename
):
92 rox_theme
= IconTheme('ROX')