def create_control(self, parent):
        """ Creates the toolkit-specific control that represents the view. """

        self.shell = IPythonWidget(parent,
                                   banner='\n'.join(self._banner),
                                   interp=self.interpreter)

        # Namespace contributions.
        for bindings in self._bindings:
            for name, value in bindings.items():
                self.bind(name, value)

        for command in self._commands:
            try:
                self.execute_command(command)
            except Exception as e:
                logger.exception(
                    "The command '%s' supplied to the Ipython shell "
                    "plugin has raised an exception:\n%s" %
                    (command, traceback.format_exc()))

        # Register the view as a service.
        self.window.application.register_service(IPythonShell, self)

        ns_view = self.window.application.get_service(INamespaceView)
        if ns_view is not None:
            self.on_trait_change(ns_view._on_names_changed, 'names')

        def try_set_focus():
            try:
                self.shell.control.SetFocus()
            except:
                # The window may not have been created yet.
                pass

        def set_focus():
            self.window.application.gui.invoke_later(try_set_focus)

        GUI.invoke_later(set_focus)

        return self.shell.control
Example #2
0
    def _create_contents(self, parent):
        """ Create the editor. """

        self._shell = IPythonWidget(parent)

        return self._shell.control