def create_layout_stuff(self):
     """ create grid layouts into which plotter widgets are inserted """
     if self.layout_parent is None or not self.layout_created:
         self.layout_parent = QWidget(self.wparent())
         self.layout = QHBoxLayout(self.layout_parent)
         self.set_widgets(self.layout_parent,
                          self.dataitem.caption,
                          icon=self.icon())
         self.layout_created = True
     self._wtop = self.layout_parent
     self.create_2D_plotter()
Beispiel #2
0
    def __init__(self,
                 CurveNumber,
                 x_values,
                 y_values,
                 flags,
                 pen,
                 parent=None,
                 name=None):
        """ Initialises all the variables.  
        creates the main zoom plot
        connects the qt signals
    """

        QWidget.__init__(self, parent)
        self.setWindowTitle('Channel ' + str(CurveNumber))
        self._parent = parent
        self._d_zoomActive = self._d_zoom = False
        self._curve_number = CurveNumber
        self.curves = {}

        self._do_close = True  # enable closing by window manager
        self._do_pause = False  # pause mode is False at startup
        self._compare_max = False
        self._do_linear_scale = True  # linear Y axis scale by default
        self._do_fixed_scale = False  # auto scaling by default
        self._array_label = "Channel "

        #Create the plot for selected curve to zoom
        self._plotter = QwtImageDisplay(self)
        self._plotter.setZoomDisplay()

        self._zoom_plot_label = self._array_label + str(
            self._curve_number) + " Sequence (oldest to most recent)"

        self._max_crv = -1  # negative value used to indicate that this display
        self._min_crv = -1  # is not being used

        #####end of parameters set for the plot#######/

        # we seem to need a layout for PyQt
        box1 = QHBoxLayout(self)
        box1.addWidget(self._plotter)
        #   self.plotPrinter = plot_printer_qt5.plot_printer(self._plotter)

        self._plotter.winpaused.connect(self.Pausing)
        self._plotter.compare.connect(self.do_compare)
        #   self._plotter.do_print.connnect(self.plotPrinter.do_print)
        self._plotter.save_display.connect(self.handle_save_display)

        # insert flags ?
        self._plotter.initVellsContextMenu()
        self.update_plot(y_values, flags)
        self.show()
Beispiel #3
0
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)

        self.plot = BodePlot(self)
        self.plot.setContentsMargins(5, 5, 5, 0)

        self.setContextMenuPolicy(Qt.NoContextMenu)

        self.setCentralWidget(self.plot)

        toolBar = QToolBar(self)
        self.addToolBar(toolBar)

        btnPrint = QToolButton(toolBar)
        btnPrint.setText("Print")
        btnPrint.setIcon(QIcon(QPixmap(print_xpm)))
        btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnPrint)
        btnPrint.clicked.connect(self.print_)

        btnExport = QToolButton(toolBar)
        btnExport.setText("Export")
        btnExport.setIcon(QIcon(QPixmap(print_xpm)))
        btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnExport)
        btnExport.clicked.connect(self.exportDocument)

        btnSet = QToolButton(toolBar)
        btnSet.setText("Set")
        btnSet.setIcon(QIcon(QPixmap(print_xpm)))
        btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnSet)
        btnSet.clicked.connect(self.exportDocument)

        toolBar.addSeparator()

        dampBox = QWidget(toolBar)
        dampLayout = QHBoxLayout(dampBox)
        dampLayout.setSpacing(0)
        dampLayout.addWidget(QWidget(dampBox), 10)  # spacer
        dampLayout.addWidget(QLabel("Damping Factor", dampBox), 0)
        dampLayout.addSpacing(10)

        toolBar.addWidget(dampBox)

        self.statusBar()

        self.showInfo()
Beispiel #4
0
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)

        self.plot = BodePlot(self)
        self.plot.setContentsMargins(5, 5, 5, 0)

        self.setContextMenuPolicy(Qt.NoContextMenu)
        
        self.setCentralWidget(self.plot)

        toolBar = QToolBar(self)
        self.addToolBar(toolBar)

        btnPrint = QToolButton(toolBar)
        btnPrint.setText("Print")
        btnPrint.setIcon(QIcon(QPixmap(print_xpm)))
        btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnPrint)
        btnPrint.clicked.connect(self.print_)

        btnExport = QToolButton(toolBar)
        btnExport.setText("Export")
        btnExport.setIcon(QIcon(QPixmap(print_xpm)))
        btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnExport)
        btnExport.clicked.connect(self.exportDocument)
            
        toolBar.addSeparator()

        dampBox = QWidget(toolBar)
        dampLayout = QHBoxLayout(dampBox)
        dampLayout.setSpacing(0)
        dampLayout.addWidget(QWidget(dampBox), 10) # spacer
        dampLayout.addWidget(QLabel("Damping Factor", dampBox), 0)
        dampLayout.addSpacing(10)

        toolBar.addWidget(dampBox)

        self.statusBar()
        
        self.showInfo()
Beispiel #5
0
    def createDataSelectorWidgets(self, parent, parent_layout):
        """Creates toolbuttons for complex values and Vells selection"""

        #print('in createDataSelectionWidgets')
        self._ds_top = top = QWidget(parent)
        parent_layout.addWidget(top)
        self._ds_lo = lotop = QVBoxLayout(top)
        lotop.setContentsMargins(0, 0, 0, 0)
        self._ds_complex = QWidget(top)
        self._ds_complex.setVisible(False)
        lotop.addWidget(self._ds_complex)
        lo = QVBoxLayout(self._ds_complex)
        lo.setContentsMargins(0, 0, 0, 0)
        lab = QLabel("complex:")
        lab.setAlignment(Qt.AlignHCenter)
        lo.addWidget(lab)
        # add complex selector
        lo0 = QHBoxLayout()
        lo0.setContentsMargins(0, 0, 0, 0)
        lo.addLayout(lo0)
        lo1 = QGridLayout()
        lo1.setContentsMargins(0, 0, 0, 0)
        lo1.setHorizontalSpacing(0)
        lo1.setVerticalSpacing(0)
        #   lo0.addStretch(1);
        lo0.addLayout(lo1)
        #   lo0.addStretch(1);
        bgrp = QButtonGroup(self._ds_complex)
        #   tbdesc = { self.AMP:(u"\u007Ca\u007C",0,0),self.PHASE:(u"\u03D5",0,1),self.REAL:("Re",1,0),self.IMAG:("Im",1,1) };
        #   tbdesc = { self.AMP:("\\u007Ca\\u007C",0,0),self.PHASE:("\\u0278",0,1),self.REAL:("Re",1,0),self.IMAG:("Im",1,1) };
        tbdesc = {
            self.AMP: ("Amp", 0, 0),
            self.PHASE: ("Pha", 0, 1),
            self.REAL: ("Re", 1, 0),
            self.IMAG: ("Im", 1, 1)
        }
        for label, qa in list(self._qas_complex.items()):
            tbtext, row, col = tbdesc[label]
            tb = QToolButton(self._ds_complex)
            lo1.addWidget(tb, row, col)
            bgrp.addButton(tb)
            tb.setText(tbtext)
            tb.setToolButtonStyle(Qt.ToolButtonTextOnly)
            tb.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
            tb.setCheckable(True)
            tb.setChecked(label is self.complex_component)
            tb.setMinimumWidth(32)
            tb.clicked[bool].connect(qa.setChecked)
            tb.clicked[bool].connect(self._change_complex)
            qa.triggered[bool].connect(tb.setChecked)
            self._tbs_complex[label] = tb
