示例#1
0
    def __init__(self, max_n, parent=None, **kwargs):
        super(BMDemo, self).__init__(parent=parent)
        self.setWindowTitle('Curve benchmark')
        tabs = QTabWidget()
        self.setCentralWidget(tabs)
        contents = BMText()
        tabs.addTab(contents, 'Contents')
        self.resize(1000, 600)

        # Force window to show up and refresh (for test purpose only)
        self.show()
        QApplication.processEvents()

        t0g = time.time()
        for idx in range(4, -1, -1):
            points = max_n/10**idx
            t0 = time.time()
            widget = BMWidget(points)
            title = '%d points' % points
            tabs.addTab(widget, title)
            tabs.setCurrentWidget(widget)

            # Force widget to refresh (for test purpose only)
            QApplication.processEvents()

            time_str = "Elapsed time: %d ms" % ((time.time()-t0)*1000)
            widget.text.setText(time_str)
            contents.append("<br><i>%s:</i><br>%s" % (title, time_str))
        dt = time.time()-t0g
        contents.append("<br><br><u>Total elapsed time</u>: %d ms" % (dt*1000))
        tabs.setCurrentIndex(0)
示例#2
0
    def __init__(self, max_n, parent=None, **kwargs):
        super(BMDemo, self).__init__(parent=parent)
        self.setWindowTitle('Curve styles')
        tabs = QTabWidget()
        self.resize(1000, 800)

        # Force window to show up and refresh (for test purpose only)
        self.show()
        QApplication.processEvents()

        self.setCentralWidget(tabs)
        pts = 1000
        for points, symbols in zip((pts / 10, pts / 10, pts, pts),
                                   (True, False) * 2):
            t0 = time.time()
            widget = CSWidget(points, symbols)
            symtext = "with%s symbols" % ("" if symbols else "out")
            title = '%d points, %s' % (points, symtext)
            tabs.addTab(widget, title)
            tabs.setCurrentWidget(widget)

            # Force widget to refresh (for test purpose only)
            QApplication.processEvents()

            time_str = "Elapsed time: %d ms" % ((time.time() - t0) * 1000)
            widget.text.setText(time_str)
        tabs.setCurrentIndex(0)
示例#3
0
    def __init__(self, max_n, parent=None, **kwargs):
        super(BMDemo, self).__init__(parent=parent)
        self.setWindowTitle('Curve styles')
        tabs = QTabWidget()
        self.resize(1000, 800)
        
        # Force window to show up and refresh (for test purpose only)
        self.show()
        QApplication.processEvents()

        self.setCentralWidget(tabs)
        pts = 1000
        for points, symbols in zip((pts/10, pts/10, pts, pts),
                                   (True, False)*2):
            t0 = time.time()
            widget = CSWidget(points, symbols)
            symtext = "with%s symbols" % ("" if symbols else "out")
            title = '%d points, %s' % (points, symtext)
            tabs.addTab(widget, title)
            tabs.setCurrentWidget(widget)

            # Force widget to refresh (for test purpose only)
            QApplication.processEvents()

            time_str = "Elapsed time: %d ms" % ((time.time()-t0)*1000)
            widget.text.setText(time_str)
        tabs.setCurrentIndex(0)
示例#4
0
    def __init__(self, parent=None, name=None, num_curves=16, plot_label=None):
        QMainWindow.__init__(self, parent)

        # ChartPlot strip charts will be displayed via a tab widget
        self._tabwidget = QTabWidget(self)
        self._tab_resized = False
        self._num_curves = num_curves
        self._plot_label = plot_label
        self._result_range = None
        self._png_number = 0
        self._grab_name = ''

        # create control menu
        self._menu = ControlMenu(self)
        # create a dictionary of chart plot objects
        self._ChartPlot = {}
        self._click_on = "If you click on an individual stripchart with the <b>middle</b> mouse button, a popup window will appear that gives a more detailed plot of the data from that particular object. <br><br> Clicking with the <b>left</b> mouse button will cause a small popup to appear. The popup gives the actual X and Y values, corrected for offset, of the data point nearest to the location of the mouse.<br><br> Clicking with the <b>right</b> mouse button will cause a context menu to appear. The <b>Accumulate data tracks</b> option means that data in each tile will be appended to the previous data. If this option is unchecked, data will be displayed for just each individual tile. The <b>Data element selector</b> option works similarly to that associated with the standard 2-D plot display. Clicking on it causes a small submenu to appear that allows you to select different data elements for display."

        # connect menu signals
        self._menu.save_this.triggered.connect(self.save_current_display)
        self._menu.save_all.triggered.connect(self.save_all_displays)
