~glitter-team/glitter/trunk

« back to all changes in this revision

Viewing changes to glitter/image.py

  • Committer: Jan Jokela
  • Date: 2009-03-04 10:19:13 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: janjokela@gmail.com-20090304101913-h8g2dp9ocr7qe4pl
(- glitter/pixbuf_image.py) Removed; (glitter/image.py) Support for png images working again

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
import os
11
11
import sys
12
12
 
 
13
import clutter
 
14
 
13
15
from theme import Theme
14
16
from container import Container
15
17
from pixbuf_image import PixbufImage
133
135
           height == self.texture.get_height():
134
136
            return    
135
137
        
136
 
        source = os.path.splitext(self.source)[0]
 
138
        # Source filename and extension
 
139
        source_name = os.path.splitext(self.source)[0]
137
140
        source_ext = os.path.splitext(self.source)[1]
138
141
        
139
142
        theme = Theme.get_default()
140
143
        if source_ext == '.py':
141
144
            source_path = os.path.join(theme.get_path(), 'resources')
 
145
        elif os.path.exists(self.source):
 
146
            source_path = os.path.dirname(self.source)
 
147
            source = self.source
142
148
        else:
143
149
            source_path = os.path.join(theme.get_path(), 'resources')
 
150
            source = os.path.join(source_path, self.source)
144
151
        
145
152
        if os.path.exists(source_path):
146
153
            if source_ext == '.png':
147
 
                self.texture = PixbufImage(
148
 
                                 os.path.join(source_path, self.source)
149
 
                               )
 
154
                if not self.texture:
 
155
                    self.texture = clutter.Texture(filename=source)
 
156
                    self.add(self.texture)
 
157
                    self.texture.show()
150
158
                self.texture.set_width(width)
151
159
                self.texture.set_height(height)
152
160
            elif source_ext == '.svg':
153
161
                if self.texture:
154
162
                    self.remove(self.texture)
155
163
                    del(self.texture)
156
 
                self.texture = SVGImage(os.path.join(source_path, self.source), width, height)
 
164
                self.texture = SVGImage(source, width, height)
 
165
                self.add(self.texture)
 
166
                self.texture.show()
157
167
            elif source_ext == '.py':
158
168
                if self.texture:
159
169
                    self.remove(self.texture)
160
170
                    del(self.texture)
161
 
                source_import = os.path.basename(source)
 
171
                source_import = os.path.basename(source_name)
162
172
                sys.path[1] = source_path
163
173
                cairotexture = __import__(source_import)
164
174
                self.texture = cairotexture.Texture(width, height)
165
 
            self.add(self.texture)
166
 
            self.texture.show()
 
175
                self.add(self.texture)
 
176
                self.texture.show()
167
177
        else: 
168
178
            raise AttributeError, "source doesn't exist: %s" % source_path
169
179