Beispiel #1
0
 def show_layout_details(self):
     text = QwtText(
         "plotLayout().canvasRect():\n%r\n\n"
         "canvas().geometry():\n%r\n\n"
         "plotLayout().scaleRect(QwtPlot.yLeft):\n%r\n\n"
         "axisWidget(QwtPlot.yLeft).geometry():\n%r\n\n"
         "plotLayout().scaleRect(QwtPlot.yRight):\n%r\n\n"
         "axisWidget(QwtPlot.yRight).geometry():\n%r\n\n"
         "plotLayout().scaleRect(QwtPlot.xBottom):\n%r\n\n"
         "axisWidget(QwtPlot.xBottom).geometry():\n%r\n\n"
         "plotLayout().scaleRect(QwtPlot.xTop):\n%r\n\n"
         "axisWidget(QwtPlot.xTop).geometry():\n%r\n\n" % (
             self.plotLayout().canvasRect().getCoords(),
             self.canvas().geometry().getCoords(),
             self.plotLayout().scaleRect(QwtPlot.yLeft).getCoords(),
             self.axisWidget(QwtPlot.yLeft).geometry().getCoords(),
             self.plotLayout().scaleRect(QwtPlot.yRight).getCoords(),
             self.axisWidget(QwtPlot.yRight).geometry().getCoords(),
             self.plotLayout().scaleRect(QwtPlot.xBottom).getCoords(),
             self.axisWidget(QwtPlot.xBottom).geometry().getCoords(),
             self.plotLayout().scaleRect(QwtPlot.xTop).getCoords(),
             self.axisWidget(QwtPlot.xTop).geometry().getCoords(),
         ))
     text.setFont(QFont('Courier New'))
     text.setColor(Qt.blue)
     self.marker.setLabel(text)
Beispiel #2
0
 def show_layout_details(self):
     text = QwtText(
       "plotLayout().canvasRect():\n%r\n\n"
       "canvas().geometry():\n%r\n\n"
       "plotLayout().scaleRect(QwtPlot.yLeft):\n%r\n\n"
       "axisWidget(QwtPlot.yLeft).geometry():\n%r\n\n"
       "plotLayout().scaleRect(QwtPlot.yRight):\n%r\n\n"
       "axisWidget(QwtPlot.yRight).geometry():\n%r\n\n"
       "plotLayout().scaleRect(QwtPlot.xBottom):\n%r\n\n"
       "axisWidget(QwtPlot.xBottom).geometry():\n%r\n\n"
       "plotLayout().scaleRect(QwtPlot.xTop):\n%r\n\n"
       "axisWidget(QwtPlot.xTop).geometry():\n%r\n\n"
           % (self.plotLayout().canvasRect().getCoords(),
              self.canvas().geometry().getCoords(),
              self.plotLayout().scaleRect(QwtPlot.yLeft).getCoords(),
              self.axisWidget(QwtPlot.yLeft).geometry().getCoords(),
              self.plotLayout().scaleRect(QwtPlot.yRight).getCoords(),
              self.axisWidget(QwtPlot.yRight).geometry().getCoords(),
              self.plotLayout().scaleRect(QwtPlot.xBottom).getCoords(),
              self.axisWidget(QwtPlot.xBottom).geometry().getCoords(),
              self.plotLayout().scaleRect(QwtPlot.xTop).getCoords(),
              self.axisWidget(QwtPlot.xTop).geometry().getCoords(),
              )
                    )
     text.setFont(QFont('Courier New'))
     text.setColor(Qt.blue)
     self.marker.setLabel(text)
Beispiel #3
0
 def trackerText(self, pos):
     x, y = self.plot.invTransform(QwtPlot.xBottom, pos.x()), self.plot.invTransform(QwtPlot.yLeft, pos.y())
     if self.track:
         text = self.track(x, y)
         if text is not None:
             return text
     if self.label:
         text = QwtText(self.label % dict(x=x, y=y))
         text.setColor(self.color)
         return text
     return QwtText()
