Inherits from
- CHasTraits: ctraits.CHasTraits
Attributes
- on_trait_event
Make 'on_trait_event' a synonym for 'on_trait_change':
on_trait_event = on_trait_change
- trait_added
An event fired when a new trait is dynamically added to the object:
trait_added = Event(basestring)
- trait_modified
An event that can be fired to indicate that the state of the object has been modified:
trait_modified = Event
- wrappers
Mapping from dispatch type to notification wrapper class type:
wrappers = { Const('same') : Name('TraitChangeNotifyWrapper'), Const('ui') : Name('UITraitChangeNotifyWrapper'), Const('new') : Name('NewTraitChangeNotifyWrapper') }
Method summary
- __deepcopy__(self, memo)
- __getstate__(self)
- __prefix_trait__(self, name)
- __reduce_ex__(self, protocol)
- __setstate__(self, state)
- add_class_trait(cls, name, *trait)
- add_trait(self, name, *trait)
- add_trait_category(cls, category)
- add_trait_listener(self, object, prefix = '')
- all_trait_names(self)
- base_trait(self, name)
- class_default_traits_view(cls)
- class_editable_traits(cls)
- class_trait_names(cls, **metadata)
- class_trait_view(cls, name = None, view_element = None)
- class_trait_view_elements(cls)
- class_traits(cls, **metadata)
- clone_traits(self, traits = None, memo = None, copy = None, **metadata)
- configure_traits(self, filename = None, view = None, kind = None, edit = True, context = None, handler = None, id = '', scrollable = None, **args)
- copy_traits(self, other, traits = None, memo = None, copy = None, **metadata)
- copyable_trait_names(self, **metadata)
- default_traits_view(self)
- edit_traits(self, view = None, parent = None, kind = None, context = None, handler = None, id = '', scrollable = None, **args)
- editable_traits(self)
- get(self, *names, **metadata)
- on_trait_change(self, handler, name = None, remove = False, dispatch = 'same')
- print_traits(self, show_help = False, **metadata)
- remove_trait(self, name)
- remove_trait_listener(self, object, prefix = '')
- reset_traits(self, traits = None, **metadata)
- set(self, trait_change_notify = True, **traits)
- set_trait_dispatch_handler(cls, name, klass, override = False)
- sync_trait(self, trait_name, object, alias = None, mutual = True, remove = False)
- trait(self, name, force = False, copy = False)
- trait_context(self)
- trait_monitor(cls, handler, remove = False)
- trait_names(self, **metadata)
- trait_subclasses(cls, all = False)
- trait_view(self, name = None, view_element = None)
- trait_view_elements(self)
- trait_views(self, klass = None)
- traits(self, **metadata)
- validate_trait(self, name, value)
Methods
- __deepcopy__(self, memo)
Creates a deep copy of the object.
- __getstate__(self)
Returns dictionary of traits to pickle.
Subclasses should override __getstate__ and use the follow pattern to remove items that should not be persisted:
def __getstate__(self): state = super(X,self).__getstate__() for key in ['foo', 'bar']: if state.has_key(key): del state[key] return state - __prefix_trait__(self, name)
- __reduce_ex__(self, protocol)
- __setstate__(self, state)
- add_class_trait(cls, name, *trait)
Adds a named trait attribute to this class.
Parameters
- name : string
- Name of the attribute to add
- trait : a trait or a value that can be converted to a trait using Trait()
- Trait definition of the attribute. It can be a single value or a list equivalent to an argument list for the Trait() function
- add_trait(self, name, *trait)
Adds a trait attribute to this object.
Parameters
- name : string
- Name of the attribute to add
- trait : trait or a value that can be converted to a trait by Trait()
- Trait definition for name. If more than one value is specified, it is equivalent to passing the entire list of values to Trait().
- add_trait_category(cls, category)
Adds a trait category to a class.
- add_trait_listener(self, object, prefix = '')
- all_trait_names(self)
Returns the list of all trait names, including implicitly defined traits.
- base_trait(self, name)
Returns the base trait definition for a trait attribute.
Parameters
- name : string
- Name of the attribute whose trait definition is returned.
Description
This method is similar to the trait() method, and returns a different result only in the case where the trait attribute defined by name is a delegate. In this case, the base_trait() method follows the delegation chain until a non-delegated trait attribute is reached, and returns the definition of that attribute's trait as the result.
- class_default_traits_view(cls)
Returns the name of the default traits view for the class.
- class_editable_traits(cls)
Returns an alphabetically sorted list of the names of non-event trait attributes associated with the current class.
- class_trait_names(cls, **metadata)
Returns a list of the names of all trait attributes whose definitions match the set of metadata criteria specified.
Parameters
- metadata : dictionary
- Criteria for selecting trait attributes
Description
This method is similar to the traits() method, but returns only the names of the matching trait attributes, not the trait definitions.
- class_trait_view(cls, name = None, view_element = None)
- class_trait_view_elements(cls)
Returns the ViewElements object associated with the class.
The returned object can be used to access all the view elements associated with the class.
- class_traits(cls, **metadata)
Returns a dictionary containing the definitions of all of the trait attributes of the class that match the set of metadata criteria.
Parameters
- metadata : dictionary
- Criteria for selecting trait attributes
Description
The keys of the returned dictionary are the trait attribute names, and the values are their corresponding trait definition objects.
If no metadata information is specified, then all explicitly defined trait attributes defined for the class are returned.
Otherwise, the metadata keyword dictionary is assumed to define a set of search criteria for selecting trait attributes of interest. The metadata dictionary keys correspond to the names of trait metadata attributes to examine, and the values correspond to the values the metadata attribute must have in order to be included in the search results.
The metadata values either may be simple Python values like strings or integers, or may be lambda expressions or functions that return True if the trait attribute is to be included in the result. A lambda expression or function must receive a single argument, which is the value of the trait metadata attribute being tested. If more than one metadata keyword is specified, a trait attribute must match the metadata values of all keywords to be included in the result.
- clone_traits(self, traits = None, memo = None, copy = None, **metadata)
Clones a new object from this one, optionally copying only a specified set of traits.
Parameters
- traits : list of strings
- The names of the trait attributes to copy.
- memo : dictionary
- A dictionary of objects that have already been copied.
- copy : None | 'deep' | 'shallow'
- The type of copy to perform on any trait that does not have explicit 'copy' metadata. A value of None means 'copy reference'.
Returns
The newly cloned object.
Description
Creates a new object that is a clone of the current object. If traits is None (the default), then all explicit trait attributes defined for this object are cloned. If traits is 'all' or an empty list, the list of traits returned by all_trait_names() is used; otherwise, traits must be a list of the names of the trait attributes to be cloned.
- configure_traits(self, filename = None, view = None, kind = None, edit = True, context = None, handler = None, id = '', scrollable = None, **args)
Creates and displays a dialog box for editing values of trait attributes, as if it were a complete, self-contained GUI application.
Parameters
- filename : string
- The name (including path) of a file that contains a pickled representation of the current object. When this parameter is specified, the method reads the corresponding file (if it exists) to restore the saved values of the object's traits before displaying them. If the user confirms the dialog box (by clicking OK), the new values are written to the file. If this parameter is not specified, the values are loaded from the in-memory object, and are not persisted when the dialog box is closed.
- view : view or string
- A View object (or its name) that defines a user interface for editing trait attribute values of the current object. If the view is defined as an attribute on this class, use the name of the attribute. Otherwise, use a reference to the view object. If this attribute is not specified, the View object returned by trait_view() is used.
- kind : string
- The type of user interface window to create. See the enthought.traits.ui.view.kind_trait trait for values and their meanings. If kind is unspecified or None, the kind attribute of the View object is used.
- edit : Boolean
- Indicates whether to display a user interface. If filename specifies an existing file, setting edit to False loads the saved values from that file into the object without requiring user interaction.
- context : object or dictionary
- A single object or a dictionary of string/object pairs, whose trait attributes are to be edited. If not specified, the current object is used
- handler : Handler object
- A handler object used for event handling in the dialog box. If None, the default handler for Traits UI is used.
- id : string
- A unique ID for persisting preferences about this user interface, such as size and position. If not specified, no user preferences are saved.
- scrollable : Boolean
- Indicates whether the dialog box should be scrollable. When set to True, scroll bars appear on the dialog box if it is not large enough to display all of the items in the view at one time.
Description
This method is intended for use in applications that do not normally have a GUI. Control does not resume in the calling application until the user closes the dialog box.
The method attempts to open and unpickle the contents of filename before displaying the dialog box. When editing is complete, the method attempts to pickle the updated contents of the object back to filename. If the file referenced by filename does not exist, the object is not modified before displaying the dialog box. If filename is unspecified or None, no pickling or unpickling occurs.
If edit is True (the default), a dialog box for editing the current object is displayed. If edit is False or None, no dialog box is displayed. You can use edit=False if you want the object to be restored from the contents of filename, without being modified by the user.
- copy_traits(self, other, traits = None, memo = None, copy = None, **metadata)
Copies another object's trait attributes into this one.
Parameters
- other : object
- The object whose trait attribute values should be copied.
- traits : list of strings
- A list of names of trait attributes to copy. If None or unspecified, the set of names returned by trait_names() is used. If 'all' or an empty list, the set of names returned by all_trait_names() is used.
- memo : dictionary
- A dictionary of objects that have already been copied.
- copy : None | 'deep' | 'shallow'
- The type of copy to perform on any trait that does not have explicit 'copy' metadata. A value of None means 'copy reference'.
Returns
A list of attributes that the method was unable to copy, which is empty if all the attributes were successfully copied.
- copyable_trait_names(self, **metadata)
Returns the list of trait names to copy or clone by default.
- default_traits_view(self)
Returns the name of the default traits view for the object's class.
- edit_traits(self, view = None, parent = None, kind = None, context = None, handler = None, id = '', scrollable = None, **args)
Displays a user interface window for editing trait attribute values.
Parameters
- view : view or string
- A View object (or its name) that defines a user interface for editing trait attribute values of the current object. If the view is defined as an attribute on this class, use the name of the attribute. Otherwise, use a reference to the view object. If this attribute is not specified, the View object returned by trait_view() is used.
- parent : window handle
- A user interface component to use as the parent window for the object's UI window.
- kind : string
- The type of user interface window to create. See the enthought.traits.ui.view.kind_trait trait for values and their meanings. If kind is unspecified or None, the kind attribute of the View object is used.
- context : object or dictionary
- A single object or a dictionary of string/object pairs, whose trait attributes are to be edited. If not specified, the current object is used.
- handler : Handler object
- A handler object used for event handling in the dialog box. If None, the default handler for Traits UI is used.
- id : string
- A unique ID for persisting preferences about this user interface, such as size and position. If not specified, no user preferences are saved.
- scrollable : Boolean
- Indicates whether the dialog box should be scrollable. When set to True, scroll bars appear on the dialog box if it is not large enough to display all of the items in the view at one time.
- editable_traits(self)
Returns an alphabetically sorted list of the names of non-event trait attributes associated with the current object.
- get(self, *names, **metadata)
Shortcut for getting object trait attributes.
Parameters
- names : list of trait attribute names
- Trait attributes whose values are requested
Returns
A dictionary whose keys are the names passed as arguments and whose values are the corresponding trait values
Description
Looks up the value of each trait whose name is passed as an argument and returns a dictionary containing the resulting name/value pairs. If any name does not correspond to a defined trait, it is not included in the result.
If no names are specified, the result is a dictionary containing name/value pairs for all traits defined on the object.
- on_trait_change(self, handler, name = None, remove = False, dispatch = 'same')
Causes the object to invoke a handler whenever a trait attribute is modified, or removes the association.
Parameters
- handler : function
- A trait notification function for the name trait attribute.
- name : string
- The name of the trait attribute whose value changes trigger the notification
- remove : Boolean
- If True, removes the previously-set association between handler and name; if False (the default), creates the association.
Description
Multiple handlers can be defined for the same object, or even for the same trait attribute on the same object. If name is not specified or is None, handler is invoked when any trait attribute on the object is changed.
- print_traits(self, show_help = False, **metadata)
Prints the values of all explicitly-defined, non-event trait attributes on the current object, in an easily readable format.
Parameters
- show_help : boolean
- Indicates whether to display additional descriptive information.
- remove_trait(self, name)
Removes a trait attribute from this object.
Parameters
- name : string
- Name of the attribute to remove
- remove_trait_listener(self, object, prefix = '')
- reset_traits(self, traits = None, **metadata)
Resets some or all of an object's trait attributes to their default values.
Parameters
- traits : list of strings
- Names of trait attributes to reset
Returns
A list of attributes that the method was unable to reset, which is empty if all the attributes were successfully reset.
Description
Resets each of the traits whose names are specified in the traits list to their default values. If traits is None or omitted, the method resets all explicitly-defined object trait attributes to their default values. Note that this does not affect wildcard trait attraibutes or trait attributes added via add_trait(), unless they are explicitly named in traits.
- set(self, trait_change_notify = True, **traits)
Shortcut for setting object trait attributes.
Parameters
- traits : list of key/value pairs
- Trait attributes and their values to be set
Returns
- self
- The method returns this object, after setting attributes.
Description
Treats each keyword argument to the method as the name of a trait attribute and sets the corresponding trait attribute to the value specified. This is a useful shorthand when a number of trait attributes need to be set on an object, or a trait attribute value needs to be set in a lambda function. For example, you can write:
person.set(name='Bill', age=27)
instead of:
person.name = 'Bill' person.age = 27
- set_trait_dispatch_handler(cls, name, klass, override = False)
Sets a trait notification dispatch handler.
- sync_trait(self, trait_name, object, alias = None, mutual = True, remove = False)
Synchronizes the value of a trait attribute on this object with a trait attribute on another object.
Parameters
- name : string
- Name of the trait attribute on this object
- object : object
- The object with which to synchronize
- alias : string
- Name of the trait attribute on other; if None or omitted, same as name.
- mutual : Boolean or integer
- Indicates whether synchronization is mutual (True or non-zero) or one-way (False or zero)
- remove : Boolean or integer
- Indicates whether sychronization is being added (False or zero) or removed (True or non-zero)
Description
In mutual synchronization, any change to the value of the specified trait attribute of either object results in the same value being assigned to the corresponding trait attribute of the other object. In one-way synchronization, any change to the value of the attribute on this object causes the corresponding trait attribute of object to be updated, but not vice versa.
- trait(self, name, force = False, copy = False)
Returns the trait definition for the name trait attribute.
Parameters
- name : string
- Name of the attribute whose trait definition is to be returned
- force : Boolean
- Indicates whether to return a trait definition if name is not explicitly defined
- copy : Boolean
- Indicates whether to return the original trait definition or a copy
Description
If force is False (the default) and name is the name of an implicitly defined trait attribute that has never been referenced explicitly (i.e., has not yet been defined), the result is None. In all other cases, the result is the trait definition object associated with name.
If copy is True, and a valid trait definition is found for name, a copy of the trait found is returned. In all other cases, the trait definition found is returned unmodified (the default).
- trait_context(self)
Returns the default context to use for editing or configuring traits.
- trait_monitor(cls, handler, remove = False)
Adds or removes the specified handler from the list of active monitors.
Parameters
- handler : function
- The function to add or remove as a monitor.
- remove : boolean
- Flag indicating whether to remove (True) or add the specified handler as a monitor for this class.
Description
If remove is omitted or False, the specified handler is added to the list of active monitors; if remove is True, the handler is removed from the active monitor list.
- trait_names(self, **metadata)
Returns a list of the names of all trait attributes whose definitions match the set of metadata criteria specified.
Parameters
- metadata : dictionary
- Criteria for selecting trait attributes
Description
This method is similar to the traits() method, but returns only the names of the matching trait attributes, not the trait definitions.
- trait_subclasses(cls, all = False)
Returns a list of the immediate (or all) subclasses of this class.
Parameters
- all : Boolean
- Indicates whether to return all subclasses of this class. If False, only immediate subclasses are returned.
- trait_view(self, name = None, view_element = None)
Gets or sets a ViewElement associated with an object's class.
Parameters
- name : string
- Name of a view element
- view_element : a ViewElement object
- View element to associate
Returns
A view element.
Description
If both name and view_element are specified, the view element is associated with name for the current object's class. (That is, view_element is added to the ViewElements object associated with the current object's class, indexed by name.)
If only name is specified, the function returns the view element object associated with name, or None if name has no associated view element. View elements retrieved by this function are those that are bound to a class attribute in the class definition, or that are associated with a name by a previous call to this method.
If neither name nor view_element is specified, the method returns a View object, based on the following order of preference:
- If there is a View object named traits_view associated with the current object, it is returned.
- If there is exactly one View object associated the current object, it is returned.
- Otherwise, it returns a View object containing items for all the non-event trait attributes on the current object.
- trait_view_elements(self)
Returns the ViewElements object associated with the object's class.
The returned object can be used to access all the view elements associated with the class.
- trait_views(self, klass = None)
Returns a list of the names of all view elements associated with the current object's class.
Parameters
- klass : a class
A class, such that all returned names must correspond to instances of this class. Possible values include:
- Group
- Item
- View
- ViewElement
- ViewSubElement
Description
If klass is specified, the list of names is filtered such that only objects that are instances of the specified class are returned.
- traits(self, **metadata)
Returns a dictionary containing the definitions of all of the trait attributes of this object that match the set of metadata criteria.
Parameters
- metadata : dictionary
- Criteria for selecting trait attributes
Description
The keys of the returned dictionary are the trait attribute names, and the values are their corresponding trait definition objects.
If no metadata information is specified, then all explicitly defined trait attributes defined for the object are returned.
Otherwise, the metadata keyword dictionary is assumed to define a set of search criteria for selecting trait attributes of interest. The metadata dictionary keys correspond to the names of trait metadata attributes to examine, and the values correspond to the values the metadata attribute must have in order to be included in the search results.
The metadata values either may be simple Python values like strings or integers, or may be lambda expressions or functions that return True if the trait attribute is to be included in the result. A lambda expression or function must receive a single argument, which is the value of the trait metadata attribute being tested. If more than one metadata keyword is specified, a trait attribute must match the metadata values of all keywords to be included in the result.
- validate_trait(self, name, value)
Validates whether a value is legal for a trait.
Returns the validated value if it is valid.