示例#5
0
    def __init__(self, max_n, parent=None, **kwargs):
        super(BMDemo, self).__init__(parent=parent)
        title = self.TITLE
        if kwargs.get('only_lines', False):
            title = '%s (%s)' % (title, 'only lines')
        self.setWindowTitle(title)
        self.tabs = QTabWidget()
        self.setCentralWidget(self.tabs)
        self.text = BMText(self)
        self.tabs.addTab(self.text, 'Contents')
        self.resize(*self.SIZE)

        # Force window to show up and refresh (for test purpose only)
        self.show()
        QApplication.processEvents()

        t0g = time.time()
        self.run_benchmark(max_n, **kwargs)
        dt = time.time() - t0g
        self.text.append("<br><br><u>Total elapsed time</u>: %d ms" %
                         (dt * 1e3))
        self.tabs.setCurrentIndex(0)
示例#6
0
class BMDemo(QMainWindow):
    TITLE = 'Curve benchmark'
    SIZE = (1000, 800)

    def __init__(self, max_n, parent=None, **kwargs):
        super(BMDemo, self).__init__(parent=parent)
        title = self.TITLE
        if kwargs.get('only_lines', False):
            title = '%s (%s)' % (title, 'only lines')
        self.setWindowTitle(title)
        self.tabs = QTabWidget()
        self.setCentralWidget(self.tabs)
        self.text = BMText(self)
        self.tabs.addTab(self.text, 'Contents')
        self.resize(*self.SIZE)

        # Force window to show up and refresh (for test purpose only)
        self.show()
        QApplication.processEvents()

        t0g = time.time()
        self.run_benchmark(max_n, **kwargs)
        dt = time.time() - t0g
        self.text.append("<br><br><u>Total elapsed time</u>: %d ms" %
                         (dt * 1e3))
        self.tabs.setCurrentIndex(0)

    def process_iteration(self, title, description, widget, t0):
        self.tabs.addTab(widget, title)
        self.tabs.setCurrentWidget(widget)

        # Force widget to refresh (for test purpose only)
        QApplication.processEvents()

        time_str = "Elapsed time: %d ms" % ((time.time() - t0) * 1000)
        widget.text.setText(time_str)
        self.text.append("<br><i>%s:</i><br>%s" % (description, time_str))

    def run_benchmark(self, max_n, **kwargs):
        for idx in range(4, -1, -1):
            points = max_n / 10**idx
            t0 = time.time()
            widget = BMWidget(points, **kwargs)
            title = '%d points' % points
            description = '%d plots with %d curves of %d points' % (
                widget.plot_nb, widget.curve_nb, points)
            self.process_iteration(title, description, widget, t0)
