File: actions.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 (96 lines) | stat: -rw-r--r-- 3,236 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from enthought.envisage.ui.action.api import Action, ActionSet, Group
from enthought.pyface.api import FileDialog, OK
from enthought.pyface.action.api import Action as PyfaceAction
from enthought.plugins.remote_editor.api import IRemoteEditor



def get_server(window):
    """ Given an application window, retrieve the communication server.
    """
    return window.application.get_service(IRemoteEditor)

################################################################################
# Groups 
################################################################################
file_group = Group(
    id='RemoteEditorFileGroup',
    path='MenuBar/File', 
    before='ExitGroup'
)


################################################################################
# `OpenScript` class.
################################################################################
class OpenScript(PyfaceAction):
    """ An action that opens a Python file in a remote editor. """

    tooltip      = "Open a Python script in separate editor."

    description  = "Open a Python script in separate editor."


    ###########################################################################
    # 'Action' interface.
    ###########################################################################

    def perform(self, event):
        """ Performs the action. """
        server = get_server(self.window)

        wildcard = 'Python files (*.py)|*.py'
         
        parent = self.window.control
        dialog = FileDialog(parent=parent,
                            title='Open Python script in separate editor',
                            action='open', wildcard=wildcard
                            )
        if dialog.open() == OK:
            server.open_file(dialog.path)


open_script = Action(
    path        = "MenuBar/File",
    class_name  = __name__ + '.OpenScript',
    name        = "Open script in editor",
    group       = "RemoteEditorFileGroup",
)

################################################################################
# `NewScript` class.
################################################################################
class NewScript(PyfaceAction):
    """ An action that opens a new file in a remote editor. """

    tooltip       = "Open a new file in separate editor."

    description   = "Open a new file in separate editor."

    ###########################################################################
    # 'Action' interface.
    ###########################################################################

    def perform(self, event):
        """ Performs the action. """
        server = get_server(self.window)
        server.new_file()


new_script = Action(
    path        = "MenuBar/File",
    class_name  = __name__ + '.NewScript',
    name        = "New script in editor",
    group       = "RemoteEditorFileGroup",
)


################################################################################
# `RemoteEditorActionSet` class.
################################################################################
class RemoteEditorActionSet(ActionSet):
    """ The default action set for the remote editor plugin. """

    groups = [file_group, ]

    actions = [open_script, new_script]