| 1 | From: Danny Milosavljevic <[email protected]>
|
| 2 | Date: 2026-02-13
|
| 3 | Subject: Fix compatibility with matplotlib 3.6+
|
| 4 |
|
| 5 | Matplotlib 3.6 removed the `message` Qt signal from NavigationToolbar2QT.
|
| 6 | The old API was:
|
| 7 |
|
| 8 | message = QtCore.Signal(str)
|
| 9 |
|
| 10 | def set_message(self, s):
|
| 11 | self.message.emit(s)
|
| 12 | self.locLabel.setText(s)
|
| 13 |
|
| 14 | The new API just updates the label directly with no signal:
|
| 15 |
|
| 16 | def set_message(self, s):
|
| 17 | self.locLabel.setText(s)
|
| 18 |
|
| 19 | Matplotlib provides no replacement signal. The only way to intercept
|
| 20 | toolbar messages is to override the set_message method.
|
| 21 |
|
| 22 | This patch replaces the signal connection with a method override that
|
| 23 | forwards messages to the status bar.
|
| 24 |
|
| 25 | |
| 26 | |
| 27 | @@ -274,7 +274,18 @@ class PlotWindow(QtWidgets.QMainWindow):
|
| 28 |
|
| 29 | def create_status_bar(self):
|
| 30 | self.statusbar = QtWidgets.QStatusBar(self)
|
| 31 | - self.stock_toolbar.message.connect(self.statusbar.showMessage)
|
| 32 | + # Matplotlib 3.6 removed the `message` Qt signal from
|
| 33 | + # NavigationToolbar2QT. The old code was:
|
| 34 | + #
|
| 35 | + # self.stock_toolbar.message.connect(self.statusbar.showMessage)
|
| 36 | + #
|
| 37 | + # Since matplotlib provides no replacement signal, we override
|
| 38 | + # set_message to forward messages to the status bar.
|
| 39 | + original_set_message = self.stock_toolbar.set_message
|
| 40 | + def set_message_forwarding_to_statusbar(s):
|
| 41 | + original_set_message(s)
|
| 42 | + self.statusbar.showMessage(s)
|
| 43 | + self.stock_toolbar.set_message = set_message_forwarding_to_statusbar
|
| 44 | self.setStatusBar(self.statusbar)
|
| 45 |
|
| 46 | def flag_as_kept(self):
|