Esempio n. 1
0
class MplWidget(QtWidgets.QWidget):
    """Widget defined in Qt Designer"""
    def __init__(self, parent=None):
        # initialization of Qt MainWindow widget
        self.win = QtWidgets.QWidget.__init__(self, parent)
        # set the canvas to the Matplotlib widget
        self.canvas = MplCanvas()
        # create a vertical box layout
        self.vbl = QtWidgets.QVBoxLayout()
        self.ntb = NavigationToolbar(self.canvas, parent)
        self.ntb.move(235, 48)
        # add mpl widget to the vertical box
        self.vbl.addWidget(self.canvas)
        # adds navigationtoolbar to the widget
        self.ntb.addWidget(self.win)

        # set the layout to the vertical box
        self.setLayout(self.vbl)
    def create_canvas_widget(self):
        widget = QtGui.QWidget()
        canvas = FigureCanvas(Figure())
        toolbar = NavigationToolbar(canvas, self)
        b = QtGui.QPushButton('*')
        # b.setIcon(QtGui.QIcon.fromTheme("document-open"))
        b.setFixedWidth(30)
        toolbar.addWidget(b)
        # toolbar.setFrameShape(QtGui.QFrame.StyledPanel)

        self.canvas_ = canvas

        # Just some button connected to `plot` method
        button = QtGui.QPushButton('Plot')
        button.clicked.connect(self.plot)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(button)
        layout.addWidget(canvas)
        frame = QtGui.QFrame()
        frame.setFrameShape(QtGui.QFrame.StyledPanel)
        frame.setMaximumHeight(40)
        frame.setMinimumHeight(40)
        v = QtGui.QHBoxLayout(frame)
        v.addWidget(toolbar)
        v.setContentsMargins(0, 0, 0, 0)
        # frame.setContentsMargins(1,1,1,1)
        # frame.addWidget(toolbar)
        # layout.addWidget(toolbar)
        layout.addWidget(frame)
        layout.setContentsMargins(5, 5, 5, 5)
        # layout.setMinimumWidth(300)

        widget.setLayout(layout)

        return widget
Esempio n. 3
0
class plot_widget(QWidget):

    def __init__(self,
                 parent=None,
                 title='',
                 xlabel='',
                 ylabel='',
                 width=10,
                 height=5,
                 dpi=100,
                 dimension = '111',
                 bgcolor   = '#262626'
                 ):
        QWidget.__init__(self,parent)
        self.canvas        = mpl_widget(
            self,
                 title      = title,
                 xlabel     = xlabel,
                 ylabel     = ylabel,
                 xlim       = None,
                 ylim       = None,
                 xscale     = 'linear',
                 yscale     = 'linear',
                 width      = int(width),
                 height     = int(height),
                 dpi        = int(dpi),
                 dimension  = dimension,
                 bgcolor    = bgcolor,
                 hold       = True)
        self.toolbar       = NavigationToolbar(self.canvas, None)
        self.v_layout      = QVBoxLayout()
        #============vairables to hold the dialog objects==========
        self.fd = None
        self.pd = None
        #self.canvas.axes.
        #==================toolbar gui components==========
        #reader button
        self.b_read_file   = QPushButton("")
        icon1 = QIcon()
        icon1.addPixmap(QPixmap(":/imag/read_file_2.png"), QIcon.Normal, QIcon.On)
        self.b_read_file.setIcon(icon1)
        self.b_read_file.clicked.connect(self.b_read_file_clicked)
        self.b_read_file.setIconSize(QSize(48, 48));
        self.b_plot_data   = QPushButton("")
        icon1 = QIcon()
        icon1.addPixmap(QPixmap(":/imag/plot.png"), QIcon.Normal, QIcon.On)
        self.b_plot_data.setIcon(icon1)
        self.b_plot_data.clicked.connect(self.b_plot_button_clicked)
        self.b_plot_data.setIconSize(QSize(48, 48));
        #==============add widgets to toolbar
        self.toolbar.addWidget(self.b_read_file)
        self.toolbar.addWidget(self.b_plot_data)
        #
        self.setMinimumSize(self.toolbar.size())
        self.setMinimumSize(self.canvas.size())
        self.v_layout.addWidget(self.toolbar)
        self.v_layout.addWidget(self.canvas)
        self.setLayout(self.v_layout)

    def b_read_file_clicked(self):
        if (self.fd == None):
            self.fd = file_dialog()
            self.fd.exec_()
        else:
            self.fd.show()
            self.fd.exec_()
            
    def b_plot_button_clicked(self):
        if (self.fd == None):
            quit_msg = "Please open the file first, its not possible to plot"
            reply = QMessageBox.critical(self, 'File First',
                     quit_msg, QMessageBox.Close)
        else:
            if (self.pd == None):
                self.pd = plot_dialog(self,self.fd)
                self.pd.exec_()
            else:
                self.pd.show()
                self.pd.exec_()