예제 #1
0
    def begin(self,   **kwargs):
        self.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, True)
        self.setFlag(QtGui.QGraphicsItem.ItemIsFocusable, True)
        self.setAcceptsHoverEvents(True)

        self.node_editor.scene.addItem(self)
        self.setScene(self.node_editor.scene)
        self.anchorLayout = QtGui.QVBoxLayout()
        self.nodeLayout = QtGui.QVBoxLayout()
        self.nodeGraphicsLayout = QtGui.QGraphicsGridLayout()
        self.font = QtGui.QFont()
        self.font.setPointSize(15)
        self.label = QtGui.QLabel(self.parent.getTitle())
        self.label.setFont(self.font)
        self.label.setStyleSheet("color:rgb(189,195,199)")
        #self.labelProxy = QtGui.QGraphicsProxyWidget(self)
        #self.labelProxy.setWidget(self.label)
        #self.labelProxy.setParentItem(self);
        self.nodeLayout.addWidget(self.label)
        self.nodeFrame.setLayout(self.nodeLayout)
        self.nodeLayout.addLayout(self.anchorLayout)
        self.nodeFrame.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,QtGui.QSizePolicy.MinimumExpanding)
        #self.nodeLayout.addWidget(self.label)
        pProxy = QtGui.QGraphicsProxyWidget(self)
        pProxy.setWidget(self.nodeFrame)
       # self.node_editor.scene.addItem(pProxy)
        print "parent's anchors",self.parent.getAnchors()
        for anchor in self.parent.getAnchors():
            pass
            self.addAnchor(anchor)

        self.openSlotLayout = QtGui.QHBoxLayout()

        #self.addNodeLabel = QtGui.QLabel(str("Add..."))
       # self.addNodeLabel.setStyleSheet("color:rgb(139, 250, 149)")

       # self.openSlot = MAnchorPortOpenSlotItem(self.nodeFrame)
        self.addAnchorButton = QtGui.QPushButton("Add")
        self.openSlotLayout.addWidget(self.addAnchorButton)
        self.openSlotLayout.addStretch(0)
        self.addAnchorButton.clicked.connect(self.addNewParameterEvent)
        self.nodeLayout.addWidget(self.addAnchorButton)

        # Tell the gui that the item is moveable, slectable, and focusable and that
        # it accepts hover events.

        # Bounding rectangle
        self.rect = QtCore.QRectF(
            0, 0, self.nodeFrame.width(), self.nodeFrame.height())
        # Tell the gui that the item is moveable, slectable, and focusable and that
        # it accepts hover events.
        self.setColor(*self.color)
        self.textPen = QtGui.QPen()
        self.textPen.setWidth(2)
        self.textPen.setColor(QtGui.QColor(255, 100, 0))
        #self.textPen.setColor(QtGui.QColor(189, 195, 199))

        self.nodeBrush = QtGui.QBrush(QtGui.QColor(*self.color))
예제 #2
0
파일: owgrid.py 프로젝트: waqarini/orange3
    def __init__(self, parent=None):
        super().__init__(parent)

        self.setSizePolicy(QtGui.QSizePolicy.Maximum,
                           QtGui.QSizePolicy.Maximum)
        self.setContentsMargins(10, 10, 10, 10)

        self.__layout = QtGui.QGraphicsGridLayout()
        self.__layout.setContentsMargins(0, 0, 0, 0)
        self.__layout.setSpacing(10)
        self.setLayout(self.__layout)
예제 #3
0
 def __init__(self, parent=None, **kwargs):
     super().__init__(parent, **kwargs)
     self.setAcceptHoverEvents(True)
     self.__groups = []
     self.__rowNamesVisible = True
     self.__barHeight = 3
     self.__selectionRect = None
     self.__selection = numpy.asarray([], dtype=int)
     self.__selstate = None
     self.__pen = QtGui.QPen(Qt.NoPen)
     self.__brush = QtGui.QBrush(QtGui.QColor("#3FCFCF"))
     self.__layout = QtGui.QGraphicsGridLayout()
     self.__hoveredItem = None
     self.setLayout(self.__layout)
     self.layout().setColumnSpacing(0, 1.)
예제 #4
0
    def __init__(self):
        pg.GraphicsWidget.__init__(self)
        self.outside_rect = QtGui.QGraphicsRectItem(0, 0, 100, 100)
        self.inside_rect = QtGui.QGraphicsRectItem(0, 0, 50, 50)

        self._layout = QtGui.QGraphicsGridLayout()

        self.outside_rect.setPen(pg.mkPen(color=(255, 255, 255), width=1))
        self.inside_rect.setBrush(QtGui.QBrush(QtGui.QColor(255, 0, 0, 150)))

        self.__parent = None
        self.__parentAnchor = None
        self.__itemAnchor = None
        self.__offset = (0, 0)

        self.inside_rect.setParentItem(self)
        self.outside_rect.setParentItem(self)
        self.inside_rect.setZValue(-100000)
        self.outside_rect.setZValue(200)

        self._intensity_level = 0
예제 #5
0
    def __updateLayout(self, histogramHorizontal=None):
        """
        Updates the layout of the widget to change the histogram
        position (horizontal-vertical) and visibility
        :param histogramHorizontal: None if invisible, true if horizontal
        false if vertical
        :return:
        """
        # graph_control_layout

        self.graphics_view = pg.GraphicsView()

        # set the layout of the graphics view internal
        # that contains the axis and the view box to graph the spectrogram
        graphics_view_grid_layout = QtGui.QGraphicsGridLayout()
        graphics_view_grid_layout.setContentsMargins(0, 0, 0, 0)
        graphics_view_grid_layout.setHorizontalSpacing(0)
        graphics_view_grid_layout.setVerticalSpacing(0)

        graphics_view_grid_layout.addItem(self.xAxis, 1, 1)
        graphics_view_grid_layout.addItem(self.yAxis, 0, 0)
        graphics_view_grid_layout.addItem(self.viewBox, 0, 1)

        self.graphics_view.centralWidget.setLayout(graphics_view_grid_layout)
        layout = QtGui.QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.graphics_view, 0, 0)
        # add the elements in row,col

        if histogramHorizontal is not None:
            row = 1 if histogramHorizontal else 0
            col = 1 - row
            self.__histogram = HorizontalHistogramWidget() if histogramHorizontal else\
                               HistogramLUTWidget()
            self.__histogram.item.gradient.loadPreset('thermal')
            self.__histogram.item.setImageItem(self.imageItem)
            layout.addWidget(self.histogram, row, col)

        self.setLayout(layout)