Beispiel #4
0
 def _setupHistogramPlot(self):
     self._histplot.setCanvasBackground(QColor("lightgray"))
     self._histplot.setAxisFont(QwtPlot.yLeft, QApplication.font())
     self._histplot.setAxisFont(QwtPlot.xBottom, QApplication.font())
     # add histogram curves
     self._histcurve1 = TiggerPlotCurve()
     self._histcurve2 = TiggerPlotCurve()
     self._histcurve1.setStyle(QwtPlotCurve.Steps)
     self._histcurve2.setStyle(QwtPlotCurve.Steps)
     self._histcurve1.setPen(QPen(Qt.NoPen))
     self._histcurve1.setBrush(QBrush(QColor("slategrey")))
     pen = QPen(QColor("red"))
     pen.setWidth(1)
     self._histcurve2.setPen(pen)
     self._histcurve1.setZ(0)
     self._histcurve2.setZ(100)
     #    self._histcurve1.attach(self._histplot)
     self._histcurve2.attach(self._histplot)
     # add maxbin and half-max curves
     self._line_0 = self.HistogramLineMarker(self._histplot, color="grey50", linestyle=Qt.SolidLine,
                                             align=Qt.AlignTop | Qt.AlignLeft, z=90)
     self._line_mean = self.HistogramLineMarker(self._histplot, color="black", linestyle=Qt.SolidLine,
                                                align=Qt.AlignBottom | Qt.AlignRight, z=91,
                                                label="mean", zlabel=151)
     self._line_std = self.HistogramLineMarker(self._histplot, color="black", linestyle=Qt.SolidLine,
                                               align=Qt.AlignTop | Qt.AlignRight, z=91,
                                               label="std", zlabel=151)
     sym = QwtSymbol()
     sym.setStyle(QwtSymbol.VLine)
     sym.setSize(8)
     self._line_std.line.setSymbol(sym)
     self._line_maxbin = self.HistogramLineMarker(self._histplot, color="green", linestyle=Qt.DotLine,
                                                  align=Qt.AlignTop | Qt.AlignRight, z=92,
                                                  label="max bin", zlabel=150)
     self._line_halfmax = self.HistogramLineMarker(self._histplot, color="green", linestyle=Qt.DotLine,
                                                   align=Qt.AlignBottom | Qt.AlignRight, z=90,
                                                   label="half-max", yaxis=QwtPlot.yLeft)
     # add current range
     self._rangebox = TiggerPlotCurve()
     self._rangebox.setStyle(QwtPlotCurve.Steps)
     self._rangebox.setYAxis(QwtPlot.yRight)
     self._rangebox.setPen(QPen(Qt.NoPen))
     self._rangebox.setBrush(QBrush(QColor("darkgray")))
     self._rangebox.setZ(50)
     self._rangebox.attach(self._histplot)
     self._rangebox2 = TiggerPlotCurve()
     self._rangebox2.setStyle(QwtPlotCurve.Sticks)
     self._rangebox2.setYAxis(QwtPlot.yRight)
     self._rangebox2.setZ(60)
     #  self._rangebox2.attach(self._histplot)
     # add intensity transfer function
     self._itfcurve = TiggerPlotCurve()
     self._itfcurve.setStyle(QwtPlotCurve.Lines)
     self._itfcurve.setPen(QPen(QColor("blue")))
     self._itfcurve.setYAxis(QwtPlot.yRight)
     self._itfcurve.setZ(120)
     self._itfcurve.attach(self._histplot)
     self._itfmarker = TiggerPlotMarker()
     label = QwtText("ITF")
     label.setColor(QColor("blue"))
     self._itfmarker.setLabel(label)
     try:
         self._itfmarker.setSpacing(0)
     except AttributeError:
         pass
     self._itfmarker.setLabelAlignment(Qt.AlignTop | Qt.AlignRight)
     self._itfmarker.setZ(120)
     self._itfmarker.attach(self._histplot)
     # add colorbar
     self._cb_item = self.ColorBarPlotItem(1, 1 + self.ColorBarHeight)
     self._cb_item.setYAxis(QwtPlot.yRight)
     self._cb_item.attach(self._histplot)
     # add pickers
     self._hist_minpicker = self.HistLimitPicker(self._histplot, "low: %(x).4g")
     self._hist_minpicker.setMousePattern(QwtEventPattern.MouseSelect1, Qt.LeftButton)
     QObject.connect(self._hist_minpicker, SIGNAL("selected(const QwtDoublePoint &)"), self._selectLowLimit)
     self._hist_maxpicker = self.HistLimitPicker(self._histplot, "high: %(x).4g")
     self._hist_maxpicker.setMousePattern(QwtEventPattern.MouseSelect1, Qt.RightButton)
     QObject.connect(self._hist_maxpicker, SIGNAL("selected(const QwtDoublePoint &)"), self._selectHighLimit)
     self._hist_maxpicker1 = self.HistLimitPicker(self._histplot, "high: %(x).4g")
     self._hist_maxpicker1.setMousePattern(QwtEventPattern.MouseSelect1, Qt.LeftButton, Qt.CTRL)
     QObject.connect(self._hist_maxpicker1, SIGNAL("selected(const QwtDoublePoint &)"), self._selectHighLimit)
     self._hist_zoompicker = self.HistLimitPicker(self._histplot, label="zoom",
                                                  tracker_mode=QwtPicker.AlwaysOn, track=self._trackHistCoordinates,
                                                  color="black",
                                                  mode=QwtPicker.RectSelection,
                                                  rubber_band=QwtPicker.RectRubberBand)
     self._hist_zoompicker.setMousePattern(QwtEventPattern.MouseSelect1, Qt.LeftButton, Qt.SHIFT)
     QObject.connect(self._hist_zoompicker, SIGNAL("selected(const QwtDoubleRect &)"), self._zoomHistogramIntoRect)
