File: editor_plugin.py

package info (click to toggle)
python-envisageplugins 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,616 kB
  • ctags: 1,970
  • sloc: python: 7,047; makefile: 11; sh: 11; lisp: 1
file content (43 lines) | stat: -rw-r--r-- 1,002 bytes parent folder | download | duplicates (2)
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
# Standard library imports
import os
import logging

# Local imports
from enthought.plugins.remote_editor.communication.client import Client


class EditorPlugin(Client):

    # EditorPlugin interface

    def new(self):
        raise NotImplementedError

    def open(self, filename):
        raise NotImplementedError

    def run_file(self, path):
        self.send_command('run_file', path)

    def run_text(self, text):
        self.send_command('run_text', text)

    # Client interface

    self_type = "python_editor"
    other_type = "python_shell"

    def handle_command(self, command, arguments):
        if command == "new":
            self.new()
            return True

        elif command == "open":
            if os.path.exists(arguments):
                self.open(arguments)
            else:
                logging.warning("EditorPlugin recieved invalid path '%s' for "
                                "'open' command", arguments)
            return True

        return False