Repository: enthought/chaco

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



Discussion:
I get the same problem, using Chaco from git and PyQt 4.9.0 from MacPorts. However, chaco seems to be working ok. It's just the Chaco shell that is not cooperating.


Resolving patch:
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 @@ def _on_window_close(self, event):
 
 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 @@ class PlotWindow(QtGui.QFrame):
         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 @@ def __init__(self, is_image=False, bgcolor="white",
             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()
 


Test patch: