Commit 3c207b77 authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch '2-FEATURE-refresh-button' into 'master'

Resolve "FEATURE: Refresh button"

Closes #2

See merge request !2
parents 54f3d971 2f402807
import sys
# Qt4
from PyQt4 import QtGui
try:
from PyQt4 import QtGui
from PyQt4 import QtCore
Signal = QtCore.pyqtSignal
except:
from PySide import QtGui
from PySide import QtCore
QApplication = QtGui.QApplication
QWidget = QtGui.QWidget
QVBoxLayout = QtGui.QVBoxLayout
QPushButton = QtGui.QPushButton
QMainWindow = QtGui.QMainWindow
# MatPlotLib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as Canvas
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as QCanvas
# MyPlotLib
from myplotlib.test import FigTest1, readStupidData
from myplotlib.test import FigTest1, readStupidData, readStupidData2
# Local Import
from .qMyFigContainer import QMyFigContainer
from .qMyDesignWidget import QMyDesignWidget
from .qMyDesignGui import QMyDesignGui
from . import sys
from . import QApplication
from . import QMyFigContainer
from . import QMyDesignGui
app = QApplication(sys.argv)
w = QMyFigContainer()
w.resize(600, 450) # The figure is (8, 6) with 75 dpi
w.setWindowTitle('My Design Gui')
w.show()
w = QMyDesignGui()
status = app.exec_()
sys.exit(status)
from . import QMyDesignWidget
from . import QMainWindow
class QMyDesignGui(QMainWindow):
def __init__(self, parent=None):
super(QMyDesignGui, self).__init__(parent)
self.statusBar() # an ugly wrapper to create the statusBar
self.setCentralWidget(QMyDesignWidget(self))
self.centralWidget().refreshed.connect(self.refreshed)
self.resize(self.layout().sizeHint()) # For QMainWindow layout is a function that returns the QLayout object.
self.setWindowTitle('My Design Gui')
self.show()
def refreshed(self):
self.resize(self.layout().sizeHint()) # For QMainWindow layout is a function that returns the QLayout object.
self.statusBar().showMessage("> status: Figure has been refreshed.")
from . import QWidget
from . import QVBoxLayout
from . import QPushButton
from . import QMyFigContainer
from . import Signal
class QMyDesignWidget(QWidget):
refreshed = Signal()
def __init__(self, parent=None):
super(QMyDesignWidget, self).__init__(parent)
self.layout = QVBoxLayout(self)
self.figContainer = QMyFigContainer(self)
self.refreshButton = QPushButton("Refresh", self)
self.layout.addWidget(self.figContainer)
self.layout.addWidget(self.refreshButton)
self.refreshButton.clicked.connect(self.refresh)
def refresh(self):
self.figContainer.refresh() # Recreate the figure
self.resize(self.layout.sizeHint()) # Resize it-self depending on the figure.
self.refreshed.emit() # Emit refreshed such that the window knows it can refresh it-self
self.repaint() # Only then repaint to avoid blinking
def paintEvent(self, event):
self.figContainer.paint()
from . import sys
from . import QApplication
from . import QWidget
from . import QVBoxLayout
from . import QCanvas
from . import FigTest1
from . import readStupidData
from . import Canvas
from . import readStupidData, readStupidData2
class QMyFigContainer(QWidget):
......@@ -17,10 +16,43 @@ class QMyFigContainer(QWidget):
data = readStupidData('data1')
self.figure = FigTest1((data,))
self.canvas = Canvas(self.figure)
self.canvas = QCanvas(self.figure)
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.canvas)
self.figure.plot()
self.canvas.draw()
def refresh(self):
# Just a stupid data switching to see an effect
if self.figure.rawdata[0].name == 'data1':
data = readStupidData2('data2')
else:
data = readStupidData('data1')
# Destroy the figure
del self.figure
# Recreate a figure
self.figure = FigTest1((data,))
# Link the figure with the canvas
self.figure.set_canvas(self.canvas)
self.canvas.figure = self.figure
# Plot the figure
self.figure.plot()
# RESIZE
# Get the size of the figure
w, h = self.canvas.get_width_height()
# Resize the canvas to figure size
self.canvas.resize(w, h)
# Resize the Widget to the Layout size (Canvas + borders)
self.resize(self.layout.sizeHint())
def paint(self):
self.canvas.draw()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment