GTK error on Destructor of PlotWidget caused by missing parent Widget

Bug #1308272 reported by David Hornung
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
pyqtgraph
New
Undecided
Unassigned

Bug Description

Hello,
 i report a bug using PlotWidget. It appears if I closed my application(code below). But doesn't occur if watches every tab widget.

propably this could help regarding to this article http://stackoverflow.com/questions/12433491/is-this-pyqt-4-python-bug-or-wrongly-behaving-code

errors messages:

(python:30803): Gtk-CRITICAL **: IA__gtk_container_add: assertion 'GTK_IS_CONTAINER (container)' failed

(python:30803): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion 'GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed

(python:30803): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion 'GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed

(python:30803): Gtk-CRITICAL **: IA__gtk_container_add: assertion 'GTK_IS_CONTAINER (container)' failed

(python:30803): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion 'GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
.....

code snippet below:

app = QtGui.QApplication([])
mw = QtGui.QMainWindow()
cw = QtGui.QWidget(None)
cwl = QtGui.QGridLayout(cw)
tw = QtGui.QTabWidget(cw)
cwl.addWidget(tw)
mw.setCentralWidget(cw)
mw.resize(1024,600)

class MachineView():
    def __init__(self, machine):
        self.machine = machine
        self.data = []
        self.w = QtGui.QWidget(tw)
        self.l = QtGui.QVBoxLayout(self.w)
        self.pw = pg.PlotWidget(parent=self.w)
        self.pwzoom = pg.PlotWidget(parent=self.w)
        self.lr = pg.LinearRegionItem([400,700])

        self.l.addWidget(self.pw)
        self.l.addWidget(self.pwzoom)
        self.pw.addItem(self.lr)
        self.lr.sigRegionChanged.connect(self._updatePlot)
        self.pwzoom.sigXRangeChanged.connect(self._updateRegion)

        self.updateTimer = QtCore.QTimer()
        self.updateTimer.timeout.connect(self.updateData)
        self.updateTimer.start(3000)
        self.updateData()

    def updateData(self):
        self.data = [1,2,3,2]# something what you want
        self.pw.plot(self.data)
        self.pwzoom.plot(self.data)

    def getWidget(self):
        return self.w

    def _updatePlot(self):
         self.pwzoom.setXRange(*self.lr.getRegion(), padding=0)

    def _updateRegion(self):
         self.lr.setRegion(self.pwzoom.getViewBox().viewRange()[0])

class Monitor():
    def __init__(self):
        self.machines = ["m1","m2","m3"]

        self.machineViews = {}
        for machine in self.machines:
            pw = MachineView(machine)
            self.machineViews[machine] = pw
            #cwl.addWidget(pw.getWidget())
            tw.addTab(pw.getWidget(), machine)

monitor = Montior()
mw.show()

Tags: destructor gtk
description: updated
Revision history for this message
Alex K (arbitraryvalue) wrote :

I get this same issue with the following simple test program:

import pyqtgraph
from pyqtgraph.Qt import QtCore, QtGui

app = QtGui.QApplication([])
plot = pyqtgraph.PlotWidget()

Revision history for this message
Alex K (arbitraryvalue) wrote :

With these modifications, the program no longer crashes for me:

import pyqtgraph
from pyqtgraph.Qt import QtCore, QtGui

app = QtGui.QApplication([])
win = QtGui.QMainWindow()
plot = pyqtgraph.PlotWidget(parent=win)
win = None
plot = None

Revision history for this message
lcampagn (luke-campagnola) wrote :

Thanks, Alex. I will play around with this.
Please note that pyqtgraph is now hosted at http://github.com/pyqtgraph.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.