File: application_window.py

package info (click to toggle)
enthought-traits-ui 2.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 15,204 kB
  • ctags: 9,623
  • sloc: python: 45,547; sh: 32; makefile: 19
file content (140 lines) | stat: -rw-r--r-- 4,518 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#------------------------------------------------------------------------------
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
# 
# This software is provided without warranty under the terms of the BSD
# license included in enthought/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!
# 
# Author: Enthought, Inc.
# Description: <Enthought pyface package component>
#------------------------------------------------------------------------------
""" A top-level application window. """


# Major package imports.
import wx

# Enthought library imports.
from enthought.traits.api import Instance, Int, Str

# Local imports.
from action.api import MenuBarManager, StatusBarManager, ToolBarManager
from image_resource import ImageResource
from window import Window


class ApplicationWindow(Window):
    """ A top-level application window.
    
    The application window has support for a menu bar, tool bar and a status
    bar (all of which are optional).

    Usage: Create a sub-class of this class and override the protected
    '_create_contents' method.

    """

    # Default style removes the window menu.
    STYLE = Int(
        wx.DEFAULT_FRAME_STYLE | wx.FRAME_NO_WINDOW_MENU | wx.CLIP_CHILDREN
    )

    #### 'Window' interface ###################################################

    # The size of the window.
    size = (800, 600)
    
    # The window title.
    title = Str('Pyface')

    #### 'ApplicationWindow' interface ########################################
    
    # The window icon.
    icon = Instance(ImageResource, ImageResource('application.ico'))

    # The menu bar manager (None iff there is no menu bar).
    menu_bar_manager = Instance(MenuBarManager)

    # The status bar manager (None iff there is no status bar).
    status_bar_manager = Instance(StatusBarManager)

    # The tool bar manager (None iff there is no tool bar).
    tool_bar_manager = Instance(ToolBarManager)
    
    ###########################################################################
    # Protected 'Window' interface.
    ###########################################################################

    def _create_control(self, parent):
        """ Create the toolkit-specific control that represents the widget. """

        control = wx.Frame(
            parent, -1, self.title, style=self.STYLE,
            size=self.size, pos=self.position
        )
        
        # Create the 'trim' widgets (menu, tool and status bars etc).
        self._create_trim_widgets(control)

        control._pyface_reference = self

        return control
    
    ###########################################################################
    # Protected 'ApplicationWindow' interface.
    ###########################################################################

    def _create_trim_widgets(self, parent):
        """ Creates the 'trim' widgets (the widgets around the window).

        Currently these are the menu, tool and status bars.

        """

        # All of these are optional.
        self._set_window_icon(parent)
        self._create_menu_bar(parent)
        self._create_tool_bar(parent)
        self._create_status_bar(parent)
        
        return

    def _set_window_icon(self, parent):
        """ Sets the window icon (if required). """

        if self.icon is not None:
            parent.SetIcon(self.icon.create_icon())
                
        return
    
    def _create_menu_bar(self, parent):
        """ Creates the menu bar (if required). """
        
        if self.menu_bar_manager is not None:
            menu_bar = self.menu_bar_manager.create_menu_bar(parent)
            parent.SetMenuBar(menu_bar)

        return
    
    def _create_tool_bar(self, parent):
        """ Creates the tool bar (if required). """
        
        if self.tool_bar_manager is not None:
            tool_bar = self.tool_bar_manager.create_tool_bar(parent)
            parent.SetToolBar(tool_bar)

        return
    
    def _create_status_bar(self, parent):
        """ Creates the status bar (if required). """
        
        if self.status_bar_manager is not None:
            status_bar = self.status_bar_manager.create_status_bar(parent)
            parent.SetStatusBar(status_bar)

        return

#### EOF ######################################################################