| 582 | """ |
| 583 | |
| 584 | def __init__(self, canvas, num): |
| 585 | self.window = MainWindow() |
| 586 | super().__init__(canvas, num) |
| 587 | self.window.closing.connect(self._widgetclosed) |
| 588 | |
| 589 | if sys.platform != "darwin": |
| 590 | image = str(cbook._get_data_path('images/matplotlib.svg')) |
| 591 | icon = QtGui.QIcon(image) |
| 592 | self.window.setWindowIcon(icon) |
| 593 | |
| 594 | self.window._destroying = False |
| 595 | |
| 596 | if self.toolbar: |
| 597 | self.window.addToolBar(self.toolbar) |
| 598 | tbs_height = self.toolbar.sizeHint().height() |
| 599 | else: |
| 600 | tbs_height = 0 |
| 601 | |
| 602 | # resize the main window so it will display the canvas with the |
| 603 | # requested size: |
| 604 | cs = canvas.sizeHint() |
| 605 | cs_height = cs.height() |
| 606 | height = cs_height + tbs_height |
| 607 | self.window.resize(cs.width(), height) |
| 608 | |
| 609 | self.window.setCentralWidget(self.canvas) |
| 610 | |
| 611 | if mpl.is_interactive(): |
| 612 | self.window.show() |
| 613 | self.canvas.draw_idle() |
| 614 | |
| 615 | # Give the keyboard focus to the figure instead of the manager: |
| 616 | # StrongFocus accepts both tab and click to focus and will enable the |
| 617 | # canvas to process event without clicking. |
| 618 | # https://doc.qt.io/qt-5/qt.html#FocusPolicy-enum |
| 619 | self.canvas.setFocusPolicy(QtCore.Qt.FocusPolicy.StrongFocus) |
| 620 | self.canvas.setFocus() |
| 621 | |
| 622 | self.window.raise_() |
| 623 | |
| 624 | def full_screen_toggle(self): |
| 625 | if self.window.isFullScreen(): |