Exemplo n.º 1
0
    def __init__(self, cm):
        self.cm = cm
        QtGui.QTreeWidgetItem.__init__(self)
        self.argCombo = pg.ComboBox()
        self.opCombo = pg.ComboBox()
        self.minSpin = SpinBox(value=0.0, dec=True, step=1)
        self.maxSpin = SpinBox(value=1.0, dec=True, step=1)
        self.gradient = GradientWidget()
        self.updateArgList()
        self.opCombo.addItem("+")
        self.opCombo.addItem("*")
        self.remBtn = QtGui.QPushButton("Remove")
        self.remBtn.clicked.connect(self.delete)

        self.minSpin.sigValueChanged.connect(self.emitChanged)
        self.maxSpin.sigValueChanged.connect(self.emitChanged)
        self.opCombo.currentIndexChanged.connect(self.emitChanged)
        self.argCombo.currentIndexChanged.connect(self.emitChanged)
        self.gradient.sigGradientChangeFinished.connect(self.emitChanged)
Exemplo n.º 2
0
class ColorMapperItem(QtGui.QTreeWidgetItem):
    def __init__(self, cm):
        self.cm = cm
        QtGui.QTreeWidgetItem.__init__(self)
        self.argCombo = pg.ComboBox()
        self.opCombo = pg.ComboBox()
        self.minSpin = SpinBox(value=0.0, dec=True, step=1)
        self.maxSpin = SpinBox(value=1.0, dec=True, step=1)
        self.gradient = GradientWidget()
        self.updateArgList()
        self.opCombo.addItem("+")
        self.opCombo.addItem("*")
        self.remBtn = QtGui.QPushButton("Remove")
        self.remBtn.clicked.connect(self.delete)

        self.minSpin.sigValueChanged.connect(self.emitChanged)
        self.maxSpin.sigValueChanged.connect(self.emitChanged)
        self.opCombo.currentIndexChanged.connect(self.emitChanged)
        self.argCombo.currentIndexChanged.connect(self.emitChanged)
        self.gradient.sigGradientChangeFinished.connect(self.emitChanged)

    def getParamName(self):
        return str(self.argCombo.currentText())

    def emitChanged(self):
        self.cm.emitChanged()

    def postAdd(self):
        t = self.treeWidget()
        # self.setText(0, "-")
        t.setItemWidget(self, 0, self.argCombo)
        t.setItemWidget(self, 1, self.opCombo)
        t.setItemWidget(self, 2, self.minSpin)
        t.setItemWidget(self, 3, self.maxSpin)
        t.setItemWidget(self, 4, self.gradient)
        t.setItemWidget(self, 5, self.remBtn)

    def delete(self):
        self.cm.remClicked(self)

    def updateArgList(self):
        # prev = str(self.argCombo.currentText())
        # self.argCombo.clear()
        # for a in self.cm.argList:
        # self.argCombo.addItem(a)
        # if a == prev:
        # self.argCombo.setCurrentIndex(self.argCombo.count()-1)
        self.argCombo.updateList(self.cm.getArgList())

    def getColor(self, args):
        arg = str(self.argCombo.currentText())
        if arg not in args:
            raise Exception('Cannot generate color; value "%s" is not present in this data.' % arg)
        val = args[arg]
        if val is None:
            return pg.QtGui.QColor(100, 100, 100, 255)
            # raise Exception('Cannot generate color; value "%s" is empty (None).' % arg)
        mn = self.minSpin.value()
        mx = self.maxSpin.value()
        norm = np.clip((val - mn) / (mx - mn), 0.0, 1.0)
        return self.gradient.getColor(norm)

    def getColorArray(self, data):
        arg = str(self.argCombo.currentText())
        vals = data[arg]
        mn = self.minSpin.value()
        mx = self.maxSpin.value()
        lut = self.gradient.getLookupTable(512, alpha=True)
        scaled = pg.rescaleData(np.clip(vals, mn, mx), lut.shape[0] / (mx - mn), mn, dtype=np.uint16)
        return pg.applyLookupTable(scaled, lut)
        # norm = np.clip((vals - mn) / (mx - mn), 0.0, 1.0)
        # return pg.makeARGB(vals, lut, levels=[mn, mx], useRGBA=True)[0]

    def getOp(self):
        return self.opCombo.currentText()

    def saveState(self):
        state = {
            "arg": str(self.argCombo.currentText()),
            "op": str(self.opCombo.currentText()),
            "min": self.minSpin.value(),
            "max": self.maxSpin.value(),
            "gradient": self.gradient.saveState(),
        }
        return state

    def restoreState(self, state):
        ind = self.argCombo.findText(state["arg"])
        if ind != -1:
            self.argCombo.setCurrentIndex(ind)
        ind = self.opCombo.findText(state["op"])
        self.opCombo.setCurrentIndex(ind)

        self.minSpin.setValue(state["min"])
        self.maxSpin.setValue(state["max"])

        self.gradient.restoreState(state["gradient"])