示例#7
0
class BMDemo(QMainWindow):
    TITLE = 'Curve benchmark'
    SIZE = (1000, 800)
    def __init__(self, max_n, parent=None, **kwargs):
        super(BMDemo, self).__init__(parent=parent)
        title = self.TITLE
        if kwargs.get('only_lines', False):
            title = '%s (%s)' % (title, 'only lines')
        self.setWindowTitle(title)
        self.tabs = QTabWidget()
        self.setCentralWidget(self.tabs)
        self.text = BMText(self)
        self.tabs.addTab(self.text, 'Contents')
        self.resize(*self.SIZE)

        # Force window to show up and refresh (for test purpose only)
        self.show()
        QApplication.processEvents()
        
        t0g = time.time()
        self.run_benchmark(max_n, **kwargs)
        dt = time.time()-t0g
        self.text.append("<br><br><u>Total elapsed time</u>: %d ms" % (dt*1e3))
        self.tabs.setCurrentIndex(0)
        
    def process_iteration(self, title, description, widget, t0):
        self.tabs.addTab(widget, title)
        self.tabs.setCurrentWidget(widget)

        # Force widget to refresh (for test purpose only)
        QApplication.processEvents()

        time_str = "Elapsed time: %d ms" % ((time.time()-t0)*1000)
        widget.text.setText(time_str)
        self.text.append("<br><i>%s:</i><br>%s" % (description, time_str))

    def run_benchmark(self, max_n, **kwargs):
        for idx in range(4, -1, -1):
            points = max_n/10**idx
            t0 = time.time()
            widget = BMWidget(points, **kwargs)
            title = '%d points' % points
            description = '%d plots with %d curves of %d points' % (
                          widget.plot_nb, widget.curve_nb, points)
            self.process_iteration(title, description, widget, t0)
示例#8
0
    def __init__(self, max_n, parent=None, **kwargs):
        super(BMDemo, self).__init__(parent=parent)
        title = self.TITLE
        if kwargs.get('only_lines', False):
            title = '%s (%s)' % (title, 'only lines')
        self.setWindowTitle(title)
        self.tabs = QTabWidget()
        self.setCentralWidget(self.tabs)
        self.text = BMText(self)
        self.tabs.addTab(self.text, 'Contents')
        self.resize(*self.SIZE)

        # Force window to show up and refresh (for test purpose only)
        self.show()
        QApplication.processEvents()
        
        t0g = time.time()
        self.run_benchmark(max_n, **kwargs)
        dt = time.time()-t0g
        self.text.append("<br><br><u>Total elapsed time</u>: %d ms" % (dt*1e3))
        self.tabs.setCurrentIndex(0)
示例#9
0
class DisplayMainWindow(QMainWindow):
    """ This class enables the display of a collection
      of ChartPlot widgets contained within a tabwidget
  """
    number_of_tabs = pyqtSignal(int)
    auto_offset_value = pyqtSignal(float)
    showMessage = pyqtSignal(str)

    def __init__(self, parent=None, name=None, num_curves=16, plot_label=None):
        QMainWindow.__init__(self, parent)

        # ChartPlot strip charts will be displayed via a tab widget
        self._tabwidget = QTabWidget(self)
        self._tab_resized = False
        self._num_curves = num_curves
        self._plot_label = plot_label
        self._result_range = None
        self._png_number = 0
        self._grab_name = ''

        # create control menu
        self._menu = ControlMenu(self)
        # create a dictionary of chart plot objects
        self._ChartPlot = {}
        self._click_on = "If you click on an individual stripchart with the <b>middle</b> mouse button, a popup window will appear that gives a more detailed plot of the data from that particular object. <br><br> Clicking with the <b>left</b> mouse button will cause a small popup to appear. The popup gives the actual X and Y values, corrected for offset, of the data point nearest to the location of the mouse.<br><br> Clicking with the <b>right</b> mouse button will cause a context menu to appear. The <b>Accumulate data tracks</b> option means that data in each tile will be appended to the previous data. If this option is unchecked, data will be displayed for just each individual tile. The <b>Data element selector</b> option works similarly to that associated with the standard 2-D plot display. Clicking on it causes a small submenu to appear that allows you to select different data elements for display."

        # connect menu signals
        self._menu.save_this.triggered.connect(self.save_current_display)
        self._menu.save_all.triggered.connect(self.save_all_displays)

    def createDataSelectorWidgets(self, parent, layout):
        self._menu.createDataSelectorWidgets(parent, layout)

    def setDataElementLabels(self, labels, dims):
        self._menu.setVellsElementLabels(labels, dims)

    def setDataElementLabels(self, labels, dims):
        #   print 'setDataElementLabels incoming labels,dims ', labels,dims
        #   print labels
        self._menu.setVellsElementLabels(labels, dims)

    def updateEvent(self, data_dict):
        data_type = data_dict['data_type']
        #   print('Display updating with type', data_type)
        try:
            self._grab_name = data_dict['source']
        except:
            self._grab_name = ''
#   print('Display updating with _grab_name', self._grab_name)
        if data_type not in self._ChartPlot:
            self._ChartPlot[data_type] = ChartPlot(self._menu,
                                                   num_curves=self._num_curves,
                                                   parent=self)
            self._ChartPlot[data_type].setDataLabel(data_type)
            #     self._ChartPlot[data_type].set_plotter_inactive()
            #     self._ChartPlot[data_type].set_plotter_active()
            self._max_tab_index = self._tabwidget.addTab(
                self._ChartPlot[data_type], data_type)
            #     print 'tabwidget index ', self._max_tab_index
            self.number_of_tabs.emit(self._max_tab_index)

            #     self._menu.updateTabSelectorRange(self._max_tab_index)
            self._tabwidget.setCurrentWidget(self._ChartPlot[data_type])
            self._tabwidget.resize(self._tabwidget.minimumSizeHint())
            self.resize(self._tabwidget.minimumSizeHint())

            dcm_sn_descriptor = "This window shows stripcharts of data as a function of time. The display is mostly used to show radio interferometer data where the frequency data have been averaged together. Each tab window can show up to 64 interferometer baselines. The antenna pair associated with each baseline is shown with a yellow background.<br><br>"
            dcm_sn_descriptor = dcm_sn_descriptor + self._click_on
            self._ChartPlot[data_type].setWhatsThis(dcm_sn_descriptor)
            try:
                self._ChartPlot[data_type].quit_event.connect(self.quit_event)
            except:
                pass
            self._ChartPlot[data_type].auto_offset_value.connect(
                self.report_auto_value)
            if not self._plot_label is None:
                self._ChartPlot[data_type].setPlotLabel(self._plot_label)
            self._ChartPlot[data_type].show()
            # make "Save all" visibile if multiple pages
            self._menu.save_all.setVisible(len(self._ChartPlot) > 1)

        self._ChartPlot[data_type].updateEvent(data_dict)
        self._ChartPlot[data_type].setSource(self._grab_name)

    def change_tab_page(self, tab_page):
        self._tabwidget.setCurrentIndex(tab_page)

    def report_auto_value(self, auto_offset_value):
        self.auto_offset_value.emit(auto_offset_value)

    def set_range_selector(self, new_range):
        """ set or update maximum range for slider controller """
        for plot in list(self._ChartPlot.values()):
            plot.set_offset_scale(new_range)

    def set_auto_scaling(self):
        """ set or update maximum range for slider controller """
        for plot in list(self._ChartPlot.values()):
            plot.set_auto_scaling()

    def resizeEvent(self, event):
        for plot in list(self._ChartPlot.values()):
            plot.resize(event.size())
        self._tabwidget.resize(event.size())

    def setNewPlot(self):
        for plot in list(self._ChartPlot.values()):
            plot.clear_plot()

    def save_current_display(self):
        filename, error = self._save_display(self._tabwidget.currentWidget())
        if error:
            self.showMessage.emit("error writing file %s" % filename, True)
        else:
            self.showMessage.emit("saved plot to %s" % filename)

    def save_all_displays(self):
        good_files = []
        bad_files = []
        for key in sorted(self._ChartPlot.keys()):
            filename, error = self._save_display(self._ChartPlot[key])
            (bad_files if error else good_files).append(filename)
        if good_files:
            self.showMessage.emit("saved plots to %s" %
                                  (", ".join(good_files)))
        if bad_files:
            self.showMessage.emit(
                "error writing files %s" % (", ".join(bad_files)), True)

    def _save_display(self, chartplot):
        self._png_number += 1
        # put together filename components
        name_components = []
        if self._grab_name:
            name_components.append(self._grab_name)
        if self._menu.isVellsControlVisible():
            name_components.append(str(self._menu.vells_component))
        if self._menu.isComplexControlVisible():
            name_components.append(
                str(self._menu.ComplexComponentLabels[
                    self._menu.complex_component]))
        if len(self._ChartPlot) > 1:
            name_components.append(chartplot.dataLabel())
        name_components.append(str(self._png_number))
        save_file = "_".join(name_components).replace(' ', '_') + ".png"
        try:
            pm = QPixmap.grabWidget(chartplot)
            pm.save(save_file, "PNG")
            return save_file, None
        except:
            traceback.print_exc()
            print('failed to grab or save pixmap')
            return save_file, True


