We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Chaco not working with PyQt4.9.1
Hi,

I have got chaco 4.2 from the pypi repository, and its kind of not working with PyQt4.9.1. Wondering if Chaco is not intended to work with PyQt > 4.7.3 or ... ?

Here is my stack trace from ipython if it helps.

Thanks
Somu

import numpy as np
from chaco.shell import *

x = np.linspace(-2_np.pi, 2_np.pi, 100)
y = np.sin(x)

plot(x, y, "r-")
title("First plot")
ytitle("sin(x)")
show()

---

TypeError                                 Traceback (most recent call last)
C:\Users\a0393049<ipython-input-3-2bc550675863> in <module>()
      5 y = np.sin(x)
      6 
----> 7 plot(x, y, "r-")
      8 title("First plot")
      9 ytitle("sin(x)")

C:\AppsDir\Python\2.7.3\lib\site-packages\chaco-4.2.0-py2.7-win32.egg\chaco\shell\commands.pyc in plot(_data, *_kwargs)
    304     """
    305 
--> 306     cont = _do_plot_boilerplate(kwargs)
    307 
    308     plots = plot_maker.do_plot(session.data, cont,

C:\AppsDir\Python\2.7.3\lib\site-packages\chaco-4.2.0-py2.7-win32.egg\chaco\shell\commands.pyc in _do_plot_boilerplate(kwargs, image)
    272             activate(win)
    273         else:
--> 274             figure()
    275 
    276     cont = session.active_window.get_container()

C:\AppsDir\Python\2.7.3\lib\site-packages\chaco-4.2.0-py2.7-win32.egg\chaco\shell\commands.pyc in figure(name, title)
    153         method uses the value of default_window_name in the Preferences.
    154     """
--> 155     win = session.new_window(name, title)
    156     activate(win)
    157     return win

C:\AppsDir\Python\2.7.3\lib\site-packages\chaco-4.2.0-py2.7-win32.egg\chaco\shell\session.pyc in new_window(self, name, title, is_image)
     59             size=(self.prefs.window_width, self.prefs.window_height),
     60             bgcolor=self.prefs.bgcolor,
---> 61             image_default_origin=self.prefs.image_default_origin,
     62         )
     63         new_win.data = self.data

C:\AppsDir\Python\2.7.3\lib\site-packages\chaco-4.2.0-py2.7-win32.egg\chaco\shell\plot_window.pyc in **init**(self, is_image, bgcolor, image_default_origin, _args, *_kw)
    138                      image_default_origin="top left", _args, *_kw):
    139 
--> 140             super(PlotWindow, self).**init**(None, _args, *_kw )
    141 
    142             # Some defaults which should be overridden by preferences.

