コード例 #1
0
class Ui_plotWindow(QtGui.QWidget, subpanel):
    def setupUi(self, plotWindow, commTransport):
        plotWindow.setObjectName(_fromUtf8("plotWindow"))
        plotWindow.resize(818, 418)
        self.gridLayout = QtGui.QGridLayout(plotWindow)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.graphicsView = PlotWidget(plotWindow)
        self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
        self.gridLayout.addWidget(self.graphicsView, 0, 0, 1, 1)

        self.retranslateUi(plotWindow)
        QtCore.QMetaObject.connectSlotsByName(plotWindow)

        self.serialComm = commTransport
        self.graphicsView.hideAxis('bottom')
        self.graphicsView.getAxis('left').setWidth(100)

        # custom code added
        '''
        self.dataPlot.hideAxis('bottom')
        self.dataPlot.showGrid(y=True)
        self.dataPlot.getAxis('left').setWidth(100)
        
        plotSize = 256
        self.plotCount = 6

        self.output = []
        for i in range(self.plotCount):
            self.output.append(deque([0.0]*plotSize))
            
        self.axis = deque(range(plotSize))
        self.value = plotSize
        '''

    def retranslateUi(self, plotWindow):
        plotWindow.setWindowTitle(
            QtGui.QApplication.translate("plotWindow", "Form", None,
                                         QtGui.QApplication.UnicodeUTF8))

    def readContinuousData(self, serialComm):
        '''
コード例 #2
0
class Ui_plotWindow(QtGui.QWidget, subpanel):
    def setupUi(self, plotWindow, commTransport):
        plotWindow.setObjectName(_fromUtf8("plotWindow"))
        plotWindow.resize(818, 418)
        self.gridLayout = QtGui.QGridLayout(plotWindow)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.graphicsView = PlotWidget(plotWindow)
        self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
        self.gridLayout.addWidget(self.graphicsView, 0, 0, 1, 1)

        self.retranslateUi(plotWindow)
        QtCore.QMetaObject.connectSlotsByName(plotWindow)
        
        self.serialComm = commTransport
        self.graphicsView.hideAxis('bottom')
        self.graphicsView.getAxis('left').setWidth(100)
        
        # custom code added
        '''
        self.dataPlot.hideAxis('bottom')
        self.dataPlot.showGrid(y=True)
        self.dataPlot.getAxis('left').setWidth(100)
        
        plotSize = 256
        self.plotCount = 6

        self.output = []
        for i in range(self.plotCount):
            self.output.append(deque([0.0]*plotSize))
            
        self.axis = deque(range(plotSize))
        self.value = plotSize
        '''

    def retranslateUi(self, plotWindow):
        plotWindow.setWindowTitle(QtGui.QApplication.translate("plotWindow", "Form", None, QtGui.QApplication.UnicodeUTF8))

    def readContinuousData(self, serialComm):
        '''
コード例 #3
0
class Window(QtGui.QWidget):

    # Default application settings.
    period = 30
    analog_channel = 0
    trigger_channel = 8
    rate_index = 0
    out_string = 'Data'
    directory = os.path.dirname(os.path.realpath(__file__)) + '/data'
    settings_port = ''

    # Initialization of application variables.
    volts = []
    times = []
    port_name = ''
    last_multiple = period
    time = 0
    sweep = 0
    reading = False

    def __init__(self, parent=None):
        super(Window, self).__init__(parent)

        # Replace default settings with settings from file.
        self.readSettings()

        # Initialize serial communication.
        self.ser = Serial()
        self.ser.baudrate = BAUD_RATE
        self.ser.timeout = TIMEOUT

        # Create graph for plotting data. Disable mouse by default.
        self.graph = PlotWidget()
        self.graph.hideAxis('bottom')
        self.graph.showAxis('bottom')
        self.graph.setMouseEnabled(False, False)
        self.graph.hideButtons()
        self.graph.setYRange(0, GRAPH_RANGE_Y)
        self.graph.setXRange(0, self.period)

        # Create user interface elements and connect them to corresponding functions.
        self.start_button = QtGui.QPushButton('Start')
        self.start_button.clicked.connect(self.startPlot)

        self.stop_button = QtGui.QPushButton('Stop')
        self.stop_button.clicked.connect(self.stopPlot)
        self.stop_button.setEnabled(False)
        self.stop_button.setCheckable(True)

        channel_label = QtGui.QLabel('Analog Channel')

        self.channel_box = QtGui.QSpinBox()
        self.channel_box.setValue(self.analog_channel)
        self.channel_box.valueChanged.connect(self.channel)
        self.channel(self.analog_channel)

        trigger_label = QtGui.QLabel('Trigger Channel')

        self.trigger_box = QtGui.QSpinBox()
        self.trigger_box.setValue(self.trigger_channel)
        self.trigger_box.valueChanged.connect(self.trigger)
        self.trigger(self.trigger_channel)

        rate_label = QtGui.QLabel('Data Acquisition Rate (Hz)')

        self.rate_box = QtGui.QComboBox()
        self.rate_box.addItems(['10', '20', '50', '100', '200', '250', '500'])
        self.rate_box.setCurrentIndex(self.rate_index)
        self.rate_box.currentIndexChanged.connect(self.refresh)
        self.refresh(self.rate_index)

        port_label = QtGui.QLabel('Serial Port')

        self.port_box = QtGui.QComboBox()
        # Find valid ports.
        self.refreshPorts()
        self.port_box.currentIndexChanged.connect(self.portChanged)
        # Check if previously used port is still valid.
        if self.settings_port != '':
            index = self.port_box.findText(self.settings_port)
            if index > -1:
                self.port_box.setCurrentIndex(index)
            else:
                self.port_name = ''

        self.refresh_button = QtGui.QPushButton('Refresh Ports')
        self.refresh_button.clicked.connect(self.refreshPorts)

        period_label = QtGui.QLabel('Graph Period (s)')

        self.period_box = QtGui.QSpinBox()
        self.period_box.setMaximum(1000000)
        self.period_box.setValue(self.period)
        self.period_box.valueChanged.connect(self.changePeriod)

        output_label = QtGui.QLabel('Data Output Prefix')

        self.output_edit = QtGui.QLineEdit()
        self.output_edit.setText(self.out_string)
        self.output_edit.editingFinished.connect(self.outputString)

        self.dir_button = QtGui.QPushButton('Choose Data Directory')
        self.dir_button.clicked.connect(self.chooseDirectory)

        # Add user interface elements to panel.
        button_box = QtGui.QVBoxLayout()
        button_box.addWidget(port_label)
        button_box.addWidget(self.port_box)
        button_box.addWidget(self.refresh_button)
        button_box.addWidget(channel_label)
        button_box.addWidget(self.channel_box)
        button_box.addWidget(trigger_label)
        button_box.addWidget(self.trigger_box)
        button_box.addWidget(rate_label)
        button_box.addWidget(self.rate_box)
        button_box.addWidget(period_label)
        button_box.addWidget(self.period_box)
        button_box.addWidget(output_label)
        button_box.addWidget(self.output_edit)
        button_box.addWidget(self.dir_button)
        # Displace start and stop buttons to bottom of panel.
        button_box.addStretch(1)
        button_box.addWidget(self.start_button)
        button_box.addWidget(self.stop_button)

        # Place panel on left side of application and graph on right.
        layout = QtGui.QHBoxLayout()
        layout.addLayout(button_box)
        layout.addWidget(self.graph, 1)

        self.setLayout(layout)

        # Create timers to control repeating functions.
        self.plot_timer = QtCore.QTimer(self)
        self.plot_timer.timeout.connect(self.plot)

        self.read_timer = QtCore.QTimer(self)
        self.read_timer.timeout.connect(self.read)

        self.trigger_timer = QtCore.QTimer(self)
        self.trigger_timer.timeout.connect(self.checkTrigger)
        self.trigger_timer.start()

    def refreshPorts(self):
        # Loop through com ports and try to open each.
        self.port_box.clear()
        for p in serial.tools.list_ports.comports():
            try:
                self.openPort(p[0])
                # If the port opened, add it to the list.
                if (self.ser.read() == READY_COMMAND):
                    self.port_box.addItem(p[0])
            except:
                pass
        if self.port_box.count() == 0:
            self.port_name = ''

    def closeEvent(self, event):
        # When user closes application, stop reading and save settings.
        if self.reading:
            self.stopPlot()

        settings = open(
            os.path.dirname(os.path.realpath(__file__)) + '/settings.dat',
            'w+')

        settings.write('PORT=' + self.port_name + '\n')
        settings.write('ANALOG_CHANNEL=' + str(self.analog_channel) + '\n')
        settings.write('DATA_RATE=' + str(self.rate_index) + '\n')
        settings.write('PERIOD=' + str(self.period) + '\n')
        settings.write('PREFIX=' + self.out_string + '\n')
        settings.write('DIRECTORY=' + self.directory + '\n')

        settings.close()
        event.accept()

    def read(self):
        # If full transmission of 6 bytes is available, read data from arduino.
        #print(self.ser.inWaiting())
        if (self.ser.inWaiting() >= 6):
            # Convert reading to voltage by using conversion factor 1 bit = 0.125 mV.
            volt = (4.096 * int(binascii.hexlify(self.ser.read(2)), 16) /
                    32768.0)
            #volt = 4.096*(int(self.ser.read(2).encode('hex'), 16)/32768.0)

            # Convert time reading from microseconds to seconds.
            #self.time += (int(self.ser.read(4).encode('hex'), 16)/1000000.0)
            self.time += (int(binascii.hexlify(self.ser.read(4)), 16) /
                          1000000.0)

            # If graph has reached edge, reset with new sweep.
            if (self.time > self.last_multiple):
                self.last_multiple += self.period
                self.newSweep()

            # Add readings to lists of readings.
            self.times.append(self.time)
            self.volts.append(volt)

    def plot(self):
        # Plot current lists of data on graph after clearing previous graph.
        self.graph.plot(self.times, self.volts, clear=True)

    def startPlot(self):
        if self.port_name == '':
            # If no ports are available, inform user and end function.
            warn = QtGui.QMessageBox()
            warn.setWindowTitle('Warning')
            warn.setText('No open ports.')
            warn.exec_()
            return
        if not self.ping():
            # If currently selected port is not open, warn user and end function.
            warn = QtGui.QMessageBox()
            warn.setWindowTitle('Warning')
            warn.setText('Could not connect to port: ' + self.ser.port)
            warn.exec_()
            return
        if (self.period *
                int(self.rate_box.itemText(self.rate_box.currentIndex())) >
                20000):
            # If the user chose too large of a period, inform user and end function.
            # This is in place to avoid memory issues caused by overly large lists of data.
            warn = QtGui.QMessageBox()
            warn.setWindowTitle('Warning')
            warn.setText('Period too large for current data acquisition rate.\n\n'\
                    'Maximum Periods:\n'\
                    '10\tHz\t\t\t2,000\ts\n'\
                    '20\tHz\t\t\t1,000\ts\n'\
                    '50\tHz\t\t\t400\ts\n'\
                    '100\tHz\t\t\t200\ts\n'\
                    '200\tHz\t\t\t100\ts\n'\
                    '250\tHz\t\t\t80\ts\n'\
                    '500\tHz\t\t\t40\ts')
            warn.exec_()
            return

        self.reading = True

        # Send current pin and data rate to the arduino.
        self.ser.write(PIN_COMMAND)
        self.ser.write(bytes(str(self.analog_channel), 'utf_8'))
        self.ser.write(b'\n')

        self.ser.write(RATE_COMMAND)
        self.ser.write(
            bytes(str(int(self.rate_box.itemText(self.rate_index))), 'utf_8'))
        self.ser.write(b'\n')

        # Reset data lists and graph variables to starting values.
        self.volts = []
        self.times = []
        self.sweep = 0
        self.time = 0
        self.last_multiple = self.period
        self.graph.setXRange(0, self.period)

        # Disable all user interface elements that should not be changed while acquiring data.
        self.start_button.setEnabled(False)
        self.channel_box.setEnabled(False)
        self.trigger_box.setEnabled(False)
        self.rate_box.setEnabled(False)
        self.period_box.setEnabled(False)
        self.port_box.setEnabled(False)
        self.output_edit.setEnabled(False)
        self.dir_button.setEnabled(False)

        # Enable stop button.
        self.stop_button.setEnabled(True)

        # Tell arduino to start reading, and start the timers to read and plot data.
        self.ser.write(READ_COMMAND)
        self.ser.flushInput()
        # Graph updates at 50 Hz to smoothly graph while avoiding performance issues.
        self.plot_timer.start(20)
        self.read_timer.start()

    def stopPlot(self):
        # Export the current sweep to data file.
        self.autoExport()
        if self.reading:
            # Stop timers from reading and plotting data.
            #self.plot_timer.stop()
            #self.read_timer.stop()
            self.reading = False

        # Re-enable user interface.
        self.start_button.setEnabled(True)
        self.channel_box.setEnabled(True)
        self.trigger_box.setEnabled(True)
        self.rate_box.setEnabled(True)
        self.period_box.setEnabled(True)
        self.port_box.setEnabled(True)
        self.output_edit.setEnabled(True)
        self.dir_button.setEnabled(True)

        # Disable stop button.
        self.stop_button.setEnabled(False)

        # If connection was not lost, tell arduino to stop reading.
        try:
            self.ser.write(READ_COMMAND)
            #self.ser.write(b'\n')
        except:
            pass

        # Stop timers from reading and plotting data.
        self.plot_timer.stop()
        self.read_timer.stop()

    def channel(self, new_channel):
        # Controls which channel arduino should read from.
        self.analog_channel = new_channel

    def trigger(self, new_channel):
        # Controls which channel arduino should read trigger from.
        self.trigger_channel = new_channel
        if self.ping():
            self.ser.write(TRIGGER_COMMAND)
            self.ser.write(bytes(self.trigger_channel))
            self.ser.write(b'\n')

    def refresh(self, rate_index):
        # Controls rate arduino should read at.
        self.rate_index = rate_index

    def openPort(self, port_name):
        # Close current port, reinitialize to new port, and attempt to open new port.
        self.ser.close()
        self.port_name = port_name
        self.ser.port = port_name
        self.ser.open()

    def portChanged(self, port_index):
        # When new port is chosen from list, try to open it.
        try:
            name = str(self.port_box.itemText(port_index))
            if self.port_name != name:
                self.openPort(name)
        except:
            pass

    def newSweep(self):
        # When graph reaches edge, dump data to file and reset for new sweep.
        self.autoExport()
        self.times = []
        self.volts = []
        self.sweep += 1
        self.graph.setXRange(self.period * self.sweep,
                             self.period * (self.sweep + 1))

    def autoExport(self):
        # Checks specified directory for data. If it doesn't exist, it is created.
        dir = self.directory + '/' + self.out_string
        if not os.path.exists(dir):
            os.makedirs(dir)
        # Creates or opens data file corresponding to current sweep of graph.
        f = open(
            dir + '/' + self.out_string + '_' + ('%03d' % self.sweep) + '.txt',
            'w')
        # Writes data to that file.
        for time, volt in zip(self.times, self.volts):
            f.write(str(time) + '\t' + str(volt) + '\n')
        f.close()

    def changePeriod(self, new_period):
        # Changes period of graph and sweep.
        self.period = new_period
        self.last_multiple = new_period
        self.graph.setXRange(0, new_period)

    def outputString(self):
        # Changes prefix of data files.
        self.out_string = str(self.output_edit.text())

    def chooseDirectory(self):
        # Opens dialog for user to choose where to save data.
        new_dir = str(
            QtGui.QFileDialog.getExistingDirectory(self, 'Select Directory'))
        if (new_dir):
            self.directory = new_dir

    def readSettings(self):
        # Open or create settings file.
        path = os.path.dirname(os.path.realpath(__file__)) + '/settings.dat'
        if os.path.exists(path):
            settings = open(path, 'r+')
        else:
            settings = open(path, 'w+')
        # Parse through file and read settings.
        for line in settings.readlines():
            key, value = line.split('=')
            value = value.rstrip()
            if (key == 'PORT'):
                self.settings_port = value
            elif (key == 'ANALOG_CHANNEL'):
                self.analog_channel = int(value)
            elif (key == 'DATA_RATE'):
                self.rate_index = int(value)
            elif (key == 'PERIOD'):
                self.period = int(value)
            elif (key == 'PREFIX'):
                self.out_string = value
            elif (key == 'DIRECTORY'):
                self.directory = value
        settings.close()

    def ping(self):
        # Check if arduino is still connected.
        try:
            self.ser.write(READY_COMMAND)
            return True
        except:
            return False

    def checkTrigger(self):
        #print(self.reading)
        '''
    #print(self.plot_timer.timerId())
    while self.reading == False and self.port_name != '':
      print("this stopped")
      #print(self.ser.inWaiting())
      self.plot_timer.stop()
      self.read_timer.stop()
      self.reading = False
      #if self.plot_timer.timerId() == -1 and self.read_timer.timerId() == -1 and self.ser.inWaiting:
      #  break
    #  if not self.ser.inWaiting():
    #    break
    '''

        if not self.reading and self.port_name != '' and self.ser.inWaiting(
        ) and not self.stop_button.isChecked():
            if self.ser.read() == READ_COMMAND:
                self.startPlot()
                self.ser.flushInput()