Beispiel #5
0
 def setText(self, text):
     label = QwtText(text)
     label.setColor(self.color)
     self.marker.setLabel(label)
Beispiel #6
0
    def __init__(self, image, parent, imgman, name=None, save=False):
        QFrame.__init__(self, parent)
        self.setFrameStyle(QFrame.StyledPanel | QFrame.Raised)
        # init state
        self.image = image
        self._imgman = imgman
        self._currier = PersistentCurrier()
        self._control_dialog = None
        # create widgets
        self._lo = lo = QHBoxLayout(self)
        lo.setContentsMargins(0, 0, 0, 0)
        lo.setSpacing(2)
        # raise button
        self._wraise = QToolButton(self)
        lo.addWidget(self._wraise)
        self._wraise.setIcon(pixmaps.raise_up.icon())
        self._wraise.setAutoRaise(True)
        self._can_raise = False
        QObject.connect(self._wraise, SIGNAL("clicked()"), self._raiseButtonPressed)
        self._wraise.setToolTip("""<P>Click here to raise this image above other images. Hold the button down briefly to
      show a menu of image operations.</P>""")
        # center label
        self._wcenter = QLabel(self)
        self._wcenter.setPixmap(pixmaps.center_image.pm())
        self._wcenter.setToolTip(
            "<P>The plot is currently centered on (the reference pixel %d,%d) of this image.</P>" % self.image.referencePixel())
        lo.addWidget(self._wcenter)
        # name/filename label
        self.name = image.name
        self._wlabel = QLabel(self.name, self)
        self._number = 0
        self.setName(self.name)
        self._wlabel.setToolTip("%s %s" % (image.filename, "\u00D7".join(map(str, image.data().shape))))
        lo.addWidget(self._wlabel, 1)
        # if 'save' is specified, create a "save" button
        if save:
            self._wsave = QToolButton(self)
            lo.addWidget(self._wsave)
            self._wsave.setText("save")
            self._wsave.setAutoRaise(True)
            self._save_dir = save if isinstance(save, str) else "."
            QObject.connect(self._wsave, SIGNAL("clicked()"), self._saveImage)
            self._wsave.setToolTip("""<P>Click here to write this image to a FITS file.</P>""")
        # render control
        dprint(2, "creating RenderControl")
        self._rc = RenderControl(image, self)
        dprint(2, "done")
        # selectors for extra axes
        self._wslicers = []
        curslice = self._rc.currentSlice();  # this may be loaded from config, so not necessarily 0
        for iextra, axisname, labels in self._rc.slicedAxes():
            if axisname.upper() not in ["STOKES", "COMPLEX"]:
                lbl = QLabel("%s:" % axisname, self)
                lo.addWidget(lbl)
            else:
                lbl = None
            slicer = QComboBox(self)
            self._wslicers.append(slicer)
            lo.addWidget(slicer)
            slicer.addItems(labels)
            slicer.setToolTip("""<P>Selects current slice along the %s axis.</P>""" % axisname)
            slicer.setCurrentIndex(curslice[iextra])
            QObject.connect(slicer, SIGNAL("activated(int)"), self._currier.curry(self._rc.changeSlice, iextra))
        # min/max display ranges
        lo.addSpacing(5)
        self._wrangelbl = QLabel(self)
        lo.addWidget(self._wrangelbl)
        self._minmaxvalidator = FloatValidator(self)
        self._wmin = QLineEdit(self)
        self._wmax = QLineEdit(self)
        width = self._wmin.fontMetrics().width("1.234567e-05")
        for w in self._wmin, self._wmax:
            lo.addWidget(w, 0)
            w.setValidator(self._minmaxvalidator)
            w.setMaximumWidth(width)
            w.setMinimumWidth(width)
            QObject.connect(w, SIGNAL("editingFinished()"), self._changeDisplayRange)
        # full-range button
        self._wfullrange = QToolButton(self)
        lo.addWidget(self._wfullrange, 0)
        self._wfullrange.setIcon(pixmaps.zoom_range.icon())
        self._wfullrange.setAutoRaise(True)
        QObject.connect(self._wfullrange, SIGNAL("clicked()"), self.renderControl().resetSubsetDisplayRange)
        rangemenu = QMenu(self)
        rangemenu.addAction(pixmaps.full_range.icon(), "Full subset", self.renderControl().resetSubsetDisplayRange)
        for percent in (99.99, 99.9, 99.5, 99, 98, 95):
            rangemenu.addAction("%g%%" % percent, self._currier.curry(self._changeDisplayRangeToPercent, percent))
        self._wfullrange.setPopupMode(QToolButton.DelayedPopup)
        self._wfullrange.setMenu(rangemenu)
        # update widgets from current display range
        self._updateDisplayRange(*self._rc.displayRange())
        # lock button
        self._wlock = QToolButton(self)
        self._wlock.setIcon(pixmaps.unlocked.icon())
        self._wlock.setAutoRaise(True)
        self._wlock.setToolTip("""<P>Click to lock or unlock the intensity range. When the intensity range is locked across multiple images, any changes in the intensity
          range of one are propagated to the others. Hold the button down briefly for additional options.</P>""")
        lo.addWidget(self._wlock)
        QObject.connect(self._wlock, SIGNAL("clicked()"), self._toggleDisplayRangeLock)
        QObject.connect(self.renderControl(), SIGNAL("displayRangeLocked"), self._setDisplayRangeLock)
        QObject.connect(self.renderControl(), SIGNAL("dataSubsetChanged"), self._dataSubsetChanged)
        lockmenu = QMenu(self)
        lockmenu.addAction(pixmaps.locked.icon(), "Lock all to this",
                           self._currier.curry(imgman.lockAllDisplayRanges, self.renderControl()))
        lockmenu.addAction(pixmaps.unlocked.icon(), "Unlock all", imgman.unlockAllDisplayRanges)
        self._wlock.setPopupMode(QToolButton.DelayedPopup)
        self._wlock.setMenu(lockmenu)
        self._setDisplayRangeLock(self.renderControl().isDisplayRangeLocked())
        # dialog button
        self._wshowdialog = QToolButton(self)
        lo.addWidget(self._wshowdialog)
        self._wshowdialog.setIcon(pixmaps.colours.icon())
        self._wshowdialog.setAutoRaise(True)
        self._wshowdialog.setToolTip("""<P>Click for colourmap and intensity policy options.</P>""")
        QObject.connect(self._wshowdialog, SIGNAL("clicked()"), self.showRenderControls)
        tooltip = """<P>You can change the currently displayed intensity range by entering low and high limits here.</P>
    <TABLE>
      <TR><TD><NOBR>Image min:</NOBR></TD><TD>%g</TD><TD>max:</TD><TD>%g</TD></TR>
      </TABLE>""" % self.image.imageMinMax()
        for w in self._wmin, self._wmax, self._wrangelbl:
            w.setToolTip(tooltip)

        # create image operations menu
        self._menu = QMenu(self.name, self)
        self._qa_raise = self._menu.addAction(pixmaps.raise_up.icon(), "Raise image",
                                              self._currier.curry(self.image.emit, SIGNAL("raise")))
        self._qa_center = self._menu.addAction(pixmaps.center_image.icon(), "Center plot on image",
                                               self._currier.curry(self.image.emit, SIGNAL("center")))
        self._qa_show_rc = self._menu.addAction(pixmaps.colours.icon(), "Colours && Intensities...",
                                                self.showRenderControls)
        if save:
            self._qa_save = self._menu.addAction("Save image...", self._saveImage)
        self._menu.addAction("Export image to PNG file...", self._exportImageToPNG)
        self._export_png_dialog = None
        self._menu.addAction("Unload image", self._currier.curry(self.image.emit, SIGNAL("unload")))
        self._wraise.setMenu(self._menu)
        self._wraise.setPopupMode(QToolButton.DelayedPopup)

        # connect updates from renderControl and image
        self.image.connect(SIGNAL("slice"), self._updateImageSlice)
        QObject.connect(self._rc, SIGNAL("displayRangeChanged"), self._updateDisplayRange)

        # default plot depth of image markers
        self._z_markers = None
        # and the markers themselves
        self._image_border = QwtPlotCurve()
        self._image_label = QwtPlotMarker()

        # subset markers
        self._subset_pen = QPen(QColor("Light Blue"))
        self._subset_border = QwtPlotCurve()
        self._subset_border.setPen(self._subset_pen)
        self._subset_border.setVisible(False)
        self._subset_label = QwtPlotMarker()
        text = QwtText("subset")
        text.setColor(self._subset_pen.color())
        self._subset_label.setLabel(text)
        self._subset_label.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom)
        self._subset_label.setVisible(False)
        self._setting_lmrect = False

        self._all_markers = [self._image_border, self._image_label, self._subset_border, self._subset_label]