File: debug_view.py

package info (click to toggle)
python-pyface 8.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,944 kB
  • sloc: python: 54,107; makefile: 82
file content (96 lines) | stat: -rw-r--r-- 2,911 bytes parent folder | download
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
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
""" A view containing a main walter canvas. """


from pyface.workbench.api import View, WorkbenchWindow
from traits.api import HasTraits, Instance, Str, observe
from traitsui.api import View as TraitsView


class DebugViewModel(HasTraits):
    """ The model for the debug view! """

    # 'Model' interface ----------------------------------------------------

    active_editor = Str()
    active_part = Str()
    active_view = Str()

    window = Instance(WorkbenchWindow)

    # ------------------------------------------------------------------------
    # 'Model' interface.
    # ------------------------------------------------------------------------

    @observe("window.active_editor,window.active_part,window.active_view")
    def refresh(self, event):
        """ Refresh the model. """

        self.active_editor = self._get_id(self.window.active_editor)
        self.active_part = self._get_id(self.window.active_part)
        self.active_view = self._get_id(self.window.active_view)

    def _window_changed(self):
        """ Window changed! """

        self.refresh()

        return

    # ------------------------------------------------------------------------
    # Private interface.
    # ------------------------------------------------------------------------

    def _get_id(self, obj):
        """ Return the Id of an object. """

        if obj is None:
            id = "None"

        else:
            id = obj.id

        return id


class DebugView(View):
    """ A view containing a main walter canvas. """

    # 'IWorkbenchPart' interface -------------------------------------------

    # The part's name (displayed to the user).
    name = "Debug"

    # 'DebugView' interface ------------------------------------------------

    # The model for the debug view!
    model = Instance(DebugViewModel)

    # ------------------------------------------------------------------------
    # 'IWorkbenchPart' interface.
    # ------------------------------------------------------------------------

    def create_control(self, parent):
        """ Creates the toolkit-specific control that represents the view.

        'parent' is the toolkit-specific control that is the view's parent.

        """

        self.model = DebugViewModel(window=self.window)

        ui = self.model.edit_traits(
            parent=parent,
            kind="subpanel",
            view=TraitsView("active_part", "active_editor", "active_view"),
        )

        return ui.control