コード例 #4
0
ファイル: __init__.py プロジェクト: LeCoz/Tiare
class Tiare(QtGui.QMainWindow):
    def __init__(self, *args):
        QtGui.QMainWindow.__init__(self, *args)
        self.statusBar().showMessage('Pret')
        self.th = 0
        self.widget = QtGui.QWidget(self)
        exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Quitter', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip("Ferme l'application")
        exitAction.triggered.connect(self.close)

        openAction = QtGui.QAction(QtGui.QIcon('open.png'), '&Charger', self)
        openAction.setShortcut('Ctrl+L')
        openAction.setStatusTip("Charge un fichier wav")
        openAction.triggered.connect(self.load)

        self.saveAction = QtGui.QAction(QtGui.QIcon('save.png'), '&Exporter', self)
        self.saveAction.setShortcut('Ctrl+S')
        self.saveAction.setStatusTip("Exporter en CSV")
        self.saveAction.triggered.connect(self.export)
        self.saveAction.setEnabled(False)
        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&Fichier')
        fileMenu.addAction(openAction)
        fileMenu.addAction(self.saveAction)
        fileMenu.addAction(exitAction)

        self.th_slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.th_slider.setValue(self.th)
        self.th_slider.valueChanged[int].connect(self.change_threshold)

        self.min_len = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.min_len.setValue(10)
        self.min_len.setMinimum(1)
        self.min_len.setMaximum(100)
        self.min_len.valueChanged[int].connect(self.change_min_len)

        self.min_len_sil = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.min_len_sil.setValue(10)
        self.min_len_sil.setMinimum(1)
        self.min_len_sil.setMaximum(100)
        self.min_len_sil.valueChanged[int].connect(self.change_min_len)


        # Make sizer and embed stuff
        self.sizer = QtGui.QVBoxLayout(self.widget)
        self.fig_signal = PlotWidget(self.widget, background="w")
        self.fig_signal.setLimits(xMin=0, yMin=-1, yMax=1, minXRange=1, maxXRange=30, minYRange=2, maxYRange=2)
        self.fig_energy = PlotWidget(self.widget, background="w")
        self.fig_energy.setXLink(self.fig_signal)
        self.fig_segments = PlotWidget(self.widget, background="w")
        self.fig_segments.setXLink(self.fig_signal)
        self.fig_segments.hideAxis('bottom')
        self.fig_segments.hideAxis('left')
        self.fig_segments.setLimits(yMin=-1, yMax=1, minYRange=2, maxYRange=2)

        self.sizer.addWidget(self.fig_signal, 5)
        self.sizer.addWidget(self.fig_energy, 5)
        self.sizer.addWidget(self.fig_segments, 3)
        self.sizer.addWidget(QtGui.QLabel('Seuil de segmentation'), 0)
        self.sizer.addWidget(self.th_slider, 0)
        self.min_seg_label = QtGui.QLabel('Longeur minimal de segment (%.3f s)' % (float(self.min_len.value())/100))
        self.sizer.addWidget(self.min_seg_label, 0)
        self.sizer.addWidget(self.min_len, 0)

        self.min_sil_label = QtGui.QLabel('Longeur minimal de silence (%.3f s)' % (float(self.min_len_sil.value())/100))
        self.sizer.addWidget(self.min_sil_label, 0)
        self.sizer.addWidget(self.min_len_sil, 0)

        # Apply sizers
        self.setCentralWidget(self.widget)

        # Finish
        self.resize(560, 420)
        self.setWindowTitle('Tiare')
        self.energy_tl, self.energy = [], []
        self.thline = None
        self.seg_up = None
        self.seg_down = None
        self.fig_energy_plot = None
        self.segments = []
        self.samples = []
        self.sr = 0
        self.filepath = None
        self.widget.hide()
        self.show()

    def change_threshold(self, value):
        value = float(value)/100
        if self.thline is not None :
            self.thline.setData([self.energy_tl[0], self.energy_tl[-1]], [value]*2)
            self.segments = map(lambda (x, y): (self.energy_tl[x],self.energy_tl[y]),
                                cut(self.energy, value, self.min_len.value(), self.min_len_sil.value()))
            x = [v for start, stop in self.segments for v in [start, start, stop, stop]]
            y = [v for _ in self.segments for v in [-0.85, 0.85, 0.85, -0.85]]
            self.seg_up.setData(x, y)
            self.seg_down.setData([self.energy_tl[0], self.energy_tl[-1]], [-0.85, -0.85])

    def change_min_len(self, value=0):
        self.min_seg_label.setText("Longeur minimale d'un segment (%.3f s)" % (float(self.min_len.value())/100))
        self.min_sil_label.setText("Longeur minimale d'un silence (%.3f s)" % (float(self.min_len_sil.value())/100))
        self.change_threshold(self.th_slider.value())

    def compute_energy(self, value=None):
        self.energy_tl, self.energy = energy(self.samples, self.sr)
        if self.fig_energy_plot is not None:
            self.fig_energy_plot.setData(self.energy_tl, self.energy)
            self.change_min_len()

    def export(self):
        fpath = QtGui.QFileDialog.getSaveFileName(self, "Sauvegader en CSV", self.filepath+".csv")
        if fpath:
            with open(fpath[0], "w") as f:

                for start, stop in self.segments:
                    f.write("Segments\t%s\t%s\n" % (datetime(day=1, month=1, year=1901, second=int(start),
                                                             microsecond=int(10e5*(start % 1)))
                                                    .strftime("%H:%M:%S.%f"),
                                                    datetime(day=1, month=1, year=1901, second=int(stop),
                                                             microsecond=int(10e5*(stop % 1)))
                                                    .strftime("%H:%M:%S.%f")))

    def load(self):
        fpath, _ = QtGui.QFileDialog.getOpenFileName(self, 'Choisir un fichier', '~/', filter="*.wav")
        self.widget.show()
        if fpath:
            self.filepath = fpath
            self.saveAction.setEnabled(True)

            self.samples, self.sr = load_sound(fpath)
            m = max(map(abs, self.samples))
            timeline = [float(t)/self.sr for t in range(len(self.samples))]
            self.fig_signal.setLimits(xMax=timeline[-1])

            self.compute_energy()

            self.fig_signal.getPlotItem().plot(timeline, map(lambda x: x/m, self.samples))
            self.fig_energy_plot = self.fig_energy.getPlotItem().plot(self.energy_tl, self.energy)
            self.thline = self.fig_energy.getPlotItem().plot([self.energy_tl[0], self.energy_tl[-1]],
                                                             [float(self.th_slider.value())/100]*2,
                                               pen=({'color': "k", "width": 1.5}))
            self.seg_up = self.fig_segments.getPlotItem().plot([self.energy_tl[0], self.energy_tl[-1]],
                                                               [-0.85, -0.85])

            self.seg_down = self.fig_segments.getPlotItem().plot([self.energy_tl[0], self.energy_tl[-1]],
                                                                 [-0.85, -0.85])
            self.segments = FillBetweenItem(self.seg_up, self.seg_down, 0.7)
            self.fig_segments.addItem(self.segments)