class CollectionsPlotter(GriddedPlugin):
    """ a class to visualize data, VellSets or visu data, that is 
      contained within a node's cache_result record. Objects of 
      this class are launched from the meqbrowser GUI """

    _icon = pixmaps.bars3d
    viewer_name = "Collections Plotter"

    def is_viewable(data):
        return len(data) > 0

    is_viewable = staticmethod(is_viewable)

    def __init__(self, gw, dataitem, cellspec={}, **opts):
        GriddedPlugin.__init__(self, gw, dataitem, cellspec=cellspec)
        """ Instantiate plotter object that is used to display plots
    """
        self.set_init_parameters()
        # back to 'real' work
        self.dataitem = dataitem
        if dataitem and dataitem.data is not None:
            self.set_data(dataitem)

    def set_init_parameters(self):
        self._rec = None
        self._plot_type = None
        self._wtop = None
        self._vells_data = None
        self.layout_created = False
        self.layout_parent = None
        self.layout = None
        self._visu_plotter = None
        self.counter = 0
        self.max_range = 0
        self._node_name = None
        self._prev_rq_id = -1
        self._plot_label = None
        self._tab_label = 'Page'
        self.prev_label = "===="

    def wtop(self):
        """ function needed by Oleg for reasons known only to him! """
        return self._wtop

    def create_layout_stuff(self):
        """ create grid layouts into which plotter widgets are inserted """
        if self.layout_parent is None or not self.layout_created:
            self.layout_parent = QWidget(self.wparent())
            self.layout = QHBoxLayout(self.layout_parent)
            self.set_widgets(self.layout_parent,
                             self.dataitem.caption,
                             icon=self.icon())
            self.layout_created = True
        self._wtop = self.layout_parent
        self.create_2D_plotter()

    def create_2D_plotter(self):
        if self._visu_plotter is None:
            self._visu_plotter = DisplayMainWindow(
                parent=None,
                name=" ",
                num_curves=self._max_per_display,
                plot_label=self._plot_label)
            self.layout.addWidget(self._visu_plotter, 100)
            self._visu_plotter.showMessage.connect(self._gw.show_message)
            lo0 = QVBoxLayout()
            lo0.setContentsMargins(0, 0, 0, 0)
            self.layout.addLayout(lo0, 0)

            self._results_range = ResultsRange(parent=self.layout_parent,
                                               name="",
                                               horizontal=False,
                                               add_spacer=False)
            self._results_range.setMaxValue(max_value=0, allow_shrink=True)
            lo0.addWidget(self._results_range)
            self._tab_selector = ResultsRange(parent=self.layout_parent,
                                              horizontal=True,
                                              hide_slider=True,
                                              add_spacer=False)
            self._tab_selector.setLabel('Page selector:')
            self._tab_selector.hideNDControllerOption()
            self._tab_selector.set_offset_index(0)
            self._tab_selector.set_emit(True)
            lo0.addWidget(self._tab_selector)

            # add data selectors
            self._visu_plotter.createDataSelectorWidgets(
                self.layout_parent, lo0)
            spacer = QSpacerItem(9, 22, QSizePolicy.Minimum,
                                 QSizePolicy.Expanding)
            lo0.addItem(spacer)

            self._visu_plotter.show()
            self._results_range.set_offset_index(0)
            self._visu_plotter.auto_offset_value.connect(
                self.set_range_selector)
            self._visu_plotter.number_of_tabs.connect(
                self.updateTabSelectorRange)
            self._results_range.result_index.connect(
                self._visu_plotter.set_range_selector)
            self._results_range.set_auto_scaling.connect(
                self._visu_plotter.set_auto_scaling)
            self._tab_selector.result_index.connect(
                self._visu_plotter.change_tab_page)

    # create_2D_plotter

    def set_range_selector(self, max_range):
        """ set or update maximum range for slider controller """
        self.max_range = max_range
        self._results_range.set_emit(False)
        self._results_range.setMinValue(0)
        self._results_range.setMaxValue(max_range)
        self._results_range.setTickInterval(max_range // 10)
        self._results_range.setValue(max_range)
        self._results_range.setLabel('offset:', align=Qt.AlignHCenter)
        self._results_range.hideNDControllerOption()
        self._results_range.set_emit(True)
        self._results_range.show()

    def updateTabSelectorRange(self, max_range):
        """ set or update maximum range for tab page selector """
        self._tab_selector.set_emit(False)
        self._tab_selector.setMinValue(0)
        self._tab_selector.setMaxValue(max_range, allow_shrink=True)
        self._tab_selector.set_emit(True)

    def set_data(self, dataitem, default_open=None, **opts):
        """ this callback receives data from the meqbrowser, when the
        user has requested a plot. It decides whether the data is
        from a VellSet or visu data record, and  after any
        necessary preprocssing forwards the data to one of
        the functions which does the actual plotting """

        if HAS_TIMBA: _dprint(3, '** in collections_plotter:set_data callback')
        self._rec = dataitem.data
        if HAS_TIMBA:
            _dprint(3, 'set_data: initial self._rec ', self._rec)
            _dprint(3, 'incoming record has keys ', list(self._rec.keys()))
# if we are single stepping through requests, Oleg may reset the
# cache, so check for a non-data record situation
        if self._rec is None:
            return
        if isinstance(self._rec, bool):
            return

        try:
            self._node_name = self._rec.name
        except:
            pass
        if HAS_TIMBA:
            _dprint(3, 'node name is ', self._node_name)

        if hasattr(self._rec, 'plot_label'):
            self._plot_label = self._rec.plot_label
        if hasattr(self._rec, 'tab_label'):
            self._tab_label = self._rec.tab_label
        self._vells_label = getattr(self._rec, 'vells_label', [])
        if not isinstance(self._vells_label, (list, tuple)):
            self._vells_label = []
# previous_statement_gives example output: self._vells_label ('XX', 'XY', 'YX', 'YY'
        self.label = ''
        # extra label, filled in if possible
        # there's a problem here somewhere ...
        if dmi_typename(
                self._rec) != 'MeqResult':  # data is not already a result?
            # try to put request ID in label
            rq_id_found = False
            data_failure = False
            try:
                if "request_id" in self._rec.cache:
                    self.label = "rq " + str(self._rec.cache.request_id)
                    rq_id_found = True
                if "result" in self._rec.cache:
                    self._rec = self._rec.cache.result
                    # look for cache.result record
                    if not rq_id_found and "request_id" in self._rec:
                        self.label = "rq " + str(self._rec.request_id)
                        rq_id_found = True
                else:
                    data_failure = True
                if HAS_TIMBA: _dprint(3, 'we have req id ', self.label)
            except:
                data_failure = True
            if data_failure:
                if HAS_TIMBA: _dprint(3, ' we have a data failure')
                # cached_result not found, display an empty viewer with a "no result
                # in this node record" message (the user can then use the Display with
                # menu to switch to a different viewer)
                Message = "No cache result record was found for this node, so no plot can be made."
                cache_message = QLabel(Message, self.wparent())
                cache_message.setTextFormat(Qt.RichText)
                self._wtop = cache_message
                self.set_widgets(cache_message)
                self.set_init_parameters()
                return
            if HAS_TIMBA: _dprint(3, 'collections: request id ', self.label)
            end_str = len(self.label)
            self._rq_id_end = int(self.label[end_str - 1:end_str])
            if self._rq_id_end == self._prev_rq_id:
                new_plot = False
            else:
                new_plot = True
                self._prev_rq_id = self._rq_id_end

            if self.label.find(self.prev_label) >= 0:
                # we have already plotted this stuff, so return
                return
            else:
                self.prev_label = self.label

# are we dealing with Vellsets?
        self.counter = self.counter + 1
        self._max_per_display = 64
        if "dims" in self._rec:
            if HAS_TIMBA: _dprint(3, '*** dims field exists ', self._rec.dims)
            self.dims = list(self._rec.dims)
        else:
            self.dims = None
        if "vellsets" in self._rec:
            self._number_of_planes = len(self._rec["vellsets"])
            self.dims_per_group = 1
            index_labels = None
            # make labels for multi-dim result
            if not self.dims is None:
                # in collections plotter, assume that first 'dims'
                # corresponds to tracks that are displayed , so determine
                # size of group from second dimension and up
                if len(self.dims) > 1:
                    dims_start = 1
                    for i in range(dims_start, len(self.dims)):
                        self.dims_per_group = self.dims_per_group * self.dims[i]
                    if self.dims_per_group == len(self._vells_label):
                        index_labels = self._vells_label
                    else:
                        if len(self._vells_label) > 0:
                            if self._vells_label[
                                    0] == 'XX' or self._vells_label[0] == 'RR':
                                # we have correlator data to display
                                # - ignore self.dims_per_group stuff
                                index_labels = self._vells_label
                        else:
                            # setup index array -- this makes a list such as [1,1],[1,2],[2,1],[2,2] (for e.g. a 2x2 array)
                            indices = numpy.ndindex(*self.dims[dims_start:])
                            # sep = "," if any([dim>9 for dim in self.dims[dims_start:]]) else "";
                            index_labels = [
                                ",".join([str(x + 1) for x in ind])
                                for ind in indices
                            ]
            # index labels not set by the above? set them here
            if index_labels is None:
                if self._number_of_planes == len(self._vells_label):
                    index_labels = self._vells_label
                else:
                    index_labels = list(range(0, 1))
            # replace index labels with vells labels
            if self._visu_plotter is None:
                self.create_layout_stuff()
            if new_plot:
                self._visu_plotter.setNewPlot()
            data_dict = {}
            self._visu_plotter.setDataElementLabels(
                index_labels,
                list(self.dims[1:]) if self.dims is not None else (1, ))
            for i in range(self._number_of_planes):
                channel = int(i / self.dims_per_group)
                if self._node_name is None:
                    data_dict['source'] = "Channel " + str(channel)
                else:
                    data_dict['source'] = self._node_name
                data_dict['channel'] = channel
                data_dict['sequence_number'] = self.counter
                screen_num = channel // self._max_per_display
                #       data_dict['data_type'] = self._tab_label + ' ' + str(screen_num+1)
                data_dict['data_type'] = self._tab_label + ' ' + str(
                    screen_num)
                index = i - channel * self.dims_per_group

                if index == 0:
                    data_dict['value'] = {}
                    data_dict['flags'] = {}
                try:
                    datakey = index_labels[index]
                except:
                    pass
#       if channel == 100:
#         data_dict['value'][index] = 100.0 * self._rec.vellsets[i].value
#       else:

# hopefully handle cases with non-existent results
                try:
                    if "value" in self._rec.vellsets[i]:
                        data_dict['value'][datakey] = self._rec.vellsets[
                            i].value
                    else:
                        data_dict['value'][datakey] = None
                except:
                    data_dict['value'][datakey] = None
# for test purposes
#       if index == 2:
#           data_dict['value'][datakey] = None
                try:
                    if "flags" in self._rec.vellsets[i]:
                        data_dict['flags'][datakey] = self._rec.vellsets[
                            i].flags
                    else:
                        data_dict['flags'][datakey] = None
                except:
                    data_dict['flags'][datakey] = None
                if index == self.dims_per_group - 1:
                    self._visu_plotter.updateEvent(data_dict)
                    data_dict = {}


# enable & highlight the cell
        self.enable()
        self.flash_refresh()
        if HAS_TIMBA: _dprint(3, 'exiting process_data')
Beispiel #7
0
    def __init__(self, parent=None, name="",horizontal=False,draw_scale=True,hide_slider=False, use_int=False, add_spacer=True):
#     QWidget.__init__(self, parent, name)
      QWidget.__init__(self, parent)

      self.menu_table = {
      'Adjust results buffer size': 301,
      'Display summary plot': 302,
      'X Axis': 303,
      'Y Axis': 304,
      'Z Axis': 305,
      'Show 2D Display': 306,
      'Update': 307,
      'Toggle ND Controller': 308,
      'Print to Postscript file': 309,
      'Align Camera': 310,
      'Reset Auto Scaling': 312,
      'Save Display in PNG Format': 313,
      }

      self.horizontal = horizontal
      self.hide_slider = hide_slider
      self.use_int = use_int
      self.add_spacer = add_spacer
      self.allow_emit = False
      self.allow_summary = False
      self.summary_request = True
      self.toggle_ND_Controller = 1
      self.toggle_scale_display = False
      self.draw_scale = draw_scale
      self.menu = None
      self.maxVal = 100
      self.minVal = 0
      self.scaler = 1
      self.label_info = QLabel('', self)
      self.string_info =  ' '
      self.offset_index = -1
      if self.horizontal or self.use_int:
        self.spinbox = QSpinBox(self)
      else:
        self.spinbox = QDoubleSpinBox(self)
        self.spinbox.setSingleStep(0.1)
      self.spinbox.setMinimum(self.minVal)
      self.spinbox.setMaximum(self.maxVal)

      if self.horizontal:
        self.slider = QSlider(Qt.Horizontal, self)
        if self.draw_scale:
          self.slider.setTickPosition(QSlider.TicksBelow)
          self.slider.setTickInterval(self.minVal)
        self.slider.setRange(self.minVal, self.maxVal)
        self.slider.valueChanged[int].connect(self.update_slider)
        self.spinbox.valueChanged[int].connect(self.update_spinbox)
      else:
         #print('creating standard vertical QSlider')
         self.slider = QSlider(Qt.Vertical, self)
         if not self.use_int:
           self.scaler = 10000000
         min = self.scaler * self.minVal
         max = self.scaler * self.maxVal
         if self.draw_scale:
           self.slider.setTickPosition(QSlider.TicksRight)
           step = int((max-min) /20)
           #print('slider step should me ', step)
           self.slider.setTickInterval(step)
         #print('slider min and max', min,max)
         self.slider.setRange(min, max)
         self.slider.valueChanged[int].connect(self.update_slider)

        # we may not want a slider - e.g. when selecion tab pages in collections plotter
      self.spinbox.setWrapping(True)
      #print('wrapping should be set')

      if self.hide_slider:
        self.slider.hide()

      if self.horizontal or self.use_int:
        self.spinbox.valueChanged[int].connect(self.update_spinbox)
      else:
        self.spinbox.valueChanged[float].connect(self.update_spinbox)

      if self.horizontal:
        self.label_info1 = QLabel('          ', self)
        self.layout = QHBoxLayout(self)
        if self.add_spacer:
          spacer = QSpacerItem(22,9,QSizePolicy.Expanding,QSizePolicy.Minimum)
          self.layout.addItem(spacer)
        self.layout.addWidget(self.label_info)
        self.layout.addWidget(self.spinbox)
        self.layout.addWidget(self.label_info1)
        self.layout.addWidget(self.slider)
        self.setValue()
      else:
        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.label_info)
        self.layout.addWidget(self.slider)
        self.layout.addWidget(self.spinbox)
        if self.add_spacer:
          spacer = QSpacerItem(9,22,QSizePolicy.Minimum,QSizePolicy.Expanding)
          self.layout.addItem(spacer)
        self.setValue(0,reset_auto=True)

