~glitter-team/glitter/trunk

« back to all changes in this revision

Viewing changes to glitter/pixbuf_image.py

  • Committer: Jan Jokela
  • Date: 2009-03-04 10:20:09 UTC
  • mfrom: (7.1.10 global_widget_fixes)
  • Revision ID: janjokela@gmail.com-20090304102009-0do12fmrue3nkqyy
(Merge) Merged from branch that fixes PNG support and removes obsolete code

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# !/usr/bin/python
2
 
# -*- coding: utf-8 -*-
3
 
 
4
 
# Glitter Toolkit
5
 
 
6
 
__authors__ = ["Jan Jokela <janjokela@gmail.com>"]
7
 
__licenses__ = ["LICENSE.LGPL"]
8
 
__description__ = "Pixbuf image" 
9
 
 
10
 
import gtk.gdk as gdk
11
 
import gobject
12
 
import clutter
13
 
 
14
 
class PixbufImage(clutter.Texture):
15
 
 
16
 
    """ A clutter.Texture based on a gtk.gdk.pixbuf """ 
17
 
    
18
 
    __gproperties__ = {'uri': (gobject.TYPE_STRING,
19
 
                               'pixbuf uri',
20
 
                               'pixbuf uri, standard uri formats apply',
21
 
                               'None',
22
 
                               gobject.PARAM_READWRITE),
23
 
                       'ratio': (gobject.TYPE_FLOAT,
24
 
                                 'width-height ratio',
25
 
                                 'width-height ratio, if value is 0, no ratio '
26
 
                                 'will be set',
27
 
                                 0,
28
 
                                 1000,
29
 
                                 0,
30
 
                                 gobject.PARAM_READWRITE),
31
 
                       'ratio_lock': (gobject.TYPE_STRING,
32
 
                                      'lock ratio to width or height',
33
 
                                      'lock ratio to width or height',
34
 
                                      'width',
35
 
                                      gobject.PARAM_READWRITE)    
36
 
                      }
37
 
    
38
 
    def __init__(self, uri, ratio=1.0, ratio_lock='width'):
39
 
    
40
 
        """
41
 
        uri (str) -- source location, standard uri format
42
 
        ratio (float) -- ratio depending on ratio_lock, 0.0 none is applied
43
 
        ratio_lock (str) -- locks ratio to width or height
44
 
        """
45
 
    
46
 
        self.uri = uri
47
 
        self.ratio = ratio
48
 
        self.ratio_lock = ratio_lock
49
 
        
50
 
        self.__gobject_init__(uri=self.uri, ratio=self.ratio, ratio_lock=self.ratio_lock)
51
 
    
52
 
        clutter.Texture.__init__(self)
53
 
        
54
 
        self._set_pixbuf()
55
 
 
56
 
    def do_get_property(self, property):
57
 
        """ Get GObject property """
58
 
    
59
 
        if property.name == 'uri':
60
 
            return self.uri
61
 
        elif property.name == 'ratio':
62
 
            return self.ratio
63
 
        elif property.name == 'ratio-lock':
64
 
            return self.ratio_lock
65
 
        else:
66
 
            raise AttributeError, 'unknown property: %s' % property.name
67
 
        
68
 
    def do_set_property(self, property, value):
69
 
        """ Set GObject property """
70
 
        
71
 
        if property.name == 'uri':
72
 
            self.uri = value
73
 
        elif property.name == 'ratio':
74
 
            self.ratio = value
75
 
        elif property.name == 'ratio-lock':
76
 
            self.ratio_lock = value
77
 
        else:
78
 
            raise AttributeError, 'unknown property: %s' % property.name   
79
 
        
80
 
    def _set_pixbuf(self):
81
 
        """ Sets pixbuf based on source """
82
 
        
83
 
        pixbuf = gdk.pixbuf_new_from_file(self.uri)
84
 
        self.set_pixbuf(pixbuf)
85
 
        
86
 
          
87
 
gobject.type_register(PixbufImage)