From 91e1b964155c9e3d0f0f797f70223cd66c5f768d Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 17 Sep 2018 17:40:13 +0200 Subject: [PATCH] Unbreak formlayout for image edits. As of master, the qt editor is broken when editing an axes that contains an image throws an error when clicking OK. This is because `self.data` needs to be modified *in-place* in FormWidget.setup, as FormWidget.get later checks some explicit types in there. This means, as a side note, that passing a tuple instead of a list to generate a QComboBox is broken (one can test that by modifying the example at the bottom of the module -- the results are different depending on whether 'list2' is a list or a tuple) but that's something we can deal with some other day... --- lib/matplotlib/backends/qt_editor/formlayout.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/qt_editor/formlayout.py b/lib/matplotlib/backends/qt_editor/formlayout.py index 1389cda1e309..d4cf62601303 100644 --- a/lib/matplotlib/backends/qt_editor/formlayout.py +++ b/lib/matplotlib/backends/qt_editor/formlayout.py @@ -243,8 +243,14 @@ def setup(self): elif isinstance(value, str): field = QtWidgets.QLineEdit(value, self) elif isinstance(value, (list, tuple)): + if isinstance(value, tuple): + value = list(value) + # Note: get() below checks the type of value[0] in self.data so + # it is essential that value gets modified in-place. + # This means that the code is actually broken in the case where + # value is a tuple, but fortunately we always pass a list... + selindex = value.pop(0) field = QtWidgets.QComboBox(self) - selindex, *value = value if isinstance(value[0], (list, tuple)): keys = [key for key, _val in value] value = [val for _key, val in value]