def main(): """ Run FigurePlugin by itself. """ from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer import mooseutils widget = PostprocessorViewer(mooseutils.VectorPostprocessorReader, plugins=[FigurePlugin]) widget.initialize([]) widget.currentWidget().FigurePlugin.setFixedSize(QtCore.QSize(375, 375)) widget.show() return widget
def main(): """ Run FigurePlugin by itself. """ from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer import mooseutils widget = PostprocessorViewer(mooseutils.VectorPostprocessorReader, plugins=[FigurePlugin]) widget.onSetFilenames([]) widget.currentWidget().FigurePlugin.setFixedSize(QtCore.QSize(375, 375)) widget.show() return widget
def main(filenames): from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer from FigurePlugin import FigurePlugin from PostprocessorSelectPlugin import PostprocessorSelectPlugin import mooseutils widget = PostprocessorViewer(mooseutils.PostprocessorReader, timeout=None, plugins=[FigurePlugin, AxisTabsPlugin, PostprocessorSelectPlugin]) widget.onSetFilenames(filenames) control = widget.currentWidget().AxisTabsPlugin window = widget.currentWidget().FigurePlugin window.setFixedSize(QtCore.QSize(625, 625)) widget.show() return control, widget, window
def main(filenames, reader=mooseutils.VectorPostprocessorReader): """ Create widgets for running PostprocessorSelectPlugin """ """ Run FigurePlugin by itself. """ from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer from FigurePlugin import FigurePlugin widget = PostprocessorViewer(reader, timeout=None, plugins=[FigurePlugin, PostprocessorSelectPlugin]) widget.onSetFilenames(filenames) control = widget.currentWidget().PostprocessorSelectPlugin window = widget.currentWidget().FigurePlugin window.setFixedSize(QtCore.QSize(625, 625)) widget.show() return control, widget, window
def main(filenames, reader=mooseutils.VectorPostprocessorReader): """ Create widgets for running PostprocessorSelectPlugin """ """ Run FigurePlugin by itself. """ from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer from FigurePlugin import FigurePlugin widget = PostprocessorViewer(reader, timeout=None, plugins=[FigurePlugin, PostprocessorSelectPlugin]) widget.onSetFilenames(filenames) control = widget.currentWidget().PostprocessorSelectPlugin window = widget.currentWidget().FigurePlugin window.setFixedSize(QtCore.QSize(625, 625)) widget.show() return control, widget, window
def main(*args): """ Create a LineSettingsWidget for testing. """ from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer from FigurePlugin import FigurePlugin # Load the viewer widget = PostprocessorViewer(plugins=[FigurePlugin]) widget.onSetFilenames(['empty_file']) layout = widget.currentWidget().LeftLayout window = widget.currentWidget().FigurePlugin window.setFixedSize(QtCore.QSize(375, 375)) # Test the line setting widget toggle = LineSettingsWidget(*args) layout.addWidget(toggle) widget.show() return widget, toggle, window
def main(filenames): from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer from PostprocessorSelectPlugin import PostprocessorSelectPlugin from MediaControlPlugin import MediaControlPlugin widget = PostprocessorViewer(mooseutils.VectorPostprocessorReader, timeout=None, plugins=[OutputPlugin, PostprocessorSelectPlugin, MediaControlPlugin]) widget.onSetFilenames(filenames) control = widget.currentWidget().OutputPlugin widget.show() return control, widget
def main(filenames): from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer from PostprocessorSelectPlugin import PostprocessorSelectPlugin from MediaControlPlugin import MediaControlPlugin widget = PostprocessorViewer( mooseutils.VectorPostprocessorReader, timeout=None, plugins=[OutputPlugin, PostprocessorSelectPlugin, MediaControlPlugin]) widget.initialize(filenames) control = widget.currentWidget().OutputPlugin widget.show() return control, widget
def main(data, pp_class=mooseutils.VectorPostprocessorReader): """ Create widgets for running LineGroupWidget """ from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer from FigurePlugin import FigurePlugin import matplotlib.pyplot as plt import numpy as np import itertools # Create main widget widget = PostprocessorViewer(plugins=[FigurePlugin]) widget.onSetFilenames(['empty_file']) layout = widget.currentWidget().LeftLayout window = widget.currentWidget().FigurePlugin window.setFixedSize(QtCore.QSize(625, 625)) # Create LineGroupWidget cycle = itertools.product(['-', '--', '-.', ':'], plt.cm.Paired(np.linspace(0, 1, 11))) control = LineGroupWidget(window.axes(), data, cycle) layout.addWidget(control) control.axesModified.connect(window.onAxesModified) def axis_label(): """ A labeling function for setting axis labels. """ x, y, y2 = control.getAxisLabels() control._axes[0].set_xlabel(x) control._axes[0].set_ylabel('; '.join(y)) control._axes[1].set_ylabel('; '.join(y2)) control.variablesChanged.connect(axis_label) widget.show() return control, widget, window
def main(data, pp_class=mooseutils.VectorPostprocessorReader): """ Create widgets for running LineGroupWidget """ from peacock.PostprocessorViewer.PostprocessorViewer import PostprocessorViewer from FigurePlugin import FigurePlugin import matplotlib.pyplot as plt import numpy as np import itertools # Create main widget widget = PostprocessorViewer(plugins=[FigurePlugin]) widget.onSetFilenames(['empty_file']) layout = widget.currentWidget().LeftLayout window = widget.currentWidget().FigurePlugin window.setFixedSize(QtCore.QSize(625, 625)) # Create LineGroupWidget cycle = itertools.product(['-', '--', '-.', ':'], plt.cm.Paired(np.linspace(0, 1, 11))) control = LineGroupWidget(window.axes(), data, cycle) layout.addWidget(control) control.axesModified.connect(window.onAxesModified) def axis_label(): """ A labeling function for setting axis labels. """ x,y,y2 = control.getAxisLabels() control._axes[0].set_xlabel(x) control._axes[0].set_ylabel('; '.join(y)) control._axes[1].set_ylabel('; '.join(y2)) control.variablesChanged.connect(axis_label) widget.show() return control, widget, window
class TestPostprocessorViewer(Testing.PeacockImageTestCase): """ Test class for the ArtistToggleWidget which toggles postprocessor lines. """ #: QApplication: The main App for QT, this must be static to work correctly. qapp = QtWidgets.QApplication(sys.argv) def setUp(self): """ Creates the GUI containing the ArtistGroupWidget and the matplotlib figure axes. """ self._filename = "{}_test.csv".format(self.__class__.__name__) self._widget = PostprocessorViewer( reader=mooseutils.PostprocessorReader, timeout=None) self._widget.onSetFilenames([self._filename]) def copyfiles(self): """ Copy to temprary location. """ shutil.copyfile('../input/white_elephant_jan_2016.csv', self._filename) for data in self._widget._data: data.load() def tearDown(self): """ Remove temporary. """ if os.path.exists(self._filename): os.remove(self._filename) def write(self, filename): """ Overload the write method. """ self._widget.currentWidget().OutputPlugin.write.emit(filename) def plot(self): """ Create plot with all widgets modified. """ widget = self._widget.currentWidget() # Plot some data toggle = widget.PostprocessorSelectPlugin._groups[0]._toggles[ 'air_temp_set_1'] toggle.CheckBox.setCheckState(QtCore.Qt.Checked) toggle.PlotAxis.setCurrentIndex(1) toggle.LineStyle.setCurrentIndex(1) toggle.LineWidth.setValue(5) toggle.clicked.emit() # Add title and legend ax = widget.AxesSettingsPlugin ax.Title.setText('Snow Data') ax.Title.editingFinished.emit() ax.Legend2.setCheckState(QtCore.Qt.Checked) ax.Legend2.clicked.emit(True) ax.Legend2Location.setCurrentIndex(4) ax.Legend2Location.currentIndexChanged.emit(4) ax.onAxesModified() # Set limits and axis titles (y2-only) ax = widget.AxisTabsPlugin.Y2AxisTab ax.Label.setText('Air Temperature [C]') ax.Label.editingFinished.emit() ax.RangeMinimum.setText('0') ax.RangeMinimum.editingFinished.emit() def testEmpty(self): """ Test that empty plot is working. """ self.assertImage('testEmpty.png') def testWidgets(self): """ Test that the widgets contained in PostprocessorPlotWidget are working. """ self.copyfiles() self.plot() self.assertImage('testWidgets.png') self.assertFalse(self._widget.cornerWidget().CloseButton.isEnabled()) self.assertEqual(self._widget.tabText(self._widget.currentIndex()), 'Results') def testCloneClose(self): """ Test clone button works. """ self.copyfiles() self._widget.cornerWidget().clone.emit() self.assertEqual(self._widget.count(), 2) self.assertEqual(self._widget.tabText(self._widget.currentIndex()), 'Results (2)') self.assertTrue(self._widget.cornerWidget().CloseButton.isEnabled()) self.assertImage('testEmpty.png') # Plot something self.plot() self.assertImage('testWidgets.png') # Switch to first tab self._widget.setCurrentIndex(0) self.assertEqual(self._widget.tabText(self._widget.currentIndex()), 'Results') self.assertImage('testEmpty.png') self.plot() self.assertImage('testWidgets.png') # Close the first tab self._widget.cornerWidget().close.emit() self.assertEqual(self._widget.count(), 1) self.assertEqual(self._widget.tabText(self._widget.currentIndex()), 'Results (2)') self.assertFalse(self._widget.cornerWidget().CloseButton.isEnabled())
class TestPostprocessorViewer(Testing.PeacockImageTestCase): """ Test class for the ArtistToggleWidget which toggles postprocessor lines. """ #: QApplication: The main App for QT, this must be static to work correctly. qapp = QtWidgets.QApplication(sys.argv) def setUp(self): """ Creates the GUI containing the ArtistGroupWidget and the matplotlib figure axes. """ self._filename = "{}_test.csv".format(self.__class__.__name__) self._widget = PostprocessorViewer(reader=mooseutils.PostprocessorReader, timeout=None) self._widget.onSetFilenames([self._filename]) def copyfiles(self): """ Copy to temprary location. """ shutil.copyfile('../input/white_elephant_jan_2016.csv', self._filename) for data in self._widget._data: data.load() def tearDown(self): """ Remove temporary. """ if os.path.exists(self._filename): os.remove(self._filename) def write(self, filename): """ Overload the write method. """ self._widget.currentWidget().OutputPlugin.write.emit(filename) def plot(self): """ Create plot with all widgets modified. """ widget = self._widget.currentWidget() # Plot some data toggle = widget.PostprocessorSelectPlugin._groups[0]._toggles['air_temp_set_1'] toggle.CheckBox.setCheckState(QtCore.Qt.Checked) toggle.PlotAxis.setCurrentIndex(1) toggle.LineStyle.setCurrentIndex(1) toggle.LineWidth.setValue(5) toggle.clicked.emit() # Add title and legend ax = widget.AxesSettingsPlugin ax.Title.setText('Snow Data') ax.Title.editingFinished.emit() ax.Legend2.setCheckState(QtCore.Qt.Checked) ax.Legend2.clicked.emit(True) ax.Legend2Location.setCurrentIndex(4) ax.Legend2Location.currentIndexChanged.emit(4) ax.onAxesModified() # Set limits and axis titles (y2-only) ax = widget.AxisTabsPlugin.Y2AxisTab ax.Label.setText('Air Temperature [C]') ax.Label.editingFinished.emit() ax.RangeMinimum.setText('0') ax.RangeMinimum.editingFinished.emit() def testEmpty(self): """ Test that empty plot is working. """ self.assertImage('testEmpty.png') def testWidgets(self): """ Test that the widgets contained in PostprocessorPlotWidget are working. """ self.copyfiles() self.plot() self.assertImage('testWidgets.png') self.assertFalse(self._widget.cornerWidget().CloseButton.isEnabled()) self.assertEqual(self._widget.tabText(self._widget.currentIndex()), 'Results') def testCloneClose(self): """ Test clone button works. """ self.copyfiles() self._widget.cornerWidget().clone.emit() self.assertEqual(self._widget.count(), 2) self.assertEqual(self._widget.tabText(self._widget.currentIndex()), 'Results (2)') self.assertTrue(self._widget.cornerWidget().CloseButton.isEnabled()) self.assertImage('testEmpty.png') # Plot something self.plot() self.assertImage('testWidgets.png') # Switch to first tab self._widget.setCurrentIndex(0) self.assertEqual(self._widget.tabText(self._widget.currentIndex()), 'Results') self.assertImage('testEmpty.png') self.plot() self.assertImage('testWidgets.png') # Close the first tab self._widget.cornerWidget().close.emit() self.assertEqual(self._widget.count(), 1) self.assertEqual(self._widget.tabText(self._widget.currentIndex()), 'Results (2)') self.assertFalse(self._widget.cornerWidget().CloseButton.isEnabled())