# add on-line help
      self.setWhatsThis(results_range_help)
    def __init__(self, buffersize=0, parent=None, name=None, modal=True, fl=0):
        QDialog.__init__(self, parent)

        self.setModal(modal)

        BufferSizeDialogLayout = QVBoxLayout(self)

        layout1 = QHBoxLayout(None)

        self.label = QLabel(self)
        layout1.addWidget(self.label)

        self.spinBox1 = QSpinBox(self)
        self.spinBox1.setMinimum(0)
        self.spinBox1.setWrapping(True)
        self.spinBox1.setValue(buffersize)
        self.value = buffersize

        layout1.addWidget(self.spinBox1)
        BufferSizeDialogLayout.addLayout(layout1)

        layout3 = QHBoxLayout(None)
        spacer1 = QSpacerItem(71, 31, QSizePolicy.Expanding,
                              QSizePolicy.Minimum)
        layout3.addItem(spacer1)

        self.okButton = QPushButton("okButton", self)
        layout3.addWidget(self.okButton)

        self.cancelButton = QPushButton("cancelButton", self)
        layout3.addWidget(self.cancelButton)
        BufferSizeDialogLayout.addLayout(layout3)

        self.resize(QSize(267, 84).expandedTo(self.minimumSizeHint()))

        self.okButton.clicked.connect(self.runDone)
        self.cancelButton.clicked.connect(self.runCancel)
        self.spinBox1.valueChanged.connect(self.updateValue)

        self.label.setBuddy(self.spinBox1)