class _ContextShellEditor ( Editor ): #--------------------------------------------------------------------------- # Trait definitions: #--------------------------------------------------------------------------- # Indicate that the plot editor is scrollable (default override): scrollable = True #--------------------------------------------------------------------------- # Finishes initializing the editor by creating the underlying toolkit # widget: #--------------------------------------------------------------------------- def init ( self, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self._shell = ContextPythonShell( parent, block_unit = self.factory.block_unit ) self.control = self._shell.control if self.factory.execute != '': self._shell.on_trait_change( self._do_execute, 'command_executed', dispatch = 'ui' ) self._do_execute() #--------------------------------------------------------------------------- # Updates the editor when the object trait changes external to the editor: #--------------------------------------------------------------------------- def update_editor ( self ): """ Updates the editor when the object trait changes external to the editor. """ self._shell.context = self.value #--------------------------------------------------------------------------- # Handles a shell editor command being executed: #--------------------------------------------------------------------------- def _do_execute ( self ): setattr( self.object, self.factory.execute, self.control ) #--------------------------------------------------------------------------- # Disposes of the contents of an editor: #--------------------------------------------------------------------------- def dispose ( self ): """ Disposes of the contents of an editor. """ super( _ContextShellEditor, self ).dispose() if self.factory is not None and self.factory.execute != '': self._shell.on_trait_change( self._do_execute, 'command_executed', remove = True )
def init ( self, parent ): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self._shell = ContextPythonShell( parent, block_unit = self.factory.block_unit ) self.control = self._shell.control if self.factory.execute != '': self._shell.on_trait_change( self._do_execute, 'command_executed', dispatch = 'ui' ) self._do_execute()