def __init__(self): super(OutputPlugin, self).__init__() self.MainLayout = QtWidgets.QHBoxLayout(self) self.LiveScriptWindow = TextSubWindow() self.hide() self.LiveScript = None self.ExportPNG = None self.ExportPython = None self.setup() self._observer = None
def __init__(self): super(OutputWidgetBase, self).__init__() self._icon_size = QtCore.QSize(32, 32) self.MainLayout = QtWidgets.QHBoxLayout() self.MainLayout.setContentsMargins(0, 0, 0, 0) self.MainLayout.setSpacing(5) self.PythonButton = QtWidgets.QPushButton() self.PDFButton = QtWidgets.QPushButton() self.PNGButton = QtWidgets.QPushButton() self.LiveScriptButton = QtWidgets.QPushButton() self.LiveScript = TextSubWindow() self.setLayout(self.MainLayout) self.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) self.MainLayout.addWidget(self.PythonButton) self.MainLayout.addWidget(self.PDFButton) self.MainLayout.addWidget(self.PNGButton) self.MainLayout.addWidget(self.LiveScriptButton)
class OutputPlugin(QtWidgets.QGroupBox, ExodusPlugin): """ Plugin responsible for triggering the creation of png/py files and live script viewing. """ #: pyqtSignal: Write the chigger script portions from this plugin write = QtCore.pyqtSignal(str) #: pyqtSignal: Create an observer for the given event with the supplied method callback function addObserver = QtCore.pyqtSignal(type(vtk.vtkCommand.RenderEvent), types.MethodType) def __init__(self): super(OutputPlugin, self).__init__() self.MainLayout = QtWidgets.QHBoxLayout(self) self.LiveScriptWindow = TextSubWindow() self.hide() self.LiveScript = None self.ExportPNG = None self.ExportPython = None self.setup() self._observer = None def addToMenu(self, menu): """ Adds output options to the 'Results' menu. """ self.LiveScript = menu.addAction('Show live script') self.LiveScript.setCheckable(True) self.LiveScript.setChecked(False) self.LiveScript.setEnabled(False) self.LiveScript.toggled.connect(self._callbackLiveScript) export = menu.addMenu('Export') self.ExportPNG = export.addAction('PNG') self.ExportPNG.triggered.connect(self._callbackExportPNG) self.ExportPNG.setEnabled(False) self.ExportPython = export.addAction('Python') self.ExportPython.triggered.connect(self._callbackExportPython) self.ExportPython.setEnabled(False) def updateLiveScriptWindow(self, *args): """ Updates the chigger script live view. """ if self.LiveScriptWindow.isVisible() and hasattr( self, "_plugin_manager"): # don't reset the text if it is the same. This allows for easier select/copy s = self._plugin_manager.repr() if s != self.LiveScriptWindow.toPlainText(): self.LiveScriptWindow.setText(s) def onWindowReset(self): """ Disable the live view when there are no results. """ self.LiveScript.setEnabled(False) self.ExportPNG.setEnabled(False) self.ExportPython.setEnabled(False) def onWindowResult(self, *args): """ Adds an observer for the live window update to the VTK renderer. """ self.addObserver.emit(vtk.vtkCommand.RenderEvent, self.updateLiveScriptWindow) self.LiveScript.setEnabled(True) self.ExportPNG.setEnabled(True) self.ExportPython.setEnabled(True) def _setupLiveScriptWindow(self, qobject): qobject.setReadOnly(True) qobject.hide() qobject.windowClosed.connect(self._callbackCloseLiveScriptWindow) def _callbackLiveScript(self, *args): if self.LiveScript.isChecked() and hasattr(self, "_plugin_manager"): self.LiveScriptWindow.show() self.updateLiveScriptWindow() else: self.LiveScriptWindow.hide() def _callbackExportPNG(self): """ Write a png file of figure. """ dialog = QtWidgets.QFileDialog() dialog.setWindowTitle('Write *.png of figure') dialog.setNameFilter('PNG files (*.png)') dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog) dialog.setDefaultSuffix("png") if dialog.exec_() == QtWidgets.QDialog.Accepted: filename = str(dialog.selectedFiles()[0]) self.write.emit(filename) def _callbackExportPython(self): """ Open dialog and write script. """ dialog = QtWidgets.QFileDialog() dialog.setWindowTitle('Write Python Script') dialog.setNameFilter('Python Files (*.py)') dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog) if dialog.exec_() == QtWidgets.QDialog.Accepted: filename = str(dialog.selectedFiles()[0]) self.write.emit(filename) def _callbackCloseLiveScriptWindow(self, *args): self.LiveScript.setChecked(False)
class OutputWidgetBase(QtWidgets.QWidget): """ Plugin responsible for triggering the creation of png/pdf/py files and live script window. """ write = QtCore.pyqtSignal(str) def __init__(self): super(OutputWidgetBase, self).__init__() self._icon_size = QtCore.QSize(32, 32) self.MainLayout = QtWidgets.QHBoxLayout() self.MainLayout.setContentsMargins(0, 0, 0, 0) self.MainLayout.setSpacing(5) self.PythonButton = QtWidgets.QPushButton() self.PDFButton = QtWidgets.QPushButton() self.PNGButton = QtWidgets.QPushButton() self.LiveScriptButton = QtWidgets.QPushButton() self.LiveScript = TextSubWindow() self.setLayout(self.MainLayout) self.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) self.MainLayout.addWidget(self.PythonButton) self.MainLayout.addWidget(self.PDFButton) self.MainLayout.addWidget(self.PNGButton) self.MainLayout.addWidget(self.LiveScriptButton) def updateLiveScriptText(self): """ Updates the live script view. """ if self.LiveScript.isVisible() and hasattr(self, "_plugin_manager"): # don't reset the text if it is the same. This allows for easier select/copy s = self._plugin_manager.repr() if s != self.LiveScript.toPlainText(): self.LiveScript.setText(s) def _setupPythonButton(self, qobject): """ Setup method for python script output button. """ qobject.clicked.connect(self._callbackPythonButton) qobject.setIcon(WidgetUtils.createIcon('py.svg')) qobject.setIconSize(self._icon_size) qobject.setFixedSize(qobject.iconSize()) qobject.setToolTip("Create python script to reproduce this figure.") qobject.setStyleSheet("QPushButton {border:none}") def _callbackPythonButton(self): """ Open dialog and write script. """ dialog = QtWidgets.QFileDialog() dialog.setWindowTitle('Write Python Script') dialog.setNameFilter('Python Files (*.py)') dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog) if dialog.exec_() == QtWidgets.QDialog.Accepted: filename = str(dialog.selectedFiles()[0]) self.write.emit(filename) def _setupPDFButton(self, qobject): """ Setup method pdf image output. """ qobject.clicked.connect(self._callbackPDFButton) qobject.setIcon(WidgetUtils.createIcon('pdf.svg')) qobject.setIconSize(self._icon_size) qobject.setFixedSize(qobject.iconSize()) qobject.setToolTip("Create a pdf file of the current figure.") qobject.setStyleSheet("QPushButton {border:none}") def _callbackPDFButton(self): """ Write a PDF file of figure. """ dialog = QtWidgets.QFileDialog() dialog.setWindowTitle('Write *.pdf of figure') dialog.setNameFilter('PDF files (*.pdf)') dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog) if dialog.exec_() == QtWidgets.QDialog.Accepted: filename = str(dialog.selectedFiles()[0]) self.write.emit(filename) def _setupPNGButton(self, qobject): """ Setup method png image output. """ qobject.clicked.connect(self._callbackPNGButton) qobject.setIcon(WidgetUtils.createIcon('png.svg')) qobject.setIconSize(self._icon_size) qobject.setFixedSize(qobject.iconSize()) qobject.setToolTip("Create a png file of the current figure.") qobject.setStyleSheet("QPushButton {border:none}") def _callbackPNGButton(self): """ Write a png file of figure. """ dialog = QtWidgets.QFileDialog() dialog.setWindowTitle('Write *.png of figure') dialog.setNameFilter('PNG files (*.png)') dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog) dialog.setDefaultSuffix("png") if dialog.exec_() == QtWidgets.QDialog.Accepted: filename = str(dialog.selectedFiles()[0]) self.write.emit(filename) def _setupLiveScriptButton(self, qobject): """ Setup method png image output. """ qobject.clicked.connect(self._callbackLiveScriptButton) qobject.setIcon(WidgetUtils.createIcon('script.svg')) qobject.setIconSize(self._icon_size) qobject.setFixedSize(qobject.iconSize()) qobject.setToolTip("Show the current python script.") qobject.setStyleSheet("QPushButton {border:none}") def _callbackLiveScriptButton(self): """ Write a png file of figure. """ self.LiveScript.show() self.updateLiveScriptText() def _setupLiveScript(self, qobject): """ Setup for the script text window. """ self.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) qobject.setReadOnly(True)
class OutputWidgetBase(QtWidgets.QWidget): """ Plugin responsible for triggering the creation of png/pdf/py files and live script window. """ write = QtCore.pyqtSignal(str) def __init__(self): super(OutputWidgetBase, self).__init__() self._icon_size = QtCore.QSize(32, 32) self.MainLayout = QtWidgets.QHBoxLayout() self.MainLayout.setContentsMargins(0, 0, 0, 0) self.MainLayout.setSpacing(5) self.PythonButton = QtWidgets.QPushButton() self.PDFButton = QtWidgets.QPushButton() self.PNGButton = QtWidgets.QPushButton() self.LiveScriptButton = QtWidgets.QPushButton() self.LiveScript = TextSubWindow() self.setLayout(self.MainLayout) self.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) self.MainLayout.addWidget(self.PythonButton) self.MainLayout.addWidget(self.PDFButton) self.MainLayout.addWidget(self.PNGButton) self.MainLayout.addWidget(self.LiveScriptButton) def updateLiveScriptText(self): """ Updates the live script view. """ if self.LiveScript.isVisible() and hasattr(self, "_plugin_manager"): s = self._plugin_manager.repr() self.LiveScript.setText(s) def _setupPythonButton(self, qobject): """ Setup method for python script output button. """ qobject.clicked.connect(self._callbackPythonButton) qobject.setIcon(WidgetUtils.createIcon('py.svg')) qobject.setIconSize(self._icon_size) qobject.setFixedSize(qobject.iconSize()) qobject.setToolTip("Create python script to reproduce this figure.") qobject.setStyleSheet("QPushButton {border:none}") def _callbackPythonButton(self): """ Open dialog and write script. """ dialog = QtWidgets.QFileDialog() dialog.setWindowTitle('Write Python Script') dialog.setNameFilter('Python Files (*.py)') dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog) if dialog.exec_() == QtWidgets.QDialog.Accepted: filename = str(dialog.selectedFiles()[0]) self.write.emit(filename) def _setupPDFButton(self, qobject): """ Setup method pdf image output. """ qobject.clicked.connect(self._callbackPDFButton) qobject.setIcon(WidgetUtils.createIcon('pdf.svg')) qobject.setIconSize(self._icon_size) qobject.setFixedSize(qobject.iconSize()) qobject.setToolTip("Create a pdf file of the current figure.") qobject.setStyleSheet("QPushButton {border:none}") def _callbackPDFButton(self): """ Write a PDF file of figure. """ dialog = QtWidgets.QFileDialog() dialog.setWindowTitle('Write *.pdf of figure') dialog.setNameFilter('PDF files (*.pdf)') dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog) if dialog.exec_() == QtWidgets.QDialog.Accepted: filename = str(dialog.selectedFiles()[0]) self.write.emit(filename) def _setupPNGButton(self, qobject): """ Setup method png image output. """ qobject.clicked.connect(self._callbackPNGButton) qobject.setIcon(WidgetUtils.createIcon('png.svg')) qobject.setIconSize(self._icon_size) qobject.setFixedSize(qobject.iconSize()) qobject.setToolTip("Create a png file of the current figure.") qobject.setStyleSheet("QPushButton {border:none}") def _callbackPNGButton(self): """ Write a png file of figure. """ dialog = QtWidgets.QFileDialog() dialog.setWindowTitle('Write *.png of figure') dialog.setNameFilter('PNG files (*.png)') dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setOption(QtWidgets.QFileDialog.DontUseNativeDialog) dialog.setDefaultSuffix("png") if dialog.exec_() == QtWidgets.QDialog.Accepted: filename = str(dialog.selectedFiles()[0]) self.write.emit(filename) def _setupLiveScriptButton(self, qobject): """ Setup method png image output. """ qobject.clicked.connect(self._callbackLiveScriptButton) qobject.setIcon(WidgetUtils.createIcon('script.svg')) qobject.setIconSize(self._icon_size) qobject.setFixedSize(qobject.iconSize()) qobject.setToolTip("Show the current python script.") qobject.setStyleSheet("QPushButton {border:none}") def _callbackLiveScriptButton(self): """ Write a png file of figure. """ self.LiveScript.show() self.updateLiveScriptText() def _setupLiveScript(self, qobject): """ Setup for the script text window. """ self.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) qobject.setReadOnly(True)