예제 #6
0
파일: sudoku_grid.py 프로젝트: Razor00/code
    def __init__(self, N, path):
        super(SUDOKU_GRID, self).__init__()
        self.path = path
        self.inp = None
        self.result = None
        self.N = N
        self.bw = 40
        self.bh = 40
        self.hs = 8
        self.vs = 8
        scene = QtGui.QGraphicsScene(self)
        scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
        scene.setSceneRect(0, 0, (self.bw + self.hs) * N,
                           (self.bh + self.vs) * N)
        self.setScene(scene)
        self.setCacheMode(QtGui.QGraphicsView.CacheBackground)
        self.setViewportUpdateMode(
            QtGui.QGraphicsView.BoundingRectViewportUpdate)
        self.setRenderHint(QtGui.QPainter.Antialiasing)
        self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
        self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter)

        self.max = SUDOKU_GRID.maxDigits(self.N)
        self.layout = QtGui.QGraphicsGridLayout()
        self.layout.setHorizontalSpacing(self.hs)
        self.layout.setVerticalSpacing(self.vs)
        bpen = QtGui.QPen()
        pen = QtGui.QPen()
        #pen.setColor(QtGui.QColor("red"))
        pen.setWidth(3)
        sN = int(math.sqrt(N))
        for i in range(N):
            x1 = 0
            y1 = i * (self.bh + self.vs)
            x2 = N * (self.bw + self.hs)
            y2 = y1
            if i % sN == 0:
                scene.addLine(x1, y1, x2, y2, pen)
            else:
                scene.addLine(x1, y1, x2, y2)

            font = QtGui.QFont("Times", 14, QtGui.QFont.Bold, True)
            for j in range(N):
                ledt = QtGui.QLineEdit()
                ledt.setMaxLength(self.max)
                ledt.setMaximumSize(self.bw, self.bh)
                ledt.setMinimumSize(self.bw, self.bh)
                ledt.setFont(font)
                proxy = scene.addWidget(ledt)
                self.layout.addItem(proxy, i, j)

                x_1 = (j) * (self.bw + self.hs)
                y_1 = 0
                x_2 = x_1
                y_2 = N * (self.bh + self.vs)
                if j % sN == 0:
                    scene.addLine(x_1, y_1, x_2, y_2, pen)
                else:
                    scene.addLine(x_1, y_1, x_2, y_2)

            x_1 = (j + 1) * (self.bw + self.hs)
            y_1 = 0
            x_2 = x_1
            y_2 = N * (self.bh + self.vs)
            if (j + 1) % sN == 0:
                scene.addLine(x_1, y_1, x_2, y_2, pen)
            else:
                scene.addLine(x_1, y_1, x_2, y_2)

        x1 = 0
        x1 = 0
        y1 = (i + 1) * (self.bh + self.vs)
        x2 = N * (self.bw + self.hs)
        y2 = y1
        if (i + 1) % sN == 0:
            scene.addLine(x1, y1, x2, y2, pen)
        else:
            scene.addLine(x1, y1, x2, y2)

        print self.layout.horizontalSpacing(), self.layout.verticalSpacing()

        gw = QtGui.QGraphicsWidget()
        gw.setLayout(self.layout)
        scene.addItem(gw)
        self.move(400, 400)
        self.ensureVisible(0, 0, 800, 800)
예제 #7
0
def matplotlibExport(object=None, title=None, show=True, size=None):
    """
    Constructs a matplotlib window that shows the current plots laid out in the same
    format as the pyqtgraph window
    You might use this for publication purposes, since matplotlib allows export
    of the window to a variety of formats, and will contain proper fonts (not "outlined").
    Also can be used for automatic generation of PDF files with savefig.

    :param: object is either a QWindow or a QtGridLayout object that specifies
            how the grid was built
            The layout will contain pyqtgraph widgets added with .addLayout
    :return: nothing

    """
    if not HAVE_MPL:
        raise Exception(
            "Method matplotlibExport requires matplotlib; not importable.")
    if object.__class__ == pg.graphicsWindows.GraphicsWindow:
        gridlayout = object.ci.layout
        if gridlayout is None or gridlayout.__class__ != QtGui.QGraphicsGridLayout(
        ).__class__:
            raise Exception(
                "Method matplotlibExport: With graphicsWindow, requires a central item of type QGraphicsGridLayout"
            )
        ltype = 'QGGL'
    elif object.__class__ == QtGui.QGridLayout().__class__:
        gridlayout = object
        ltype = 'QGL'
    else:
        raise Exception(
            "Method matplotlibExport requires Window or gridlayout as first argument (object=)"
        )
    if size is not None:
        pylab.rcParams['figure.figsize'] = size[0], size[1]
    fig = pylab.figure()  # create the matplotlib figure
    pylab.rcParams['text.usetex'] = False
    # escape filename information so it can be rendered by removing
    # common characters that trip up latex...:
    escs = re.compile('[\\\/_]')
    #print title
    if title is not None:
        title = remove_html_markup(title)
        tiname = '%r' % title
        tiname = re.sub(escs, cleanRepl, tiname)[1:-1]
        fig.suptitle(r'' + tiname)
    pylab.autoscale(enable=True, axis='both', tight=None)
    # build the plot based on the grid layout
    gs = gridspec.GridSpec(
        gridlayout.rowCount(),
        gridlayout.columnCount())  # build matplotlib gridspec
    if ltype == 'QGGL':  # object of type QGraphicsGridLayout
        for r in range(gridlayout.rowCount()):
            for c in range(gridlayout.columnCount()):
                panel = gridlayout.itemAt(
                    r, c)  #.widget()  # retrieve the plot widget...
                if panel is not None:
                    mplax = pylab.subplot(gs[r,
                                             c])  # map to mpl subplot geometry
                    export_panel(panel, mplax)  # now fill the plot
    elif ltype == 'QGL':  # object of type QGridLayout
        for i in range(gridlayout.count()):
            w = gridlayout.itemAt(i).widget()  # retrieve the plot widget...
            (x, y, c,
             r) = gridlayout.getItemPosition(i)  # and gridspecs paramters
            mplax = pylab.subplot(gs[x:(c + x),
                                     y:(r + y)])  # map to mpl subplot geometry
            export_panel(w.getPlotItem(), mplax)  # now fill the ploti += 1
    else:
        raise ValueError(
            'Object must be a QWindow with a QGraphicsGridLayout, or a QGridLayout; neither received'
        )
    gs.update(wspace=0.25, hspace=0.5)  # adjust spacing
    # hook to save figure - not used here, but could be added as a flag.
    #       pylab.savefig(os.path.join(outputfile))
    if show:
        pylab.show()
예제 #8
0
    def __init__(self, x, y):
        super(BandSelectorWidget, self).__init__()

        # parameters
        self.width = 3
        self.x = 20
        self.x_max = 30.
        self.gran = x[1] - x[0]

        graphics_widget = pg.GraphicsWidget()

        self.middle = pg.LinearRegionItem([self.x, self.x],
                                          pg.LinearRegionItem.Vertical)
        self.middle.setBounds(
            [0 + self.width / 2, self.x_max - self.width / 2])
        self.middle.sigRegionChanged.connect(self.regionChanged)
        self.region = pg.LinearRegionItem(
            [self.x - self.width / 2, self.x + self.width / 2],
            pg.LinearRegionItem.Vertical,
            movable=False)
        self.region.setBounds((0, self.x_max))
        self.region.sigRegionChanged.connect(self.regionChanged)

        view_box = pg.ViewBox(parent=graphics_widget,
                              enableMouse=False,
                              enableMenu=False)
        #view_box.setAspectLocked()
        view_box.setYRange(0, 1)
        #view_box.enableAutoRange(view_box.XYAxes)

        axis = pg.AxisItem('bottom', linkView=view_box, parent=graphics_widget)
        plot = pg.PlotDataItem()
        plot.setData(x, y / (max(y[x < self.x_max]) or 1))
        view_box.setXRange(0, self.x_max)

        view_box.addItem(plot)
        view_box.addItem(self.region)
        view_box.addItem(self.middle)
        self.view_box = view_box

        # setup grid layout
        grid_layout = QtGui.QGraphicsGridLayout(graphics_widget)
        grid_layout.addItem(axis, 1, 0)
        grid_layout.addItem(view_box, 0, 0)

        # view
        view = pg.GraphicsView()
        view.setCentralItem(graphics_widget)
        self.width_slider = ParameterSlider('Band width:',
                                            1,
                                            10,
                                            interval=0.1,
                                            value=self.width,
                                            units='Hz')
        self.width_slider.valueChanged.connect(self.changeWidth)
        main_layout = QtGui.QVBoxLayout(self)
        main_layout.addWidget(view)
        main_layout.addWidget(self.width_slider)
        self.band = None
        btn = QtGui.QPushButton('Select')
        btn.clicked.connect(self.select_band)
        btn.setMaximumWidth(200)

        self.band_str = QtGui.QLabel(
            'Band:\t{}\t-\t{} Hz'.format(*self.region.getRegion()))
        main_layout.addWidget(self.band_str)
        main_layout.addWidget(btn)
예제 #9
0
    def __init__(self, parent=None, useOpenGL=True):
        """Re-implementation of QGraphicsView that removes scrollbars and allows unambiguous control of the 
        viewed coordinate range. Also automatically creates a QGraphicsScene and a central QGraphicsWidget
        that is automatically scaled to the full view geometry.
        
        By default, the view coordinate system matches the widget's pixel coordinates and 
        automatically updates when the view is resized. This can be overridden by setting 
        autoPixelRange=False. The exact visible range can be set with setRange().
        
        The view can be panned using the middle mouse button and scaled using the right mouse button if
        enabled via enableMouse()."""
        self.closed = False

        QtGui.QGraphicsView.__init__(self, parent)
        if 'linux' in sys.platform:  ## linux has bugs in opengl implementation
            useOpenGL = False
        self.useOpenGL(useOpenGL)

        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(244, 244, 244))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        self.setPalette(palette)
        #self.setProperty("cursor",QtCore.QVariant(QtCore.Qt.ArrowCursor))
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.setFrameShape(QtGui.QFrame.NoFrame)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setTransformationAnchor(QtGui.QGraphicsView.NoAnchor)
        self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter)
        #self.setResizeAnchor(QtGui.QGraphicsView.NoAnchor)
        self.setViewportUpdateMode(QtGui.QGraphicsView.SmartViewportUpdate)
        self.setSceneRect(QtCore.QRectF(-1e10, -1e10, 2e10, 2e10))
        #self.setSceneRect(1, 1, 0, 0) ## Set an empty (but non-zero) scene rect so that the view doesn't try to automatically update for us.
        #self.setInteractive(False)
        self.lockedViewports = []
        self.lastMousePos = None
        #self.setMouseTracking(False)
        self.aspectLocked = False
        self.yInverted = True
        self.range = QtCore.QRectF(0, 0, 1, 1)
        self.autoPixelRange = True
        self.currentItem = None
        self.clearMouse()
        self.updateMatrix()
        self.sceneObj = QtGui.QGraphicsScene()
        self.setScene(self.sceneObj)

        ## by default we set up a central widget with a grid layout.
        ## this can be replaced if needed.
        self.centralWidget = None
        self.setCentralItem(QtGui.QGraphicsWidget())
        self.centralLayout = QtGui.QGraphicsGridLayout()
        self.centralWidget.setLayout(self.centralLayout)

        self.mouseEnabled = False
        self.scaleCenter = False  ## should scaling center around view center (True) or mouse click (False)
        self.clickAccepted = False
예제 #10
0
    def __init__(self, image=None, fillHistogram=True):
        """ constructor

        :param image: 2d image
        :type image: :class:`pyqtgraph.ImageItem`
        :param fillHistogram: histogram will be filled in
        :type fillHistogram: :obj:`bool`
        """
        _pg.graphicsItems.GraphicsWidget.GraphicsWidget.__init__(self)

        #: (:class:`numpy.ndarray`) look up table
        self.lut = None
        if _VMAJOR == '0' and int(_VMINOR) < 10 and int(_VPATCH) < 9:
            #: (:class:`weakref.ref` or :class:`pyqtgraph.ImageItem`)
            #: weakref to image item or image item itself  (for < 0.9.8)
            self.imageItem = None
        else:
            self.imageItem = lambda: None

        #: (:class:`PyQt4.QtGui.QGraphicsGridLayout`) grid layout
        self.layout = QtGui.QGraphicsGridLayout()
        self.setLayout(self.layout)
        self.layout.setContentsMargins(1, 1, 1, 1)
        self.layout.setSpacing(0)

        #: (:class:`pyqtgraph.graphicsItems.ViewBox.ViewBox`) view box
        self.vb = _pg.graphicsItems.ViewBox.ViewBox()
        # self.vb.setMaximumHeight(152)
        self.vb.setMinimumHeight(45)
        self.vb.setMouseEnabled(x=True, y=False)
        # self.vb.setMouseEnabled(x=False, y=True)

        #: (:class:`GradientEditorItemWS`) gradient editor item with a signal
        self.gradient = GradientEditorItemWS()
        self.gradient.setOrientation('bottom')
        self.gradient.loadPreset('grey')

        #: (:class:`pyqtgraph.graphicsItems.LinearRegionItem.LinearRegionItem`)
        #:    linear region item
        self.region = _pg.graphicsItems.LinearRegionItem.LinearRegionItem(
            [0, 1],
            _pg.graphicsItems.LinearRegionItem.LinearRegionItem.Vertical)
        self.region.setZValue(1000)
        self.vb.addItem(self.region)

        #: (:class:`pyqtgraph.graphicsItems.AxisItem.AxisItem`) axis item
        self.axis = _pg.graphicsItems.AxisItem.AxisItem('top',
                                                        linkView=self.vb,
                                                        maxTickLength=-10,
                                                        showValues=False)

        self.layout.addItem(self.axis, 0, 0)
        self.layout.addItem(self.vb, 1, 0)
        self.layout.addItem(self.gradient, 2, 0)
        self.range = None

        self.gradient.setFlag(self.gradient.ItemStacksBehindParent)
        self.vb.setFlag(self.gradient.ItemStacksBehindParent)

        self.gradient.sigGradientChanged.connect(self.gradientChanged)
        self.region.sigRegionChanged.connect(self.regionChanging)
        self.region.sigRegionChangeFinished.connect(self.regionChanged)
        self.vb.sigRangeChanged.connect(self.viewRangeChanged)
        self.plot = _pg.graphicsItems.PlotDataItem.PlotDataItem()
        # self.plot.dataBounds(1, 0.9)
        # self.plot.dataBounds(0, 0.9)

        self.fillHistogram(fillHistogram)

        self.vb.addItem(self.plot)
        self.autoHistogramRange()

        if image is not None:
            self.setImageItem(image)
예제 #11
0
from PyQt4 import QtGui, QtCore
import pyqtgraph as pg

app = QtGui.QApplication([])
mw = QtGui.QMainWindow()
cw = QtGui.QWidget()
vl = QtGui.QVBoxLayout()
cw.setLayout(vl)
mw.setCentralWidget(cw)
mw.show()
mw.resize(800, 600)


gv = pg.GraphicsView(cw)
gv.enableMouse(False)    ## Mouse interaction will be handled by the ViewBox
l = QtGui.QGraphicsGridLayout()
l.setHorizontalSpacing(0)
l.setVerticalSpacing(0)


vb = pg.ViewBox()
p1 = pg.PlotCurveItem()
vb.addItem(p1)
vl.addWidget(gv)

class movableRect(QtGui.QGraphicsRectItem):
    def __init__(self, *args):
        QtGui.QGraphicsRectItem.__init__(self, *args)
        self.setAcceptHoverEvents(True)
    def hoverEnterEvent(self, ev):
        self.savedPen = self.pen()
예제 #12
0
    def __init__(self, parent=None, name=None, labels=None, **kargs):
        QtGui.QGraphicsWidget.__init__(self, parent)

        ## Set up control buttons

        self.ctrlBtn = QtGui.QToolButton()
        self.ctrlBtn.setText('?')
        self.autoBtn = QtGui.QToolButton()
        self.autoBtn.setText('A')
        self.autoBtn.hide()
        self.proxies = []
        for b in [self.ctrlBtn, self.autoBtn]:
            proxy = QtGui.QGraphicsProxyWidget(self)
            proxy.setWidget(b)
            proxy.setAcceptHoverEvents(False)
            b.setStyleSheet(
                "background-color: #000000; color: #888; font-size: 6pt")
            self.proxies.append(proxy)
        #QtCore.QObject.connect(self.ctrlBtn, QtCore.SIGNAL('clicked()'), self.ctrlBtnClicked)
        self.ctrlBtn.clicked.connect(self.ctrlBtnClicked)
        #QtCore.QObject.connect(self.autoBtn, QtCore.SIGNAL('clicked()'), self.enableAutoScale)
        self.autoBtn.clicked.connect(self.enableAutoScale)

        self.layout = QtGui.QGraphicsGridLayout()
        self.layout.setContentsMargins(1, 1, 1, 1)
        self.setLayout(self.layout)
        self.layout.setHorizontalSpacing(0)
        self.layout.setVerticalSpacing(0)

        self.vb = ViewBox()
        #QtCore.QObject.connect(self.vb, QtCore.SIGNAL('xRangeChanged'), self.xRangeChanged)
        self.vb.sigXRangeChanged.connect(self.xRangeChanged)
        #QtCore.QObject.connect(self.vb, QtCore.SIGNAL('yRangeChanged'), self.yRangeChanged)
        self.vb.sigYRangeChanged.connect(self.yRangeChanged)
        #QtCore.QObject.connect(self.vb, QtCore.SIGNAL('rangeChangedManually'), self.enableManualScale)
        self.vb.sigRangeChangedManually.connect(self.enableManualScale)

        #QtCore.QObject.connect(self.vb, QtCore.SIGNAL('viewChanged'), self.viewChanged)
        self.vb.sigRangeChanged.connect(self.viewRangeChanged)

        self.layout.addItem(self.vb, 2, 1)
        self.alpha = 1.0
        self.autoAlpha = True
        self.spectrumMode = False

        self.autoScale = [True, True]

        ## Create and place scale items
        self.scales = {
            'top': {
                'item': ScaleItem(orientation='top', linkView=self.vb),
                'pos': (1, 1)
            },
            'bottom': {
                'item': ScaleItem(orientation='bottom', linkView=self.vb),
                'pos': (3, 1)
            },
            'left': {
                'item': ScaleItem(orientation='left', linkView=self.vb),
                'pos': (2, 0)
            },
            'right': {
                'item': ScaleItem(orientation='right', linkView=self.vb),
                'pos': (2, 2)
            }
        }
        for k in self.scales:
            self.layout.addItem(self.scales[k]['item'], *self.scales[k]['pos'])

        ## Create and place label items
        #self.labels = {
        #'title':  {'item': LabelItem('title', size='11pt'),  'pos': (0, 2), 'text': ''},
        #'top':    {'item': LabelItem('top'),    'pos': (1, 2), 'text': '', 'units': '', 'unitPrefix': ''},
        #'bottom': {'item': LabelItem('bottom'), 'pos': (5, 2), 'text': '', 'units': '', 'unitPrefix': ''},
        #'left':   {'item': LabelItem('left'),   'pos': (3, 0), 'text': '', 'units': '', 'unitPrefix': ''},
        #'right':  {'item': LabelItem('right'),  'pos': (3, 4), 'text': '', 'units': '', 'unitPrefix': ''}
        #}
        #self.labels['left']['item'].setAngle(-90)
        #self.labels['right']['item'].setAngle(-90)
        #for k in self.labels:
        #self.layout.addItem(self.labels[k]['item'], *self.labels[k]['pos'])
        self.titleLabel = LabelItem('', size='11pt')
        self.layout.addItem(self.titleLabel, 0, 1)
        self.setTitle(None)  ## hide

        for i in range(4):
            self.layout.setRowPreferredHeight(i, 0)
            self.layout.setRowMinimumHeight(i, 0)
            self.layout.setRowSpacing(i, 0)
            self.layout.setRowStretchFactor(i, 1)

        for i in range(3):
            self.layout.setColumnPreferredWidth(i, 0)
            self.layout.setColumnMinimumWidth(i, 0)
            self.layout.setColumnSpacing(i, 0)
            self.layout.setColumnStretchFactor(i, 1)
        self.layout.setRowStretchFactor(2, 100)
        self.layout.setColumnStretchFactor(1, 100)

        ## Wrap a few methods from viewBox
        for m in [
                'setXRange', 'setYRange', 'setRange', 'autoRange', 'viewRect',
                'setMouseEnabled'
        ]:
            setattr(self, m, getattr(self.vb, m))

        self.items = []
        self.curves = []
        self.dataItems = []
        self.paramList = {}
        self.avgCurves = {}

        ### Set up context menu

        w = QtGui.QWidget()
        self.ctrl = c = Ui_Form()
        c.setupUi(w)
        dv = QtGui.QDoubleValidator(self)
        self.ctrlMenu = QtGui.QMenu()
        self.menuAction = QtGui.QWidgetAction(self)
        self.menuAction.setDefaultWidget(w)
        self.ctrlMenu.addAction(self.menuAction)

        if HAVE_WIDGETGROUP:
            self.stateGroup = WidgetGroup(self.ctrlMenu)

        self.fileDialog = None

        self.xLinkPlot = None
        self.yLinkPlot = None
        self.linksBlocked = False

        #self.ctrlBtn.setFixedWidth(60)
        self.setAcceptHoverEvents(True)

        ## Connect control widgets
        #QtCore.QObject.connect(c.xMinText, QtCore.SIGNAL('editingFinished()'), self.setManualXScale)
        c.xMinText.editingFinished.connect(self.setManualXScale)
        #QtCore.QObject.connect(c.xMaxText, QtCore.SIGNAL('editingFinished()'), self.setManualXScale)
        c.xMaxText.editingFinished.connect(self.setManualXScale)
        #QtCore.QObject.connect(c.yMinText, QtCore.SIGNAL('editingFinished()'), self.setManualYScale)
        c.yMinText.editingFinished.connect(self.setManualYScale)
        #QtCore.QObject.connect(c.yMaxText, QtCore.SIGNAL('editingFinished()'), self.setManualYScale)
        c.yMaxText.editingFinished.connect(self.setManualYScale)

        #QtCore.QObject.connect(c.xManualRadio, QtCore.SIGNAL('clicked()'), self.updateXScale)
        c.xManualRadio.clicked.connect(lambda: self.updateXScale())
        #QtCore.QObject.connect(c.yManualRadio, QtCore.SIGNAL('clicked()'), self.updateYScale)
        c.yManualRadio.clicked.connect(lambda: self.updateYScale())

        #QtCore.QObject.connect(c.xAutoRadio, QtCore.SIGNAL('clicked()'), self.updateXScale)
        c.xAutoRadio.clicked.connect(self.updateXScale)
        #QtCore.QObject.connect(c.yAutoRadio, QtCore.SIGNAL('clicked()'), self.updateYScale)
        c.yAutoRadio.clicked.connect(self.updateYScale)

        #QtCore.QObject.connect(c.xAutoPercentSpin, QtCore.SIGNAL('valueChanged(int)'), self.replot)
        c.xAutoPercentSpin.valueChanged.connect(self.replot)
        #QtCore.QObject.connect(c.yAutoPercentSpin, QtCore.SIGNAL('valueChanged(int)'), self.replot)
        c.yAutoPercentSpin.valueChanged.connect(self.replot)

        #QtCore.QObject.connect(c.xLogCheck, QtCore.SIGNAL('toggled(bool)'), self.setXLog)
        #QtCore.QObject.connect(c.yLogCheck, QtCore.SIGNAL('toggled(bool)'), self.setYLog)

        #QtCore.QObject.connect(c.alphaGroup, QtCore.SIGNAL('toggled(bool)'), self.updateAlpha)
        c.alphaGroup.toggled.connect(self.updateAlpha)
        #QtCore.QObject.connect(c.alphaSlider, QtCore.SIGNAL('valueChanged(int)'), self.updateAlpha)
        c.alphaSlider.valueChanged.connect(self.updateAlpha)
        #QtCore.QObject.connect(c.autoAlphaCheck, QtCore.SIGNAL('toggled(bool)'), self.updateAlpha)
        c.autoAlphaCheck.toggled.connect(self.updateAlpha)

        #QtCore.QObject.connect(c.gridGroup, QtCore.SIGNAL('toggled(bool)'), self.updateGrid)
        c.gridGroup.toggled.connect(self.updateGrid)
        #QtCore.QObject.connect(c.gridAlphaSlider, QtCore.SIGNAL('valueChanged(int)'), self.updateGrid)
        c.gridAlphaSlider.valueChanged.connect(self.updateGrid)

        #QtCore.QObject.connect(c.powerSpectrumGroup, QtCore.SIGNAL('toggled(bool)'), self.updateSpectrumMode)
        c.powerSpectrumGroup.toggled.connect(self.updateSpectrumMode)
        #QtCore.QObject.connect(c.saveSvgBtn, QtCore.SIGNAL('clicked()'), self.saveSvgClicked)
        c.saveSvgBtn.clicked.connect(self.saveSvgClicked)
        #QtCore.QObject.connect(c.saveImgBtn, QtCore.SIGNAL('clicked()'), self.saveImgClicked)
        c.saveImgBtn.clicked.connect(self.saveImgClicked)
        #QtCore.QObject.connect(c.saveCsvBtn, QtCore.SIGNAL('clicked()'), self.saveCsvClicked)
        c.saveCsvBtn.clicked.connect(self.saveCsvClicked)

        #QtCore.QObject.connect(c.gridGroup, QtCore.SIGNAL('toggled(bool)'), self.updateGrid)
        #QtCore.QObject.connect(c.gridAlphaSlider, QtCore.SIGNAL('valueChanged(int)'), self.updateGrid)

        #QtCore.QObject.connect(self.ctrl.xLinkCombo, QtCore.SIGNAL('currentIndexChanged(int)'), self.xLinkComboChanged)
        self.ctrl.xLinkCombo.currentIndexChanged.connect(
            self.xLinkComboChanged)
        #QtCore.QObject.connect(self.ctrl.yLinkCombo, QtCore.SIGNAL('currentIndexChanged(int)'), self.yLinkComboChanged)
        self.ctrl.yLinkCombo.currentIndexChanged.connect(
            self.yLinkComboChanged)

        #QtCore.QObject.connect(c.downsampleSpin, QtCore.SIGNAL('valueChanged(int)'), self.updateDownsampling)
        c.downsampleSpin.valueChanged.connect(self.updateDownsampling)

        #QtCore.QObject.connect(self.ctrl.avgParamList, QtCore.SIGNAL('itemClicked(QListWidgetItem*)'), self.avgParamListClicked)
        self.ctrl.avgParamList.itemClicked.connect(self.avgParamListClicked)
        #QtCore.QObject.connect(self.ctrl.averageGroup, QtCore.SIGNAL('toggled(bool)'), self.avgToggled)
        self.ctrl.averageGroup.toggled.connect(self.avgToggled)

        #QtCore.QObject.connect(self.ctrl.pointsGroup, QtCore.SIGNAL('toggled(bool)'), self.updatePointMode)
        #QtCore.QObject.connect(self.ctrl.autoPointsCheck, QtCore.SIGNAL('toggled(bool)'), self.updatePointMode)

        #QtCore.QObject.connect(self.ctrl.maxTracesCheck, QtCore.SIGNAL('toggled(bool)'), self.updateDecimation)
        self.ctrl.maxTracesCheck.toggled.connect(self.updateDecimation)
        #QtCore.QObject.connect(self.ctrl.maxTracesSpin, QtCore.SIGNAL('valueChanged(int)'), self.updateDecimation)
        self.ctrl.maxTracesSpin.valueChanged.connect(self.updateDecimation)
        #QtCore.QObject.connect(c.xMouseCheck, QtCore.SIGNAL('toggled(bool)'), self.mouseCheckChanged)
        c.xMouseCheck.toggled.connect(self.mouseCheckChanged)
        #QtCore.QObject.connect(c.yMouseCheck, QtCore.SIGNAL('toggled(bool)'), self.mouseCheckChanged)
        c.yMouseCheck.toggled.connect(self.mouseCheckChanged)

        self.xLinkPlot = None
        self.yLinkPlot = None
        self.linksBlocked = False
        self.manager = None

        #self.showLabel('right', False)
        #self.showLabel('top', False)
        #self.showLabel('title', False)
        #self.showLabel('left', False)
        #self.showLabel('bottom', False)
        self.showScale('right', False)
        self.showScale('top', False)
        self.showScale('left', True)
        self.showScale('bottom', True)

        if name is not None:
            self.registerPlot(name)

        if labels is not None:
            for k in labels:
                if isinstance(labels[k], basestring):
                    labels[k] = (labels[k], )
                self.setLabel(k, *labels[k])

        if len(kargs) > 0:
            self.plot(**kargs)