コード例 #5
0
ファイル: camviewer.py プロジェクト: slaclab/pydm
class CamViewer(Display):
    # Emitted when the user changes the value.
    roi_x_signal = Signal(str)
    roi_y_signal = Signal(str)
    roi_w_signal = Signal(str)
    roi_h_signal = Signal(str)

    def __init__(self, parent=None, args=None):
        super(CamViewer, self).__init__(parent=parent, args=args)

        # Set up the list of cameras, and all the PVs
        test_dict = { "image": "ca://MTEST:Image", "max_width": "ca://MTEST:ImageWidth", "max_height": "ca://MTEST:ImageWidth", "roi_x": None, "roi_y": None, "roi_width": None, "roi_height": None }
        # self.cameras = { "VCC": vcc_dict, "C-Iris": c_iris_dict, "Test": test_dict }
        self.cameras = {"Testing IOC Image": test_dict }
        self._channels = []
        self.imageChannel = None

        # Populate the camera combo box
        self.ui.cameraComboBox.clear()
        for camera in self.cameras:
            self.ui.cameraComboBox.addItem(camera)

        # When the camera combo box changes, disconnect from PVs, re-initialize, then reconnect.
        self.ui.cameraComboBox.activated[str].connect(self.cameraChanged)

        # Set up the color map combo box.
        self.ui.colorMapComboBox.clear()
        for key, map_name in cmap_names.items():
            self.ui.colorMapComboBox.addItem(map_name, userData=key)
        self.ui.imageView.colorMap = self.ui.colorMapComboBox.currentData()
        self.ui.colorMapComboBox.activated[str].connect(self.colorMapChanged)

        # Set up the color map limit sliders and line edits.
        # self._color_map_limit_sliders_need_config = True
        self.ui.colorMapMinSlider.valueChanged.connect(self.setColorMapMin)
        self.ui.colorMapMaxSlider.valueChanged.connect(self.setColorMapMax)
        self.ui.colorMapMinLineEdit.returnPressed.connect(self.colorMapMinLineEditChanged)
        self.ui.colorMapMaxLineEdit.returnPressed.connect(self.colorMapMaxLineEditChanged)

        # Set up the stuff for single-shot and average modes.
        self.ui.singleShotRadioButton.setChecked(True)
        self._average_mode_enabled = False
        self.ui.singleShotRadioButton.clicked.connect(self.enableSingleShotMode)
        self.ui.averageRadioButton.clicked.connect(self.enableAverageMode)
        self.ui.numShotsLineEdit.returnPressed.connect(self.numAverageChanged)

        # Add a plot for vertical lineouts
        self.yLineoutPlot = PlotWidget()
        self.yLineoutPlot.setMaximumWidth(80)
        self.yLineoutPlot.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Expanding)
        self.yLineoutPlot.getPlotItem().invertY()
        self.yLineoutPlot.hideAxis('bottom')
        # self.yLineoutPlot.setYLink(self.ui.imageView.getView())
        self.ui.imageGridLayout.addWidget(self.yLineoutPlot, 0, 0)
        self.yLineoutPlot.hide()
        # We do some mangling of the .ui file here and move the imageView over a cell, kind of ugly.
        self.ui.imageGridLayout.removeWidget(self.ui.imageView)
        self.ui.imageGridLayout.addWidget(self.ui.imageView, 0, 1)

        # Add a plot for the horizontal lineouts
        self.xLineoutPlot = PlotWidget()
        self.xLineoutPlot.setMaximumHeight(80)
        self.xLineoutPlot.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.xLineoutPlot.hideAxis('left')
        # self.xLineoutPlot.setXLink(self.ui.imageView.getView())
        self.ui.imageGridLayout.addWidget(self.xLineoutPlot, 1, 1)
        self.xLineoutPlot.hide()

        # Update the lineout plot ranges when the image gets panned or zoomed
        self.ui.imageView.getView().sigRangeChanged.connect(self.updateLineoutRange)

        # Instantiate markers.
        self.marker_dict = {1:{}, 2:{}, 3:{}, 4:{}}
        marker_size = QPointF(20., 20.)
        self.marker_dict[1]['marker'] = ImageMarker((0, 0), size=marker_size, pen=mkPen((100, 100, 255), width=5))
        self.marker_dict[1]['button'] = self.ui.marker1Button
        self.marker_dict[1]['xlineedit'] = self.ui.marker1XPosLineEdit
        self.marker_dict[1]['ylineedit'] = self.ui.marker1YPosLineEdit

        self.marker_dict[2]['marker'] = ImageMarker((0, 0), size=marker_size, pen=mkPen((255, 100, 100), width=5))
        self.marker_dict[2]['button'] = self.ui.marker2Button
        self.marker_dict[2]['xlineedit'] = self.ui.marker2XPosLineEdit
        self.marker_dict[2]['ylineedit'] = self.ui.marker2YPosLineEdit

        self.marker_dict[3]['marker'] = ImageMarker((0, 0), size=marker_size, pen=mkPen((60, 255, 60), width=5))
        self.marker_dict[3]['button'] = self.ui.marker3Button
        self.marker_dict[3]['xlineedit'] = self.ui.marker3XPosLineEdit
        self.marker_dict[3]['ylineedit'] = self.ui.marker3YPosLineEdit

        self.marker_dict[4]['marker'] = ImageMarker((0, 0), size=marker_size, pen=mkPen((255, 60, 255), width=5))
        self.marker_dict[4]['button'] = self.ui.marker4Button
        self.marker_dict[4]['xlineedit'] = self.ui.marker4XPosLineEdit
        self.marker_dict[4]['ylineedit'] = self.ui.marker4YPosLineEdit
        # Disable auto-ranging the image (it feels strange when the zoom changes as you move markers around.)
        self.ui.imageView.getView().disableAutoRange()
        for d in self.marker_dict:
            marker = self.marker_dict[d]['marker']
            marker.setZValue(20)
            marker.hide()
            marker.sigRegionChanged.connect(self.markerMoved)
            self.ui.imageView.getView().addItem(marker)
            self.marker_dict[d]['button'].toggled.connect(self.enableMarker)
            curvepen = QPen(marker.pen)
            curvepen.setWidth(1)
            self.marker_dict[d]['xcurve'] = self.xLineoutPlot.plot(pen=curvepen)
            self.marker_dict[d]['ycurve'] = self.yLineoutPlot.plot(pen=curvepen)
            self.marker_dict[d]['xlineedit'].returnPressed.connect(self.markerPositionLineEditChanged)
            self.marker_dict[d]['ylineedit'].returnPressed.connect(self.markerPositionLineEditChanged)

        # Set up zoom buttons
        self.ui.zoomInButton.clicked.connect(self.zoomIn)
        self.ui.zoomOutButton.clicked.connect(self.zoomOut)
        self.ui.zoomToActualSizeButton.clicked.connect(self.zoomToActualSize)

        # Set up ROI buttons
        self.ui.setROIButton.clicked.connect(self.setROI)
        self.ui.resetROIButton.clicked.connect(self.resetROI)

        self.destroyed.connect(functools.partial(widget_destroyed, self.channels))


    @Slot()
    def zoomIn(self):
        self.ui.imageView.getView().scaleBy((0.5, 0.5))

    @Slot()
    def zoomOut(self):
        self.ui.imageView.getView().scaleBy((2.0, 2.0))

    @Slot()
    def zoomToActualSize(self):
        if len(self.image_data) == 0:
            return
        self.ui.imageView.getView().setRange(xRange=(0, self.image_data.shape[0]), yRange=(0, self.image_data.shape[1]), padding=0.0)

    def disable_all_markers(self):
        for d in self.marker_dict:
            self.marker_dict[d]['button'].setChecked(False)
            self.marker_dict[d]['marker'].setPos((0, 0))

    @Slot(bool)
    def enableMarker(self, checked):
        any_markers_visible = False
        for d in self.marker_dict:
            marker = self.marker_dict[d]['marker']
            button = self.marker_dict[d]['button']
            any_markers_visible = any_markers_visible or button.isChecked()
            marker.setVisible(button.isChecked())
            self.markerMoved(d)
            self.marker_dict[d]['xcurve'].setVisible(button.isChecked())
            self.marker_dict[d]['ycurve'].setVisible(button.isChecked())
            self.marker_dict[d]['xlineedit'].setEnabled(button.isChecked())
            self.marker_dict[d]['ylineedit'].setEnabled(button.isChecked())
        if any_markers_visible:
            self.xLineoutPlot.show()
            self.yLineoutPlot.show()
        else:
            self.xLineoutPlot.hide()
            self.yLineoutPlot.hide()

    @Slot()
    def markerPositionLineEditChanged(self):
        for d in self.marker_dict:
            marker = self.marker_dict[d]['marker']
            x_line_edit = self.marker_dict[d]['xlineedit']
            y_line_edit = self.marker_dict[d]['ylineedit']
            try:
                new_x = int(x_line_edit.text())
                new_y = int(y_line_edit.text())
                if new_x <= marker.maxBounds.width() and new_y <= marker.maxBounds.height():
                    marker.setPos((new_x, new_y))
            except:
                pass
            coords = marker.getPixelCoords()
            x_line_edit.setText(str(coords[0]))
            y_line_edit.setText(str(coords[1]))

    @Slot(object)
    def markerMoved(self, marker):
        self.updateLineouts()
        for marker_index in self.marker_dict:
            marker = self.marker_dict[marker_index]['marker']
            x_line_edit = self.marker_dict[marker_index]['xlineedit']
            y_line_edit = self.marker_dict[marker_index]['ylineedit']
            coords = marker.getPixelCoords()
            x_line_edit.setText(str(coords[0]))
            y_line_edit.setText(str(coords[1]))

    @Slot(object, object)
    def updateLineoutRange(self, view, new_ranges):
        self.ui.xLineoutPlot.setRange(xRange=new_ranges[0], padding=0.0)
        self.ui.yLineoutPlot.setRange(yRange=new_ranges[1], padding=0.0)

    def updateLineouts(self):
        for marker_index in self.marker_dict:
            marker = self.marker_dict[marker_index]['marker']
            xcurve = self.marker_dict[marker_index]['xcurve']
            ycurve = self.marker_dict[marker_index]['ycurve']
            if marker.isVisible():
                result, coords = marker.getArrayRegion(self.image_data, self.ui.imageView.getImageItem())
                xcurve.setData(y=result[0], x=np.arange(len(result[0])))
                ycurve.setData(y=np.arange(len(result[1])), x=result[1])

    @Slot()
    def enableSingleShotMode(self):
        self._average_mode_enabled = False
        self._average_buffer = np.ndarray(0)

    @Slot()
    def enableAverageMode(self):
        self._average_mode_enabled = True

    @Slot(str)
    def cameraChanged(self, new_camera):
        new_camera = str(new_camera)
        if self.imageChannel == self.cameras[new_camera]["image"]:
            return
        close_widget_connections(self)
        self.disable_all_markers()
        self.initializeCamera(new_camera)

    def initializeCamera(self, new_camera):
        new_camera = str(new_camera)
        self._color_map_limit_sliders_need_config = True
        self.times = np.zeros(10)
        self.old_timestamp = 0
        self.image_width = 0  # current width (width of ROI)
        self.image_max_width = 0  # full width.  Only used to reset ROI to full.
        self.image_max_height = 0  # full height.  Only used to reset ROI to full.
        self.image_data = np.zeros(0)
        self._average_counter = 0
        self._average_buffer = np.ndarray(0)
        self._needs_auto_range = True
        self.imageChannel = self.cameras[new_camera]["image"]
        self.widthChannel = self.cameras[new_camera]["roi_width"] or self.cameras[new_camera]["max_width"]
        self.maxWidthChannel = self.cameras[new_camera]["max_width"]
        self.maxHeightChannel = self.cameras[new_camera]["max_height"]
        self.roiXChannel = self.cameras[new_camera]["roi_x"]
        self.roiYChannel = self.cameras[new_camera]["roi_y"]
        self.roiWidthChannel = self.cameras[new_camera]["roi_width"]
        self.roiHeightChannel = self.cameras[new_camera]["roi_height"]

        self._channels = [PyDMChannel(address=self.imageChannel, connection_slot=self.connectionStateChanged, value_slot=self.receiveImageWaveform, severity_slot=self.alarmSeverityChanged),
                                            PyDMChannel(address=self.widthChannel, value_slot=self.receiveImageWidth),
                                            PyDMChannel(address=self.maxWidthChannel, value_slot=self.receiveMaxWidth),
                                            PyDMChannel(address=self.maxHeightChannel, value_slot=self.receiveMaxHeight)]
        if self.roiXChannel and self.roiYChannel and self.roiWidthChannel and self.roiHeightChannel:
            self._channels.extend([PyDMChannel(address=self.roiXChannel, value_slot=self.receiveRoiX, value_signal=self.roi_x_signal, write_access_slot=self.roiWriteAccessChanged),
                                                         PyDMChannel(address=self.roiYChannel, value_slot=self.receiveRoiY, value_signal=self.roi_y_signal),
                                                         PyDMChannel(address=self.roiWidthChannel, value_slot=self.receiveRoiWidth, value_signal=self.roi_w_signal),
                                                         PyDMChannel(address=self.roiHeightChannel, value_slot=self.receiveRoiHeight, value_signal=self.roi_h_signal)])
            self.ui.roiXLineEdit.setEnabled(True)
            self.ui.roiYLineEdit.setEnabled(True)
            self.ui.roiWLineEdit.setEnabled(True)
            self.ui.roiHLineEdit.setEnabled(True)
        else:
            self.ui.roiXLineEdit.clear()
            self.ui.roiXLineEdit.setEnabled(False)
            self.ui.roiYLineEdit.clear()
            self.ui.roiYLineEdit.setEnabled(False)
            self.ui.roiWLineEdit.clear()
            self.ui.roiWLineEdit.setEnabled(False)
            self.ui.roiHLineEdit.clear()
            self.ui.roiHLineEdit.setEnabled(False)
        establish_widget_connections(self)

    @Slot()
    def setROI(self):
        self.roi_x_signal.emit(self.ui.roiXLineEdit.text())
        self.roi_y_signal.emit(self.ui.roiYLineEdit.text())
        self.roi_w_signal.emit(self.ui.roiWLineEdit.text())
        self.roi_h_signal.emit(self.ui.roiHLineEdit.text())

    @Slot()
    def resetROI(self):
        self.roi_x_signal.emit(str(0))
        self.roi_y_signal.emit(str(0))
        self.roi_w_signal.emit(str(self.image_max_width))
        self.roi_h_signal.emit(str(self.image_max_height))

    @Slot(str)
    def colorMapChanged(self, _):
        self.ui.imageView.colorMap = self.ui.colorMapComboBox.currentData()

    def configureColorMapLimitSliders(self, max_int):
        self.ui.colorMapMinSlider.setMaximum(max_int)
        self.ui.colorMapMaxSlider.setMaximum(max_int)
        self.ui.colorMapMaxSlider.setValue(max_int)
        self.ui.colorMapMinSlider.setValue(0)
        self.setColorMapMin(0)
        self.setColorMapMax(max_int)
        self._color_map_limit_sliders_need_config = False

    @Slot()
    def colorMapMinLineEditChanged(self):
        try:
            new_min = int(self.ui.colorMapMinLineEdit.text())
        except:
            self.ui.colorMapMinLineEdit.setText(str(self.ui.colorMapMinSlider.value()))
            return
        if new_min < 0:
            new_min = 0
        if new_min > self.ui.colorMapMinSlider.maximum():
            new_min = self.ui.colorMapMinSlider.maximum()
        self.ui.colorMapMinSlider.setValue(new_min)

    @Slot(int)
    def setColorMapMin(self, new_min):
        if new_min > self.ui.colorMapMaxSlider.value():
            self.ui.colorMapMaxSlider.setValue(new_min)
            self.ui.colorMapMaxLineEdit.setText(str(new_min))
        self.ui.colorMapMinLineEdit.setText(str(new_min))
        self.ui.imageView.setColorMapLimits(new_min, self.ui.colorMapMaxSlider.value())

    @Slot()
    def colorMapMaxLineEditChanged(self):
        try:
            new_max = int(self.ui.colorMapMaxLineEdit.text())
        except:
            self.ui.colorMapMaxLineEdit.setText(str(self.ui.colorMapMaxSlider.value()))
            return
        if new_max < 0:
            new_max = 0
        if new_max > self.ui.colorMapMaxSlider.maximum():
            new_max = self.ui.colorMapMaxSlider.maximum()
        self.ui.colorMapMaxSlider.setValue(new_max)

    @Slot(int)
    def setColorMapMax(self, new_max):
        if new_max < self.ui.colorMapMinSlider.value():
            self.ui.colorMapMinSlider.setValue(new_max)
            self.ui.colorMapMinLineEdit.setText(str(new_max))
        self.ui.colorMapMaxLineEdit.setText(str(new_max))
        self.ui.imageView.setColorMapLimits(self.ui.colorMapMinSlider.value(), new_max)

    def createAverageBuffer(self, size, type, initial_val=[]):
        num_shots = 1
        try:
            num_shots = int(self.ui.numShotsLineEdit.text())
        except:
            self.ui.numShotsLineEdit.setText(str(num_shots))
        if num_shots < 1:
            num_shots = 1
            self.ui.numShotsLineEdit.setText(str(num_shots))
        if num_shots > 200:
            num_shots = 200
            self.ui.numShotsLineEdit.setText(str(num_shots))
        if len(initial_val) > 0:
            return np.full((num_shots, size), initial_val, dtype=type)
        else:
            return np.zeros(shape=(num_shots, size), dtype=type)

    @Slot()
    def numAverageChanged(self):
        self._average_buffer = np.zeros(0)

    @Slot(np.ndarray)
    def receiveImageWaveform(self, new_waveform):
        if not self.image_width:
            return

        # Calculate the average rate
        new_timestamp = time.time()
        if not (self.old_timestamp == 0):
            delta = new_timestamp - self.old_timestamp
            self.times = np.roll(self.times, 1)
            self.times[0] = delta
            avg_delta = np.mean(self.times)
            self.ui.dataRateLabel.setText("{:.1f} Hz".format((1.0 / avg_delta)))
            self.ui.displayRateLabel.setText("{:.1f} Hz".format((1.0 / avg_delta)))
        self.old_timestamp = new_timestamp

        # If this is the first image, set up the color map slider limits
        if self._color_map_limit_sliders_need_config:
            max_int = np.iinfo(new_waveform.dtype).max
            self.configureColorMapLimitSliders(max_int)

        # If we are in average mode, add this image to the circular averaging buffer, otherwise just display it.
        if self._average_mode_enabled:
            if len(self._average_buffer) == 0:
                self._average_buffer = self.createAverageBuffer(len(new_waveform), new_waveform.dtype, new_waveform)
                self._average_counter = 0
            self._average_counter = (self._average_counter + 1) % len(self._average_buffer)
            # self._average_buffer = np.roll(self._average_buffer, 1, axis=0)
            self._average_buffer[self._average_counter] = new_waveform
            mean = np.mean(self._average_buffer, axis=0).astype(new_waveform.dtype)
            self.image_data = mean.reshape((int(self.image_width), -1), order='F')
        else:
            self.image_data = new_waveform.reshape((int(self.image_width), -1), order='F')
        self.setMarkerBounds()
        self.updateLineouts()
        self.ui.imageView.image_value_changed(self.image_data)
        self.calculateStats()
        if self._needs_auto_range:
            self.ui.imageView.getView().autoRange(padding=0.0)
            current_range = self.ui.imageView.getView().viewRange()
            self._needs_auto_range = False

    def calculateStats(self):
        # Full image stats
        mean = np.mean(self.image_data)
        std = np.std(self.image_data)
        width = self.image_data.shape[0]
        height = self.image_data.shape[1]
        min_val = np.min(self.image_data)
        max_val = np.max(self.image_data)
        self.ui.imageStatsLabel.setText("Mean: {0:.2f}, Std: {1:.2f}, Min: {2}, Max: {3}, Width: {4}, Height: {5}".format(mean, std, min_val, max_val, width, height))
        # Current view stats
        current_range = self.ui.imageView.getView().viewRange()
        view_x_min = int(max(0, current_range[0][0]))
        view_x_max = int(min(self.image_data.shape[0], current_range[0][1]))
        view_y_min = int(max(0, current_range[1][0]))
        view_y_max = int(min(self.image_data.shape[1], current_range[1][1]))
        view_slice = self.image_data[view_x_min:view_x_max, view_y_min:view_y_max]
        mean = np.mean(view_slice)
        std = np.std(view_slice)
        width = view_slice.shape[0]
        height = view_slice.shape[1]
        min_val = np.min(view_slice)
        max_val = np.max(view_slice)
        self.ui.viewStatsLabel.setText("Mean: {0:.2f}, Std: {1:.2f}, Min: {2}, Max: {3}, Width: {4}, Height: {5}".format(mean, std, min_val, max_val, width, height))

    def setMarkerBounds(self):
        for marker_index in self.marker_dict:
            marker = self.marker_dict[marker_index]['marker']
            marker.maxBounds = QRectF(0, 0, self.image_data.shape[0] + marker.size()[0] - 1, self.image_data.shape[1] + marker.size()[1] - 1)

    @Slot(int)
    def receiveImageWidth(self, new_width):
        self.image_width = new_width
        self.ui.imageView.image_width_changed(self.image_width)

    @Slot(int)
    def receiveMaxWidth(self, new_max_width):
        self.image_max_width = new_max_width

    @Slot(int)
    def receiveMaxHeight(self, new_max_height):
        self.image_max_height = new_max_height

    @Slot(int)
    def receiveRoiX(self, new_roi_x):
        self.ui.roiXLineEdit.setText(str(new_roi_x))

    @Slot(int)
    def receiveRoiY(self, new_roi_y):
        self.ui.roiYLineEdit.setText(str(new_roi_y))

    @Slot(int)
    def receiveRoiWidth(self, new_roi_w):
        self.ui.roiWLineEdit.setText(str(new_roi_w))

    @Slot(int)
    def receiveRoiHeight(self, new_roi_h):
        self.ui.roiHLineEdit.setText(str(new_roi_h))

    # -2 to +2, -2 is LOLO, -1 is LOW, 0 is OK, etc.
    @Slot(int)
    def alarmStatusChanged(self, new_alarm_state):
        pass

    # 0 = NO_ALARM, 1 = MINOR, 2 = MAJOR, 3 = INVALID
    @Slot(int)
    def alarmSeverityChanged(self, new_alarm_severity):
        pass

    @Slot(bool)
    def roiWriteAccessChanged(self, can_write_roi):
        self.ui.setROIButton.setEnabled(can_write_roi)
        self.ui.resetROIButton.setEnabled(can_write_roi)
        self.ui.roiXLineEdit.setReadOnly(not can_write_roi)
        self.ui.roiYLineEdit.setReadOnly(not can_write_roi)
        self.ui.roiWLineEdit.setReadOnly(not can_write_roi)
        self.ui.roiHLineEdit.setReadOnly(not can_write_roi)

    # false = disconnected, true = connected
    @Slot(bool)
    def connectionStateChanged(self, connected):
        if connected:
            self.ui.imageView.redraw_timer.start()
        else:
            self.ui.imageView.redraw_timer.stop()
        self.ui.connectedLabel.setText({True: "Yes", False: "No"}[connected])

    def ui_filename(self):
        return 'camviewer.ui'

    def channels(self):
        return self._channels
