File: ipython_shell_actions.py

package info (click to toggle)
python-envisageplugins 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,600 kB
  • sloc: python: 6,968; sh: 11; makefile: 8; lisp: 1
file content (59 lines) | stat: -rw-r--r-- 1,924 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
from enthought.envisage.ui.action.api import Action, ActionSet, Group
from enthought.pyface.action.api import Action as PyfaceAction
from enthought.plugins.python_shell.api import IPythonShell


def get_shell(window):
    """ Given an application window, retrieve the ipython shell.
    """
    return window.application.get_service(IPythonShell)

################################################################################
# Groups 
################################################################################
ipython_shell_group = Group(
    id='IPythonShellGroup',
    path='MenuBar/Tools', 
    #before='ExitGroup'
)


################################################################################
# `ClearScreen` class.
################################################################################
class ClearScreen(PyfaceAction):
    """ An action that clears the IPython screen. """

    tooltip      = "Clear the IPython screen."

    description  = "Clear the IPython screen."


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

    def perform(self, event):
        """ Performs the action. """
        shell = get_shell(self.window)

        if shell is not None:
            shell.control.clear_screen()

clear_screen = Action(
    path        = "MenuBar/Tools",
    class_name  = __name__ + '.ClearScreen',
    name        = "Clear IPython screen",
    group       = "IPythonShellGroup",
)


################################################################################
# `IPythonShellActionSet` class.
################################################################################
class IPythonShellActionSet(ActionSet):
    """ The default action set for the IPython shell plugin. """

    groups = [ipython_shell_group, ]

    actions = [clear_screen]