1
#------------------------------------------------------------------------------
3
# Copyright (c) 2005, 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 various range editors for the wxPython user interface toolkit.
21
#-------------------------------------------------------------------------------
23
#-------------------------------------------------------------------------------
32
import TraitError, Str, Float, Any, Bool
34
# FIXME: ToolkitEditorFactory is a proxy class defined here just for backward
35
# compatibility. The class has been moved to the
36
# traitsui.editors.range_editor file.
37
from traitsui.editors.range_editor \
38
import ToolkitEditorFactory
47
import OKColor, ErrorColor
50
import TraitsUIPanel, Slider
52
#-------------------------------------------------------------------------------
53
# 'BaseRangeEditor' class:
54
#-------------------------------------------------------------------------------
56
class BaseRangeEditor ( Editor ):
57
""" The base class for Range editors. Using an evaluate trait, if specified,
58
when assigning numbers the object trait.
61
#---------------------------------------------------------------------------
63
#---------------------------------------------------------------------------
65
# Function to evaluate floats/ints
68
#---------------------------------------------------------------------------
69
# Sets the associated object trait's value:
70
#---------------------------------------------------------------------------
72
def _set_value ( self, value ):
73
if self.evaluate is not None:
74
value = self.evaluate( value )
75
Editor._set_value( self, value )
77
#-------------------------------------------------------------------------------
78
# 'SimpleSliderEditor' class:
79
#-------------------------------------------------------------------------------
81
class SimpleSliderEditor ( BaseRangeEditor ):
82
""" Simple style of range editor that displays a slider and a text field.
84
The user can set a value either by moving the slider or by typing a value
88
#---------------------------------------------------------------------------
90
#---------------------------------------------------------------------------
92
# Low value for the slider range
95
# High value for the slider range
98
# Formatting string used to format value and labels
101
# Flag indicating that the UI is in the process of being updated
102
ui_changing = Bool( False )
104
#---------------------------------------------------------------------------
105
# Finishes initializing the editor by creating the underlying toolkit
107
#---------------------------------------------------------------------------
109
def init ( self, parent ):
110
""" Finishes initializing the editor by creating the underlying toolkit
113
factory = self.factory
114
if not factory.low_name:
115
self.low = factory.low
117
if not factory.high_name:
118
self.high = factory.high
120
self.format = factory.format
122
self.evaluate = factory.evaluate
123
self.sync_value( factory.evaluate_name, 'evaluate', 'from' )
125
size = wx.DefaultSize
126
if factory.label_width > 0:
127
size = wx.Size( factory.label_width, 20 )
129
self.sync_value( factory.low_name, 'low', 'from' )
130
self.sync_value( factory.high_name, 'high', 'from' )
131
self.control = panel = TraitsUIPanel( parent, -1 )
132
sizer = wx.BoxSizer( wx.HORIZONTAL )
135
if not (self.low <= fvalue <= self.high):
140
fvalue_text = self.format % fvalue
141
except (ValueError, TypeError), e:
144
ivalue = self._convert_to_slider(fvalue)
146
self._label_lo = wx.StaticText( panel, -1, '999999', size = size,
147
style = wx.ALIGN_RIGHT | wx.ST_NO_AUTORESIZE )
148
sizer.Add( self._label_lo, 0, wx.ALIGN_CENTER )
149
panel.slider = slider = Slider( panel, -1, ivalue, 0, 10000,
150
size = wx.Size( 80, 20 ),
151
style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS )
152
slider.SetTickFreq( 1000, 1 )
153
slider.SetPageSize( 1000 )
154
slider.SetLineSize( 100 )
155
wx.EVT_SCROLL( slider, self.update_object_on_scroll )
156
sizer.Add( slider, 1, wx.EXPAND )
157
self._label_hi = wx.StaticText( panel, -1, '999999', size = size )
158
sizer.Add( self._label_hi, 0, wx.ALIGN_CENTER )
160
panel.text = text = wx.TextCtrl( panel, -1, fvalue_text,
161
size = wx.Size( 56, 20 ),
162
style = wx.TE_PROCESS_ENTER )
163
wx.EVT_TEXT_ENTER( panel, text.GetId(), self.update_object_on_enter )
164
wx.EVT_KILL_FOCUS( text, self.update_object_on_enter )
166
sizer.Add( text, 0, wx.LEFT | wx.EXPAND, 4 )
168
low_label = factory.low_label
169
if factory.low_name != '':
170
low_label = self.format % self.low
172
high_label = factory.high_label
173
if factory.high_name != '':
174
high_label = self.format % self.high
176
self._label_lo.SetLabel( low_label )
177
self._label_hi.SetLabel( high_label )
178
self.set_tooltip( slider )
179
self.set_tooltip( self._label_lo )
180
self.set_tooltip( self._label_hi )
181
self.set_tooltip( text )
184
panel.SetSizerAndFit( sizer )
186
#---------------------------------------------------------------------------
187
# Handles the user changing the current slider value:
188
#---------------------------------------------------------------------------
190
def update_object_on_scroll ( self, event ):
191
""" Handles the user changing the current slider value.
193
value = self._convert_from_slider(event.GetPosition())
194
event_type = event.GetEventType()
195
if ((event_type == wx.wxEVT_SCROLL_ENDSCROLL) or
196
(self.factory.auto_set and
197
(event_type == wx.wxEVT_SCROLL_THUMBTRACK)) or
198
(self.factory.enter_set and
199
(event_type == wx.wxEVT_SCROLL_THUMBRELEASE))):
201
self.ui_changing = True
202
self.control.text.SetValue( self.format % value )
207
self.ui_changing = False
209
#---------------------------------------------------------------------------
210
# Handle the user pressing the 'Enter' key in the edit control:
211
#---------------------------------------------------------------------------
213
def update_object_on_enter ( self, event ):
214
""" Handles the user pressing the Enter key in the text field.
217
# There are cases where this method is called with self.control == None.
218
if self.control is None:
223
value = self.control.text.GetValue().strip()
224
if self.factory.is_float:
228
except Exception, ex:
229
# The user entered something that didn't eval as a number (e.g., 'foo').
230
# Pretend it didn't happen (i.e. do not change self.value).
232
self.control.text.SetValue( str( value ) )
235
if not self.ui_changing:
236
self.control.slider.SetValue(
237
self._convert_to_slider(self.value) )
238
self.control.text.SetBackgroundColour(OKColor)
239
self.control.text.Refresh()
240
if self._error is not None:
246
#---------------------------------------------------------------------------
247
# Handles an error that occurs while setting the object's trait value:
248
#---------------------------------------------------------------------------
250
def error ( self, excp ):
251
""" Handles an error that occurs while setting the object's trait value.
253
if self._error is None:
256
super(SimpleSliderEditor, self).error(excp)
257
self.set_error_state( True )
259
#---------------------------------------------------------------------------
260
# Updates the editor when the object trait changes external to the editor:
261
#---------------------------------------------------------------------------
263
def update_editor ( self ):
264
""" Updates the editor when the object trait changes externally to the
269
text = self.format % value
270
1 / (self.low <= value <= self.high)
275
ivalue = self._convert_to_slider( value )
276
self.control.text.SetValue( text )
277
self.control.slider.SetValue( ivalue )
279
def _convert_to_slider(self, value):
280
""" Returns the slider setting corresponding to the user-supplied value.
282
if self.high > self.low:
283
ivalue = int( (float( value - self.low ) /
284
(self.high - self.low)) * 10000.0 )
289
def _convert_from_slider(self, ivalue):
290
""" Returns the float or integer value corresponding to the slider
293
value = self.low + ((float( ivalue ) / 10000.0) *
294
(self.high - self.low))
295
if not self.factory.is_float:
296
value = int(round(value))
299
#---------------------------------------------------------------------------
300
# Returns the editor's control for indicating error status:
301
#---------------------------------------------------------------------------
303
def get_error_control ( self ):
304
""" Returns the editor's control for indicating error status.
306
return self.control.text
308
#---------------------------------------------------------------------------
309
# Handles the 'low'/'high' traits being changed:
310
#---------------------------------------------------------------------------
312
def _low_changed ( self, low ):
314
if self.factory.is_float:
315
self.value = float( low )
317
self.value = int( low )
319
if self._label_lo is not None:
320
self._label_lo.SetLabel( self.format % low )
323
def _high_changed ( self, high ):
324
if self.value > high:
325
if self.factory.is_float:
326
self.value = float( high )
328
self.value = int( high )
330
if self._label_hi is not None:
331
self._label_hi.SetLabel( self.format % high )
335
#-------------------------------------------------------------------------------
336
class LogRangeSliderEditor ( SimpleSliderEditor ):
337
#-------------------------------------------------------------------------------
338
""" A slider editor for log-spaced values
341
def _convert_to_slider(self, value):
342
""" Returns the slider setting corresponding to the user-supplied value.
344
value = max(value, self.low)
345
ivalue = int( (log10(value) - log10(self.low)) /
346
(log10(self.high) - log10(self.low)) * 10000.0)
349
def _convert_from_slider(self, ivalue):
350
""" Returns the float or integer value corresponding to the slider
353
value = float( ivalue ) / 10000.0 * (log10(self.high) -log10(self.low))
354
# Do this to handle floating point errors, where fvalue may exceed
356
fvalue = min(self.low*10**(value), self.high)
357
if not self.factory.is_float:
358
fvalue = int(round(fvalue))
361
#-------------------------------------------------------------------------------
362
# 'LargeRangeSliderEditor' class:
363
#-------------------------------------------------------------------------------
365
class LargeRangeSliderEditor ( BaseRangeEditor ):
366
""" A slider editor for large ranges.
368
The editor displays a slider and a text field. A subset of the total
369
range is displayed in the slider; arrow buttons at each end of the
370
slider let the user move the displayed range higher or lower.
373
#---------------------------------------------------------------------------
375
#---------------------------------------------------------------------------
377
# Low value for the slider range
380
# High value for the slider range
383
# Low end of displayed range
386
# High end of displayed range
389
# Flag indicating that the UI is in the process of being updated
390
ui_changing = Bool( False )
392
#---------------------------------------------------------------------------
393
# Finishes initializing the editor by creating the underlying toolkit
395
#---------------------------------------------------------------------------
397
def init ( self, parent ):
398
""" Finishes initializing the editor by creating the underlying toolkit
401
factory = self.factory
403
# Initialize using the factory range defaults:
404
self.low = factory.low
405
self.high = factory.high
406
self.evaluate = factory.evaluate
408
# Hook up the traits to listen to the object.
409
self.sync_value( factory.low_name, 'low', 'from' )
410
self.sync_value( factory.high_name, 'high', 'from' )
411
self.sync_value( factory.evaluate_name, 'evaluate', 'from' )
418
self.control = panel = TraitsUIPanel( parent, -1 )
419
sizer = wx.BoxSizer( wx.HORIZONTAL )
422
fvalue_text = self._format % fvalue
423
1 / (low <= fvalue <= high)
429
ivalue = int( (float( fvalue - low ) / (high - low)) * 10000 )
434
label_lo = wx.StaticText( panel, -1, '999999' )
435
panel.label_lo = label_lo
436
sizer.Add( label_lo, 2, wx.ALIGN_CENTER )
438
# Lower limit button:
439
bmp = wx.ArtProvider.GetBitmap( wx.ART_GO_BACK,
441
button_lo = wx.BitmapButton( panel, -1, bitmap = bmp, size = ( -1, 20 ),
442
style = wx.BU_EXACTFIT | wx.NO_BORDER )
443
panel.button_lo = button_lo
444
button_lo.Bind( wx.EVT_BUTTON, self.reduce_range, button_lo )
445
sizer.Add( button_lo, 1, wx.ALIGN_CENTER )
448
panel.slider = slider = Slider( panel, -1, ivalue, 0, 10000,
449
size = wx.Size( 80, 20 ),
450
style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS )
451
slider.SetTickFreq( 1000, 1 )
452
slider.SetPageSize( 1000 )
453
slider.SetLineSize( 100 )
454
wx.EVT_SCROLL( slider, self.update_object_on_scroll )
455
sizer.Add( slider, 6, wx.EXPAND )
457
# Upper limit button:
458
bmp = wx.ArtProvider.GetBitmap( wx.ART_GO_FORWARD,
460
button_hi = wx.BitmapButton( panel, -1, bitmap = bmp, size = ( -1, 20 ),
461
style = wx.BU_EXACTFIT | wx.NO_BORDER )
462
panel.button_hi = button_hi
463
button_hi.Bind( wx.EVT_BUTTON, self.increase_range, button_hi )
464
sizer.Add( button_hi, 1, wx.ALIGN_CENTER )
467
label_hi = wx.StaticText( panel, -1, '999999' )
468
panel.label_hi = label_hi
469
sizer.Add( label_hi, 2, wx.ALIGN_CENTER )
472
panel.text = text = wx.TextCtrl( panel, -1, fvalue_text,
473
size = wx.Size( 56, 20 ),
474
style = wx.TE_PROCESS_ENTER )
475
wx.EVT_TEXT_ENTER( panel, text.GetId(), self.update_object_on_enter )
476
wx.EVT_KILL_FOCUS( text, self.update_object_on_enter )
478
sizer.Add( text, 0, wx.LEFT | wx.EXPAND, 4 )
481
panel.SetSizerAndFit( sizer )
482
label_lo.SetLabel( str(low) )
483
label_hi.SetLabel( str(high) )
484
self.set_tooltip( slider )
485
self.set_tooltip( label_lo )
486
self.set_tooltip( label_hi )
487
self.set_tooltip( text )
489
# Update the ranges and button just in case.
490
self.update_range_ui()
492
#---------------------------------------------------------------------------
493
# Handles the user changing the current slider value:
494
#---------------------------------------------------------------------------
496
def update_object_on_scroll ( self, event ):
497
""" Handles the user changing the current slider value.
501
value = low + ((float( event.GetPosition() ) / 10000.0) *
503
self.control.text.SetValue( self._format % value )
504
event_type = event.GetEventType()
506
self.ui_changing = True
507
if ((event_type == wx.wxEVT_SCROLL_ENDSCROLL) or
508
(self.factory.auto_set and
509
(event_type == wx.wxEVT_SCROLL_THUMBTRACK)) or
510
(self.factory.enter_set and
511
(event_type == wx.wxEVT_SCROLL_THUMBRELEASE))):
512
if self.factory.is_float:
515
self.value = int( value )
517
self.ui_changing = False
519
#---------------------------------------------------------------------------
520
# Handle the user pressing the 'Enter' key in the edit control:
521
#---------------------------------------------------------------------------
523
def update_object_on_enter ( self, event ):
524
""" Handles the user pressing the Enter key in the text field.
527
value = self.control.text.GetValue().strip()
529
if self.factory.is_float:
533
except Exception, ex:
534
# The user entered something that didn't eval as a number (e.g., 'foo').
535
# Pretend it didn't happen (i.e. do not change self.value).
537
self.control.text.SetValue( str( value ) )
540
self.control.text.SetBackgroundColour(OKColor)
541
self.control.text.Refresh()
542
# Update the slider range.
543
# Set ui_changing to True to avoid recursion:
544
# the update_range_ui method will try to set the value in the text
545
# box, which will again fire this method if auto_set is True.
546
if not self.ui_changing:
547
self.ui_changing = True
549
self.update_range_ui()
550
self.ui_changing = False
551
if self._error is not None:
554
except TraitError, excp:
557
#---------------------------------------------------------------------------
558
# Handles an error that occurs while setting the object's trait value:
559
#---------------------------------------------------------------------------
561
def error ( self, excp ):
562
""" Handles an error that occurs while setting the object's trait value.
564
if self._error is None:
567
super(LargeRangeSliderEditor, self).error(excp)
568
self.set_error_state( True )
570
#---------------------------------------------------------------------------
571
# Updates the editor when the object trait changes external to the editor:
572
#---------------------------------------------------------------------------
574
def update_editor ( self ):
575
""" Updates the editor when the object trait changes externally to the
582
text = self._format % value
583
1 / (low <= value <= high)
588
if not self.ui_changing:
590
self.update_range_ui()
592
def update_range_ui ( self ):
593
""" Updates the slider range controls.
595
low, high = self.cur_low, self.cur_high
598
self.control.label_lo.SetLabel( self._format % low )
599
self.control.label_hi.SetLabel( self._format % high )
601
ivalue = int( (float( value - low ) / (high - low)) * 10000.0 )
604
self.control.slider.SetValue( ivalue )
605
text = self._format % self.value
606
self.control.text.SetValue( text )
607
factory = self.factory
608
f_low, f_high = self.low, self.high
611
self.control.button_lo.Disable()
613
self.control.button_lo.Enable()
616
self.control.button_hi.Disable()
618
self.control.button_hi.Enable()
620
def init_range ( self ):
621
""" Initializes the slider range controls.
624
factory = self.factory
625
low, high = self.low, self.high
626
if (high is None) and (low is not None):
631
cur_low = max( value - 10, low )
632
cur_high = min( value + 10, high )
634
d = 0.5 * (10**int( log10( mag ) + 1 ))
635
cur_low = max( low, value - d )
636
cur_high = min( high, value + d )
638
self.cur_low, self.cur_high = cur_low, cur_high
640
def reduce_range ( self, event ):
641
""" Reduces the extent of the displayed range.
643
factory = self.factory
644
low, high = self.low, self.high
645
if abs( self.cur_low ) < 10:
646
self.cur_low = max( -10, low )
647
self.cur_high = min( 10, high )
648
elif self.cur_low > 0:
649
self.cur_high = self.cur_low
650
self.cur_low = max( low, self.cur_low / 10 )
652
self.cur_high = self.cur_low
653
self.cur_low = max( low, self.cur_low * 10 )
655
self.ui_changing = True
656
self.value = min( max( self.value, self.cur_low ), self.cur_high )
657
self.ui_changing = False
658
self.update_range_ui()
660
def increase_range ( self, event ):
661
""" Increased the extent of the displayed range.
663
factory = self.factory
664
low, high = self.low, self.high
665
if abs( self.cur_high ) < 10:
666
self.cur_low = max( -10, low )
667
self.cur_high = min( 10, high )
668
elif self.cur_high > 0:
669
self.cur_low = self.cur_high
670
self.cur_high = min( high, self.cur_high * 10 )
672
self.cur_low = self.cur_high
673
self.cur_high = min( high, self.cur_high / 10 )
675
self.ui_changing = True
676
self.value = min( max( self.value, self.cur_low ), self.cur_high )
677
self.ui_changing = False
678
self.update_range_ui()
680
def _set_format ( self ):
682
factory = self.factory
683
low, high = self.cur_low, self.cur_high
687
self._format = '%.2g'
689
self._format = '%%.%df' % max( 0, 4 -
690
int( log10( high - low ) ) )
692
self._format = '%.3f'
694
#---------------------------------------------------------------------------
695
# Returns the editor's control for indicating error status:
696
#---------------------------------------------------------------------------
698
def get_error_control ( self ):
699
""" Returns the editor's control for indicating error status.
701
return self.control.text
703
#---------------------------------------------------------------------------
704
# Handles the 'low'/'high' traits being changed:
705
#---------------------------------------------------------------------------
707
def _low_changed ( self, low ):
708
if self.control is not None:
710
if self.factory.is_float:
711
self.value = float( low )
713
self.value = int( low )
717
def _high_changed ( self, high ):
718
if self.control is not None:
719
if self.value > high:
720
if self.factory.is_float:
721
self.value = float( high )
723
self.value = int( high )
727
#-------------------------------------------------------------------------------
728
# 'SimpleSpinEditor' class:
729
#-------------------------------------------------------------------------------
731
class SimpleSpinEditor ( BaseRangeEditor ):
732
""" A simple style of range editor that displays a spin box control.
735
#---------------------------------------------------------------------------
737
#---------------------------------------------------------------------------
739
# Low value for the slider range
742
# High value for the slider range
745
#---------------------------------------------------------------------------
746
# Finishes initializing the editor by creating the underlying toolkit
748
#---------------------------------------------------------------------------
750
def init ( self, parent ):
751
""" Finishes initializing the editor by creating the underlying toolkit
754
factory = self.factory
755
if not factory.low_name:
756
self.low = factory.low
758
if not factory.high_name:
759
self.high = factory.high
761
self.sync_value( factory.low_name, 'low', 'from' )
762
self.sync_value( factory.high_name, 'high', 'from' )
765
self.control = wx.SpinCtrl( parent, -1, self.str_value,
768
initial = self.value )
769
wx.EVT_SPINCTRL( parent, self.control.GetId(), self.update_object )
770
if sys.platform.startswith( 'win' ):
771
wx.EVT_TEXT( parent, self.control.GetId(), self.update_object )
774
#---------------------------------------------------------------------------
775
# Handle the user selecting a new value from the spin control:
776
#---------------------------------------------------------------------------
778
def update_object ( self, event ):
779
""" Handles the user selecting a new value in the spin box.
783
self.value = self.control.GetValue()
787
#---------------------------------------------------------------------------
788
# Updates the editor when the object trait changes external to the editor:
789
#---------------------------------------------------------------------------
791
def update_editor ( self ):
792
""" Updates the editor when the object trait changes externally to the
797
self.control.SetValue( int( self.value ) )
801
#---------------------------------------------------------------------------
802
# Handles the 'low'/'high' traits being changed:
803
#---------------------------------------------------------------------------
805
def _low_changed ( self, low ):
807
if self.factory.is_float:
808
self.value = float( low )
810
self.value = int( low )
812
self.control.SetRange( self.low, self.high )
813
self.control.SetValue( int( self.value ) )
815
def _high_changed ( self, high ):
816
if self.value > high:
817
if self.factory.is_float:
818
self.value = float( high )
820
self.value = int( high )
822
self.control.SetRange( self.low, self.high )
823
self.control.SetValue( int( self.value ) )
825
#-------------------------------------------------------------------------------
826
# 'RangeTextEditor' class:
827
#-------------------------------------------------------------------------------
829
class RangeTextEditor ( TextEditor ):
830
""" Editor for ranges that displays a text field. If the user enters a
831
value that is outside the allowed range, the background of the field
832
changes color to indicate an error.
835
#---------------------------------------------------------------------------
837
#---------------------------------------------------------------------------
839
# Function to evaluate floats/ints
842
#---------------------------------------------------------------------------
843
# Finishes initializing the editor by creating the underlying toolkit
845
#---------------------------------------------------------------------------
847
def init ( self, parent ):
848
""" Finishes initializing the editor by creating the underlying toolkit
852
if self.factory.enter_set:
853
control = wx.TextCtrl( parent, -1, self.str_value,
854
style = wx.TE_PROCESS_ENTER )
855
wx.EVT_TEXT_ENTER( parent, control.GetId(), self.update_object )
857
control = wx.TextCtrl( parent, -1, self.str_value )
859
wx.EVT_KILL_FOCUS( control, self.update_object )
861
if self.factory.auto_set:
862
wx.EVT_TEXT( parent, control.GetId(), self.update_object )
864
self.evaluate = self.factory.evaluate
865
self.sync_value( self.factory.evaluate_name, 'evaluate', 'from' )
867
self.control = control
870
#---------------------------------------------------------------------------
871
# Handles the user entering input data in the edit control:
872
#---------------------------------------------------------------------------
874
def update_object ( self, event ):
875
""" Handles the user entering input data in the edit control.
878
# There are cases where this method is called with self.control == None.
879
if self.control is None:
882
value = self.control.GetValue()
884
# Try to convert the string value entered by the user to a numerical value.
886
if self.evaluate is not None:
887
value = self.evaluate(value)
889
if self.factory.is_float:
893
except Exception, excp:
894
# The conversion failed.
898
# Try to assign the numerical value to the trait.
899
# This may fail because of constraints on the trait.
902
self.control.SetBackgroundColour(OKColor)
903
self.control.Refresh()
904
if self._error is not None:
907
except TraitError, excp:
910
#---------------------------------------------------------------------------
911
# Handles an error that occurs while setting the object's trait value:
912
#---------------------------------------------------------------------------
914
def error ( self, excp ):
915
""" Handles an error that occurs while setting the object's trait value.
917
if self._error is None:
920
super(RangeTextEditor, self).error(excp)
921
self.set_error_state( True )
923
#-------------------------------------------------------------------------------
924
# 'SimpleEnumEditor' factory adaptor:
925
#-------------------------------------------------------------------------------
927
def SimpleEnumEditor ( parent, factory, ui, object, name, description ):
928
return CustomEnumEditor( parent, factory, ui, object, name, description,
931
#-------------------------------------------------------------------------------
932
# 'CustomEnumEditor' factory adaptor:
933
#-------------------------------------------------------------------------------
935
def CustomEnumEditor ( parent, factory, ui, object, name, description,
937
""" Factory adapter that returns a enumeration editor of the specified
940
if factory._enum is None:
941
import traitsui.editors.enum_editor as enum_editor
942
factory._enum = enum_editor.ToolkitEditorFactory(
943
values = range( factory.low, factory.high + 1 ),
944
cols = factory.cols )
946
if style == 'simple':
947
return factory._enum.simple_editor( ui, object, name, description,
950
return factory._enum.custom_editor( ui, object, name, description, parent )
952
#-------------------------------------------------------------------------------
953
# Defines the mapping between editor factory 'mode's and Editor classes:
954
#-------------------------------------------------------------------------------
956
# Mapping between editor factory modes and simple editor classes
958
'slider': SimpleSliderEditor,
959
'xslider': LargeRangeSliderEditor,
960
'spinner': SimpleSpinEditor,
961
'enum': SimpleEnumEditor,
962
'text': RangeTextEditor,
963
'logslider': LogRangeSliderEditor
965
# Mapping between editor factory modes and custom editor classes
967
'slider': SimpleSliderEditor,
968
'xslider': LargeRangeSliderEditor,
969
'spinner': SimpleSpinEditor,
970
'enum': CustomEnumEditor,
971
'text': RangeTextEditor,
972
'logslider': LogRangeSliderEditor
975
### EOF #######################################################################