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 """A theme's index.theme file."""
13 def __init__(self
, dir):
15 sections
= file(os
.path
.join(dir, "index.theme")).read().split('\n[')
19 sname
= lines
[0].strip()
21 # Python < 2.2.2 doesn't support an argument to strip...
22 assert sname
[-1] == ']'
23 if sname
.startswith('['):
28 section
= self
.sections
[sname
] = {}
29 for line
in lines
[1:]:
30 if not line
.strip(): continue
31 if line
.startswith('#'): continue
32 key
, value
= map(str.strip
, line
.split('=', 1))
35 self
.subdirs
= [SubDir(self
, d
) for
36 d
in self
.get('Icon Theme', 'Directories').split(';')]
38 def get(self
, section
, key
):
40 return self
.sections
.get(section
, {}).get(key
, None)
43 """A subdirectory within a theme."""
44 def __init__(self
, index
, subdir
):
45 icontype
= index
.get(subdir
, 'Type')
47 self
.size
= int(index
.get(subdir
, 'Size'))
48 if icontype
== "Fixed":
49 self
.min_size
= self
.max_size
= self
.size
50 elif icontype
== "Threshold":
51 threshold
= int(index
.get(subdir
, 'Threshold'))
52 self
.min_size
= self
.size
- threshold
53 self
.max_size
= self
.size
+ threshold
54 elif icontype
== "Scaled":
55 self
.min_size
= int(index
.get(subdir
, 'MinSize'))
56 self
.max_size
= int(index
.get(subdir
, 'MaxSize'))
58 self
.min_size
= self
.max_size
= 100000
61 """Icon themes are located by searching through various directories. You can use an IconTheme
62 to convert an icon name into a suitable image."""
64 def __init__(self
, name
):
68 for leaf
in theme_dirs
:
69 theme_dir
= os
.path
.join(leaf
, name
)
70 index_file
= os
.path
.join(theme_dir
, 'index.theme')
71 if os
.path
.exists(os
.path
.join(index_file
)):
73 self
.indexes
.append(Index(theme_dir
))
75 rox
.report_exception()
77 def lookup_icon(self
, iconname
, size
):
78 icon
= self
._lookup
_this
_theme
(iconname
, size
)
82 def _lookup_this_theme(self
, iconname
, size
):
84 for i
in self
.indexes
:
87 diff
= d
.min_size
- size
88 elif size
> d
.max_size
:
89 diff
= size
- d
.max_size
92 dirs
.append((diff
, os
.path
.join(i
.dir, d
.name
)))
94 # Sort by closeness of size
97 for _
, subdir
in dirs
:
98 for extension
in ("png", "svg"):
99 filename
= os
.path
.join(subdir
,
100 iconname
+ '.' + extension
)
101 if os
.path
.exists(filename
):
105 rox_theme
= IconTheme('ROX')