Fix Dock close event QLabel still running with no parent

This commit is contained in:
Alberto Fontán Correa 2017-07-03 10:30:39 +02:00 committed by Ogi
parent 8bd2fa87e1
commit 1f9ccccfd0

View File

@ -5,10 +5,10 @@ from ..widgets.VerticalLabel import VerticalLabel
from ..python2_3 import asUnicode from ..python2_3 import asUnicode
class Dock(QtGui.QWidget, DockDrop): class Dock(QtGui.QWidget, DockDrop):
sigStretchChanged = QtCore.Signal() sigStretchChanged = QtCore.Signal()
sigClosed = QtCore.Signal(object) sigClosed = QtCore.Signal(object)
def __init__(self, name, area=None, size=(10, 10), widget=None, hideTitle=False, autoOrientation=True, closable=False): def __init__(self, name, area=None, size=(10, 10), widget=None, hideTitle=False, autoOrientation=True, closable=False):
QtGui.QWidget.__init__(self) QtGui.QWidget.__init__(self)
DockDrop.__init__(self) DockDrop.__init__(self)
@ -68,9 +68,9 @@ class Dock(QtGui.QWidget, DockDrop):
}""" }"""
self.setAutoFillBackground(False) self.setAutoFillBackground(False)
self.widgetArea.setStyleSheet(self.hStyle) self.widgetArea.setStyleSheet(self.hStyle)
self.setStretch(*size) self.setStretch(*size)
if widget is not None: if widget is not None:
self.addWidget(widget) self.addWidget(widget)
@ -82,7 +82,7 @@ class Dock(QtGui.QWidget, DockDrop):
return ['dock'] return ['dock']
else: else:
return name == 'dock' return name == 'dock'
def setStretch(self, x=None, y=None): def setStretch(self, x=None, y=None):
""" """
Set the 'target' size for this Dock. Set the 'target' size for this Dock.
@ -109,7 +109,7 @@ class Dock(QtGui.QWidget, DockDrop):
if 'center' in self.allowedAreas: if 'center' in self.allowedAreas:
self.allowedAreas.remove('center') self.allowedAreas.remove('center')
self.updateStyle() self.updateStyle()
def showTitleBar(self): def showTitleBar(self):
""" """
Show the title bar for this Dock. Show the title bar for this Dock.
@ -130,7 +130,7 @@ class Dock(QtGui.QWidget, DockDrop):
Sets the text displayed in title bar for this Dock. Sets the text displayed in title bar for this Dock.
""" """
self.label.setText(text) self.label.setText(text)
def setOrientation(self, o='auto', force=False): def setOrientation(self, o='auto', force=False):
""" """
Sets the orientation of the title bar for this Dock. Sets the orientation of the title bar for this Dock.
@ -149,7 +149,7 @@ class Dock(QtGui.QWidget, DockDrop):
self.orientation = o self.orientation = o
self.label.setOrientation(o) self.label.setOrientation(o)
self.updateStyle() self.updateStyle()
def updateStyle(self): def updateStyle(self):
## updates orientation and appearance of title bar ## updates orientation and appearance of title bar
if self.labelHidden: if self.labelHidden:
@ -192,7 +192,7 @@ class Dock(QtGui.QWidget, DockDrop):
self.update() self.update()
action = self.drag.exec_() action = self.drag.exec_()
self.updateStyle() self.updateStyle()
def float(self): def float(self):
self.area.floatDock(self) self.area.floatDock(self)
@ -223,6 +223,7 @@ class Dock(QtGui.QWidget, DockDrop):
def close(self): def close(self):
"""Remove this dock from the DockArea it lives inside.""" """Remove this dock from the DockArea it lives inside."""
self.setParent(None) self.setParent(None)
QtGui.QLabel.close(self.label)
self.label.setParent(None) self.label.setParent(None)
self._container.apoptose() self._container.apoptose()
self._container = None self._container = None
@ -247,10 +248,10 @@ class Dock(QtGui.QWidget, DockDrop):
class DockLabel(VerticalLabel): class DockLabel(VerticalLabel):
sigClicked = QtCore.Signal(object, object) sigClicked = QtCore.Signal(object, object)
sigCloseClicked = QtCore.Signal() sigCloseClicked = QtCore.Signal()
def __init__(self, text, dock, showCloseButton): def __init__(self, text, dock, showCloseButton):
self.dim = False self.dim = False
self.fixedWidth = False self.fixedWidth = False
@ -277,7 +278,7 @@ class DockLabel(VerticalLabel):
fg = '#fff' fg = '#fff'
bg = '#66c' bg = '#66c'
border = '#55B' border = '#55B'
if self.orientation == 'vertical': if self.orientation == 'vertical':
self.vStyle = """DockLabel { self.vStyle = """DockLabel {
background-color : %s; background-color : %s;
@ -311,7 +312,7 @@ class DockLabel(VerticalLabel):
if self.dim != d: if self.dim != d:
self.dim = d self.dim = d
self.updateStyle() self.updateStyle()
def setOrientation(self, o): def setOrientation(self, o):
VerticalLabel.setOrientation(self, o) VerticalLabel.setOrientation(self, o)
self.updateStyle() self.updateStyle()
@ -321,12 +322,12 @@ class DockLabel(VerticalLabel):
self.pressPos = ev.pos() self.pressPos = ev.pos()
self.startedDrag = False self.startedDrag = False
ev.accept() ev.accept()
def mouseMoveEvent(self, ev): def mouseMoveEvent(self, ev):
if not self.startedDrag and (ev.pos() - self.pressPos).manhattanLength() > QtGui.QApplication.startDragDistance(): if not self.startedDrag and (ev.pos() - self.pressPos).manhattanLength() > QtGui.QApplication.startDragDistance():
self.dock.startDrag() self.dock.startDrag()
ev.accept() ev.accept()
def mouseReleaseEvent(self, ev): def mouseReleaseEvent(self, ev):
ev.accept() ev.accept()
if not self.startedDrag: if not self.startedDrag:
@ -335,7 +336,7 @@ class DockLabel(VerticalLabel):
def mouseDoubleClickEvent(self, ev): def mouseDoubleClickEvent(self, ev):
if ev.button() == QtCore.Qt.LeftButton: if ev.button() == QtCore.Qt.LeftButton:
self.dock.float() self.dock.float()
def resizeEvent (self, ev): def resizeEvent (self, ev):
if self.closeButton: if self.closeButton:
if self.orientation == 'vertical': if self.orientation == 'vertical':