Skip to content
This repository
Browse code

ENH: Use a common, backend-independent implementation of ColorColumn.

  • Loading branch information...
commit 55bed18efa87d370c002e68a3f6e1518da590465 1 parent 729c5d3
Robert Kern rkern authored
2  integrationtests/ui/table_editor_color_test.py
@@ -21,7 +21,7 @@
21 21 from traitsui.api \
22 22 import View, Item, TableEditor
23 23
24   -from traitsui.wx.color_column \
  24 +from traitsui.color_column \
25 25 import ColorColumn
26 26
27 27 from enable.api \
65 traitsui/color_column.py
... ... @@ -0,0 +1,65 @@
  1 +#------------------------------------------------------------------------------
  2 +#
  3 +# Copyright (c) 2005, 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: David C. Morrill
  14 +#
  15 +#------------------------------------------------------------------------------
  16 +
  17 +""" Table column object for Color traits.
  18 +"""
  19 +
  20 +#-------------------------------------------------------------------------------
  21 +# Imports:
  22 +#-------------------------------------------------------------------------------
  23 +
  24 +from traitsui.table_column \
  25 + import ObjectColumn
  26 +
  27 +#-------------------------------------------------------------------------------
  28 +# 'ColorColumn' class:
  29 +#-------------------------------------------------------------------------------
  30 +
  31 +class ColorColumn ( ObjectColumn ):
  32 + """ Table column object for Color traits. """
  33 +
  34 +#-- ObjectColumn Overrides -----------------------------------------------------
  35 +
  36 + def get_cell_color ( self, object ):
  37 + """ Returns the cell background color for the column for a specified
  38 + object.
  39 + """
  40 + color_values = getattr( object, self.name + '_' )
  41 + if type( color_values ) is tuple:
  42 + tk_color = self._as_int_rgb_tuple( color_values )
  43 + else:
  44 + tk_color = super( ColorColumn, self ).get_cell_color( object )
  45 + return tk_color
  46 +
  47 + def get_value ( self, object ):
  48 + """ Gets the value of the column for a specified object.
  49 + """
  50 + value = getattr( self.get_object( object ), self.name )
  51 + if type( value ) is tuple:
  52 + value = "(%3d, %3d, %3d)" % self._as_int_rgb_tuple( value[:-1] )
  53 + elif type( value ) is not str:
  54 + value = str( value )
  55 +
  56 + return value
  57 +
  58 +#-- Private Methods ------------------------------------------------------------
  59 +
  60 + def _as_int_rgb_tuple ( self, color_values ):
  61 + """ Returns object color as RGB integers. """
  62 + return ( int( 255 * color_values[0] ),
  63 + int( 255 * color_values[1] ),
  64 + int( 255 * color_values[2] ) )
  65 +
51 traitsui/wx/color_column.py
@@ -17,52 +17,9 @@
17 17 """ Table column object for Color traits.
18 18 """
19 19
20   -#-------------------------------------------------------------------------------
21   -# Imports:
22   -#-------------------------------------------------------------------------------
  20 +import warnings
  21 +warnings.warn("traitsui.wx.color_column is deprecated. Use the "
  22 + "backend-independent implementation in traitsui.color_column")
23 23
24   -from wx \
25   - import Colour as WxColour
26   -
27   -from traitsui.table_column \
28   - import ObjectColumn
29   -
30   -#-------------------------------------------------------------------------------
31   -# 'ColorColumn' class:
32   -#-------------------------------------------------------------------------------
33   -
34   -class ColorColumn ( ObjectColumn ):
35   - """ Table column object for Color traits. """
36   -
37   -#-- ObjectColumn Overrides -----------------------------------------------------
38   -
39   - def get_cell_color ( self, object ):
40   - """ Returns the cell background color for the column for a specified
41   - object.
42   - """
43   - color_values = getattr( object, self.name + '_' )
44   - if type( color_values ) is tuple:
45   - wxcolor = WxColour( *self._as_int_rgb_tuple( color_values ) )
46   - else:
47   - wxcolor = super( ColorColumn, self ).get_cell_color( object )
48   - return wxcolor
49   -
50   - def get_value ( self, object ):
51   - """ Gets the value of the column for a specified object.
52   - """
53   - value = getattr( self.get_object( object ), self.name )
54   - if type( value ) is tuple:
55   - value = "(%3d, %3d, %3d)" % self._as_int_rgb_tuple( value[:-1] )
56   - elif type( value ) is not str:
57   - value = str( value )
58   -
59   - return value
60   -
61   -#-- Private Methods ------------------------------------------------------------
62   -
63   - def _as_int_rgb_tuple ( self, color_values ):
64   - """ Returns object color as RGB integers. """
65   - return ( int( 255 * color_values[0] ),
66   - int( 255 * color_values[1] ),
67   - int( 255 * color_values[2] ) )
  24 +from traitsui.color_column import ColorColumn
68 25

0 comments on commit 55bed18

Please sign in to comment.
Something went wrong with that request. Please try again.