#void IfDisplayMainWindow.set_data_flag(Int channel, Bool flag_value)
#{
#	_ChartPlot(0).set_data_flag(channel,flag_value)
#
## if flag_value == False, we have bad data!
#	if (!flag_value) {
#    		QColor col
#		col.setNamedColor("IndianRed")
#    		statusBar().setPaletteBackgroundColor(col)
#		QString channel_number
#		channel_number.setNum(channel)
#		QString Message = "Bad TSYS detected for channel "+ channel_number
#    		statusBar().message( Message)
#        	QTimer *timer = new QTimer(this)
#        	connect( timer, SIGNAL(timeout()), this, SLOT(resetStatus()) )
## TRUE means that this will be a one-shot timer
#        	timer.start(500, TRUE)
#	}
#}

#void IfDisplayMainWindow.resetStatus()
#{
#    		QColor col
#    		col.setNamedColor("LightYellow")
#    		statusBar().setPaletteBackgroundColor(col)
#		QString Message = " "
#    		statusBar().message( Message)
#}
#

    def quit_event(self):
        self.close()

    def start_test_timer(self, time):
        # stuff for tests
        self.seq_num = 0
        self._gain = 0
        self._array = numpy.zeros((128, ), numpy.float32)
        self._array_imag = numpy.zeros((128, ), numpy.float32)
        self._array_complex = numpy.zeros((128, ), numpy.complex64)
        self.startTimer(time)

    def timerEvent(self, e):
        self.seq_num = self.seq_num + 1
        self._gain = self._gain + 0.5
        data_dict = {}
        data_dict['sequence_number'] = self.seq_num

        for i in range(16):
            data_dict['channel'] = i

            data_dict['data_type'] = 'scalar'
            data_dict['value'] = (i + 1) * random.random()
            self.updateEvent(data_dict)

            data_dict['data_type'] = 'another scalar'
            data_dict['value'] = self._gain + (i + 1) * random.random()
            self.updateEvent(data_dict)

            data_dict['data_type'] = 'arrays'
            if i == 13:
                for j in range(self._array.shape[0]):
                    self._array[j] = 11 * random.random()
                    self._array_imag[j] = 6 * random.random()
                self._array_complex.real = self._array
                self._array_complex.imag = self._array_imag
                data_dict['value'] = self._array_complex
            else:
                for j in range(self._array.shape[0]):
                    self._array[j] = (i + 1) * random.random()
                data_dict['value'] = self._array
            self.updateEvent(data_dict)

            data_dict['data_type'] = 'tensor demo'
            data_dict['value'] = {}
            for j in range(4):
                if j == 0 or j == 3:
                    gain = 1.0
                    for k in range(self._array.shape[0]):
                        self._array[k] = gain * random.random()
                    data_dict['value'][j] = self._array.copy()
                else:
                    gain = 0.1
                    for k in range(self._array.shape[0]):
                        self._array[k] = gain * random.random()
                        self._array_imag[k] = gain * random.random()
                    self._array_complex.real = self._array
                    self._array_complex.imag = self._array_imag
                    data_dict['value'][j] = self._array_complex.copy()
            self.updateEvent(data_dict)

        return