1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
""" An implementation of a client controlling a remote editor, but also using
envisage to retrieve an execution engine, and run the commands from the
editor.
"""
# Standard library imports
import logging
# Enthought library imports
from enthought.traits.api import Instance
from enthought.envisage.api import Application
from enthought.plugins.python_shell.api import IPythonShell
from enthought.pyface.api import GUI
# Local imports
from enthought.plugins.remote_editor.remote_editor_controller import \
RemoteEditorController
logger = logging.getLogger(__name__)
class EnvisageRemoteEditorController(RemoteEditorController):
""" An implementation of a client controlling a remote editor, but also
using envisage to retrieve an execution engine, and run the commands
from the editor.
"""
# Tell the Client code to play well with the wx or Qt4 event loop
ui_dispatch = 'auto'
# A reference to the Envisage application.
application = Instance(Application)
###########################################################################
# EnvisageRemoteEditorController interface
###########################################################################
def run_file(self, path):
""" Called by the server to execute a file.
"""
shell = self.application.get_service(IPythonShell)
shell.execute_file(path, hidden=False)
def run_text(self, text):
""" Called by the server to execute text.
"""
shell = self.application.get_service(IPythonShell)
shell.execute_command(text, hidden=False)
###########################################################################
# Enshell Client interface
###########################################################################
def handle_command(self, command, arguments):
""" Hande commands coming in from the server.
"""
if command == "run_file":
self.run_file(arguments)
return True
elif command == "run_text":
self.run_text(arguments)
return True
return False
|