TypeError: unable to convert a Python 'tuple' object to a C++ 'QSize' instance


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `chaco/shell/plot_window.py`
Content:
```
1 """ Defines the PlotWindow class.
2 """
3 
4 from enable.api import Window
5 from chaco.shell.scaly_plot import ScalyPlot
6 
7 from traits.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     from pyface.qt import QtGui
129 
130     class PlotWindow(QtGui.QFrame):
131         """ A window for holding top-level plot containers.
132 
133         Contains many utility methods for controlling the appearance of the
134         window, which mostly pass through to underlying Qt calls.
135         """
136 
137         def __init__(self, is_image=False, bgcolor="white",
138                      image_default_origin="top left", *args, **kw):
139 
140             super(PlotWindow, self).__init__(None, *args, **kw )
141 
142             # Some defaults which should be overridden by preferences.
143             self.bgcolor = bgcolor
144             self.image_default_origin = image_default_origin
145 
146             # Create an empty top-level container
147             if is_image:
148                 top_container = self._create_top_img_container()
149             else:
150                 top_container = self._create_top_container()
151 
152             # The PlotSession of which we are a part.  We need to know this in order
153             # to notify it of our being closed, etc.
154             self.session = None
155 
156             # Create the Enable Window object, and store a reference to it.
157             # (This will be handy later.)  The Window requires a parent object
158             # as its first argument, so we just pass 'self'.
159             self.plot_window = Window(self, component=top_container)
160 
161             layout = QtGui.QVBoxLayout()
162             layout.setContentsMargins(0, 0, 0, 0)
163             layout.addWidget(self.plot_window.control)
164             self.setLayout(layout)
165 
166             size = kw.setdefault("size", (600,600))
167             self.set_size(*size)
168 
169             self.show()
170 
171         def get_container(self):
172             return self.plot_window.component
173 
174         def set_container(self, container):
175             self.plot_window.component = container
176 
177         def iconize(self, iconize):
178             """Iconizes the window if *iconize* is True.
179             """
180             if iconize:
181                 self.showMinimized()
182             else:
183                 self.showNormal()
184 
185         def maximize(self, maximize):
186             """ If *maximize* is True, maximizes the window size; restores if False.
187             """
188             if maximize:
189                 self.showMaximized()
190             else:
191                 self.showNormal()
192 
193         def set_size(self, width, height):
194             self.resize(width, height)
195 
196         def set_title(self, title):
197             self.setWindowTitle(title)
198 
199         def raise_window(self):
200             """Raises this window to the top of the window hierarchy.
201             """
202             self.raise_()
203 
204         # This is a Python property because this is not a HasTraits subclass.
205         container = property(get_container, set_container)
206 
207         #------------------------------------------------------------------------
208         # Private methods
209         #------------------------------------------------------------------------
210 
211         def _create_top_container(self):
212             plot = ScalyPlot(
213                 padding=50,
214                 fill_padding=True,
215                 bgcolor=self.bgcolor,
216                 use_backbuffer=True,
217             )
218             return plot
219 
220         def _create_top_img_container(self):
221             plot = ScalyPlot(
222                 padding=50,
223                 fill_padding=True,
224                 bgcolor=self.bgcolor,
225                 use_backbuffer=True,
226                 default_origin=self.image_default_origin,
227             )
228             return plot
229 
230         def closeEvent(self, event):
231             if self.session:
232                 try:
233                     ndx = self.session.windows.index(self)
234                     self.session.del_window(ndx)
235                 except ValueError:
236                     pass
237 
238 else:
239     pass
240 
241 
242 # EOF
243
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/chaco/shell/plot_window.py b/chaco/shell/plot_window.py
--- a/chaco/shell/plot_window.py
+++ b/chaco/shell/plot_window.py
@@ -125,7 +125,7 @@
 
 elif ETSConfig.toolkit == "qt4":
 
-    from pyface.qt import QtGui
+    from pyface.qt import QtCore, QtGui
 
     class PlotWindow(QtGui.QFrame):
         """ A window for holding top-level plot containers.
@@ -137,6 +137,9 @@
         def __init__(self, is_image=False, bgcolor="white",
                      image_default_origin="top left", *args, **kw):
 
+            if 'size' in kw and isinstance(kw['size'], tuple):
+                # Convert to a QSize.
+                kw['size'] = QtCore.QSize(*kw['size'])
             super(PlotWindow, self).__init__(None, *args, **kw )
 
             # Some defaults which should be overridden by preferences.
@@ -163,8 +166,8 @@
             layout.addWidget(self.plot_window.control)
             self.setLayout(layout)
 
-            size = kw.setdefault("size", (600,600))
-            self.set_size(*size)
+            size = kw.get("size", QtCore.QSize(600,600))
+            self.set_size(size.width(), size.height())
 
             self.show()

{"golden_diff": "diff --git a/chaco/shell/plot_window.py b/chaco/shell/plot_window.py\n--- a/chaco/shell/plot_window.py\n+++ b/chaco/shell/plot_window.py\n@@ -125,7 +125,7 @@\n \n elif ETSConfig.toolkit == \"qt4\":\n \n-    from pyface.qt import QtGui\n+    from pyface.qt import QtCore, QtGui\n \n     class PlotWindow(QtGui.QFrame):\n         \"\"\" A window for holding top-level plot containers.\n@@ -137,6 +137,9 @@\n         def __init__(self, is_image=False, bgcolor=\"white\",\n                      image_default_origin=\"top left\", *args, **kw):\n \n+            if 'size' in kw and isinstance(kw['size'], tuple):\n+                # Convert to a QSize.\n+                kw['size'] = QtCore.QSize(*kw['size'])\n             super(PlotWindow, self).__init__(None, *args, **kw )\n \n             # Some defaults which should be overridden by preferences.\n@@ -163,8 +166,8 @@\n             layout.addWidget(self.plot_window.control)\n             self.setLayout(layout)\n \n-            size = kw.setdefault(\"size\", (600,600))\n-            self.set_size(*size)\n+            size = kw.get(\"size\", QtCore.QSize(600,600))\n+            self.set_size(size.width(), size.height())\n \n             self.show()\n", "issue": "Chaco not working with PyQt4.9.1\nHi,\n\nI have got chaco 4.2 from the pypi repository, and its kind of not working with PyQt4.9.1. Wondering if Chaco is not intended to work with PyQt > 4.7.3 or ... ?\n\nHere is my stack trace from ipython if it helps.\n\nThanks\nSomu\n\nimport numpy as np\nfrom chaco.shell import *\n\nx = np.linspace(-2_np.pi, 2_np.pi, 100)\ny = np.sin(x)\n\nplot(x, y, \"r-\")\ntitle(\"First plot\")\nytitle(\"sin(x)\")\nshow()\n\n---\n\nTypeError                                 Traceback (most recent call last)\nC:\\Users\\a0393049<ipython-input-3-2bc550675863> in <module>()\n      5 y = np.sin(x)\n      6 \n----> 7 plot(x, y, \"r-\")\n      8 title(\"First plot\")\n      9 ytitle(\"sin(x)\")\n\nC:\\AppsDir\\Python\\2.7.3\\lib\\site-packages\\chaco-4.2.0-py2.7-win32.egg\\chaco\\shell\\commands.pyc in plot(_data, *_kwargs)\n    304     \"\"\"\n    305 \n--> 306     cont = _do_plot_boilerplate(kwargs)\n    307 \n    308     plots = plot_maker.do_plot(session.data, cont,\n\nC:\\AppsDir\\Python\\2.7.3\\lib\\site-packages\\chaco-4.2.0-py2.7-win32.egg\\chaco\\shell\\commands.pyc in _do_plot_boilerplate(kwargs, image)\n    272             activate(win)\n    273         else:\n--> 274             figure()\n    275 \n    276     cont = session.active_window.get_container()\n\nC:\\AppsDir\\Python\\2.7.3\\lib\\site-packages\\chaco-4.2.0-py2.7-win32.egg\\chaco\\shell\\commands.pyc in figure(name, title)\n    153         method uses the value of default_window_name in the Preferences.\n    154     \"\"\"\n--> 155     win = session.new_window(name, title)\n    156     activate(win)\n    157     return win\n\nC:\\AppsDir\\Python\\2.7.3\\lib\\site-packages\\chaco-4.2.0-py2.7-win32.egg\\chaco\\shell\\session.pyc in new_window(self, name, title, is_image)\n     59             size=(self.prefs.window_width, self.prefs.window_height),\n     60             bgcolor=self.prefs.bgcolor,\n---> 61             image_default_origin=self.prefs.image_default_origin,\n     62         )\n     63         new_win.data = self.data\n\nC:\\AppsDir\\Python\\2.7.3\\lib\\site-packages\\chaco-4.2.0-py2.7-win32.egg\\chaco\\shell\\plot_window.pyc in **init**(self, is_image, bgcolor, image_default_origin, _args, *_kw)\n    138                      image_default_origin=\"top left\", _args, *_kw):\n    139 \n--> 140             super(PlotWindow, self).**init**(None, _args, *_kw )\n    141 \n    142             # Some defaults which should be overridden by preferences.\n\nTypeError: unable to convert a Python 'tuple' object to a C++ 'QSize' instance\n\n", "before_files": [{"content": "\"\"\" Defines the PlotWindow class.\n\"\"\"\n\nfrom enable.api import Window\nfrom chaco.shell.scaly_plot import ScalyPlot\n\nfrom traits.etsconfig.api import ETSConfig\n\nif ETSConfig.toolkit == \"wx\":\n\n    import wx\n    class PlotWindow(wx.Frame):\n        \"\"\" A window for holding top-level plot containers.\n\n        Contains many utility methods for controlling the appearance of the\n        window, which mostly pass through to underlying WX calls.\n        \"\"\"\n\n        def __init__(self, is_image=False, bgcolor=\"white\",\n                     image_default_origin=\"top left\", *args, **kw):\n\n            kw.setdefault(\"size\", (600,600))\n            wx.Frame.__init__(self, None, *args, **kw )\n\n            # Some defaults which should be overridden by preferences.\n            self.bgcolor = bgcolor\n            self.image_default_origin = image_default_origin\n\n            # Create an empty top-level container\n            if is_image:\n                top_container = self._create_top_img_container()\n            else:\n                top_container = self._create_top_container()\n\n            # The PlotSession of which we are a part.  We need to know this in order\n            # to notify it of our being closed, etc.\n            self.session = None\n\n\n            # Create the Enable Window object, and store a reference to it.\n            # (This will be handy later.)  The Window requires a WX parent object\n            # as its first argument, so we just pass 'self'.\n            self.plot_window = Window(self, component=top_container)\n\n            # We'll create a default sizer to put our plot_window in.\n            sizer = wx.BoxSizer(wx.HORIZONTAL)\n\n            # Since Window is an Enable object, we need to get its corresponding\n            # WX control.  This is stored in its \".control\" attribute.\n            sizer.Add(self.plot_window.control, 1, wx.EXPAND)\n\n            # Hook up event handlers for destroy, etc.\n            wx.EVT_WINDOW_DESTROY(self, self._on_window_close)\n\n            # More WX boilerplate.\n            self.SetSizer(sizer)\n            self.SetAutoLayout(True)\n            self.Show(True)\n            return\n\n        def get_container(self):\n            return self.plot_window.component\n\n        def set_container(self, container):\n            self.plot_window.component = container\n\n        def iconize(self, iconize):\n            \"\"\"Iconizes the window if *iconize* is True.\n            \"\"\"\n            self.Iconize(iconize)\n\n        def maximize(self, maximize):\n            \"\"\" If *maximize* is True, maximizes the window size; restores if False.\n            \"\"\"\n            self.Maximize(maximize)\n\n        def set_size(self, width, height):\n            self.SetSize((width, height))\n\n        def set_title(self, title):\n            self.SetTitle(title)\n\n        def raise_window(self):\n            \"\"\"Raises this window to the top of the window hierarchy.\n            \"\"\"\n            self.Raise()\n\n        def close(self):\n            self.Close()\n\n        # This is a Python property because this is not a HasTraits subclass.\n        container = property(get_container, set_container)\n\n        #------------------------------------------------------------------------\n        # Private methods\n        #------------------------------------------------------------------------\n\n        def _create_top_container(self):\n            plot = ScalyPlot(\n                padding=50,\n                fill_padding=True,\n                bgcolor=self.bgcolor,\n                use_backbuffer=True,\n            )\n            return plot\n\n        def _create_top_img_container(self):\n            plot = ScalyPlot(\n                padding=50,\n                fill_padding=True,\n                bgcolor=self.bgcolor,\n                use_backbuffer=True,\n                default_origin=self.image_default_origin,\n            )\n            return plot\n\n\n        def _on_window_close(self, event):\n            if self.session:\n                try:\n                    ndx = self.session.windows.index(self)\n                    self.session.del_window(ndx)\n                except ValueError:\n                    pass\n\nelif ETSConfig.toolkit == \"qt4\":\n\n    from pyface.qt import QtGui\n\n    class PlotWindow(QtGui.QFrame):\n        \"\"\" A window for holding top-level plot containers.\n\n        Contains many utility methods for controlling the appearance of the\n        window, which mostly pass through to underlying Qt calls.\n        \"\"\"\n\n        def __init__(self, is_image=False, bgcolor=\"white\",\n                     image_default_origin=\"top left\", *args, **kw):\n\n            super(PlotWindow, self).__init__(None, *args, **kw )\n\n            # Some defaults which should be overridden by preferences.\n            self.bgcolor = bgcolor\n            self.image_default_origin = image_default_origin\n\n            # Create an empty top-level container\n            if is_image:\n                top_container = self._create_top_img_container()\n            else:\n                top_container = self._create_top_container()\n\n            # The PlotSession of which we are a part.  We need to know this in order\n            # to notify it of our being closed, etc.\n            self.session = None\n\n            # Create the Enable Window object, and store a reference to it.\n            # (This will be handy later.)  The Window requires a parent object\n            # as its first argument, so we just pass 'self'.\n            self.plot_window = Window(self, component=top_container)\n\n            layout = QtGui.QVBoxLayout()\n            layout.setContentsMargins(0, 0, 0, 0)\n            layout.addWidget(self.plot_window.control)\n            self.setLayout(layout)\n\n            size = kw.setdefault(\"size\", (600,600))\n            self.set_size(*size)\n\n            self.show()\n\n        def get_container(self):\n            return self.plot_window.component\n\n        def set_container(self, container):\n            self.plot_window.component = container\n\n        def iconize(self, iconize):\n            \"\"\"Iconizes the window if *iconize* is True.\n            \"\"\"\n            if iconize:\n                self.showMinimized()\n            else:\n                self.showNormal()\n\n        def maximize(self, maximize):\n            \"\"\" If *maximize* is True, maximizes the window size; restores if False.\n            \"\"\"\n            if maximize:\n                self.showMaximized()\n            else:\n                self.showNormal()\n\n        def set_size(self, width, height):\n            self.resize(width, height)\n\n        def set_title(self, title):\n            self.setWindowTitle(title)\n\n        def raise_window(self):\n            \"\"\"Raises this window to the top of the window hierarchy.\n            \"\"\"\n            self.raise_()\n\n        # This is a Python property because this is not a HasTraits subclass.\n        container = property(get_container, set_container)\n\n        #------------------------------------------------------------------------\n        # Private methods\n        #------------------------------------------------------------------------\n\n        def _create_top_container(self):\n            plot = ScalyPlot(\n                padding=50,\n                fill_padding=True,\n                bgcolor=self.bgcolor,\n                use_backbuffer=True,\n            )\n            return plot\n\n        def _create_top_img_container(self):\n            plot = ScalyPlot(\n                padding=50,\n                fill_padding=True,\n                bgcolor=self.bgcolor,\n                use_backbuffer=True,\n                default_origin=self.image_default_origin,\n            )\n            return plot\n\n        def closeEvent(self, event):\n            if self.session:\n                try:\n                    ndx = self.session.windows.index(self)\n                    self.session.del_window(ndx)\n                except ValueError:\n                    pass\n\nelse:\n    pass\n\n\n# EOF\n", "path": "chaco/shell/plot_window.py"}], "after_files": [{"content": "\"\"\" Defines the PlotWindow class.\n\"\"\"\n\nfrom enable.api import Window\nfrom chaco.shell.scaly_plot import ScalyPlot\n\nfrom traits.etsconfig.api import ETSConfig\n\nif ETSConfig.toolkit == \"wx\":\n\n    import wx\n    class PlotWindow(wx.Frame):\n        \"\"\" A window for holding top-level plot containers.\n\n        Contains many utility methods for controlling the appearance of the\n        window, which mostly pass through to underlying WX calls.\n        \"\"\"\n\n        def __init__(self, is_image=False, bgcolor=\"white\",\n                     image_default_origin=\"top left\", *args, **kw):\n\n            kw.setdefault(\"size\", (600,600))\n            wx.Frame.__init__(self, None, *args, **kw )\n\n            # Some defaults which should be overridden by preferences.\n            self.bgcolor = bgcolor\n            self.image_default_origin = image_default_origin\n\n            # Create an empty top-level container\n            if is_image:\n                top_container = self._create_top_img_container()\n            else:\n                top_container = self._create_top_container()\n\n            # The PlotSession of which we are a part.  We need to know this in order\n            # to notify it of our being closed, etc.\n            self.session = None\n\n\n            # Create the Enable Window object, and store a reference to it.\n            # (This will be handy later.)  The Window requires a WX parent object\n            # as its first argument, so we just pass 'self'.\n            self.plot_window = Window(self, component=top_container)\n\n            # We'll create a default sizer to put our plot_window in.\n            sizer = wx.BoxSizer(wx.HORIZONTAL)\n\n            # Since Window is an Enable object, we need to get its corresponding\n            # WX control.  This is stored in its \".control\" attribute.\n            sizer.Add(self.plot_window.control, 1, wx.EXPAND)\n\n            # Hook up event handlers for destroy, etc.\n            wx.EVT_WINDOW_DESTROY(self, self._on_window_close)\n\n            # More WX boilerplate.\n            self.SetSizer(sizer)\n            self.SetAutoLayout(True)\n            self.Show(True)\n            return\n\n        def get_container(self):\n            return self.plot_window.component\n\n        def set_container(self, container):\n            self.plot_window.component = container\n\n        def iconize(self, iconize):\n            \"\"\"Iconizes the window if *iconize* is True.\n            \"\"\"\n            self.Iconize(iconize)\n\n        def maximize(self, maximize):\n            \"\"\" If *maximize* is True, maximizes the window size; restores if False.\n            \"\"\"\n            self.Maximize(maximize)\n\n        def set_size(self, width, height):\n            self.SetSize((width, height))\n\n        def set_title(self, title):\n            self.SetTitle(title)\n\n        def raise_window(self):\n            \"\"\"Raises this window to the top of the window hierarchy.\n            \"\"\"\n            self.Raise()\n\n        def close(self):\n            self.Close()\n\n        # This is a Python property because this is not a HasTraits subclass.\n        container = property(get_container, set_container)\n\n        #------------------------------------------------------------------------\n        # Private methods\n        #------------------------------------------------------------------------\n\n        def _create_top_container(self):\n            plot = ScalyPlot(\n                padding=50,\n                fill_padding=True,\n                bgcolor=self.bgcolor,\n                use_backbuffer=True,\n            )\n            return plot\n\n        def _create_top_img_container(self):\n            plot = ScalyPlot(\n                padding=50,\n                fill_padding=True,\n                bgcolor=self.bgcolor,\n                use_backbuffer=True,\n                default_origin=self.image_default_origin,\n            )\n            return plot\n\n\n        def _on_window_close(self, event):\n            if self.session:\n                try:\n                    ndx = self.session.windows.index(self)\n                    self.session.del_window(ndx)\n                except ValueError:\n                    pass\n\nelif ETSConfig.toolkit == \"qt4\":\n\n    from pyface.qt import QtCore, QtGui\n\n    class PlotWindow(QtGui.QFrame):\n        \"\"\" A window for holding top-level plot containers.\n\n        Contains many utility methods for controlling the appearance of the\n        window, which mostly pass through to underlying Qt calls.\n        \"\"\"\n\n        def __init__(self, is_image=False, bgcolor=\"white\",\n                     image_default_origin=\"top left\", *args, **kw):\n\n            if 'size' in kw and isinstance(kw['size'], tuple):\n                # Convert to a QSize.\n                kw['size'] = QtCore.QSize(*kw['size'])\n            super(PlotWindow, self).__init__(None, *args, **kw )\n\n            # Some defaults which should be overridden by preferences.\n            self.bgcolor = bgcolor\n            self.image_default_origin = image_default_origin\n\n            # Create an empty top-level container\n            if is_image:\n                top_container = self._create_top_img_container()\n            else:\n                top_container = self._create_top_container()\n\n            # The PlotSession of which we are a part.  We need to know this in order\n            # to notify it of our being closed, etc.\n            self.session = None\n\n            # Create the Enable Window object, and store a reference to it.\n            # (This will be handy later.)  The Window requires a parent object\n            # as its first argument, so we just pass 'self'.\n            self.plot_window = Window(self, component=top_container)\n\n            layout = QtGui.QVBoxLayout()\n            layout.setContentsMargins(0, 0, 0, 0)\n            layout.addWidget(self.plot_window.control)\n            self.setLayout(layout)\n\n            size = kw.get(\"size\", QtCore.QSize(600,600))\n            self.set_size(size.width(), size.height())\n\n            self.show()\n\n        def get_container(self):\n            return self.plot_window.component\n\n        def set_container(self, container):\n            self.plot_window.component = container\n\n        def iconize(self, iconize):\n            \"\"\"Iconizes the window if *iconize* is True.\n            \"\"\"\n            if iconize:\n                self.showMinimized()\n            else:\n                self.showNormal()\n\n        def maximize(self, maximize):\n            \"\"\" If *maximize* is True, maximizes the window size; restores if False.\n            \"\"\"\n            if maximize:\n                self.showMaximized()\n            else:\n                self.showNormal()\n\n        def set_size(self, width, height):\n            self.resize(width, height)\n\n        def set_title(self, title):\n            self.setWindowTitle(title)\n\n        def raise_window(self):\n            \"\"\"Raises this window to the top of the window hierarchy.\n            \"\"\"\n            self.raise_()\n\n        # This is a Python property because this is not a HasTraits subclass.\n        container = property(get_container, set_container)\n\n        #------------------------------------------------------------------------\n        # Private methods\n        #------------------------------------------------------------------------\n\n        def _create_top_container(self):\n            plot = ScalyPlot(\n                padding=50,\n                fill_padding=True,\n                bgcolor=self.bgcolor,\n                use_backbuffer=True,\n            )\n            return plot\n\n        def _create_top_img_container(self):\n            plot = ScalyPlot(\n                padding=50,\n                fill_padding=True,\n                bgcolor=self.bgcolor,\n                use_backbuffer=True,\n                default_origin=self.image_default_origin,\n            )\n            return plot\n\n        def closeEvent(self, event):\n            if self.session:\n                try:\n                    ndx = self.session.windows.index(self)\n                    self.session.del_window(ndx)\n                except ValueError:\n                    pass\n\nelse:\n    pass\n\n\n# EOF\n", "path": "chaco/shell/plot_window.py"}]}