예제 #13
0
    def __init__(self,
                 xmin,
                 xmax,
                 ymax,
                 parent=None,
                 name=None,
                 labels=None,
                 **kargs):  # xmin, xmax, ymax,
        QtGui.QGraphicsWidget.__init__(self, parent)

        ## Set up control buttons

        self.ctrlBtn = QtGui.QToolButton()
        self.ctrlBtn.setIcon(QtGui.QIcon('gui/icons/configure_shortcuts.png'))
        self.autoBtn = QtGui.QToolButton()
        self.autoBtn.setIcon(QtGui.QIcon('gui/icons/zoom_fit_best.png'))

        self.ctrlBtn.clicked.connect(self.ctrlBtnClicked)
        self.autoBtn.clicked.connect(self.enableAutoScale)

        stylesheet = '''
        QToolBar {
         background: qlineargradient(x1: 0, y1:0, x2: 1, y2: 1,
                    stop: 0 #a6a6a6, stop: 0.08 #7f7f7f,
                    stop: 0.39999 #717171, stop: 0.4 #626262,
                    stop: 0.9 #4c4c4c, stop: 1 #333333);
         spacing: 10px; /* spacing between items in the tool bar */
         }'''
        self.toolBar = QtGui.QToolBar()
        self.toolBar.setStyleSheet(stylesheet)
        self.toolBar.addWidget(self.ctrlBtn)
        self.toolBar.addWidget(self.autoBtn)

        self.layout = QtGui.QGraphicsGridLayout()
        self.layout.setContentsMargins(1, 1, 1, 1)
        self.setLayout(self.layout)
        self.layout.setHorizontalSpacing(0)
        self.layout.setVerticalSpacing(0)

        self.vb = ViewBox(xmin, xmax, ymax)  #xmin, xmax, ymax
        #QtCore.QObject.connect(self.vb, QtCore.SIGNAL('xRangeChangedc'), self.xRangeChanged)
        self.vb.sigXRangeChanged.connect(self.xRangeChanged)
        #QtCore.QObject.connect(self.vb, QtCore.SIGNAL('yRangeChanged'), self.yRangeChanged)
        self.vb.sigYRangeChanged.connect(self.yRangeChanged)
        #QtCore.QObject.connect(self.vb, QtCore.SIGNAL('rangeChangedManually'), self.enableManualScale)
        self.vb.sigRangeChangedManually.connect(self.enableManualScale)

        #QtCore.QObject.connect(self.vb, QtCore.SIGNAL('viewChanged'), self.viewChanged)
        self.vb.sigRangeChanged.connect(self.viewRangeChanged)

        self.layout.addItem(self.vb, 2, 1)

        self.alpha = 1.0
        self.autoAlpha = True
        self.spectrumMode = False

        self.autoScale = [True, True]

        ## Create and place scale items
        self.scales = {
            'top': {
                'item': ScaleItem(orientation='top', linkView=self.vb),
                'pos': (1, 1)
            },
            'bottom': {
                'item': ScaleItem(orientation='bottom', linkView=self.vb),
                'pos': (3, 1)
            },
            'left': {
                'item': ScaleItem(orientation='left', linkView=self.vb),
                'pos': (2, 0)
            },
            'right': {
                'item': ScaleItem(orientation='right', linkView=self.vb),
                'pos': (2, 2)
            }
        }
        for k in self.scales:
            #self.scales[k]['item'].setGrid(False)
            self.layout.addItem(self.scales[k]['item'], *self.scales[k]['pos'])

        self.titleLabel = LabelItem('', size='11pt', color='000')
        self.layout.addItem(self.titleLabel, 0, 1)
        #self.setTitle(None)  ## hide

        for i in range(4):
            self.layout.setRowPreferredHeight(i, 0)
            self.layout.setRowMinimumHeight(i, 0)
            self.layout.setRowSpacing(i, 0)
            self.layout.setRowStretchFactor(i, 1)

        for i in range(3):
            self.layout.setColumnPreferredWidth(i, 0)
            self.layout.setColumnMinimumWidth(i, 0)
            self.layout.setColumnSpacing(i, 0)
            self.layout.setColumnStretchFactor(i, 1)
        self.layout.setRowStretchFactor(2, 100)
        self.layout.setColumnStretchFactor(1, 100)

        ## Wrap a few methods from viewBox
        for m in [
                'setXRange', 'setYRange', 'setRange', 'autoRange', 'viewRect',
                'setMouseEnabled'
        ]:
            setattr(self, m, getattr(self.vb, m))

        self.items = []
        self.curves = []
        self.dataItems = []
        self.paramList = {}
        self.avgCurves = {}

        ### Set up context menu

        w = QtGui.QWidget()
        self.ctrl = c = Ui_Form()
        c.setupUi(w)
        dv = QtGui.QDoubleValidator(self)
        self.ctrlMenu = QtGui.QMenu()
        self.menuAction = QtGui.QWidgetAction(self)
        self.menuAction.setDefaultWidget(w)
        self.ctrlMenu.addAction(self.menuAction)

        if HAVE_WIDGETGROUP:
            self.stateGroup = WidgetGroup(self.ctrlMenu)

        self.fileDialog = None

        self.xLinkPlot = None
        self.yLinkPlot = None
        self.linksBlocked = False

        #self.ctrlBtn.setFixedWidth(60)
        self.setAcceptHoverEvents(True)

        ## Connect control widgets
        #QtCore.QObject.connect(c.xMinText, QtCore.SIGNAL('editingFinished()'), self.setManualXScale)
        c.xMinText.editingFinished.connect(self.setManualXScale)
        #QtCore.QObject.connect(c.xMaxText, QtCore.SIGNAL('editingFinished()'), self.setManualXScale)
        c.xMaxText.editingFinished.connect(self.setManualXScale)
        #QtCore.QObject.connect(c.yMinText, QtCore.SIGNAL('editingFinished()'), self.setManualYScale)
        c.yMinText.editingFinished.connect(self.setManualYScale)
        #QtCore.QObject.connect(c.yMaxText, QtCore.SIGNAL('editingFinished()'), self.setManualYScale)
        c.yMaxText.editingFinished.connect(self.setManualYScale)

        #QtCore.QObject.connect(c.xManualRadio, QtCore.SIGNAL('clicked()'), self.updateXScale)
        c.xManualRadio.clicked.connect(lambda: self.updateXScale())
        #QtCore.QObject.connect(c.yManualRadio, QtCore.SIGNAL('clicked()'), self.updateYScale)
        c.yManualRadio.clicked.connect(lambda: self.updateYScale())

        #QtCore.QObject.connect(c.xAutoRadio, QtCore.SIGNAL('clicked()'), self.updateXScale)
        c.xAutoRadio.clicked.connect(self.updateXScale)
        #QtCore.QObject.connect(c.yAutoRadio, QtCore.SIGNAL('clicked()'), self.updateYScale)
        c.yAutoRadio.clicked.connect(self.updateYScale)

        #QtCore.QObject.connect(c.xAutoPercentSpin, QtCore.SIGNAL('valueChanged(int)'), self.replot)
        c.xAutoPercentSpin.valueChanged.connect(self.replot)
        #QtCore.QObject.connect(c.yAutoPercentSpin, QtCore.SIGNAL('valueChanged(int)'), self.replot)
        c.yAutoPercentSpin.valueChanged.connect(self.replot)

        #QtCore.QObject.connect(c.xLogCheck, QtCore.SIGNAL('toggled(bool)'), self.setXLog)
        #QtCore.QObject.connect(c.yLogCheck, QtCore.SIGNAL('toggled(bool)'), self.setYLog)

        #QtCore.QObject.connect(c.alphaGroup, QtCore.SIGNAL('toggled(bool)'), self.updateAlpha)
        c.alphaGroup.toggled.connect(self.updateAlpha)
        #QtCore.QObject.connect(c.alphaSlider, QtCore.SIGNAL('valueChanged(int)'), self.updateAlpha)
        c.alphaSlider.valueChanged.connect(self.updateAlpha)
        #QtCore.QObject.connect(c.autoAlphaCheck, QtCore.SIGNAL('toggled(bool)'), self.updateAlpha)
        c.autoAlphaCheck.toggled.connect(self.updateAlpha)

        #QtCore.QObject.connect(c.gridGroup, QtCore.SIGNAL('toggled(bool)'), self.updateGrid)
        c.gridGroup.toggled.connect(self.updateGrid)
        #QtCore.QObject.connect(c.gridAlphaSlider, QtCore.SIGNAL('valueChanged(int)'), self.updateGrid)
        c.gridAlphaSlider.valueChanged.connect(self.updateGrid)

        #QtCore.QObject.connect(c.powerSpectrumGroup, QtCore.SIGNAL('toggled(bool)'), self.updateSpectrumMode)
        c.powerSpectrumGroup.toggled.connect(self.updateSpectrumMode)
        #QtCore.QObject.connect(c.saveSvgBtn, QtCore.SIGNAL('clicked()'), self.saveSvgClicked)
        c.saveSvgBtn.clicked.connect(self.saveSvgClicked)
        #QtCore.QObject.connect(c.saveImgBtn, QtCore.SIGNAL('clicked()'), self.saveImgClicked)
        c.saveImgBtn.clicked.connect(self.saveImgClicked)
        #QtCore.QObject.connect(c.saveCsvBtn, QtCore.SIGNAL('clicked()'), self.saveCsvClicked)
        c.saveCsvBtn.clicked.connect(self.saveCsvClicked)

        #QtCore.QObject.connect(c.gridGroup, QtCore.SIGNAL('toggled(bool)'), self.updateGrid)
        #QtCore.QObject.connect(c.gridAlphaSlider, QtCore.SIGNAL('valueChanged(int)'), self.updateGrid)

        #QtCore.QObject.connect(self.ctrl.xLinkCombo, QtCore.SIGNAL('currentIndexChanged(int)'), self.xLinkComboChanged)
        self.ctrl.xLinkCombo.currentIndexChanged.connect(
            self.xLinkComboChanged)
        #QtCore.QObject.connect(self.ctrl.yLinkCombo, QtCore.SIGNAL('currentIndexChanged(int)'), self.yLinkComboChanged)
        self.ctrl.yLinkCombo.currentIndexChanged.connect(
            self.yLinkComboChanged)

        #QtCore.QObject.connect(c.downsampleSpin, QtCore.SIGNAL('valueChanged(int)'), self.updateDownsampling)
        c.downsampleSpin.valueChanged.connect(self.updateDownsampling)

        #QtCore.QObject.connect(self.ctrl.avgParamList, QtCore.SIGNAL('itemClicked(QListWidgetItem*)'), self.avgParamListClicked)
        self.ctrl.avgParamList.itemClicked.connect(self.avgParamListClicked)
        #QtCore.QObject.connect(self.ctrl.averageGroup, QtCore.SIGNAL('toggled(bool)'), self.avgToggled)
        self.ctrl.averageGroup.toggled.connect(self.avgToggled)

        #QtCore.QObject.connect(self.ctrl.pointsGroup, QtCore.SIGNAL('toggled(bool)'), self.updatePointMode)
        #QtCore.QObject.connect(self.ctrl.autoPointsCheck, QtCore.SIGNAL('toggled(bool)'), self.updatePointMode)

        #QtCore.QObject.connect(self.ctrl.maxTracesCheck, QtCore.SIGNAL('toggled(bool)'), self.updateDecimation)
        self.ctrl.maxTracesCheck.toggled.connect(self.updateDecimation)
        #QtCore.QObject.connect(self.ctrl.maxTracesSpin, QtCore.SIGNAL('valueChanged(int)'), self.updateDecimation)
        self.ctrl.maxTracesSpin.valueChanged.connect(self.updateDecimation)
        #QtCore.QObject.connect(c.xMouseCheck, QtCore.SIGNAL('toggled(bool)'), self.mouseCheckChanged)
        c.xMouseCheck.toggled.connect(self.mouseCheckChanged)
        #QtCore.QObject.connect(c.yMouseCheck, QtCore.SIGNAL('toggled(bool)'), self.mouseCheckChanged)
        c.yMouseCheck.toggled.connect(self.mouseCheckChanged)

        self.xLinkPlot = None
        self.yLinkPlot = None
        self.linksBlocked = False
        self.manager = None

        #self.showLabel('right', False)
        #self.showLabel('top', False)
        #self.showLabel('title', False)
        #self.showLabel('left', False)
        #self.showLabel('bottom', False)
        self.showScale('right', False)
        self.showScale('top', False)
        self.showScale('left', True)
        self.showScale('bottom', True)

        if name is not None:
            self.registerPlot(name)

        if labels is not None:
            for k in labels:
                if isinstance(labels[k], basestring):
                    labels[k] = (labels[k], )
                self.setLabel(k, *labels[k])

        if len(kargs) > 0:
            self.plot(**kargs)