test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lumiQTWidget.py
Go to the documentation of this file.
1 import sys,os
2 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
3 from PyQt4 import QtGui, QtCore
4 
5 
6 class LumiCanvas(FigureCanvas):
7  """this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
8  def __init__(self, parent=None, fig=None):
9  FigureCanvas.__init__(self, fig)
10  self.setParent(parent)
11  FigureCanvas.setSizePolicy(self,
12  QtGui.QSizePolicy.Expanding,
13  QtGui.QSizePolicy.Expanding)
14  FigureCanvas.updateGeometry(self)
15 
16 class ApplicationWindow(QtGui.QMainWindow):
17  '''
18  main evt loop
19  '''
20  def __init__(self,fig=None):
21  self.qApp=QtGui.QApplication(sys.argv)#every PyQt4 application must create an application object
22  QtGui.QMainWindow.__init__(self)
23  self.setWindowTitle('lumi plot')
24  self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
25  self.main_widget = QtGui.QWidget(self)
26  l = QtGui.QVBoxLayout(self.main_widget)
27  sc = LumiCanvas(self.main_widget,fig=fig)
28  bn = QtGui.QPushButton("Save to File",self.main_widget)
29  bn.clicked.connect(lambda:self.saveAs(fig))
30  l.addWidget(sc)
31  l.addWidget(bn)
32  self.main_widget.setFocus()
33  self.setCentralWidget(self.main_widget)
34 
35  def saveAs(self,fig):
36  filename=QtGui.QFileDialog.getSaveFileName(self,"Save plot as file","","(*.png)")
37  if filename == "": return
38  fig.savefig(filename,format="PNG")
39  def fileQuit(self):
40  self.close()
41  def closeEvent(self, ce):
42  self.fileQuit()
43  def destroy(self):
44  sys.exit(self.qApp.exec_())
45 
46 if __name__ == "__main__":
47  from numpy import arange, sin, pi
48  from matplotlib.figure import Figure
49  fig=Figure(figsize=(7.2,5.4),dpi=120)#create fig
50  t = arange(0.0,3.0,0.01)
51  s = sin(2*pi*t)
52  ax=fig.add_subplot(111)
53  ax.plot(t,s)
54  aw=ApplicationWindow(fig=fig)
55  aw.show()
56  aw.destroy()
Sin< T >::type sin(const T &t)
Definition: Sin.h:22