|
9 | 9 |
|
10 | 10 | import numpy as np |
11 | 11 | from guidata.qthelpers import qt_app_context |
12 | | -from qtpy import QtCore as QC |
13 | 12 | from qtpy import QtGui as QG |
14 | | -from qtpy import QtWidgets as QW |
15 | 13 |
|
16 | 14 | from plotpy.builder import make |
17 | 15 | from plotpy.config import _ |
18 | | -from plotpy.plot import BasePlot, PlotOptions, SubplotWidget, set_widget_title_icon |
19 | | -from plotpy.plot.manager import PlotManager |
| 16 | +from plotpy.plot import BasePlot, PlotOptions |
| 17 | +from plotpy.plot.plotwidget import SyncPlotWindow |
20 | 18 | from plotpy.tests.data import gen_2d_gaussian |
21 | 19 |
|
22 | 20 |
|
23 | | -class SyncPlotWindow(QW.QMainWindow): |
24 | | - """Window for showing plots, optionally synchronized""" |
25 | | - |
26 | | - def __init__(self, parent=None, title=None, options=None): |
27 | | - super().__init__(parent) |
28 | | - title = self.__doc__ if title is None else title |
29 | | - set_widget_title_icon(self, title, "plotpy.svg") |
30 | | - self.manager = PlotManager(None) |
31 | | - self.manager.set_main(self) |
32 | | - self.subplotwidget = SubplotWidget(self.manager, parent=self, options=options) |
33 | | - self.setCentralWidget(self.subplotwidget) |
34 | | - toolbar = QW.QToolBar(_("Tools"), self) |
35 | | - self.manager.add_toolbar(toolbar, "default") |
36 | | - toolbar.setMovable(True) |
37 | | - toolbar.setFloatable(True) |
38 | | - self.addToolBar(toolbar) |
39 | | - |
40 | | - def finalize_configuration(self): |
41 | | - """Configure plot manager and register all tools""" |
42 | | - self.subplotwidget.add_panels_to_manager() |
43 | | - self.subplotwidget.register_tools() |
44 | | - |
45 | | - def rescale_plots(self): |
46 | | - """Rescale all plots""" |
47 | | - QW.QApplication.instance().processEvents() |
48 | | - for plot in self.subplotwidget.plots: |
49 | | - plot.do_autoscale() |
50 | | - |
51 | | - def showEvent(self, event): # pylint: disable=C0103 |
52 | | - """Reimplement Qt method""" |
53 | | - super().showEvent(event) |
54 | | - QC.QTimer.singleShot(0, self.rescale_plots) |
55 | | - |
56 | | - def add_plot(self, row, col, plot, sync=False, plot_id=None): |
57 | | - """Add plot to window""" |
58 | | - if plot_id is None: |
59 | | - plot_id = str(len(self.subplotwidget.plots) + 1) |
60 | | - self.subplotwidget.add_plot(plot, row, col, plot_id) |
61 | | - if sync and len(self.subplotwidget.plots) > 1: |
62 | | - syncaxis = self.manager.synchronize_axis |
63 | | - for i_plot in range(len(self.subplotwidget.plots) - 1): |
64 | | - syncaxis(BasePlot.X_BOTTOM, [plot_id, f"{i_plot + 1}"]) |
65 | | - syncaxis(BasePlot.Y_LEFT, [plot_id, f"{i_plot + 1}"]) |
66 | | - |
67 | | - def get_plots(self) -> list[BasePlot]: |
68 | | - """Return the plots |
69 | | -
|
70 | | - Returns: |
71 | | - list[BasePlot]: The plots |
72 | | - """ |
73 | | - return self.subplotwidget.get_plots() |
74 | | - |
75 | | - |
76 | 21 | def plot(plot_type, *itemlists): |
77 | 22 | """Plot items in SyncPlotDialog""" |
78 | 23 | win = SyncPlotWindow(options=PlotOptions(type=plot_type)) |
|
0 commit comments