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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def _init_toolbar(self):

        for text, tooltip_text, image_file, callback in self.toolitems:

            if text is None:
                # bug fix to avoid duplicated separators in the task bar
                continue

            if text == 'Home':
                home_action = self.addAction(self._icon('home.png'),
                                             'Reset view', self.home)
                home_action.setToolTip('Reset view')
                self._actions['home'] = home_action
            elif text == 'Back':
                back_action = self.addAction(self._icon('back.png'), 'Back',
                                             self.back)
                back_action.setToolTip('Previous view')
                self._actions['back'] = back_action
            elif text == 'Forward':
                forward_action = self.addAction(self._icon('forward.png'),
                                                'Forward', self.forward)
                forward_action.setToolTip('Next view')
                self._actions['forward'] = forward_action
                self.addSeparator()
            elif text == 'Pan':
                pan_action = self.addAction(self._icon('pan.png'), 'Pan',
                                            self.pan)
                pan_action.setToolTip('Pan on plot')
                pan_action.setCheckable(True)
                self._actions['pan'] = pan_action
                scale_action = self.addAction(self._icon('scale.png'), 'Scale',
                                              self.scale)
                scale_action.setToolTip('Scale plot')
                scale_action.setCheckable(True)
                self._actions['scale'] = scale_action
            elif text == 'Zoom':
                zoom_in_action = self.addAction(self._icon('zoomin.png'),
                                                'Zoom in', self.zoom_in)
                zoom_in_action.setToolTip('Zoom in area')
                zoom_in_action.setCheckable(True)
                self._actions['zoom_in'] = zoom_in_action
                zoom_out_action = self.addAction(self._icon('zoomout.png'),
                                                 'Zoom out', self.zoom_out)
                zoom_out_action.setToolTip('Zoom out area')
                zoom_out_action.setCheckable(True)
                self._actions['zoom_out'] = zoom_out_action
                # flag/unflag actions
                self.flag_action = self.addAction(self._icon("flag.png"),
                                                  'Flag', self.flag)
                self.flag_action.setToolTip('Flag samples')
                self.flag_action.setCheckable(True)
                self._actions['flag'] = self.flag_action
                self.unflag_action = self.addAction(self._icon("unflag.png"),
                                                    'Unflag', self.unflag)
                self.unflag_action.setToolTip('Unflag samples')
                self.unflag_action.setCheckable(True)
                self._actions['unflag'] = self.unflag_action
                self.insert_action = self.addAction(self._icon("insert.png"),
                                                    'Insert', self.insert)
                self.insert_action.setToolTip('Insert samples')
                self.insert_action.setCheckable(True)
                self._actions['insert'] = self.insert_action
                self.addSeparator()
            elif text == 'Subplots':
                self.flagged_action = self.addAction(self._icon("flagged.png"),
                                                     'Flagged',
                                                     self.flagged_plot)
                self.flagged_action.setToolTip('Hide flagged')
                self.flagged_action.setCheckable(True)
                self.flagged_action.setChecked(True)
                self._actions['flagged'] = self.flagged_action
                self.grid_action = self.addAction(self._icon("plot_grid.png"),
                                                  'Grid', self.grid_plot)
                self.grid_action.setToolTip('Toggle grids')
                self.grid_action.setCheckable(True)
                self.grid_action.setChecked(True)
                self._actions['grid'] = self.grid_action
                self.legend_action = self.addAction(
                    self._icon("plot_legend.png"), 'Legend', self.legend_plot)
                self.legend_action.setToolTip('Toggle legends')
                self.legend_action.setCheckable(True)
                self.legend_action.setChecked(False)
                self._actions['legend'] = self.legend_action
                subplots_action = self.addAction(self._icon('subplots.png'),
                                                 'Subplots',
                                                 self.configure_subplots)
                subplots_action.setToolTip('Configure subplots')
                self._actions['subplots'] = subplots_action
                if figureoptions is not None:
                    a = self.addAction(self._icon("qt4_editor_options.png"),
                                       'Customize', self.edit_parameters)
                    a.setToolTip('Edit curves line and axes parameters')
            elif text == 'Save':
                self.addSeparator()
                save_action = self.addAction(self._icon('filesave.png'),
                                             'Save', self.save_figure)
                save_action.setToolTip('Save the figure')
                self._actions['save'] = save_action
            else:
                a = self.addAction(self._icon(image_file + '.png'), text,
                                   getattr(self, callback))
                self._actions[callback] = a
                if tooltip_text is not None:
                    a.setToolTip(tooltip_text)

        # Add the x,y location widget at the right side of the toolbar
        if self.coordinates:
            frame = QtGui.QFrame()
            # policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Ignored)
            # frame.setSizePolicy(policy)
            self.addWidget(frame)
            hbox = QtGui.QHBoxLayout()
            frame.setLayout(hbox)
            hbox.addStretch()
            vbox = QtGui.QVBoxLayout()
            hbox.addLayout(vbox)
            # - location label
            self.locLabel = QtWidgets.QLabel("", self)
            self.locLabel.setAlignment(QtCore.Qt.AlignRight
                                       | QtCore.Qt.AlignTop)
            vbox.addWidget(self.locLabel)
            # - insert label
            self.mon_label = QtWidgets.QLabel("", self)
            self.mon_label.setAlignment(QtCore.Qt.AlignRight
                                        | QtCore.Qt.AlignTop)
            self.mon_label.setStyleSheet("QLabel { color : red; }")
            vbox.addWidget(self.mon_label)
            # vbox.addStretch()
        # reference holder for subplots_adjust window
        self.adj_window = None
Ejemplo n.º 4
0
    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()