コード例 #6
0
class CamViewer(Display):
    #Emitted when the user changes the value.
    roi_x_signal = pyqtSignal(str)
    roi_y_signal = pyqtSignal(str)
    roi_w_signal = pyqtSignal(str)
    roi_h_signal = pyqtSignal(str)

    def __init__(self, display_manager_window):
        super(CamViewer, self).__init__(display_manager_window)

        #Set up the list of cameras, and all the PVs
        vcc_dict = {
            "image": "ca://CAMR:IN20:186:IMAGE",
            "max_width": "ca://CAMR:IN20:186:N_OF_COL",
            "max_height": "ca://CAMR:IN20:186:N_OF_ROW",
            "roi_x": None,
            "roi_y": None,
            "roi_width": None,
            "roi_height": None
        }
        c_iris_dict = {
            "image": "ca://CAMR:LR20:119:Image:ArrayData",
            "max_width": "ca://CAMR:LR20:119:MaxSizeX_RBV",
            "max_height": "ca://CAMR:LR20:119:MaxSizeY_RBV",
            "roi_x": "ca://CAMR:LR20:119:MinX",
            "roi_y": "ca://CAMR:LR20:119:MinY",
            "roi_width": "ca://CAMR:LR20:119:SizeX",
            "roi_height": "ca://CAMR:LR20:119:SizeY"
        }
        test_dict = {
            "image": "ca://MTEST:Image",
            "max_width": "ca://MTEST:ImageWidth",
            "max_height": "ca://MTEST:ImageWidth",
            "roi_x": None,
            "roi_y": None,
            "roi_width": None,
            "roi_height": None
        }
        self.cameras = {
            "VCC": vcc_dict,
            "C-Iris": c_iris_dict,
            "Test": test_dict
        }
        self._channels = []

        #Populate the camera combo box
        self.ui.cameraComboBox.clear()
        for camera in self.cameras:
            self.ui.cameraComboBox.addItem(camera)

        #Clear out any image data, reset width, get PVs ready for connection
        self.initializeCamera(self.ui.cameraComboBox.currentText())

        #When the camera combo box changes, disconnect from PVs, re-initialize, then reconnect.
        self.ui.cameraComboBox.activated[str].connect(self.cameraChanged)

        #Set up the color map combo box.
        self.ui.colorMapComboBox.clear()
        for map_name in self.ui.imageView.color_maps:
            self.ui.colorMapComboBox.addItem(map_name)
        self.ui.imageView.setColorMapToPreset(
            self.ui.colorMapComboBox.currentText())
        self.ui.colorMapComboBox.activated[str].connect(self.colorMapChanged)

        #Set up the color map limit sliders and line edits.
        #self._color_map_limit_sliders_need_config = True
        self.ui.colorMapMinSlider.valueChanged.connect(self.setColorMapMin)
        self.ui.colorMapMaxSlider.valueChanged.connect(self.setColorMapMax)
        self.ui.colorMapMinLineEdit.returnPressed.connect(
            self.colorMapMinLineEditChanged)
        self.ui.colorMapMaxLineEdit.returnPressed.connect(
            self.colorMapMaxLineEditChanged)

        #Set up the stuff for single-shot and average modes.
        self.ui.singleShotRadioButton.setChecked(True)
        self._average_mode_enabled = False
        self.ui.singleShotRadioButton.clicked.connect(
            self.enableSingleShotMode)
        self.ui.averageRadioButton.clicked.connect(self.enableAverageMode)
        self.ui.numShotsLineEdit.returnPressed.connect(self.numAverageChanged)

        #Add a plot for vertical lineouts
        self.yLineoutPlot = PlotWidget()
        self.yLineoutPlot.setMaximumWidth(80)
        self.yLineoutPlot.setSizePolicy(QSizePolicy.Minimum,
                                        QSizePolicy.Expanding)
        self.yLineoutPlot.getPlotItem().invertY()
        self.yLineoutPlot.hideAxis('bottom')
        #self.yLineoutPlot.setYLink(self.ui.imageView.getView())
        self.ui.imageGridLayout.addWidget(self.yLineoutPlot, 0, 0)
        self.yLineoutPlot.hide()
        #We do some mangling of the .ui file here and move the imageView over a cell, kind of ugly.
        self.ui.imageGridLayout.removeWidget(self.ui.imageView)
        self.ui.imageGridLayout.addWidget(self.ui.imageView, 0, 1)

        #Add a plot for the horizontal lineouts
        self.xLineoutPlot = PlotWidget()
        self.xLineoutPlot.setMaximumHeight(80)
        self.xLineoutPlot.setSizePolicy(QSizePolicy.Expanding,
                                        QSizePolicy.Minimum)
        self.xLineoutPlot.hideAxis('left')
        #self.xLineoutPlot.setXLink(self.ui.imageView.getView())
        self.ui.imageGridLayout.addWidget(self.xLineoutPlot, 1, 1)
        self.xLineoutPlot.hide()

        #Update the lineout plot ranges when the image gets panned or zoomed
        self.ui.imageView.getView().sigRangeChanged.connect(
            self.updateLineoutRange)

        #Instantiate markers.
        self.marker_dict = {1: {}, 2: {}, 3: {}, 4: {}}
        marker_size = QPointF(20., 20.)
        self.marker_dict[1]['marker'] = ImageMarker((0, 0),
                                                    size=marker_size,
                                                    pen=mkPen((100, 100, 255),
                                                              width=3))
        self.marker_dict[1]['button'] = self.ui.marker1Button
        self.marker_dict[1]['xlineedit'] = self.ui.marker1XPosLineEdit
        self.marker_dict[1]['ylineedit'] = self.ui.marker1YPosLineEdit

        self.marker_dict[2]['marker'] = ImageMarker((0, 0),
                                                    size=marker_size,
                                                    pen=mkPen((255, 100, 100),
                                                              width=3))
        self.marker_dict[2]['button'] = self.ui.marker2Button
        self.marker_dict[2]['xlineedit'] = self.ui.marker2XPosLineEdit
        self.marker_dict[2]['ylineedit'] = self.ui.marker2YPosLineEdit

        self.marker_dict[3]['marker'] = ImageMarker((0, 0),
                                                    size=marker_size,
                                                    pen=mkPen((60, 255, 60),
                                                              width=3))
        self.marker_dict[3]['button'] = self.ui.marker3Button
        self.marker_dict[3]['xlineedit'] = self.ui.marker3XPosLineEdit
        self.marker_dict[3]['ylineedit'] = self.ui.marker3YPosLineEdit

        self.marker_dict[4]['marker'] = ImageMarker((0, 0),
                                                    size=marker_size,
                                                    pen=mkPen((255, 60, 255),
                                                              width=3))
        self.marker_dict[4]['button'] = self.ui.marker4Button
        self.marker_dict[4]['xlineedit'] = self.ui.marker4XPosLineEdit
        self.marker_dict[4]['ylineedit'] = self.ui.marker4YPosLineEdit
        #Disable auto-ranging the image (it feels strange when the zoom changes as you move markers around.)
        self.ui.imageView.getView().disableAutoRange()
        for d in self.marker_dict:
            marker = self.marker_dict[d]['marker']
            marker.setZValue(20)
            marker.hide()
            marker.sigRegionChanged.connect(self.markerMoved)
            self.ui.imageView.getView().addItem(marker)
            self.marker_dict[d]['button'].toggled.connect(self.enableMarker)
            curvepen = QPen(marker.pen)
            curvepen.setWidth(1)
            self.marker_dict[d]['xcurve'] = self.xLineoutPlot.plot(
                pen=curvepen)
            self.marker_dict[d]['ycurve'] = self.yLineoutPlot.plot(
                pen=curvepen)
            self.marker_dict[d]['xlineedit'].returnPressed.connect(
                self.markerPositionLineEditChanged)
            self.marker_dict[d]['ylineedit'].returnPressed.connect(
                self.markerPositionLineEditChanged)

        #Set up zoom buttons
        self.ui.zoomInButton.clicked.connect(self.zoomIn)
        self.ui.zoomOutButton.clicked.connect(self.zoomOut)
        self.ui.zoomToActualSizeButton.clicked.connect(self.zoomToActualSize)

        #Set up ROI buttons
        self.ui.setROIButton.clicked.connect(self.setROI)
        self.ui.resetROIButton.clicked.connect(self.resetROI)

    @pyqtSlot()
    def zoomIn(self):
        self.ui.imageView.getView().scaleBy((0.5, 0.5))

    @pyqtSlot()
    def zoomOut(self):
        self.ui.imageView.getView().scaleBy((2.0, 2.0))

    @pyqtSlot()
    def zoomToActualSize(self):
        if len(self.image_data) == 0:
            return
        self.ui.imageView.getView().setRange(xRange=(0,
                                                     self.image_data.shape[0]),
                                             yRange=(0,
                                                     self.image_data.shape[1]),
                                             padding=0.0)

    def disable_all_markers(self):
        for d in self.marker_dict:
            self.marker_dict[d]['button'].setChecked(False)
            self.marker_dict[d]['marker'].setPos((0, 0))

    @pyqtSlot(bool)
    def enableMarker(self, checked):
        any_markers_visible = False
        for d in self.marker_dict:
            marker = self.marker_dict[d]['marker']
            button = self.marker_dict[d]['button']
            any_markers_visible = any_markers_visible or button.isChecked()
            marker.setVisible(button.isChecked())
            self.markerMoved(d)
            self.marker_dict[d]['xcurve'].setVisible(button.isChecked())
            self.marker_dict[d]['ycurve'].setVisible(button.isChecked())
            self.marker_dict[d]['xlineedit'].setEnabled(button.isChecked())
            self.marker_dict[d]['ylineedit'].setEnabled(button.isChecked())
        if any_markers_visible:
            self.xLineoutPlot.show()
            self.yLineoutPlot.show()
        else:
            self.xLineoutPlot.hide()
            self.yLineoutPlot.hide()

    @pyqtSlot()
    def markerPositionLineEditChanged(self):
        for d in self.marker_dict:
            marker = self.marker_dict[d]['marker']
            x_line_edit = self.marker_dict[d]['xlineedit']
            y_line_edit = self.marker_dict[d]['ylineedit']
            try:
                new_x = int(x_line_edit.text())
                new_y = int(y_line_edit.text())
                if new_x <= marker.maxBounds.width(
                ) and new_y <= marker.maxBounds.height():
                    marker.setPos((new_x, new_y))
                    return
            except:
                pass
            coords = marker.getPixelCoords()
            x_line_edit.setText(str(coords[0]))
            y_line_edit.setText(str(coords[1]))

    @pyqtSlot(object)
    def markerMoved(self, marker):
        self.updateLineouts()
        for marker_index in self.marker_dict:
            marker = self.marker_dict[marker_index]['marker']
            x_line_edit = self.marker_dict[marker_index]['xlineedit']
            y_line_edit = self.marker_dict[marker_index]['ylineedit']
            coords = marker.getPixelCoords()
            x_line_edit.setText(str(coords[0]))
            y_line_edit.setText(str(coords[1]))

    @pyqtSlot(object, object)
    def updateLineoutRange(self, view, new_ranges):
        self.ui.xLineoutPlot.setRange(xRange=new_ranges[0], padding=0.0)
        self.ui.yLineoutPlot.setRange(yRange=new_ranges[1], padding=0.0)

    def updateLineouts(self):
        for marker_index in self.marker_dict:
            marker = self.marker_dict[marker_index]['marker']
            xcurve = self.marker_dict[marker_index]['xcurve']
            ycurve = self.marker_dict[marker_index]['ycurve']
            if marker.isVisible():
                result, coords = marker.getArrayRegion(
                    self.image_data, self.ui.imageView.getImageItem())
                xcurve.setData(y=result[0], x=np.arange(len(result[0])))
                ycurve.setData(y=np.arange(len(result[1])), x=result[1])

    @pyqtSlot()
    def enableSingleShotMode(self):
        self._average_mode_enabled = False
        self._average_buffer = np.ndarray(0)

    @pyqtSlot()
    def enableAverageMode(self):
        self._average_mode_enabled = True

    @pyqtSlot(str)
    def cameraChanged(self, new_camera):
        new_camera = str(new_camera)
        if self.imageChannel == self.cameras[new_camera]["image"]:
            return
        self.display_manager_window.close_widget_connections(self)
        self.disable_all_markers()
        self.initializeCamera(new_camera)
        self.display_manager_window.establish_widget_connections(self)

    def initializeCamera(self, new_camera):
        new_camera = str(new_camera)
        self._color_map_limit_sliders_need_config = True
        self.times = np.zeros(10)
        self.old_timestamp = 0
        self.image_width = 0  #current width (width of ROI)
        self.image_max_width = 0  #full width.  Only used to reset ROI to full.
        self.image_max_height = 0  #full height.  Only used to reset ROI to full.
        self.image_data = np.zeros(0)
        self._average_counter = 0
        self._average_buffer = np.ndarray(0)
        self._needs_auto_range = True
        self.imageChannel = self.cameras[new_camera]["image"]
        self.widthChannel = self.cameras[new_camera][
            "roi_width"] or self.cameras[new_camera]["max_width"]
        self.maxWidthChannel = self.cameras[new_camera]["max_width"]
        self.maxHeightChannel = self.cameras[new_camera]["max_height"]
        self.roiXChannel = self.cameras[new_camera]["roi_x"]
        self.roiYChannel = self.cameras[new_camera]["roi_y"]
        self.roiWidthChannel = self.cameras[new_camera]["roi_width"]
        self.roiHeightChannel = self.cameras[new_camera]["roi_height"]

        self._channels = [
            PyDMChannel(address=self.imageChannel,
                        connection_slot=self.connectionStateChanged,
                        waveform_slot=self.receiveImageWaveform,
                        severity_slot=self.alarmSeverityChanged),
            PyDMChannel(address=self.widthChannel,
                        value_slot=self.receiveImageWidth),
            PyDMChannel(address=self.maxWidthChannel,
                        value_slot=self.receiveMaxWidth),
            PyDMChannel(address=self.maxHeightChannel,
                        value_slot=self.receiveMaxHeight)
        ]
        if self.roiXChannel and self.roiYChannel and self.roiWidthChannel and self.roiHeightChannel:
            self._channels.extend([
                PyDMChannel(address=self.roiXChannel,
                            value_slot=self.receiveRoiX,
                            value_signal=self.roi_x_signal,
                            write_access_slot=self.roiWriteAccessChanged),
                PyDMChannel(address=self.roiYChannel,
                            value_slot=self.receiveRoiY,
                            value_signal=self.roi_y_signal),
                PyDMChannel(address=self.roiWidthChannel,
                            value_slot=self.receiveRoiWidth,
                            value_signal=self.roi_w_signal),
                PyDMChannel(address=self.roiHeightChannel,
                            value_slot=self.receiveRoiHeight,
                            value_signal=self.roi_h_signal)
            ])
            self.ui.roiXLineEdit.setEnabled(True)
            self.ui.roiYLineEdit.setEnabled(True)
            self.ui.roiWLineEdit.setEnabled(True)
            self.ui.roiHLineEdit.setEnabled(True)
        else:
            self.ui.roiXLineEdit.clear()
            self.ui.roiXLineEdit.setEnabled(False)
            self.ui.roiYLineEdit.clear()
            self.ui.roiYLineEdit.setEnabled(False)
            self.ui.roiWLineEdit.clear()
            self.ui.roiWLineEdit.setEnabled(False)
            self.ui.roiHLineEdit.clear()
            self.ui.roiHLineEdit.setEnabled(False)

    @pyqtSlot()
    def setROI(self):
        self.roi_x_signal.emit(self.ui.roiXLineEdit.text())
        self.roi_y_signal.emit(self.ui.roiYLineEdit.text())
        self.roi_w_signal.emit(self.ui.roiWLineEdit.text())
        self.roi_h_signal.emit(self.ui.roiHLineEdit.text())

    @pyqtSlot()
    def resetROI(self):
        self.roi_x_signal.emit(str(0))
        self.roi_y_signal.emit(str(0))
        self.roi_w_signal.emit(str(self.image_max_width))
        self.roi_h_signal.emit(str(self.image_max_height))

    @pyqtSlot(str)
    def colorMapChanged(self, new_map_name):
        self.ui.imageView.setColorMapToPreset(new_map_name)

    def configureColorMapLimitSliders(self, max_int):
        self.ui.colorMapMinSlider.setMaximum(max_int)
        self.ui.colorMapMaxSlider.setMaximum(max_int)
        self.ui.colorMapMaxSlider.setValue(max_int)
        self.ui.colorMapMinSlider.setValue(0)
        self.setColorMapMin(0)
        self.setColorMapMax(max_int)
        self._color_map_limit_sliders_need_config = False

    @pyqtSlot()
    def colorMapMinLineEditChanged(self):
        try:
            new_min = int(self.ui.colorMapMinLineEdit.text())
        except:
            self.ui.colorMapMinLineEdit.setText(
                str(self.ui.colorMapMinSlider.value()))
            return
        if new_min < 0:
            new_min = 0
        if new_min > self.ui.colorMapMinSlider.maximum():
            new_min = self.ui.colorMapMinSlider.maximum()
        self.ui.colorMapMinSlider.setValue(new_min)

    @pyqtSlot(int)
    def setColorMapMin(self, new_min):
        if new_min > self.ui.colorMapMaxSlider.value():
            self.ui.colorMapMaxSlider.setValue(new_min)
            self.ui.colorMapMaxLineEdit.setText(str(new_min))
        self.ui.colorMapMinLineEdit.setText(str(new_min))
        self.ui.imageView.setColorMapLimits(new_min,
                                            self.ui.colorMapMaxSlider.value())

    @pyqtSlot()
    def colorMapMaxLineEditChanged(self):
        try:
            new_max = int(self.ui.colorMapMaxLineEdit.text())
        except:
            self.ui.colorMapMaxLineEdit.setText(
                str(self.ui.colorMapMaxSlider.value()))
            return
        if new_max < 0:
            new_max = 0
        if new_max > self.ui.colorMapMaxSlider.maximum():
            new_max = self.ui.colorMapMaxSlider.maximum()
        self.ui.colorMapMaxSlider.setValue(new_max)

    @pyqtSlot(int)
    def setColorMapMax(self, new_max):
        if new_max < self.ui.colorMapMinSlider.value():
            self.ui.colorMapMinSlider.setValue(new_max)
            self.ui.colorMapMinLineEdit.setText(str(new_max))
        self.ui.colorMapMaxLineEdit.setText(str(new_max))
        self.ui.imageView.setColorMapLimits(self.ui.colorMapMinSlider.value(),
                                            new_max)

    def createAverageBuffer(self, size, type, initial_val=[]):
        num_shots = 1
        try:
            num_shots = int(self.ui.numShotsLineEdit.text())
        except:
            self.ui.numShotsLineEdit.setText(str(num_shots))
        if num_shots < 1:
            num_shots = 1
            self.ui.numShotsLineEdit.setText(str(num_shots))
        if num_shots > 200:
            num_shots = 200
            self.ui.numShotsLineEdit.setText(str(num_shots))
        if len(initial_val) > 0:
            return np.full((num_shots, size), initial_val, dtype=type)
        else:
            return np.zeros(shape=(num_shots, size), dtype=type)

    @pyqtSlot()
    def numAverageChanged(self):
        self._average_buffer = np.zeros(0)

    @pyqtSlot(np.ndarray)
    def receiveImageWaveform(self, new_waveform):
        if not self.image_width:
            return

        #Calculate the average rate
        new_timestamp = time.time()
        if not (self.old_timestamp == 0):
            delta = new_timestamp - self.old_timestamp
            self.times = np.roll(self.times, 1)
            self.times[0] = delta
            avg_delta = np.mean(self.times)
            self.ui.dataRateLabel.setText("{:.1f} Hz".format(
                (1.0 / avg_delta)))
            self.ui.displayRateLabel.setText("{:.1f} Hz".format(
                (1.0 / avg_delta)))
        self.old_timestamp = new_timestamp

        #If this is the first image, set up the color map slider limits
        if self._color_map_limit_sliders_need_config:
            max_int = np.iinfo(new_waveform.dtype).max
            self.configureColorMapLimitSliders(max_int)

        #If we are in average mode, add this image to the circular averaging buffer, otherwise just display it.
        if self._average_mode_enabled:
            if len(self._average_buffer) == 0:
                self._average_buffer = self.createAverageBuffer(
                    len(new_waveform), new_waveform.dtype, new_waveform)
                self._average_counter = 0
            self._average_counter = (self._average_counter + 1) % len(
                self._average_buffer)
            #self._average_buffer = np.roll(self._average_buffer, 1, axis=0)
            self._average_buffer[self._average_counter] = new_waveform
            mean = np.mean(self._average_buffer,
                           axis=0).astype(new_waveform.dtype)
            self.image_data = mean.reshape((int(self.image_width), -1),
                                           order='F')
        else:
            self.image_data = new_waveform.reshape((int(self.image_width), -1),
                                                   order='F')
        self.setMarkerBounds()
        self.updateLineouts()
        self.ui.imageView.receiveImageWaveform(self.image_data)
        self.calculateStats()
        if self._needs_auto_range:
            self.ui.imageView.getView().autoRange(padding=0.0)
            current_range = self.ui.imageView.getView().viewRange()
            self._needs_auto_range = False

    def calculateStats(self):
        # Full image stats
        mean = np.mean(self.image_data)
        std = np.std(self.image_data)
        width = self.image_data.shape[0]
        height = self.image_data.shape[1]
        min_val = np.min(self.image_data)
        max_val = np.max(self.image_data)
        self.ui.imageStatsLabel.setText(
            "Mean: {0:.2f}, Std: {1:.2f}, Min: {2}, Max: {3}, Width: {4}, Height: {5}"
            .format(mean, std, min_val, max_val, width, height))
        # Current view stats
        current_range = self.ui.imageView.getView().viewRange()
        view_x_min = int(max(0, current_range[0][0]))
        view_x_max = int(min(self.image_data.shape[0], current_range[0][1]))
        view_y_min = int(max(0, current_range[1][0]))
        view_y_max = int(min(self.image_data.shape[1], current_range[1][1]))
        view_slice = self.image_data[view_x_min:view_x_max,
                                     view_y_min:view_y_max]
        mean = np.mean(view_slice)
        std = np.std(view_slice)
        width = view_slice.shape[0]
        height = view_slice.shape[1]
        min_val = np.min(view_slice)
        max_val = np.max(view_slice)
        self.ui.viewStatsLabel.setText(
            "Mean: {0:.2f}, Std: {1:.2f}, Min: {2}, Max: {3}, Width: {4}, Height: {5}"
            .format(mean, std, min_val, max_val, width, height))

    def setMarkerBounds(self):
        for marker_index in self.marker_dict:
            marker = self.marker_dict[marker_index]['marker']
            marker.maxBounds = QRectF(
                0, 0, self.image_data.shape[0] + marker.size()[0] - 1,
                self.image_data.shape[1] + marker.size()[1] - 1)

    @pyqtSlot(int)
    def receiveImageWidth(self, new_width):
        self.image_width = new_width
        self.ui.imageView.receiveImageWidth(self.image_width)

    @pyqtSlot(int)
    def receiveMaxWidth(self, new_max_width):
        self.image_max_width = new_max_width

    @pyqtSlot(int)
    def receiveMaxHeight(self, new_max_height):
        self.image_max_height = new_max_height

    @pyqtSlot(int)
    def receiveRoiX(self, new_roi_x):
        self.ui.roiXLineEdit.setText(str(new_roi_x))

    @pyqtSlot(int)
    def receiveRoiY(self, new_roi_y):
        self.ui.roiYLineEdit.setText(str(new_roi_y))

    @pyqtSlot(int)
    def receiveRoiWidth(self, new_roi_w):
        self.ui.roiWLineEdit.setText(str(new_roi_w))

    @pyqtSlot(int)
    def receiveRoiHeight(self, new_roi_h):
        self.ui.roiHLineEdit.setText(str(new_roi_h))

    # -2 to +2, -2 is LOLO, -1 is LOW, 0 is OK, etc.
    @pyqtSlot(int)
    def alarmStatusChanged(self, new_alarm_state):
        pass

    #0 = NO_ALARM, 1 = MINOR, 2 = MAJOR, 3 = INVALID
    @pyqtSlot(int)
    def alarmSeverityChanged(self, new_alarm_severity):
        pass

    @pyqtSlot(bool)
    def roiWriteAccessChanged(self, can_write_roi):
        self.ui.setROIButton.setEnabled(can_write_roi)
        self.ui.resetROIButton.setEnabled(can_write_roi)
        self.ui.roiXLineEdit.setReadOnly(not can_write_roi)
        self.ui.roiYLineEdit.setReadOnly(not can_write_roi)
        self.ui.roiWLineEdit.setReadOnly(not can_write_roi)
        self.ui.roiHLineEdit.setReadOnly(not can_write_roi)

    #false = disconnected, true = connected
    @pyqtSlot(bool)
    def connectionStateChanged(self, connected):
        self.ui.connectedLabel.setText({True: "Yes", False: "No"}[connected])

    def ui_filename(self):
        return 'camviewer.ui'

    def ui_filepath(self):
        return path.join(path.dirname(path.realpath(__file__)),
                         self.ui_filename())

    def channels(self):
        return self._channels
