File: workbench_session.py

package info (click to toggle)
python-chaco 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,144 kB
  • sloc: python: 35,936; ansic: 1,211; cpp: 241; makefile: 124; sh: 5
file content (57 lines) | stat: -rw-r--r-- 1,701 bytes parent folder | download | duplicates (3)
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
""" A Chaco Shell PlotSession which raises Workbench Editors instead of
free-standing windows.
"""

from traits.api import Any, Dict, List, Str
from chaco.shell.session import PlotSession

from plot_editor import PlotEditor


class WorkbenchSession(PlotSession):
    """ A Chaco Shell PlotSession which raises Workbench Editors instead of
    free-standing windows.
    """

    # The Envisage Application we are in.
    application = Any()

    # The list of currently active windows.
    windows = List()

    # A dict mapping names to windows.
    window_map = Dict(Str, Any)

    def new_window(self, name=None, title=None, is_image=False):
        """Creates a new window and returns the index into the **windows** list
        for the new window.
        """
        workbench = self.application.get_service(
            'envisage.ui.workbench.workbench.Workbench')
        new_win = PlotEditor(
            is_image=is_image,
            size=(self.prefs.window_width, self.prefs.window_height),
            bgcolor=self.prefs.bgcolor,
            image_default_origin=self.prefs.image_default_origin,
            window=workbench.active_window,
        )
        new_win.data = self.data
        new_win.get_container().data = self.data
        new_win.session = self

        if title is not None:
            new_win.set_title(title)
        elif name != None:
            new_win.set_title(name)
        else:
            new_win.set_title(self.prefs.default_window_name)

        self.windows.append(new_win)
        if name != None:
            self.window_map[name] = new_win

        workbench.edit(new_win.obj, kind=lambda *args, **kwds: new_win)

        return len(self.windows)-1