~ubuntu-branches/ubuntu/vivid/python-chaco/vivid-proposed

« back to all changes in this revision

Viewing changes to enthought/chaco/shell/plot_window.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2010-02-28 14:05:25 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100228140525-1eo43ddoakb2j3j9
Tags: 3.3.0-1
* New upstream release
* Switch to source format 3.0 (quilt)
* Bump Standards-Version to 3.8.4
* Remove transition package: python-enthought-chaco2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
""" Defines the PlotWindow class.
2
2
"""
3
 
import wx
4
3
 
5
4
from enthought.enable.api import Window
6
5
from enthought.chaco.shell.scaly_plot import ScalyPlot
7
6
 
8
 
 
9
 
class PlotWindow(wx.Frame):
10
 
    """ A window for holding top-level plot containers.
11
 
    
12
 
    Contains many utility methods for controlling the appearance of the
13
 
    window, which mostly pass through to underlying WX calls.
14
 
    """
15
 
 
16
 
    def __init__(self, is_image=False, bgcolor="white", 
17
 
                 image_default_origin="top left", *args, **kw):
18
 
 
19
 
        kw.setdefault("size", (600,600))
20
 
        wx.Frame.__init__(self, None, *args, **kw )
21
 
        
22
 
        # Some defaults which should be overridden by preferences.
23
 
        self.bgcolor = bgcolor
24
 
        self.image_default_origin = image_default_origin
25
 
 
26
 
        # Create an empty top-level container
27
 
        if is_image:
28
 
            top_container = self._create_top_img_container()
29
 
        else:
30
 
            top_container = self._create_top_container()
31
 
 
32
 
        # The PlotSession of which we are a part.  We need to know this in order
33
 
        # to notify it of our being closed, etc.
34
 
        self.session = None
35
 
 
36
 
 
37
 
        # Create the Enable Window object, and store a reference to it.
38
 
        # (This will be handy later.)  The Window requires a WX parent object
39
 
        # as its first argument, so we just pass 'self'.
40
 
        self.plot_window = Window(self, component=top_container)
41
 
        
42
 
        # We'll create a default sizer to put our plot_window in.
43
 
        sizer = wx.BoxSizer(wx.HORIZONTAL)
44
 
        
45
 
        # Since Window is an Enable object, we need to get its corresponding
46
 
        # WX control.  This is stored in its ".control" attribute.
47
 
        sizer.Add(self.plot_window.control, 1, wx.EXPAND)
48
 
 
49
 
        # Hook up event handlers for destroy, etc.
50
 
        wx.EVT_WINDOW_DESTROY(self, self._on_window_close)
51
 
        
52
 
        # More WX boilerplate.
53
 
        self.SetSizer(sizer)
54
 
        self.SetAutoLayout(True)
55
 
        self.Show(True)
56
 
        return
57
 
 
58
 
    def get_container(self):
59
 
        return self.plot_window.component
60
 
 
61
 
    def set_container(self, container):
62
 
        self.plot_window.component = container
63
 
    
64
 
    def iconize(self, iconize):
65
 
        """Iconizes the window if *iconize* is True.
66
 
        """
67
 
        self.Iconize(iconize)
68
 
    
69
 
    def maximize(self, maximize):
70
 
        """ If *maximize* is True, maximizes the window size; restores if False.
71
 
        """
72
 
        self.Maximize(maximize)
73
 
 
74
 
    def set_size(self, width, height):
75
 
        self.SetSize((width, height))
76
 
 
77
 
    def set_title(self, title):
78
 
        self.SetTitle(title)
79
 
 
80
 
    def raise_window(self):
81
 
        """Raises this window to the top of the window hierarchy.
82
 
        """
83
 
        self.Raise()
84
 
 
85
 
    def close(self):
86
 
        self.Close()
87
 
 
88
 
    # This is a Python property because this is not a HasTraits subclass.
89
 
    container = property(get_container, set_container)
90
 
 
91
 
    #------------------------------------------------------------------------
92
 
    # Private methods
93
 
    #------------------------------------------------------------------------
94
 
 
95
 
    def _create_top_container(self):
96
 
        plot = ScalyPlot(
97
 
            padding=50, 
98
 
            fill_padding=True,
99
 
            bgcolor=self.bgcolor,
100
 
            use_backbuffer=True,
101
 
        )
102
 
        return plot
103
 
 
104
 
    def _create_top_img_container(self):
105
 
        plot = ScalyPlot(
106
 
            padding=50,
107
 
            fill_padding=True,
108
 
            bgcolor=self.bgcolor,
109
 
            use_backbuffer=True,
110
 
            default_origin=self.image_default_origin,
111
 
        )
112
 
        return plot
113
 
 
114
 
 
115
 
    def _on_window_close(self, event):
116
 
        if self.session:
117
 
            try:
118
 
                ndx = self.session.windows.index(self)
119
 
                self.session.del_window(ndx)
120
 
            except ValueError:
121
 
                pass
 
7
from enthought.etsconfig.api import ETSConfig
 
8
 
 
9
if ETSConfig.toolkit == "wx":
 
10
 
 
11
    import wx
 
12
    class PlotWindow(wx.Frame):
 
13
        """ A window for holding top-level plot containers.
 
14
        
 
15
        Contains many utility methods for controlling the appearance of the
 
16
        window, which mostly pass through to underlying WX calls.
 
17
        """
 
18
 
 
19
        def __init__(self, is_image=False, bgcolor="white", 
 
20
                     image_default_origin="top left", *args, **kw):
 
21
 
 
22
            kw.setdefault("size", (600,600))
 
23
            wx.Frame.__init__(self, None, *args, **kw )
 
24
            
 
25
            # Some defaults which should be overridden by preferences.
 
26
            self.bgcolor = bgcolor
 
27
            self.image_default_origin = image_default_origin
 
28
 
 
29
            # Create an empty top-level container
 
30
            if is_image:
 
31
                top_container = self._create_top_img_container()
 
32
            else:
 
33
                top_container = self._create_top_container()
 
34
 
 
35
            # The PlotSession of which we are a part.  We need to know this in order
 
36
            # to notify it of our being closed, etc.
 
37
            self.session = None
 
38
 
 
39
 
 
40
            # Create the Enable Window object, and store a reference to it.
 
41
            # (This will be handy later.)  The Window requires a WX parent object
 
42
            # as its first argument, so we just pass 'self'.
 
43
            self.plot_window = Window(self, component=top_container)
 
44
            
 
45
            # We'll create a default sizer to put our plot_window in.
 
46
            sizer = wx.BoxSizer(wx.HORIZONTAL)
 
47
            
 
48
            # Since Window is an Enable object, we need to get its corresponding
 
49
            # WX control.  This is stored in its ".control" attribute.
 
50
            sizer.Add(self.plot_window.control, 1, wx.EXPAND)
 
51
 
 
52
            # Hook up event handlers for destroy, etc.
 
53
            wx.EVT_WINDOW_DESTROY(self, self._on_window_close)
 
54
            
 
55
            # More WX boilerplate.
 
56
            self.SetSizer(sizer)
 
57
            self.SetAutoLayout(True)
 
58
            self.Show(True)
 
59
            return
 
60
 
 
61
        def get_container(self):
 
62
            return self.plot_window.component
 
63
 
 
64
        def set_container(self, container):
 
65
            self.plot_window.component = container
 
66
        
 
67
        def iconize(self, iconize):
 
68
            """Iconizes the window if *iconize* is True.
 
69
            """
 
70
            self.Iconize(iconize)
 
71
        
 
72
        def maximize(self, maximize):
 
73
            """ If *maximize* is True, maximizes the window size; restores if False.
 
74
            """
 
75
            self.Maximize(maximize)
 
76
 
 
77
        def set_size(self, width, height):
 
78
            self.SetSize((width, height))
 
79
 
 
80
        def set_title(self, title):
 
81
            self.SetTitle(title)
 
82
 
 
83
        def raise_window(self):
 
84
            """Raises this window to the top of the window hierarchy.
 
85
            """
 
86
            self.Raise()
 
87
 
 
88
        def close(self):
 
89
            self.Close()
 
90
 
 
91
        # This is a Python property because this is not a HasTraits subclass.
 
92
        container = property(get_container, set_container)
 
93
 
 
94
        #------------------------------------------------------------------------
 
95
        # Private methods
 
96
        #------------------------------------------------------------------------
 
97
 
 
98
        def _create_top_container(self):
 
99
            plot = ScalyPlot(
 
100
                padding=50, 
 
101
                fill_padding=True,
 
102
                bgcolor=self.bgcolor,
 
103
                use_backbuffer=True,
 
104
            )
 
105
            return plot
 
106
 
 
107
        def _create_top_img_container(self):
 
108
            plot = ScalyPlot(
 
109
                padding=50,
 
110
                fill_padding=True,
 
111
                bgcolor=self.bgcolor,
 
112
                use_backbuffer=True,
 
113
                default_origin=self.image_default_origin,
 
114
            )
 
115
            return plot
 
116
 
 
117
 
 
118
        def _on_window_close(self, event):
 
119
            if self.session:
 
120
                try:
 
121
                    ndx = self.session.windows.index(self)
 
122
                    self.session.del_window(ndx)
 
123
                except ValueError:
 
124
                    pass
 
125
 
 
126
elif ETSConfig.toolkit == "qt4":
 
127
 
 
128
    class PlotWindow():
 
129
        pass
 
130
 
 
131
else:
 
132
    pass
122
133
 
123
134
 
124
135
# EOF