We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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':


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pyqtgraph/dockarea/Dock.py`
Content:
```
1 from ..Qt import QtCore, QtGui
2 
3 from .DockDrop import *
4 from ..widgets.VerticalLabel import VerticalLabel
5 from ..python2_3 import asUnicode
6 
7 class Dock(QtGui.QWidget, DockDrop):
8 
9     sigStretchChanged = QtCore.Signal()
10     sigClosed = QtCore.Signal(object)
11 
12     def __init__(self, name, area=None, size=(10, 10), widget=None, hideTitle=False, autoOrientation=True, closable=False):
13         QtGui.QWidget.__init__(self)
14         DockDrop.__init__(self)
15         self._container = None
16         self._name = name
17         self.area = area
18         self.label = DockLabel(name, self, closable)
19         if closable:
20             self.label.sigCloseClicked.connect(self.close)
21         self.labelHidden = False
22         self.moveLabel = True  ## If false, the dock is no longer allowed to move the label.
23         self.autoOrient = autoOrientation
24         self.orientation = 'horizontal'
25         #self.label.setAlignment(QtCore.Qt.AlignHCenter)
26         self.topLayout = QtGui.QGridLayout()
27         self.topLayout.setContentsMargins(0, 0, 0, 0)
28         self.topLayout.setSpacing(0)
29         self.setLayout(self.topLayout)
30         self.topLayout.addWidget(self.label, 0, 1)
31         self.widgetArea = QtGui.QWidget()
32         self.topLayout.addWidget(self.widgetArea, 1, 1)
33         self.layout = QtGui.QGridLayout()
34         self.layout.setContentsMargins(0, 0, 0, 0)
35         self.layout.setSpacing(0)
36         self.widgetArea.setLayout(self.layout)
37         self.widgetArea.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
38         self.widgets = []
39         self._container = None
40         self.currentRow = 0
41         #self.titlePos = 'top'
42         self.raiseOverlay()
43         self.hStyle = """
44         Dock > QWidget {
45             border: 1px solid #000;
46             border-radius: 5px;
47             border-top-left-radius: 0px;
48             border-top-right-radius: 0px;
49             border-top-width: 0px;
50         }"""
51         self.vStyle = """
52         Dock > QWidget {
53             border: 1px solid #000;
54             border-radius: 5px;
55             border-top-left-radius: 0px;
56             border-bottom-left-radius: 0px;
57             border-left-width: 0px;
58         }"""
59         self.nStyle = """
60         Dock > QWidget {
61             border: 1px solid #000;
62             border-radius: 5px;
63         }"""
64         self.dragStyle = """
65         Dock > QWidget {
66             border: 4px solid #00F;
67             border-radius: 5px;
68         }"""
69         self.setAutoFillBackground(False)
70         self.widgetArea.setStyleSheet(self.hStyle)
71 
72         self.setStretch(*size)
73 
74         if widget is not None:
75             self.addWidget(widget)
76 
77         if hideTitle:
78             self.hideTitleBar()
79 
80     def implements(self, name=None):
81         if name is None:
82             return ['dock']
83         else:
84             return name == 'dock'
85 
86     def setStretch(self, x=None, y=None):
87         """
88         Set the 'target' size for this Dock.
89         The actual size will be determined by comparing this Dock's
90         stretch value to the rest of the docks it shares space with.
91         """
92         if x is None:
93             x = 0
94         if y is None:
95             y = 0
96         self._stretch = (x, y)
97         self.sigStretchChanged.emit()
98         
99     def stretch(self):
100         return self._stretch
101 
102     def hideTitleBar(self):
103         """
104         Hide the title bar for this Dock.
105         This will prevent the Dock being moved by the user.
106         """
107         self.label.hide()
108         self.labelHidden = True
109         if 'center' in self.allowedAreas:
110             self.allowedAreas.remove('center')
111         self.updateStyle()
112 
113     def showTitleBar(self):
114         """
115         Show the title bar for this Dock.
116         """
117         self.label.show()
118         self.labelHidden = False
119         self.allowedAreas.add('center')
120         self.updateStyle()
121 
122     def title(self):
123         """
124         Gets the text displayed in the title bar for this dock.
125         """
126         return asUnicode(self.label.text())
127 
128     def setTitle(self, text):
129         """
130         Sets the text displayed in title bar for this Dock.
131         """
132         self.label.setText(text)
133 
134     def setOrientation(self, o='auto', force=False):
135         """
136         Sets the orientation of the title bar for this Dock.
137         Must be one of 'auto', 'horizontal', or 'vertical'.
138         By default ('auto'), the orientation is determined
139         based on the aspect ratio of the Dock.
140         """
141         if o == 'auto' and self.autoOrient:
142             if self.container().type() == 'tab':
143                 o = 'horizontal'
144             elif self.width() > self.height()*1.5:
145                 o = 'vertical'
146             else:
147                 o = 'horizontal'
148         if force or self.orientation != o:
149             self.orientation = o
150             self.label.setOrientation(o)
151             self.updateStyle()
152 
153     def updateStyle(self):
154         ## updates orientation and appearance of title bar
155         if self.labelHidden:
156             self.widgetArea.setStyleSheet(self.nStyle)
157         elif self.orientation == 'vertical':
158             self.label.setOrientation('vertical')
159             if self.moveLabel:
160                 self.topLayout.addWidget(self.label, 1, 0)
161             self.widgetArea.setStyleSheet(self.vStyle)
162         else:
163             self.label.setOrientation('horizontal')
164             if self.moveLabel:
165                 self.topLayout.addWidget(self.label, 0, 1)
166             self.widgetArea.setStyleSheet(self.hStyle)
167 
168     def resizeEvent(self, ev):
169         self.setOrientation()
170         self.resizeOverlay(self.size())
171 
172     def name(self):
173         return self._name
174 
175     def addWidget(self, widget, row=None, col=0, rowspan=1, colspan=1):
176         """
177         Add a new widget to the interior of this Dock.
178         Each Dock uses a QGridLayout to arrange widgets within.
179         """
180         if row is None:
181             row = self.currentRow
182         self.currentRow = max(row+1, self.currentRow)
183         self.widgets.append(widget)
184         self.layout.addWidget(widget, row, col, rowspan, colspan)
185         self.raiseOverlay()
186         
187     def startDrag(self):
188         self.drag = QtGui.QDrag(self)
189         mime = QtCore.QMimeData()
190         self.drag.setMimeData(mime)
191         self.widgetArea.setStyleSheet(self.dragStyle)
192         self.update()
193         action = self.drag.exec_()
194         self.updateStyle()
195 
196     def float(self):
197         self.area.floatDock(self)
198             
199     def container(self):
200         return self._container
201 
202     def containerChanged(self, c):
203         if self._container is not None:
204             # ask old container to close itself if it is no longer needed
205             self._container.apoptose()
206         self._container = c
207         if c is None:
208             self.area = None
209         else:
210             self.area = c.area
211             if c.type() != 'tab':
212                 self.moveLabel = True
213                 self.label.setDim(False)
214             else:
215                 self.moveLabel = False
216                 
217             self.setOrientation(force=True)
218 
219     def raiseDock(self):
220         """If this Dock is stacked underneath others, raise it to the top."""
221         self.container().raiseDock(self)
222 
223     def close(self):
224         """Remove this dock from the DockArea it lives inside."""
225         self.setParent(None)
226         QtGui.QLabel.close(self.label)
227         self.label.setParent(None)
228         self._container.apoptose()
229         self._container = None
230         self.sigClosed.emit(self)
231 
232     def __repr__(self):
233         return "<Dock %s %s>" % (self.name(), self.stretch())
234 
235     ## PySide bug: We need to explicitly redefine these methods
236     ## or else drag/drop events will not be delivered.
237     def dragEnterEvent(self, *args):
238         DockDrop.dragEnterEvent(self, *args)
239 
240     def dragMoveEvent(self, *args):
241         DockDrop.dragMoveEvent(self, *args)
242 
243     def dragLeaveEvent(self, *args):
244         DockDrop.dragLeaveEvent(self, *args)
245 
246     def dropEvent(self, *args):
247         DockDrop.dropEvent(self, *args)
248 
249 
250 class DockLabel(VerticalLabel):
251 
252     sigClicked = QtCore.Signal(object, object)
253     sigCloseClicked = QtCore.Signal()
254 
255     def __init__(self, text, dock, showCloseButton):
256         self.dim = False
257         self.fixedWidth = False
258         VerticalLabel.__init__(self, text, orientation='horizontal', forceWidth=False)
259         self.setAlignment(QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter)
260         self.dock = dock
261         self.updateStyle()
262         self.setAutoFillBackground(False)
263         self.startedDrag = False
264 
265         self.closeButton = None
266         if showCloseButton:
267             self.closeButton = QtGui.QToolButton(self)
268             self.closeButton.clicked.connect(self.sigCloseClicked)
269             self.closeButton.setIcon(QtGui.QApplication.style().standardIcon(QtGui.QStyle.SP_TitleBarCloseButton))
270 
271     def updateStyle(self):
272         r = '3px'
273         if self.dim:
274             fg = '#aaa'
275             bg = '#44a'
276             border = '#339'
277         else:
278             fg = '#fff'
279             bg = '#66c'
280             border = '#55B'
281 
282         if self.orientation == 'vertical':
283             self.vStyle = """DockLabel {
284                 background-color : %s;
285                 color : %s;
286                 border-top-right-radius: 0px;
287                 border-top-left-radius: %s;
288                 border-bottom-right-radius: 0px;
289                 border-bottom-left-radius: %s;
290                 border-width: 0px;
291                 border-right: 2px solid %s;
292                 padding-top: 3px;
293                 padding-bottom: 3px;
294             }""" % (bg, fg, r, r, border)
295             self.setStyleSheet(self.vStyle)
296         else:
297             self.hStyle = """DockLabel {
298                 background-color : %s;
299                 color : %s;
300                 border-top-right-radius: %s;
301                 border-top-left-radius: %s;
302                 border-bottom-right-radius: 0px;
303                 border-bottom-left-radius: 0px;
304                 border-width: 0px;
305                 border-bottom: 2px solid %s;
306                 padding-left: 3px;
307                 padding-right: 3px;
308             }""" % (bg, fg, r, r, border)
309             self.setStyleSheet(self.hStyle)
310 
311     def setDim(self, d):
312         if self.dim != d:
313             self.dim = d
314             self.updateStyle()
315 
316     def setOrientation(self, o):
317         VerticalLabel.setOrientation(self, o)
318         self.updateStyle()
319 
320     def mousePressEvent(self, ev):
321         if ev.button() == QtCore.Qt.LeftButton:
322             self.pressPos = ev.pos()
323             self.startedDrag = False
324             ev.accept()
325 
326     def mouseMoveEvent(self, ev):
327         if not self.startedDrag and (ev.pos() - self.pressPos).manhattanLength() > QtGui.QApplication.startDragDistance():
328             self.dock.startDrag()
329         ev.accept()
330 
331     def mouseReleaseEvent(self, ev):
332         ev.accept()
333         if not self.startedDrag:
334             self.sigClicked.emit(self, ev)
335         
336     def mouseDoubleClickEvent(self, ev):
337         if ev.button() == QtCore.Qt.LeftButton:
338             self.dock.float()
339 
340     def resizeEvent (self, ev):
341         if self.closeButton:
342             if self.orientation == 'vertical':
343                 size = ev.size().width()
344                 pos = QtCore.QPoint(0, 0)
345             else:
346                 size = ev.size().height()
347                 pos = QtCore.QPoint(ev.size().width() - size, 0)
348             self.closeButton.setFixedSize(QtCore.QSize(size, size))
349             self.closeButton.move(pos)
350         super(DockLabel,self).resizeEvent(ev)
351
```
--- 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/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 @@
         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'

{"golden_diff": "diff --git a/pyqtgraph/dockarea/Dock.py b/pyqtgraph/dockarea/Dock.py\n--- a/pyqtgraph/dockarea/Dock.py\n+++ b/pyqtgraph/dockarea/Dock.py\n@@ -1,3 +1,4 @@\n+# -*- coding: utf-8 -*-\n from ..Qt import QtCore, QtGui\n \n from .DockDrop import *\n@@ -138,6 +139,12 @@\n         By default ('auto'), the orientation is determined\n         based on the aspect ratio of the Dock.\n         \"\"\"\n+        # setOrientation may be called before the container is set in some cases\n+        # (via resizeEvent), so there's no need to do anything here until called\n+        # again by containerChanged\n+        if self.container() is None:\n+            return\n+\n         if o == 'auto' and self.autoOrient:\n             if self.container().type() == 'tab':\n                 o = 'horizontal'\n", "issue": "    if self.container().type() == 'tab': AttributeError: 'NoneType' object has no attribute 'type'\nNot 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. \r\n\r\n            if self.container() is not None and self.container().type() == 'tab':\r\n\n", "before_files": [{"content": "from ..Qt import QtCore, QtGui\n\nfrom .DockDrop import *\nfrom ..widgets.VerticalLabel import VerticalLabel\nfrom ..python2_3 import asUnicode\n\nclass Dock(QtGui.QWidget, DockDrop):\n\n    sigStretchChanged = QtCore.Signal()\n    sigClosed = QtCore.Signal(object)\n\n    def __init__(self, name, area=None, size=(10, 10), widget=None, hideTitle=False, autoOrientation=True, closable=False):\n        QtGui.QWidget.__init__(self)\n        DockDrop.__init__(self)\n        self._container = None\n        self._name = name\n        self.area = area\n        self.label = DockLabel(name, self, closable)\n        if closable:\n            self.label.sigCloseClicked.connect(self.close)\n        self.labelHidden = False\n        self.moveLabel = True  ## If false, the dock is no longer allowed to move the label.\n        self.autoOrient = autoOrientation\n        self.orientation = 'horizontal'\n        #self.label.setAlignment(QtCore.Qt.AlignHCenter)\n        self.topLayout = QtGui.QGridLayout()\n        self.topLayout.setContentsMargins(0, 0, 0, 0)\n        self.topLayout.setSpacing(0)\n        self.setLayout(self.topLayout)\n        self.topLayout.addWidget(self.label, 0, 1)\n        self.widgetArea = QtGui.QWidget()\n        self.topLayout.addWidget(self.widgetArea, 1, 1)\n        self.layout = QtGui.QGridLayout()\n        self.layout.setContentsMargins(0, 0, 0, 0)\n        self.layout.setSpacing(0)\n        self.widgetArea.setLayout(self.layout)\n        self.widgetArea.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)\n        self.widgets = []\n        self._container = None\n        self.currentRow = 0\n        #self.titlePos = 'top'\n        self.raiseOverlay()\n        self.hStyle = \"\"\"\n        Dock > QWidget {\n            border: 1px solid #000;\n            border-radius: 5px;\n            border-top-left-radius: 0px;\n            border-top-right-radius: 0px;\n            border-top-width: 0px;\n        }\"\"\"\n        self.vStyle = \"\"\"\n        Dock > QWidget {\n            border: 1px solid #000;\n            border-radius: 5px;\n            border-top-left-radius: 0px;\n            border-bottom-left-radius: 0px;\n            border-left-width: 0px;\n        }\"\"\"\n        self.nStyle = \"\"\"\n        Dock > QWidget {\n            border: 1px solid #000;\n            border-radius: 5px;\n        }\"\"\"\n        self.dragStyle = \"\"\"\n        Dock > QWidget {\n            border: 4px solid #00F;\n            border-radius: 5px;\n        }\"\"\"\n        self.setAutoFillBackground(False)\n        self.widgetArea.setStyleSheet(self.hStyle)\n\n        self.setStretch(*size)\n\n        if widget is not None:\n            self.addWidget(widget)\n\n        if hideTitle:\n            self.hideTitleBar()\n\n    def implements(self, name=None):\n        if name is None:\n            return ['dock']\n        else:\n            return name == 'dock'\n\n    def setStretch(self, x=None, y=None):\n        \"\"\"\n        Set the 'target' size for this Dock.\n        The actual size will be determined by comparing this Dock's\n        stretch value to the rest of the docks it shares space with.\n        \"\"\"\n        if x is None:\n            x = 0\n        if y is None:\n            y = 0\n        self._stretch = (x, y)\n        self.sigStretchChanged.emit()\n        \n    def stretch(self):\n        return self._stretch\n\n    def hideTitleBar(self):\n        \"\"\"\n        Hide the title bar for this Dock.\n        This will prevent the Dock being moved by the user.\n        \"\"\"\n        self.label.hide()\n        self.labelHidden = True\n        if 'center' in self.allowedAreas:\n            self.allowedAreas.remove('center')\n        self.updateStyle()\n\n    def showTitleBar(self):\n        \"\"\"\n        Show the title bar for this Dock.\n        \"\"\"\n        self.label.show()\n        self.labelHidden = False\n        self.allowedAreas.add('center')\n        self.updateStyle()\n\n    def title(self):\n        \"\"\"\n        Gets the text displayed in the title bar for this dock.\n        \"\"\"\n        return asUnicode(self.label.text())\n\n    def setTitle(self, text):\n        \"\"\"\n        Sets the text displayed in title bar for this Dock.\n        \"\"\"\n        self.label.setText(text)\n\n    def setOrientation(self, o='auto', force=False):\n        \"\"\"\n        Sets the orientation of the title bar for this Dock.\n        Must be one of 'auto', 'horizontal', or 'vertical'.\n        By default ('auto'), the orientation is determined\n        based on the aspect ratio of the Dock.\n        \"\"\"\n        if o == 'auto' and self.autoOrient:\n            if self.container().type() == 'tab':\n                o = 'horizontal'\n            elif self.width() > self.height()*1.5:\n                o = 'vertical'\n            else:\n                o = 'horizontal'\n        if force or self.orientation != o:\n            self.orientation = o\n            self.label.setOrientation(o)\n            self.updateStyle()\n\n    def updateStyle(self):\n        ## updates orientation and appearance of title bar\n        if self.labelHidden:\n            self.widgetArea.setStyleSheet(self.nStyle)\n        elif self.orientation == 'vertical':\n            self.label.setOrientation('vertical')\n            if self.moveLabel:\n                self.topLayout.addWidget(self.label, 1, 0)\n            self.widgetArea.setStyleSheet(self.vStyle)\n        else:\n            self.label.setOrientation('horizontal')\n            if self.moveLabel:\n                self.topLayout.addWidget(self.label, 0, 1)\n            self.widgetArea.setStyleSheet(self.hStyle)\n\n    def resizeEvent(self, ev):\n        self.setOrientation()\n        self.resizeOverlay(self.size())\n\n    def name(self):\n        return self._name\n\n    def addWidget(self, widget, row=None, col=0, rowspan=1, colspan=1):\n        \"\"\"\n        Add a new widget to the interior of this Dock.\n        Each Dock uses a QGridLayout to arrange widgets within.\n        \"\"\"\n        if row is None:\n            row = self.currentRow\n        self.currentRow = max(row+1, self.currentRow)\n        self.widgets.append(widget)\n        self.layout.addWidget(widget, row, col, rowspan, colspan)\n        self.raiseOverlay()\n        \n    def startDrag(self):\n        self.drag = QtGui.QDrag(self)\n        mime = QtCore.QMimeData()\n        self.drag.setMimeData(mime)\n        self.widgetArea.setStyleSheet(self.dragStyle)\n        self.update()\n        action = self.drag.exec_()\n        self.updateStyle()\n\n    def float(self):\n        self.area.floatDock(self)\n            \n    def container(self):\n        return self._container\n\n    def containerChanged(self, c):\n        if self._container is not None:\n            # ask old container to close itself if it is no longer needed\n            self._container.apoptose()\n        self._container = c\n        if c is None:\n            self.area = None\n        else:\n            self.area = c.area\n            if c.type() != 'tab':\n                self.moveLabel = True\n                self.label.setDim(False)\n            else:\n                self.moveLabel = False\n                \n            self.setOrientation(force=True)\n\n    def raiseDock(self):\n        \"\"\"If this Dock is stacked underneath others, raise it to the top.\"\"\"\n        self.container().raiseDock(self)\n\n    def close(self):\n        \"\"\"Remove this dock from the DockArea it lives inside.\"\"\"\n        self.setParent(None)\n        QtGui.QLabel.close(self.label)\n        self.label.setParent(None)\n        self._container.apoptose()\n        self._container = None\n        self.sigClosed.emit(self)\n\n    def __repr__(self):\n        return \"<Dock %s %s>\" % (self.name(), self.stretch())\n\n    ## PySide bug: We need to explicitly redefine these methods\n    ## or else drag/drop events will not be delivered.\n    def dragEnterEvent(self, *args):\n        DockDrop.dragEnterEvent(self, *args)\n\n    def dragMoveEvent(self, *args):\n        DockDrop.dragMoveEvent(self, *args)\n\n    def dragLeaveEvent(self, *args):\n        DockDrop.dragLeaveEvent(self, *args)\n\n    def dropEvent(self, *args):\n        DockDrop.dropEvent(self, *args)\n\n\nclass DockLabel(VerticalLabel):\n\n    sigClicked = QtCore.Signal(object, object)\n    sigCloseClicked = QtCore.Signal()\n\n    def __init__(self, text, dock, showCloseButton):\n        self.dim = False\n        self.fixedWidth = False\n        VerticalLabel.__init__(self, text, orientation='horizontal', forceWidth=False)\n        self.setAlignment(QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter)\n        self.dock = dock\n        self.updateStyle()\n        self.setAutoFillBackground(False)\n        self.startedDrag = False\n\n        self.closeButton = None\n        if showCloseButton:\n            self.closeButton = QtGui.QToolButton(self)\n            self.closeButton.clicked.connect(self.sigCloseClicked)\n            self.closeButton.setIcon(QtGui.QApplication.style().standardIcon(QtGui.QStyle.SP_TitleBarCloseButton))\n\n    def updateStyle(self):\n        r = '3px'\n        if self.dim:\n            fg = '#aaa'\n            bg = '#44a'\n            border = '#339'\n        else:\n            fg = '#fff'\n            bg = '#66c'\n            border = '#55B'\n\n        if self.orientation == 'vertical':\n            self.vStyle = \"\"\"DockLabel {\n                background-color : %s;\n                color : %s;\n                border-top-right-radius: 0px;\n                border-top-left-radius: %s;\n                border-bottom-right-radius: 0px;\n                border-bottom-left-radius: %s;\n                border-width: 0px;\n                border-right: 2px solid %s;\n                padding-top: 3px;\n                padding-bottom: 3px;\n            }\"\"\" % (bg, fg, r, r, border)\n            self.setStyleSheet(self.vStyle)\n        else:\n            self.hStyle = \"\"\"DockLabel {\n                background-color : %s;\n                color : %s;\n                border-top-right-radius: %s;\n                border-top-left-radius: %s;\n                border-bottom-right-radius: 0px;\n                border-bottom-left-radius: 0px;\n                border-width: 0px;\n                border-bottom: 2px solid %s;\n                padding-left: 3px;\n                padding-right: 3px;\n            }\"\"\" % (bg, fg, r, r, border)\n            self.setStyleSheet(self.hStyle)\n\n    def setDim(self, d):\n        if self.dim != d:\n            self.dim = d\n            self.updateStyle()\n\n    def setOrientation(self, o):\n        VerticalLabel.setOrientation(self, o)\n        self.updateStyle()\n\n    def mousePressEvent(self, ev):\n        if ev.button() == QtCore.Qt.LeftButton:\n            self.pressPos = ev.pos()\n            self.startedDrag = False\n            ev.accept()\n\n    def mouseMoveEvent(self, ev):\n        if not self.startedDrag and (ev.pos() - self.pressPos).manhattanLength() > QtGui.QApplication.startDragDistance():\n            self.dock.startDrag()\n        ev.accept()\n\n    def mouseReleaseEvent(self, ev):\n        ev.accept()\n        if not self.startedDrag:\n            self.sigClicked.emit(self, ev)\n        \n    def mouseDoubleClickEvent(self, ev):\n        if ev.button() == QtCore.Qt.LeftButton:\n            self.dock.float()\n\n    def resizeEvent (self, ev):\n        if self.closeButton:\n            if self.orientation == 'vertical':\n                size = ev.size().width()\n                pos = QtCore.QPoint(0, 0)\n            else:\n                size = ev.size().height()\n                pos = QtCore.QPoint(ev.size().width() - size, 0)\n            self.closeButton.setFixedSize(QtCore.QSize(size, size))\n            self.closeButton.move(pos)\n        super(DockLabel,self).resizeEvent(ev)\n", "path": "pyqtgraph/dockarea/Dock.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nfrom ..Qt import QtCore, QtGui\n\nfrom .DockDrop import *\nfrom ..widgets.VerticalLabel import VerticalLabel\nfrom ..python2_3 import asUnicode\n\nclass Dock(QtGui.QWidget, DockDrop):\n\n    sigStretchChanged = QtCore.Signal()\n    sigClosed = QtCore.Signal(object)\n\n    def __init__(self, name, area=None, size=(10, 10), widget=None, hideTitle=False, autoOrientation=True, closable=False):\n        QtGui.QWidget.__init__(self)\n        DockDrop.__init__(self)\n        self._container = None\n        self._name = name\n        self.area = area\n        self.label = DockLabel(name, self, closable)\n        if closable:\n            self.label.sigCloseClicked.connect(self.close)\n        self.labelHidden = False\n        self.moveLabel = True  ## If false, the dock is no longer allowed to move the label.\n        self.autoOrient = autoOrientation\n        self.orientation = 'horizontal'\n        #self.label.setAlignment(QtCore.Qt.AlignHCenter)\n        self.topLayout = QtGui.QGridLayout()\n        self.topLayout.setContentsMargins(0, 0, 0, 0)\n        self.topLayout.setSpacing(0)\n        self.setLayout(self.topLayout)\n        self.topLayout.addWidget(self.label, 0, 1)\n        self.widgetArea = QtGui.QWidget()\n        self.topLayout.addWidget(self.widgetArea, 1, 1)\n        self.layout = QtGui.QGridLayout()\n        self.layout.setContentsMargins(0, 0, 0, 0)\n        self.layout.setSpacing(0)\n        self.widgetArea.setLayout(self.layout)\n        self.widgetArea.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)\n        self.widgets = []\n        self._container = None\n        self.currentRow = 0\n        #self.titlePos = 'top'\n        self.raiseOverlay()\n        self.hStyle = \"\"\"\n        Dock > QWidget {\n            border: 1px solid #000;\n            border-radius: 5px;\n            border-top-left-radius: 0px;\n            border-top-right-radius: 0px;\n            border-top-width: 0px;\n        }\"\"\"\n        self.vStyle = \"\"\"\n        Dock > QWidget {\n            border: 1px solid #000;\n            border-radius: 5px;\n            border-top-left-radius: 0px;\n            border-bottom-left-radius: 0px;\n            border-left-width: 0px;\n        }\"\"\"\n        self.nStyle = \"\"\"\n        Dock > QWidget {\n            border: 1px solid #000;\n            border-radius: 5px;\n        }\"\"\"\n        self.dragStyle = \"\"\"\n        Dock > QWidget {\n            border: 4px solid #00F;\n            border-radius: 5px;\n        }\"\"\"\n        self.setAutoFillBackground(False)\n        self.widgetArea.setStyleSheet(self.hStyle)\n\n        self.setStretch(*size)\n\n        if widget is not None:\n            self.addWidget(widget)\n\n        if hideTitle:\n            self.hideTitleBar()\n\n    def implements(self, name=None):\n        if name is None:\n            return ['dock']\n        else:\n            return name == 'dock'\n\n    def setStretch(self, x=None, y=None):\n        \"\"\"\n        Set the 'target' size for this Dock.\n        The actual size will be determined by comparing this Dock's\n        stretch value to the rest of the docks it shares space with.\n        \"\"\"\n        if x is None:\n            x = 0\n        if y is None:\n            y = 0\n        self._stretch = (x, y)\n        self.sigStretchChanged.emit()\n        \n    def stretch(self):\n        return self._stretch\n\n    def hideTitleBar(self):\n        \"\"\"\n        Hide the title bar for this Dock.\n        This will prevent the Dock being moved by the user.\n        \"\"\"\n        self.label.hide()\n        self.labelHidden = True\n        if 'center' in self.allowedAreas:\n            self.allowedAreas.remove('center')\n        self.updateStyle()\n\n    def showTitleBar(self):\n        \"\"\"\n        Show the title bar for this Dock.\n        \"\"\"\n        self.label.show()\n        self.labelHidden = False\n        self.allowedAreas.add('center')\n        self.updateStyle()\n\n    def title(self):\n        \"\"\"\n        Gets the text displayed in the title bar for this dock.\n        \"\"\"\n        return asUnicode(self.label.text())\n\n    def setTitle(self, text):\n        \"\"\"\n        Sets the text displayed in title bar for this Dock.\n        \"\"\"\n        self.label.setText(text)\n\n    def setOrientation(self, o='auto', force=False):\n        \"\"\"\n        Sets the orientation of the title bar for this Dock.\n        Must be one of 'auto', 'horizontal', or 'vertical'.\n        By default ('auto'), the orientation is determined\n        based on the aspect ratio of the Dock.\n        \"\"\"\n        # setOrientation may be called before the container is set in some cases\n        # (via resizeEvent), so there's no need to do anything here until called\n        # again by containerChanged\n        if self.container() is None:\n            return\n\n        if o == 'auto' and self.autoOrient:\n            if self.container().type() == 'tab':\n                o = 'horizontal'\n            elif self.width() > self.height()*1.5:\n                o = 'vertical'\n            else:\n                o = 'horizontal'\n        if force or self.orientation != o:\n            self.orientation = o\n            self.label.setOrientation(o)\n            self.updateStyle()\n\n    def updateStyle(self):\n        ## updates orientation and appearance of title bar\n        if self.labelHidden:\n            self.widgetArea.setStyleSheet(self.nStyle)\n        elif self.orientation == 'vertical':\n            self.label.setOrientation('vertical')\n            if self.moveLabel:\n                self.topLayout.addWidget(self.label, 1, 0)\n            self.widgetArea.setStyleSheet(self.vStyle)\n        else:\n            self.label.setOrientation('horizontal')\n            if self.moveLabel:\n                self.topLayout.addWidget(self.label, 0, 1)\n            self.widgetArea.setStyleSheet(self.hStyle)\n\n    def resizeEvent(self, ev):\n        self.setOrientation()\n        self.resizeOverlay(self.size())\n\n    def name(self):\n        return self._name\n\n    def addWidget(self, widget, row=None, col=0, rowspan=1, colspan=1):\n        \"\"\"\n        Add a new widget to the interior of this Dock.\n        Each Dock uses a QGridLayout to arrange widgets within.\n        \"\"\"\n        if row is None:\n            row = self.currentRow\n        self.currentRow = max(row+1, self.currentRow)\n        self.widgets.append(widget)\n        self.layout.addWidget(widget, row, col, rowspan, colspan)\n        self.raiseOverlay()\n        \n    def startDrag(self):\n        self.drag = QtGui.QDrag(self)\n        mime = QtCore.QMimeData()\n        self.drag.setMimeData(mime)\n        self.widgetArea.setStyleSheet(self.dragStyle)\n        self.update()\n        action = self.drag.exec_()\n        self.updateStyle()\n\n    def float(self):\n        self.area.floatDock(self)\n            \n    def container(self):\n        return self._container\n\n    def containerChanged(self, c):\n        if self._container is not None:\n            # ask old container to close itself if it is no longer needed\n            self._container.apoptose()\n        self._container = c\n        if c is None:\n            self.area = None\n        else:\n            self.area = c.area\n            if c.type() != 'tab':\n                self.moveLabel = True\n                self.label.setDim(False)\n            else:\n                self.moveLabel = False\n                \n            self.setOrientation(force=True)\n\n    def raiseDock(self):\n        \"\"\"If this Dock is stacked underneath others, raise it to the top.\"\"\"\n        self.container().raiseDock(self)\n\n    def close(self):\n        \"\"\"Remove this dock from the DockArea it lives inside.\"\"\"\n        self.setParent(None)\n        QtGui.QLabel.close(self.label)\n        self.label.setParent(None)\n        self._container.apoptose()\n        self._container = None\n        self.sigClosed.emit(self)\n\n    def __repr__(self):\n        return \"<Dock %s %s>\" % (self.name(), self.stretch())\n\n    ## PySide bug: We need to explicitly redefine these methods\n    ## or else drag/drop events will not be delivered.\n    def dragEnterEvent(self, *args):\n        DockDrop.dragEnterEvent(self, *args)\n\n    def dragMoveEvent(self, *args):\n        DockDrop.dragMoveEvent(self, *args)\n\n    def dragLeaveEvent(self, *args):\n        DockDrop.dragLeaveEvent(self, *args)\n\n    def dropEvent(self, *args):\n        DockDrop.dropEvent(self, *args)\n\n\nclass DockLabel(VerticalLabel):\n\n    sigClicked = QtCore.Signal(object, object)\n    sigCloseClicked = QtCore.Signal()\n\n    def __init__(self, text, dock, showCloseButton):\n        self.dim = False\n        self.fixedWidth = False\n        VerticalLabel.__init__(self, text, orientation='horizontal', forceWidth=False)\n        self.setAlignment(QtCore.Qt.AlignTop|QtCore.Qt.AlignHCenter)\n        self.dock = dock\n        self.updateStyle()\n        self.setAutoFillBackground(False)\n        self.startedDrag = False\n\n        self.closeButton = None\n        if showCloseButton:\n            self.closeButton = QtGui.QToolButton(self)\n            self.closeButton.clicked.connect(self.sigCloseClicked)\n            self.closeButton.setIcon(QtGui.QApplication.style().standardIcon(QtGui.QStyle.SP_TitleBarCloseButton))\n\n    def updateStyle(self):\n        r = '3px'\n        if self.dim:\n            fg = '#aaa'\n            bg = '#44a'\n            border = '#339'\n        else:\n            fg = '#fff'\n            bg = '#66c'\n            border = '#55B'\n\n        if self.orientation == 'vertical':\n            self.vStyle = \"\"\"DockLabel {\n                background-color : %s;\n                color : %s;\n                border-top-right-radius: 0px;\n                border-top-left-radius: %s;\n                border-bottom-right-radius: 0px;\n                border-bottom-left-radius: %s;\n                border-width: 0px;\n                border-right: 2px solid %s;\n                padding-top: 3px;\n                padding-bottom: 3px;\n            }\"\"\" % (bg, fg, r, r, border)\n            self.setStyleSheet(self.vStyle)\n        else:\n            self.hStyle = \"\"\"DockLabel {\n                background-color : %s;\n                color : %s;\n                border-top-right-radius: %s;\n                border-top-left-radius: %s;\n                border-bottom-right-radius: 0px;\n                border-bottom-left-radius: 0px;\n                border-width: 0px;\n                border-bottom: 2px solid %s;\n                padding-left: 3px;\n                padding-right: 3px;\n            }\"\"\" % (bg, fg, r, r, border)\n            self.setStyleSheet(self.hStyle)\n\n    def setDim(self, d):\n        if self.dim != d:\n            self.dim = d\n            self.updateStyle()\n\n    def setOrientation(self, o):\n        VerticalLabel.setOrientation(self, o)\n        self.updateStyle()\n\n    def mousePressEvent(self, ev):\n        if ev.button() == QtCore.Qt.LeftButton:\n            self.pressPos = ev.pos()\n            self.startedDrag = False\n            ev.accept()\n\n    def mouseMoveEvent(self, ev):\n        if not self.startedDrag and (ev.pos() - self.pressPos).manhattanLength() > QtGui.QApplication.startDragDistance():\n            self.dock.startDrag()\n        ev.accept()\n\n    def mouseReleaseEvent(self, ev):\n        ev.accept()\n        if not self.startedDrag:\n            self.sigClicked.emit(self, ev)\n        \n    def mouseDoubleClickEvent(self, ev):\n        if ev.button() == QtCore.Qt.LeftButton:\n            self.dock.float()\n\n    def resizeEvent (self, ev):\n        if self.closeButton:\n            if self.orientation == 'vertical':\n                size = ev.size().width()\n                pos = QtCore.QPoint(0, 0)\n            else:\n                size = ev.size().height()\n                pos = QtCore.QPoint(ev.size().width() - size, 0)\n            self.closeButton.setFixedSize(QtCore.QSize(size, size))\n            self.closeButton.move(pos)\n        super(DockLabel,self).resizeEvent(ev)\n", "path": "pyqtgraph/dockarea/Dock.py"}]}