Skip to content

TypeError when adding items to histogram menu in 0.13.4 #2959

@samtygier-stfc

Description

@samtygier-stfc

Short description

In 0.13.3 I was able to add additional items to the menu of the histogram gradient. The changes in 0.13.4 mean that this now gives a TypeError

  File ".../pyqtgraph/graphicsItems/GradientEditorItem.py", line 499, in contextMenuClicked
    name, source = action.data()
TypeError: cannot unpack non-iterable NoneType objec

Code to reproduce

import pyqtgraph as pg
import numpy as np
from pyqtgraph.Qt import QtWidgets

app = pg.mkQApp("ImageView Example")
win = QtWidgets.QMainWindow()
img = pg.ImageView()
img.setImage(np.zeros((100,100)))
win.setCentralWidget(img)

action = QtWidgets.QAction("Test")
action.triggered.connect(lambda :print("Action triggered"))
menu = img.getHistogramWidget().gradient.menu
menu.addAction(action)

win.show()
if __name__ == '__main__':
    pg.exec()

Expected behavior

Add a new menu entry that can be used. (works in 0.13..3)

Real behavior

Menu item works, but gives the above error message

Tested environment(s)

  • PyQtGraph version: 0.13.4
  • Qt Python binding: PyQt5 5.15.9 Qt 5.15.8'
  • Python version: 3.10.13
  • NumPy version: 1.21.6
  • Operating system: Linux
  • Installation method: conda

Additional context

I think this was introduced by
#2779
c2372a2

The menu items in the GradientEditorItem are now expected to have data, that is used to change the gradient:

name, source = action.data()

I can provide a patch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions