Repository: pyqtgraph/pyqtgraph

Issue:
    if self.container().type() == 'tab': AttributeError: 'NoneType' object has no attribute 'type'
Not sure why I was seeing this or why no one else had. But I seem to have solved the problem by just adding a check that container is not None on line 155 of Dock.py. 

            if self.container() is not None and self.container().type() == 'tab':



Discussion:
Just letting you know, that I have observed the same problem, so thank you for the tip.
Did you notice any other problems if you continue executing the code? When the exceptions is raised the rest of the code is skipped.

What I am wondering is how self.container() can return None when adding a new dock?
I fear this check just hides the underlying problem and I would like to know what causes it.
But I haven't spend the time to properly investigate.
I have also encountered the same issue, I fixed it by chaning the setOrientation function 

From:
https://github.com/pyqtgraph/pyqtgraph/blob/20c74954a5a18ee37958383e0d4e5c4769bd98e5/pyqtgraph/dockarea/Dock.py#L146-L164

To:

```python
def setOrientation(self, o='auto', force=False):
        """
        Sets the orientation of the title bar for this Dock.
        Must be one of 'auto', 'horizontal', or 'vertical'.
        By default ('auto'), the orientation is determined
        based on the aspect ratio of the Dock.
        """
        #print self.name(), "setOrientation", o, force
        if o == 'auto' and self.autoOrient:
            if 'type' in dir(self.container()):
                if self.container().type() == 'tab':
                    o = 'horizontal'
                elif self.width() > self.height()*1.5:
                    o = 'vertical'
                else:
                    o = 'horizontal'
            elif self.width() > self.height() * 1.5:
                o = 'vertical'
            else:
                o = 'horizontal'
        if force or self.orientation != o:
            self.orientation = o
            self.label.setOrientation(o)
            self.updateStyle()

```
Could you provide some more details about when you see the error? I don't seem to be able to reproduce the issue with `examples/dockarea.py`.
Not sure about @arielja87 but my problem was trying to add the dock to an area immediately after it has been closed using the sigClosed signal. 

In the context of `examples/dockarea.py` it would go something like this:
```python
def d6_closed():
    area.addDock(d6, 'top', d4)

win.show()

d6.sigClosed.connect(d6_closed)
```

I should probably rejig how I'm operating, but is this behaviour intended?
I see, thanks. I'm able to reproduce the issue now. When the `Dock` is closed, it does some cleanup which includes setting its `_container` attr to `None`. I don't think that should be changed. When it is re-inserted into a container, `setOrientation` is getting called before `containerChanged` (the latter sets the `_container` attribute to not `None`), resulting in the error.

Now, the proposed fix does seem like a bit of a bandage over the underlying issue, but I'm thinking it may work fine because once `containerChanged` *does* end up getting called, *it* will call `setOrientation`. That is, I'm not seeing any unintended side effects.

@arielja87 @UsYer: any examples of other use cases where this issue occurs would be helpful. Re-inserting a closed dock is a somewhat odd case so I'm curious if there are others.
@ixjlyons This issues also happens when adding a Dock forces other Docks to resize.
```python
from pyqtgraph.dockarea import DockArea, Dock
from pyqtgraph.Qt import QtGui

app = QtGui.QApplication([])
area=DockArea()
d1=Dock('Dock1', size=(100,100))
area.addDock(d1,'left')
area.show()

d2=Dock('Dock2', size=(100,100))
area.addDock(d2,'right',d1)

import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
    QtGui.QApplication.instance().exec_()

```

Tested with pyqtgraph 0.11.0rc0


Resolving patch:
diff --git a/pyqtgraph/dockarea/Dock.py b/pyqtgraph/dockarea/Dock.py
--- a/pyqtgraph/dockarea/Dock.py
+++ b/pyqtgraph/dockarea/Dock.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 from ..Qt import QtCore, QtGui
 
 from .DockDrop import *
@@ -138,6 +139,12 @@ def setOrientation(self, o='auto', force=False):
         By default ('auto'), the orientation is determined
         based on the aspect ratio of the Dock.
         """
+        # setOrientation may be called before the container is set in some cases
+        # (via resizeEvent), so there's no need to do anything here until called
+        # again by containerChanged
+        if self.container() is None:
+            return
+
         if o == 'auto' and self.autoOrient:
             if self.container().type() == 'tab':
                 o = 'horizontal'


Test patch: