1
#------------------------------------------------------------------------------
3
# Copyright (c) 2008, Enthought, Inc.
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
11
# Thanks for using Enthought open source!
13
# Author: David C. Morrill
16
#------------------------------------------------------------------------------
18
""" Defines the button editor factory for all traits toolkit backends.
21
#-------------------------------------------------------------------------------
23
#-------------------------------------------------------------------------------
25
from __future__ import absolute_import
27
from traits.api import Str, Range, Enum, Property, Trait
29
# CIRCULAR IMPORT FIXME: Importing from the source rather than traits.ui.api
30
# to avoid circular imports, as this EditorFactory will be part of
31
# traits.ui.api as well.
33
from ..view import View
35
from ..ui_traits import AView, Image
37
from ..editor_factory import EditorFactory
39
#-------------------------------------------------------------------------------
40
# 'ToolkitEditorFactory' class:
41
#-------------------------------------------------------------------------------
43
class ToolkitEditorFactory ( EditorFactory ):
44
""" Editor factory for buttons.
47
#---------------------------------------------------------------------------
49
#---------------------------------------------------------------------------
51
# Value to set when the button is clicked
54
# Optional label for the button
57
# The name of the external object trait that the button label is synced to
60
# The name of the trait on the object that contains the list of possible
61
# values. If this is set, then the value, label, and label_value traits
62
# are ignored; instead, they will be set from this list. When this button
63
# is clicked, the value set will be the one selected from the drop-down.
64
values_trait = Trait(None, None, Str)
66
# (Optional) Image to display on the button
69
# Extra padding to add to both the left and the right sides
70
width_padding = Range( 0, 31, 7 )
72
# Extra padding to add to both the top and the bottom sides
73
height_padding = Range( 0, 31, 5 )
76
style = Enum( 'button', 'radio', 'toolbar', 'checkbox' )
78
# Orientation of the text relative to the image
79
orientation = Enum( 'vertical', 'horizontal' )
81
# The optional view to display when the button is clicked:
84
#---------------------------------------------------------------------------
85
# Traits view definition:
86
#---------------------------------------------------------------------------
88
traits_view = View( [ 'label', 'value', '|[]' ] )
90
#---------------------------------------------------------------------------
91
# Implementation of the 'value' property:
92
#---------------------------------------------------------------------------
94
def _get_value ( self ):
97
def _set_value ( self, value ):
99
if isinstance(value, basestring):
101
self._value = int( value )
104
self._value = float( value )
108
#---------------------------------------------------------------------------
109
# Initializes the object:
110
#---------------------------------------------------------------------------
112
def __init__ ( self, **traits ):
114
super( ToolkitEditorFactory, self ).__init__( **traits )
117
# Define the ButtonEditor class
118
ButtonEditor = ToolkitEditorFactory
120
### EOF ---------------------------------------------------------------------