taurus-org / taurus

Moved to https://gitlab.com/taurus-org/taurus
http://taurus-scada.org
43 stars 46 forks source link

TaurusLabelControllerAttribute._stateObj can be None #1080

Open vallsv opened 4 years ago

vallsv commented 4 years ago

Hi again,

I also receive this weird traceback from a TaurusLabel. I still have to figure out if the problem is on my side or on yours.

But looking at the code, _stateObj could be None, so my problem could be fixed on your side?

Traceback (most recent call last):
  File "/users/valls/workspace/id16/taurus.git/lib/taurus/qt/qtgui/base/taurusbase.py", line 394, in filterEvent
    self.handleEvent(*evt)
  File "/users/valls/workspace/id16/taurus.git/lib/taurus/qt/qtgui/display/tauruslabel.py", line 327, in handleEvent
    ctrl.handleEvent(evt_src, evt_type, evt_value)
  File "/users/valls/workspace/id16/taurus.git/lib/taurus/qt/qtgui/base/tauruscontroller.py", line 122, in handleEvent
    self.update()
  File "/users/valls/workspace/id16/taurus.git/lib/taurus/qt/qtgui/base/tauruscontroller.py", line 139, in update
    self._updateForeground(widget)
  File "/users/valls/workspace/id16/taurus.git/lib/taurus/qt/qtgui/display/tauruslabel.py", line 98, in _updateForeground
    print(self.state())
  File "/users/valls/workspace/id16/taurus.git/lib/taurus/qt/qtgui/base/tauruscontroller.py", line 98, in state
    return self._stateObj.state
AttributeError: 'NoneType' object has no attribute 'state'

It happens at the creation or the destruction of something.

vallsv commented 4 years ago

At a popup close, i set the model to "".

taurusbase.py:filterEvent receive a bunch of events, and when the source /state with the value None are received, the code raises this exception.

vallsv commented 4 years ago

Maybe that's again something about relative model.

vallsv commented 4 years ago

I tried to reproduce the problem, i did once, but now the test deadlock when i call setModel. I guess i forget an obvious thing. In case you have an idea.

BTW if you agree to patch _stateObj with None state, i can provide a patch. That's an easier way for me, cause i did not found a way to fix it on my side.

from taurus.qt.qtgui.application import TaurusApplication
from taurus.qt.qtgui.display.tauruslabel import TaurusLabel
from taurus.qt.qtgui.container import TaurusWidget
from PyQt5 import Qt
import logging

app = TaurusApplication([])

class Popup(Qt.QWidget):

    def __init__(self, parent=None):
        Qt.QWidget.__init__(self, parent=parent)
        self.setWindowFlags(Qt.Qt.Popup)
        self.setAttribute(Qt.Qt.WA_DeleteOnClose)

        w = TaurusWidget(self)
        l1 = Qt.QVBoxLayout(self)
        l1.addWidget(w)

        l = TaurusLabel(self)
        l.setModel("/State")
        l.setBgRole("state")
        l.setUseParentModel(True)
        l2 = Qt.QVBoxLayout(w)
        l2.addWidget(l)

        self.w = w

    def closeEvent(self, event):
        print("closeEvent")
        try:
            self.w.setModel("")
            pass
        except:
            logging.error("Arg", exc_info=True)
        print("Never reached")
        Qt.QWidget.closeEvent(self, event)

win = Qt.QMainWindow()
button = Qt.QPushButton()
win.setCentralWidget(button)

def clicked():
        print("clicked")
    popup = Popup(button)
    popup.w.setModel("sys/tg_test/1")
    p = Qt.QPoint(0, button.height())
    p = button.mapToGlobal(p)
    popup.move(p)
    popup.show()

button.clicked.connect(clicked)
win.show()
app.exec_()
vallsv commented 4 years ago

I maybe fixed the problem on my side.

Calling _detach instead of setModel(None). Do you think it can be enough? In this case it's fine for me, the issue can be closed.

The widget is supposed to be destroyed just after, but without that i guess it was persisting in the background.

cpascual commented 4 years ago

Calling _detach instead of setModel(None). Do you think it can be enough?

Calling setModel(None) should work. If it does not, but _detach does, I would say that it is a bug in taurus. Maybe the deadlock is related to https://github.com/tango-controls/pytango/issues/292, https://github.com/tango-controls/cppTango/issues/686 ?

BTW if you agree to patch _stateObj with None state, i can provide a patch

Of course. Please submit it!