~ubuntu-branches/ubuntu/utopic/python-traitsui/utopic

« back to all changes in this revision

Viewing changes to traitsui/qt4/image_editor.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-09 13:57:39 UTC
  • Revision ID: james.westby@ubuntu.com-20110709135739-x5u20q86huissmn1
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#-------------------------------------------------------------------------------
 
2
#
 
3
#  Copyright (c) 2009, Enthought, Inc.
 
4
#  All rights reserved.
 
5
#
 
6
#  This software is provided without warranty under the terms of the BSD
 
7
#  license included in enthought/LICENSE.txt and may be redistributed only
 
8
#  under the conditions described in the aforementioned license.  The license
 
9
#  is also available online at http://www.enthought.com/licenses/BSD.txt
 
10
#
 
11
#  Thanks for using Enthought open source!
 
12
#
 
13
#  Author: Evan Patterson
 
14
#  Date:   07/21/2009
 
15
#
 
16
#-------------------------------------------------------------------------------
 
17
 
 
18
""" Traits UI 'display only' image editor.
 
19
"""
 
20
 
 
21
#-------------------------------------------------------------------------------
 
22
#  Imports:
 
23
#-------------------------------------------------------------------------------
 
24
 
 
25
from pyface.qt import QtGui
 
26
 
 
27
from pyface.image_resource \
 
28
    import ImageResource
 
29
 
 
30
from traitsui.ui_traits \
 
31
    import convert_bitmap
 
32
 
 
33
# FIXME: ImageEditor is a proxy class defined here just for backward
 
34
# compatibility. The class has been moved to the
 
35
# traitsui.editors.image_editor file.
 
36
from traitsui.editors.image_editor \
 
37
    import ImageEditor
 
38
 
 
39
from editor \
 
40
    import Editor
 
41
 
 
42
#-------------------------------------------------------------------------------
 
43
#  '_ImageEditor' class:
 
44
#-------------------------------------------------------------------------------
 
45
 
 
46
class _ImageEditor ( Editor ):
 
47
    """ Traits UI 'display only' image editor.
 
48
    """
 
49
 
 
50
    #---------------------------------------------------------------------------
 
51
    #  Finishes initializing the editor by creating the underlying toolkit
 
52
    #  widget:
 
53
    #---------------------------------------------------------------------------
 
54
 
 
55
    def init ( self, parent ):
 
56
        """ Finishes initializing the editor by creating the underlying toolkit
 
57
            widget.
 
58
        """
 
59
        image = self.factory.image
 
60
        if image is None:
 
61
            image = self.value
 
62
 
 
63
        self.control = QtGui.QLabel()
 
64
        self.control.setPixmap( convert_bitmap( image ) )
 
65
 
 
66
        self.set_tooltip()
 
67
 
 
68
    #---------------------------------------------------------------------------
 
69
    #  Updates the editor when the object trait changes external to the editor:
 
70
    #---------------------------------------------------------------------------
 
71
 
 
72
    def update_editor ( self ):
 
73
        """ Updates the editor when the object trait changes externally to the
 
74
            editor.
 
75
        """
 
76
        if self.factory.image is None:
 
77
            value = self.value
 
78
            if isinstance( value, ImageResource ):
 
79
                self.control.setPixmap( convert_bitmap( value ) )