Skip to content

Commit

Permalink
Re-render graphics on window resize.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoereth committed Sep 10, 2017
1 parent 672416f commit afb8c37
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions MPLAnimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def initUI(self):
self.w = QtWidgets.QWidget()
self.layout = QtWidgets.QVBoxLayout()
self.w.setLayout(self.layout)
self.w.resizeEvent = self._onResize

# using a stacked layout for the figure
# allows for quick exchange between pre-rendered image-view vs matplotlib figure
Expand Down Expand Up @@ -134,11 +135,7 @@ def visualize(self, i=None):
self.prerender()
if self.stack.currentWidget() != self.label:
self.stack.setCurrentWidget(self.label)
pm = QtGui.QPixmap('{}/{}.png'.format(self.dir, i))
pm = pm.scaled(self.label.width(), self.label.height(),
Qt.KeepAspectRatio, Qt.SmoothTransformation)
self.label.setPixmap(pm)
self.label.setMinimumSize(1, 1) # Allow downsizing the window.
self._renderFrameFromFile(i)
else:
if self.stack.currentWidget() != self.canvas:
self.stack.setCurrentWidget(self.canvas)
Expand Down Expand Up @@ -179,3 +176,18 @@ def run(self, clear=False, prerendered=False, initialFrame=0):
self.visualize(initialFrame)
self.slider.setValue(initialFrame)
self.qApp.exec()

def _renderFrameFromFile(self, i=None):
"""Render graphic from file given a frame number."""
if i == None:
i = self.slider.value()
pm = QtGui.QPixmap('{}/{}.png'.format(self.dir, i))
pm = pm.scaled(self.label.width(), self.label.height(),
Qt.KeepAspectRatio, Qt.SmoothTransformation)
self.label.setPixmap(pm)
self.label.setMinimumSize(1, 1) # Allow downsizing the window.

def _onResize(self, event): # pylint: disable=unused-argument
"""Re-render prerendered graphics on window resize."""
if self.prerender_checkbox.isChecked():
self._renderFrameFromFile()

0 comments on commit afb8c37

Please sign in to comment.