コード例 #7
0
ファイル: mainWindow.py プロジェクト: YousseFSalaH0/Bio-Gene
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(963, 704)
        MainWindow.setStyleSheet("background-color: rgb(255, 255, 255);\n"
                                 "color: rgb(0, 0, 0);")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(False)
        font.setWeight(50)
        self.tabWidget.setFont(font)
        self.tabWidget.setStyleSheet("background-color: rgb(255, 255, 255);\n"
                                     "color: rgb(0, 0, 0);")
        self.tabWidget.setObjectName("tabWidget")
        self.tab_4 = QtWidgets.QWidget()
        self.tab_4.setObjectName("tab_4")
        self.gridLayout_5 = QtWidgets.QGridLayout(self.tab_4)
        self.gridLayout_5.setObjectName("gridLayout_5")
        self.msaOutputText_2 = QtWidgets.QTextBrowser(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(10)
        self.msaOutputText_2.setFont(font)
        self.msaOutputText_2.setStyleSheet("color: rgb(0, 0, 0);")
        self.msaOutputText_2.setObjectName("msaOutputText_2")
        self.gridLayout_5.addWidget(self.msaOutputText_2, 5, 0, 1, 3)
        self.resultBtn_4 = QtWidgets.QPushButton(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.resultBtn_4.setFont(font)
        self.resultBtn_4.setStyleSheet("background-color: rgb(255, 0, 0);\n"
                                       "color: rgb(255, 255, 255);")
        self.resultBtn_4.setObjectName("resultBtn_4")
        self.gridLayout_5.addWidget(self.resultBtn_4, 6, 2, 1, 1)
        self.browseBtn_5 = QtWidgets.QPushButton(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.browseBtn_5.setFont(font)
        self.browseBtn_5.setStyleSheet("background-color: rgb(255, 85, 0);\n"
                                       "color: rgb(255, 255, 255);")
        self.browseBtn_5.setObjectName("browseBtn_5")
        self.gridLayout_5.addWidget(self.browseBtn_5, 3, 0, 1, 1)
        self.browseBtn_4 = QtWidgets.QPushButton(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.browseBtn_4.setFont(font)
        self.browseBtn_4.setStyleSheet("background-color: rgb(85, 85, 255);\n"
                                       "color: rgb(255, 255, 255);")
        self.browseBtn_4.setObjectName("browseBtn_4")
        self.gridLayout_5.addWidget(self.browseBtn_4, 1, 0, 2, 1)
        self.filepathView_5 = QtWidgets.QLabel(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.filepathView_5.setFont(font)
        self.filepathView_5.setStyleSheet(
            "background-color: rgb(216, 216, 216);")
        self.filepathView_5.setObjectName("filepathView_5")
        self.gridLayout_5.addWidget(self.filepathView_5, 3, 1, 1, 2)
        self.comboBox_4 = QtWidgets.QComboBox(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(False)
        font.setWeight(50)
        self.comboBox_4.setFont(font)
        self.comboBox_4.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.comboBox_4.setObjectName("comboBox_4")
        self.comboBox_4.addItem("")
        self.comboBox_4.addItem("")
        self.comboBox_4.addItem("")
        self.gridLayout_5.addWidget(self.comboBox_4, 0, 0, 1, 3)
        self.filepathView_4 = QtWidgets.QLabel(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.filepathView_4.setFont(font)
        self.filepathView_4.setStyleSheet(
            "background-color: rgb(216, 216, 216);")
        self.filepathView_4.setObjectName("filepathView_4")
        self.gridLayout_5.addWidget(self.filepathView_4, 1, 1, 2, 2)
        self.tabWidget.addTab(self.tab_4, "")
        self.tab_3 = QtWidgets.QWidget()
        self.tab_3.setObjectName("tab_3")
        self.gridLayout_4 = QtWidgets.QGridLayout(self.tab_3)
        self.gridLayout_4.setObjectName("gridLayout_4")
        self.graphicsView = PlotWidget(self.tab_3)
        self.graphicsView.setStyleSheet("color: rgb(0, 0, 0);")
        self.graphicsView.setObjectName("graphicsView")
        ##
        self.graphicsView.hideAxis('bottom')
        self.graphicsView.hideAxis('left')
        self.graphicsView.setBackground("w")
        ##
        self.gridLayout_4.addWidget(self.graphicsView, 2, 2, 2, 2)
        self.resultBtn_3 = QtWidgets.QPushButton(self.tab_3)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.resultBtn_3.setFont(font)
        self.resultBtn_3.setStyleSheet("background-color: rgb(255, 0, 0);\n"
                                       "color: rgb(255, 255, 255);")
        self.resultBtn_3.setObjectName("resultBtn_3")
        self.gridLayout_4.addWidget(self.resultBtn_3, 4, 3, 1, 1)
        self.msaOutputText = QtWidgets.QTextBrowser(self.tab_3)
        font = QtGui.QFont()
        font.setPointSize(10)
        self.msaOutputText.setFont(font)
        self.msaOutputText.setStyleSheet("color: rgb(0, 0, 0);")
        self.msaOutputText.setObjectName("msaOutputText")
        self.gridLayout_4.addWidget(self.msaOutputText, 2, 0, 1, 2)
        self.comboBox_3 = QtWidgets.QComboBox(self.tab_3)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(False)
        font.setWeight(50)
        self.comboBox_3.setFont(font)
        self.comboBox_3.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.comboBox_3.setObjectName("comboBox_3")
        self.comboBox_3.addItem("")
        self.comboBox_3.addItem("")
        self.comboBox_3.addItem("")
        self.gridLayout_4.addWidget(self.comboBox_3, 0, 1, 1, 3)
        self.filepathView_3 = QtWidgets.QLabel(self.tab_3)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.filepathView_3.setFont(font)
        self.filepathView_3.setStyleSheet(
            "background-color: rgb(216, 216, 216);")
        self.filepathView_3.setObjectName("filepathView_3")
        self.gridLayout_4.addWidget(self.filepathView_3, 1, 1, 1, 3)
        self.browseBtn_3 = QtWidgets.QPushButton(self.tab_3)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.browseBtn_3.setFont(font)
        self.browseBtn_3.setStyleSheet("background-color: rgb(85, 85, 255);\n"
                                       "color: rgb(255, 255, 255);")
        self.browseBtn_3.setObjectName("browseBtn_3")
        self.gridLayout_4.addWidget(self.browseBtn_3, 0, 0, 2, 1)
        self.tabWidget.addTab(self.tab_3, "")
        self.tab = QtWidgets.QWidget()
        font = QtGui.QFont()
        font.setPointSize(8)
        self.tab.setFont(font)
        self.tab.setObjectName("tab")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.tab)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.textLabel = QtWidgets.QLabel(self.tab)
        self.textLabel.setMinimumSize(QtCore.QSize(200, 40))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.textLabel.setFont(font)
        self.textLabel.setStyleSheet("")
        self.textLabel.setObjectName("textLabel")
        self.gridLayout_2.addWidget(self.textLabel, 2, 0, 1, 1)
        self.inputTextView = QtWidgets.QPlainTextEdit(self.tab)
        font = QtGui.QFont()
        font.setFamily("Candara")
        font.setPointSize(14)
        self.inputTextView.setFont(font)
        self.inputTextView.setStyleSheet("color: rgb(0, 0, 0);")
        self.inputTextView.setObjectName("inputTextView")
        self.gridLayout_2.addWidget(self.inputTextView, 4, 0, 1, 3)
        self.resultBtn = QtWidgets.QPushButton(self.tab)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.resultBtn.setFont(font)
        self.resultBtn.setStyleSheet("background-color: rgb(255, 0, 0);\n"
                                     "color: rgb(255, 255, 255);")
        self.resultBtn.setObjectName("resultBtn")
        self.gridLayout_2.addWidget(self.resultBtn, 5, 2, 1, 1)
        self.textLabel_2 = QtWidgets.QLabel(self.tab)
        self.textLabel_2.setMinimumSize(QtCore.QSize(200, 40))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.textLabel_2.setFont(font)
        self.textLabel_2.setStyleSheet("")
        self.textLabel_2.setObjectName("textLabel_2")
        self.gridLayout_2.addWidget(self.textLabel_2, 5, 0, 1, 1)
        self.outputTextView = QtWidgets.QTextBrowser(self.tab)
        font = QtGui.QFont()
        font.setFamily("MS Sans Serif")
        font.setPointSize(14)
        self.outputTextView.setFont(font)
        self.outputTextView.setStyleSheet("color: rgb(0, 0, 0);")
        self.outputTextView.setObjectName("outputTextView")
        self.gridLayout_2.addWidget(self.outputTextView, 6, 0, 1, 3)
        self.comboBox = QtWidgets.QComboBox(self.tab)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.comboBox.setFont(font)
        self.comboBox.setStyleSheet("background-color: rgb(216, 216, 216);\n"
                                    "color: rgb(0, 0, 0);")
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.gridLayout_2.addWidget(self.comboBox, 2, 1, 1, 2)
        self.browseBtn = QtWidgets.QPushButton(self.tab)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.browseBtn.setFont(font)
        self.browseBtn.setStyleSheet("background-color: rgb(85, 85, 255);\n"
                                     "color: rgb(255, 255, 255);\n"
                                     "background-color: rgb(65, 65, 195);")
        self.browseBtn.setObjectName("browseBtn")
        self.gridLayout_2.addWidget(self.browseBtn, 3, 2, 1, 1)
        self.label = QtWidgets.QLabel(self.tab)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setStyleSheet("background-color: rgb(216, 216, 216);")
        self.label.setObjectName("label")
        self.gridLayout_2.addWidget(self.label, 3, 0, 1, 2)
        self.tabWidget.addTab(self.tab, "")
        self.tab_2 = QtWidgets.QWidget()
        self.tab_2.setObjectName("tab_2")
        self.gridLayout_3 = QtWidgets.QGridLayout(self.tab_2)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.resultBtn_2 = QtWidgets.QPushButton(self.tab_2)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.resultBtn_2.setFont(font)
        self.resultBtn_2.setStyleSheet("background-color: rgb(255, 0, 0);\n"
                                       "color: rgb(255, 255, 255);")
        self.resultBtn_2.setObjectName("resultBtn_2")
        self.gridLayout_3.addWidget(self.resultBtn_2, 4, 2, 1, 1)
        self.textLabel_4 = QtWidgets.QLabel(self.tab_2)
        self.textLabel_4.setMinimumSize(QtCore.QSize(200, 40))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.textLabel_4.setFont(font)
        self.textLabel_4.setStyleSheet("")
        self.textLabel_4.setObjectName("textLabel_4")
        self.gridLayout_3.addWidget(self.textLabel_4, 4, 0, 1, 1)
        self.textLabel_3 = QtWidgets.QLabel(self.tab_2)
        self.textLabel_3.setMinimumSize(QtCore.QSize(200, 40))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.textLabel_3.setFont(font)
        self.textLabel_3.setStyleSheet("\n" "")
        self.textLabel_3.setObjectName("textLabel_3")
        self.gridLayout_3.addWidget(self.textLabel_3, 0, 0, 1, 1)
        self.extractBtn = QtWidgets.QPushButton(self.tab_2)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.extractBtn.setFont(font)
        self.extractBtn.setStyleSheet("background-color: rgb(0, 0, 0);\n"
                                      "color: rgb(255, 255, 255);")
        self.extractBtn.setObjectName("extractBtn")
        self.gridLayout_3.addWidget(self.extractBtn, 6, 1, 1, 1)
        self.outputTextView_2 = QtWidgets.QTextBrowser(self.tab_2)
        font = QtGui.QFont()
        font.setFamily("MS Sans Serif")
        font.setPointSize(14)
        self.outputTextView_2.setFont(font)
        self.outputTextView_2.setStyleSheet("color: rgb(0, 0, 0);")
        self.outputTextView_2.setObjectName("outputTextView_2")
        self.gridLayout_3.addWidget(self.outputTextView_2, 5, 0, 1, 3)
        self.inputTextView_2 = QtWidgets.QPlainTextEdit(self.tab_2)
        font = QtGui.QFont()
        font.setFamily("Candara")
        font.setPointSize(14)
        self.inputTextView_2.setFont(font)
        self.inputTextView_2.setStyleSheet("color: rgb(0, 0, 0);")
        self.inputTextView_2.setObjectName("inputTextView_2")
        self.gridLayout_3.addWidget(self.inputTextView_2, 3, 0, 1, 3)
        self.browseBtn_2 = QtWidgets.QPushButton(self.tab_2)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.browseBtn_2.setFont(font)
        self.browseBtn_2.setStyleSheet("background-color: rgb(85, 85, 255);\n"
                                       "background-color: rgb(65, 65, 195);\n"
                                       "color: rgb(255, 255, 255);")
        self.browseBtn_2.setObjectName("browseBtn_2")
        self.gridLayout_3.addWidget(self.browseBtn_2, 1, 2, 1, 1)
        self.label_2 = QtWidgets.QLabel(self.tab_2)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("background-color: rgb(216, 216, 216);")
        self.label_2.setObjectName("label_2")
        self.gridLayout_3.addWidget(self.label_2, 1, 0, 1, 2)
        self.comboBox_2 = QtWidgets.QComboBox(self.tab_2)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.comboBox_2.setFont(font)
        self.comboBox_2.setStyleSheet("background-color: rgb(216, 216, 216);")
        self.comboBox_2.setObjectName("comboBox_2")
        self.comboBox_2.addItem("")
        self.comboBox_2.addItem("")
        self.comboBox_2.addItem("")
        self.comboBox_2.addItem("")
        self.comboBox_2.setItemText(3, "")
        self.comboBox_2.addItem("")
        self.comboBox_2.setItemText(4, "")
        self.gridLayout_3.addWidget(self.comboBox_2, 0, 1, 1, 2)
        self.tabWidget.addTab(self.tab_2, "")
        self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.resultBtn_4.setText(_translate("MainWindow", "Result"))
        self.browseBtn_5.setText(_translate("MainWindow", "File"))
        self.browseBtn_4.setText(_translate("MainWindow", "File"))
        self.filepathView_5.setText(_translate("MainWindow", "---"))
        self.comboBox_4.setItemText(0, _translate("MainWindow",
                                                  "Choose Method"))
        self.comboBox_4.setItemText(
            1, _translate("MainWindow", "Global Alignment"))
        self.comboBox_4.setItemText(
            2, _translate("MainWindow", "Local Alignment"))
        self.filepathView_4.setText(_translate("MainWindow", "---"))
        self.tabWidget.setTabText(
            self.tabWidget.indexOf(self.tab_4),
            _translate("MainWindow", "Pairwise Sequence Alignment"))
        self.resultBtn_3.setText(_translate("MainWindow", "Result"))
        self.comboBox_3.setItemText(0, _translate("MainWindow",
                                                  "Choose Method"))
        self.comboBox_3.setItemText(
            1, _translate("MainWindow", "Sequence Alignment"))
        self.comboBox_3.setItemText(
            2, _translate("MainWindow", "Phylogenetic Tree"))
        self.filepathView_3.setText(_translate("MainWindow", "---"))
        self.browseBtn_3.setText(_translate("MainWindow", "File"))
        self.tabWidget.setTabText(
            self.tabWidget.indexOf(self.tab_3),
            _translate("MainWindow", "Multiple Sequence Alignment"))
        self.textLabel.setText(_translate("MainWindow", "Text or a file"))
        self.resultBtn.setText(_translate("MainWindow", "Result"))
        self.textLabel_2.setText(_translate("MainWindow", "Output"))
        self.comboBox.setItemText(0, _translate("MainWindow", "Choose Type"))
        self.comboBox.setItemText(1, _translate("MainWindow", "DNA"))
        self.comboBox.setItemText(2, _translate("MainWindow", "RNA"))
        self.comboBox.setItemText(3, _translate("MainWindow", "Protein"))
        self.browseBtn.setText(_translate("MainWindow", "File"))
        self.label.setText(_translate("MainWindow", "---"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab),
                                  _translate("MainWindow", "Calculations"))
        self.resultBtn_2.setText(_translate("MainWindow", "Result"))
        self.textLabel_4.setText(_translate("MainWindow", "Output"))
        self.textLabel_3.setText(_translate("MainWindow", "Text or a file"))
        self.extractBtn.setText(_translate("MainWindow", "Extract File"))
        self.browseBtn_2.setText(_translate("MainWindow", "File"))
        self.label_2.setText(_translate("MainWindow", "---"))
        self.comboBox_2.setItemText(0, _translate("MainWindow",
                                                  "Choose Method"))
        self.comboBox_2.setItemText(1, _translate("MainWindow", "Transcribe"))
        self.comboBox_2.setItemText(2, _translate("MainWindow", "Translate"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2),
                                  _translate("MainWindow", "Conversions"))
コード例 #8
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(829, 821)
        MainWindow.setStyleSheet("background-color: rgb(255, 255, 255);\n"
"\n"
"\n"
"\n"
"\n"
"")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout_6 = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout_6.setObjectName("gridLayout_6")
        self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.tabWidget.setFont(font)
        self.tabWidget.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.tabWidget.setObjectName("tabWidget")
        self.tab = QtWidgets.QWidget()
        self.tab.setObjectName("tab")
        self.gridLayout_8 = QtWidgets.QGridLayout(self.tab)
        self.gridLayout_8.setObjectName("gridLayout_8")
        self.showResult = QtWidgets.QPushButton(self.tab)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.showResult.setFont(font)
        self.showResult.setStyleSheet("color: rgb(255, 255, 255);\n"
"background-color: rgb(85, 85, 255);\n"
"")
        self.showResult.setObjectName("showResult")
        self.gridLayout_8.addWidget(self.showResult, 3, 0, 1, 1)
        self.label_3 = QtWidgets.QLabel(self.tab)
        self.label_3.setStyleSheet("font: 14pt \"MS Shell Dlg 2\";")
        self.label_3.setAlignment(QtCore.Qt.AlignCenter)
        self.label_3.setObjectName("label_3")
        self.gridLayout_8.addWidget(self.label_3, 1, 0, 1, 1)
        self.gridLayout_7 = QtWidgets.QGridLayout()
        self.gridLayout_7.setObjectName("gridLayout_7")
        self.label_2 = QtWidgets.QLabel(self.tab)
        self.label_2.setMaximumSize(QtCore.QSize(150, 16777215))
        self.label_2.setStyleSheet("font: 10pt \"MS Shell Dlg 2\";")
        self.label_2.setObjectName("label_2")
        self.gridLayout_7.addWidget(self.label_2, 0, 0, 1, 1)
        self.browseButton = QtWidgets.QPushButton(self.tab)
        self.browseButton.setMaximumSize(QtCore.QSize(100, 16777215))
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.browseButton.setFont(font)
        self.browseButton.setStyleSheet("color: rgb(255, 255, 255);\n"
"background-color: rgb(85, 85, 255);\n"
"border-color: rgb(85, 85, 255);\n"
"gridline-color: rgb(85, 85, 255);\n"
"")
        self.browseButton.setObjectName("browseButton")
        self.gridLayout_7.addWidget(self.browseButton, 0, 1, 1, 1)
        self.soundRecogniserOuput = QtWidgets.QTextBrowser(self.tab)
        self.soundRecogniserOuput.setMaximumSize(QtCore.QSize(16777215, 16777215))
        self.soundRecogniserOuput.setStyleSheet("color: rgb(85, 85, 255);\n"
"border-color: rgb(85, 85, 255);")
        self.soundRecogniserOuput.setObjectName("soundRecogniserOuput")
        self.gridLayout_7.addWidget(self.soundRecogniserOuput, 1, 0, 2, 1)
        self.recordingButton = QtWidgets.QPushButton(self.tab)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.recordingButton.setFont(font)
        self.recordingButton.setStyleSheet("background-color: rgb(255, 0, 4);\n"
"color: rgb(255, 255, 255);")
        self.recordingButton.setObjectName("recordingButton")
        self.gridLayout_7.addWidget(self.recordingButton, 1, 1, 1, 1)
        self.playButton = QtWidgets.QPushButton(self.tab)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.playButton.setFont(font)
        self.playButton.setStyleSheet("background-color: rgb(0, 0, 0);\n"
"color: rgb(255, 255, 255);")
        self.playButton.setObjectName("playButton")
        self.gridLayout_7.addWidget(self.playButton, 2, 1, 1, 1)
        self.gridLayout_8.addLayout(self.gridLayout_7, 0, 0, 1, 1)
        self.soundRecogniserOuput_2 = QtWidgets.QTableWidget(self.tab)
        self.soundRecogniserOuput_2.setObjectName("soundRecogniserOuput_2")
        self.soundRecogniserOuput_2.setColumnCount(0)
        self.soundRecogniserOuput_2.setRowCount(0)
        self.gridLayout_8.addWidget(self.soundRecogniserOuput_2, 2, 0, 1, 1)
        self.tabWidget.addTab(self.tab, "")
        self.tab_3 = QtWidgets.QWidget()
        self.tab_3.setObjectName("tab_3")
        self.gridLayout_5 = QtWidgets.QGridLayout(self.tab_3)
        self.gridLayout_5.setObjectName("gridLayout_5")
        self.gridLayout_4 = QtWidgets.QGridLayout()
        self.gridLayout_4.setObjectName("gridLayout_4")
        self.plottingGraph = PlotWidget(self.tab_3)
        self.plottingGraph.setStyleSheet("border-color: rgb(0, 0, 0);")
        self.plottingGraph.setObjectName("plottingGraph")
        self.plottingGraph.hideAxis('bottom')
        self.plottingGraph.hideAxis('left')
        self.plottingGraph.setBackground('w')
        self.plottingGraph.setStyleSheet( "border:1px solid rgb(0, 0, 0);")
        self.gridLayout_4.addWidget(self.plottingGraph, 1, 0, 1, 1)
        self.comboBox = QtWidgets.QComboBox(self.tab_3)
        font = QtGui.QFont()
        font.setPointSize(11)
        font.setBold(True)
        font.setWeight(75)
        self.comboBox.setFont(font)
        self.comboBox.setStyleSheet("color: rgb(85, 85, 255);")
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.gridLayout_4.addWidget(self.comboBox, 0, 0, 1, 1)
        self.gridLayout_5.addLayout(self.gridLayout_4, 0, 0, 1, 1)
        self.tabWidget.addTab(self.tab_3, "")
        self.tab_2 = QtWidgets.QWidget()
        self.tab_2.setObjectName("tab_2")
        self.gridLayout_13 = QtWidgets.QGridLayout(self.tab_2)
        self.gridLayout_13.setObjectName("gridLayout_13")
        self.browseButton_2 = QtWidgets.QPushButton(self.tab_2)
        self.browseButton_2.setMaximumSize(QtCore.QSize(16777215, 16777215))
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.browseButton_2.setFont(font)
        self.browseButton_2.setStyleSheet("color: rgb(255, 255, 255);\n"
"background-color: rgb(85, 85, 255);\n"
"border-color: rgb(85, 85, 255);\n"
"gridline-color: rgb(85, 85, 255);\n"
"")
        self.browseButton_2.setObjectName("browseButton_2")
        self.gridLayout_13.addWidget(self.browseButton_2, 0, 1, 1, 1)
        self.gridLayout_11 = QtWidgets.QGridLayout()
        self.gridLayout_11.setObjectName("gridLayout_11")
        self.horizontalSlider_1 = QtWidgets.QSlider(self.tab_2)
        self.horizontalSlider_1.setOrientation(QtCore.Qt.Horizontal)
        self.horizontalSlider_1.setObjectName("horizontalSlider_1")
        self.horizontalSlider_1.setMaximum(100)
        self.gridLayout_11.addWidget(self.horizontalSlider_1, 1, 2, 1, 1)
        self.label_13 = QtWidgets.QLabel(self.tab_2)
        self.label_13.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";")
        self.label_13.setAlignment(QtCore.Qt.AlignRight)
        self.label_13.setObjectName("label_13")
        self.gridLayout_11.addWidget(self.label_13, 0, 1, 1, 1)
        self.songval = QtWidgets.QLabel(self.tab_2)
        self.songval.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";")
        self.songval.setText("")
        self.songval.setObjectName("songval")
        self.gridLayout_11.addWidget(self.songval, 0, 2, 1, 1)
        # self.label_9 = QtWidgets.QLabel(self.tab_2)
        # self.label_9.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";")
        # self.label_9.setObjectName("label_9")
        # self.gridLayout_11.addWidget(self.label_9, 0, 0, 1, 1)
        self.gridLayout_13.addLayout(self.gridLayout_11, 0, 0, 1, 1)
        self.gridLayout_10 = QtWidgets.QGridLayout()
        self.gridLayout_10.setObjectName("gridLayout_10")
        self.spectogrambutton = QtWidgets.QPushButton(self.tab_2)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.spectogrambutton.setFont(font)
        self.spectogrambutton.setStyleSheet("color: rgb(255, 255, 255);\n"
"background-color: rgb(85, 85, 255);\n"
"")
        self.spectogrambutton.setObjectName("spectogrambutton")
        self.gridLayout_10.addWidget(self.spectogrambutton, 2, 0, 1, 1)
        self.showResult_2 = QtWidgets.QPushButton(self.tab_2)
        
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.showResult_2.setFont(font)
        self.showResult_2.setStyleSheet("color: rgb(255, 255, 255);\n"
"background-color: rgb(85, 85, 255);\n"
"")
        self.showResult_2.setObjectName("showResult_2")
        self.gridLayout_10.addWidget(self.showResult_2, 1, 0, 1, 1)
        self.soundRecogniserOuput_3 = QtWidgets.QTableWidget(self.tab)
        self.soundRecogniserOuput_3.setObjectName("soundRecogniserOuput_3")
        self.soundRecogniserOuput_3.setColumnCount(0)
        self.soundRecogniserOuput_3.setRowCount(0)
        self.gridLayout_10.addWidget(self.soundRecogniserOuput_3, 0, 0, 1, 1)
        self.gridLayout_13.addLayout(self.gridLayout_10, 4, 0, 1, 2)
        self.browseButton_3= QtWidgets.QPushButton(self.tab_2)
        self.browseButton_3.setMaximumSize(QtCore.QSize(16777215, 16777215))
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.browseButton_3.setFont(font)
        self.browseButton_3.setStyleSheet("color: rgb(255, 255, 255);\n"
"background-color: rgb(85, 85, 255);\n"
"border-color: rgb(85, 85, 255);\n"
"gridline-color: rgb(85, 85, 255);\n"
"")
        self.browseButton_3.setObjectName("browseButton_3")
        self.gridLayout_13.addWidget(self.browseButton_3, 2, 1, 2, 1)
        self.gridLayout_12 = QtWidgets.QGridLayout()
        self.gridLayout_12.setObjectName("gridLayout_12")
        self.label_10 = QtWidgets.QLabel(self.tab_2)
        self.label_10.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";")
        self.label_10.setText("")
        self.label_10.setObjectName("label_10")
        self.gridLayout_12.addWidget(self.label_10, 0, 2, 1, 1)
        # self.label_11 = QtWidgets.QLabel(self.tab_2)
        # self.label_11.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";")
        # self.label_11.setObjectName("label_11")
        # self.gridLayout_12.addWidget(self.label_11, 0, 0, 1, 1)
        self.label_14 = QtWidgets.QLabel(self.tab_2)
        self.label_14.setStyleSheet("font: 75 12pt \"MS Shell Dlg 2\";")
        self.label_14.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.label_14.setObjectName("label_14")
        self.gridLayout_12.addWidget(self.label_14, 0, 1, 1, 1)
        self.horizontalSlider_2 = QtWidgets.QLabel(self.tab_2)
        self.horizontalSlider_2.setObjectName("horizontalSlider_2")
        self.gridLayout_12.addWidget(self.horizontalSlider_2, 1, 2, 1, 1)
        self.gridLayout_13.addLayout(self.gridLayout_12, 2, 0, 1, 1)
        self.tabWidget.addTab(self.tab_2, "")
        self.tab_4 = QtWidgets.QWidget()
        self.tab_4.setObjectName("tab_4")
        self.gridLayout_9 = QtWidgets.QGridLayout(self.tab_4)
        self.gridLayout_9.setObjectName("gridLayout_9")
        self.label_5 = QtWidgets.QLabel(self.tab_4)
        self.label_5.setMaximumSize(QtCore.QSize(120, 16777215))
        self.label_5.setText("")
        self.label_5.setObjectName("label_5")
        self.gridLayout_9.addWidget(self.label_5, 0, 2, 1, 1)
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.plottingGraph_2 = PlotWidget(self.tab_4)
        self.plottingGraph_2.setStyleSheet("border-color: rgb(0, 0, 0);")
        self.plottingGraph_2.setObjectName("plottingGraph_2")
        self.plottingGraph_2.hideAxis('bottom')
        self.plottingGraph_2.hideAxis('left')
        self.plottingGraph_2.setBackground('w')
        self.plottingGraph_2.setStyleSheet( "border:1px solid rgb(0, 0, 0);")
        self.gridLayout.addWidget(self.plottingGraph_2, 1, 0, 1, 1)
        self.plottingGraph_3 = PlotWidget(self.tab_4)
        self.plottingGraph_3.setStyleSheet("border-color: rgb(0, 0, 0);")
        self.plottingGraph_3.setObjectName("plottingGraph_3")
        self.plottingGraph_3.hideAxis('bottom')
        self.plottingGraph_3.hideAxis('left')
        self.plottingGraph_3.setBackground('w')
        self.plottingGraph_3.setStyleSheet( "border:1px solid rgb(0, 0, 0);")
        self.gridLayout.addWidget(self.plottingGraph_3, 1, 1, 1, 1)
        self.label_8 = QtWidgets.QLabel(self.tab_4)
        self.label_8.setStyleSheet("font: 14pt \"MS Shell Dlg 2\";")
        self.label_8.setAlignment(QtCore.Qt.AlignCenter)
        self.label_8.setObjectName("label_8")
        self.gridLayout.addWidget(self.label_8, 0, 1, 1, 1)
        self.label_7 = QtWidgets.QLabel(self.tab_4)
        self.label_7.setStyleSheet("font: 14pt \"MS Shell Dlg 2\";")
        self.label_7.setAlignment(QtCore.Qt.AlignCenter)
        self.label_7.setObjectName("label_7")
        self.gridLayout.addWidget(self.label_7, 0, 0, 1, 1)
        self.gridLayout_9.addLayout(self.gridLayout, 1, 0, 1, 3)
        self.label_4 = QtWidgets.QLabel(self.tab_4)
        self.label_4.setMaximumSize(QtCore.QSize(120, 16777215))
        self.label_4.setText("")
        self.label_4.setObjectName("label_4")
        self.gridLayout_9.addWidget(self.label_4, 0, 0, 1, 1)
        self.gridLayout_2 = QtWidgets.QGridLayout()
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.mixpausebutton = QtWidgets.QPushButton(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.mixpausebutton.setFont(font)
        self.mixpausebutton.setStyleSheet("background-color: rgb(255, 214, 62);\n"
"\n"
"color: rgb(255, 255, 255);")
        self.mixpausebutton.setObjectName("mixpausebutton")
        self.gridLayout_2.addWidget(self.mixpausebutton, 0, 0, 1, 1)
        self.mixplaybutton = QtWidgets.QPushButton(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.mixplaybutton.setFont(font)
        self.mixplaybutton.setStyleSheet("background-color: rgb(0, 170, 0);\n"
"color: rgb(255, 255, 255);")
        self.mixplaybutton.setObjectName("mixplaybutton")
        self.gridLayout_2.addWidget(self.mixplaybutton, 0, 1, 1, 1)
        self.mixstopbutton = QtWidgets.QPushButton(self.tab_4)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.mixstopbutton.setFont(font)
        self.mixstopbutton.setStyleSheet("background-color: rgb(255, 0, 4);\n"
"color: rgb(255, 255, 255);")
        self.mixstopbutton.setObjectName("mixstopbutton")
        self.gridLayout_2.addWidget(self.mixstopbutton, 0, 2, 1, 1)
        self.gridLayout_9.addLayout(self.gridLayout_2, 3, 0, 1, 3)
        self.gridLayout_3 = QtWidgets.QGridLayout()
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.label_6 = QtWidgets.QLabel(self.tab_4)
        self.label_6.setStyleSheet("font: 14pt \"MS Shell Dlg 2\";")
        self.label_6.setAlignment(QtCore.Qt.AlignCenter)
        self.label_6.setObjectName("label_6")
        self.gridLayout_3.addWidget(self.label_6, 0, 0, 1, 1)
        self.plottingGraph_4 = PlotWidget(self.tab_4)
        self.plottingGraph_4.setStyleSheet("border-color: rgb(0, 0, 0);")
        self.plottingGraph_4.setObjectName("plottingGraph_4")
        self.plottingGraph_4.hideAxis('bottom')
        self.plottingGraph_4.hideAxis('left')
        self.plottingGraph_4.setBackground('w')
        self.plottingGraph_4.setStyleSheet( "border:1px solid rgb(0, 0, 0);")
        self.gridLayout_3.addWidget(self.plottingGraph_4, 1, 0, 1, 1)
        self.gridLayout_9.addLayout(self.gridLayout_3, 2, 0, 1, 3)
        self.label = QtWidgets.QLabel(self.tab_4)
        self.label.setText("")
        self.label.setObjectName("label")
        self.gridLayout_9.addWidget(self.label, 0, 1, 1, 1)
        self.tabWidget.addTab(self.tab_4, "")
        self.gridLayout_6.addWidget(self.tabWidget, 0, 1, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.showResult.setText(_translate("MainWindow", "Show Result"))
        self.label_3.setText(_translate("MainWindow", "SIMILAR SONGS"))
        self.label_2.setText(_translate("MainWindow", "SONG INFO:"))
        self.browseButton.setText(_translate("MainWindow", "Browse"))
        self.recordingButton.setText(_translate("MainWindow", "Record"))
        self.playButton.setText(_translate("MainWindow", "Play"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Sound Recogniser"))
        self.comboBox.setItemText(0, _translate("MainWindow", "Choose Spectrogram"))
        self.comboBox.setItemText(1, _translate("MainWindow", "Browsed audio"))
        self.comboBox.setItemText(2, _translate("MainWindow", "Recorded Audio"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_3), _translate("MainWindow", "Spectrogram"))
        self.browseButton_2.setText(_translate("MainWindow", "SONG 1 Browse"))
        self.label_13.setText(_translate("MainWindow", "Mixing Slider Value:"))
        # self.label_9.setText(_translate("MainWindow", "SONG 1"))
        self.spectogrambutton.setText(_translate("MainWindow", "Spectogram"))
        self.showResult_2.setText(_translate("MainWindow", "Show Result"))
        self.browseButton_3.setText(_translate("MainWindow", "SONG 2 Browse"))
        # self.label_11.setText(_translate("MainWindow", "SONG 2"))
        self.label_14.setText(_translate("MainWindow", ""))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Mixer"))
        self.label_8.setText(_translate("MainWindow", "SONG 2 SPECTOGRAM"))
        self.label_7.setText(_translate("MainWindow", "SONG 1 SPECTOGRAM"))
        self.mixpausebutton.setText(_translate("MainWindow", "PAUSE"))
        self.mixplaybutton.setText(_translate("MainWindow", "PLAY"))
        self.mixstopbutton.setText(_translate("MainWindow", "STOP"))
        self.label_6.setText(_translate("MainWindow", "MIXED SPECTROGRAM"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_4), _translate("MainWindow", "Mixer Spectogram"))