def __init__(self): QtGui.QMainWindow.__init__(self) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle("application main window") self.file_menu = QtGui.QMenu('&File', self) self.file_menu.addAction('&Quit', self.fileQuit, QtCore.Qt.CTRL + QtCore.Qt.Key_Q) self.menuBar().addMenu(self.file_menu) self.help_menu = QtGui.QMenu('&Help', self) self.menuBar().addSeparator() self.menuBar().addMenu(self.help_menu) self.help_menu.addAction('&About', self.about) self.main_widget = QtGui.QWidget(self) l = QtGui.QVBoxLayout(self.main_widget) sc = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100) dc = MyDynamicMplCanvas(self.main_widget, width=5, height=4, dpi=100) l.addWidget(sc) l.addWidget(dc) self.main_widget.setFocus() self.setCentralWidget(self.main_widget) self.statusBar().showMessage("All hail matplotlib!", 2000)
def create_main_frame(self): self.main_frame = QtGui.QWidget() self.fig = Figure((5.0, 4.0), dpi=100) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self.main_frame) self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus) self.canvas.setFocus() self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame) self.canvas.mpl_connect('key_press_event', self.on_key_press) vbox = QtGui.QVBoxLayout() vbox.addWidget(self.canvas) # the matplotlib canvas vbox.addWidget(self.mpl_toolbar) self.main_frame.setLayout(vbox) self.setCentralWidget(self.main_frame)
def __init__(self, windowTitle='Window', x=0, y=0, legend=True, parent=None): super(Window, self).__init__(parent) # set UI style -- options: u'Windows', u'Motif', u'CDE', u'Plastique', u'Cleanlooks', u'Macintosh (aqua)' # QtGui.QApplication.setStyle(QtGui.QStyleFactory.create(u'Plastique')) # layout self.setAutoFillBackground(True) self.centralwidget = QtGui.QWidget(self) self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget) self.verticalLayout.setMargin(0) self.setCentralWidget(self.centralwidget) self.setBackgroundColor(QtCore.Qt.white) # create menu bar self.menubar = QtGui.QMenuBar(self) self.menubar.setGeometry(QtCore.QRect(0, 0, 340, 22)) # create menus self.menuFile = QtGui.QMenu(self.menubar) self.menuFile.setTitle("File") self.menuConfigurePlot = QtGui.QMenu(self.menubar) self.menuConfigurePlot.setTitle("Configure Plot") # create actions self.actionSaveAs = QtGui.QAction(self) self.actionSaveAs.setText("Save As...") self.actionConfigureSubplots = QtGui.QAction(self) self.actionConfigureSubplots.setText('Configure Subplots') self.actionConfigureAxis = QtGui.QAction(self) self.actionConfigureAxis.setText('Configure Axis and Curve') # add actions to menu self.menuFile.addAction(self.actionSaveAs) self.menubar.addAction(self.menuFile.menuAction()) self.menuConfigurePlot.addAction(self.actionConfigureSubplots) self.menuConfigurePlot.addAction(self.actionConfigureAxis) self.menubar.addAction(self.menuConfigurePlot.menuAction()) # enable menu bar self.setMenuBar(self.menubar) QtCore.QMetaObject.connectSlotsByName(self) # get arguments self.windowTitle = windowTitle # moves menu bar into application -- mac only windows sux self.menubar.setNativeMenuBar(False) # set window title self.setWindowTitle(self.windowTitle) self.initCanvas() self.toolbar = CustomToolbar(self.canvas, self) self.verticalLayout.addWidget(self.toolbar) self.setWindowPosition(x, y) # bind file menu actions self.connect(self.actionSaveAs, QtCore.SIGNAL('triggered()'), self.toolbar.save_figure) # bind configure menu actions self.connect(self.actionConfigureSubplots, QtCore.SIGNAL('triggered()'), self.toolbar.configure_subplots) self.connect(self.actionConfigureAxis, QtCore.SIGNAL('triggered()'), self.toolbar.edit_parameters) if legend: self.generateLegendMenu() # create instance of Plotter class self.plotter = plotter.Plotter()