Hi,
I'm writing a program to calculate and display a large number of curves. 
These are structured in several groups of the same type. Now I like to 
select each curve separately or pressing one button for showing all 
respectively another button to hide all curves. How can it be done that the 
function 'changes()' is called only once?

Thanks,
Ben

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/aba1bd3a-a3f3-4a76-8e47-4c987a341848%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import pyqtgraph as pg
from PyQt5 import QtCore, QtGui, QtWidgets

import pyqtgraph.parametertree.parameterTypes as pTypes
from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, registerParameterType

app = QtGui.QApplication([])

counter = 0
counter_check_all = 0
counter_uncheck_all = 0


class BoolItems(pTypes.GroupParameter):
    def __init__(self, **opts):
        opts['type'] = 'bool'
        opts['value'] = True
        opts['expanded'] = False
        pTypes.GroupParameter.__init__(self, **opts)

        self.addChild({
            'name': 'plotBool_1',
            'type': 'bool',
            'value': True,
            'title': 'Bool 1'
        })
        self.plotBool_1 = self.param('plotBool_1')

        self.addChild({
            'name': 'plotBool_2',
            'type': 'bool',
            'value': True,
            'title': 'Bool 2'
        })
        self.plotBool_2 = self.param('plotBool_2')

        self.addChild({
            'name': 'plotBool_3',
            'type': 'bool',
            'value': True,
            'title': 'Bool 3'
        })
        self.plotBool_3 = self.param('plotBool_3')


class SelectBoolItems(pTypes.GroupParameter):
    def __init__(self, **opts):
        opts['name'] = 'Select Bool items'
        opts['type'] = 'bool'
        opts['value'] = True
        opts['expanded'] = True

        pTypes.GroupParameter.__init__(self, **opts)

        self.addChild({
            'name': 'Check all',
            'type': 'action',
        })
        self.btnShowAll = self.param('Check all')

        self.addChild({
            'name': 'Uncheck all',
            'type': 'action',
        })
        self.btnHideAll = self.param('Uncheck all')

        self.groupItems1 = BoolItems(
            name='groupItems1', title='Group items 1')
        self.groupItems2 = BoolItems(
            name='groupItems2', title='Group items 2')
        self.groupItems3 = BoolItems(
            name='groupItems3', title='Group items 3')

        self.addChildren([
            self.btnShowAll,
            self.btnHideAll,
            self.groupItems1,
            self.groupItems2,
            self.groupItems3,
        ])


class BoolGroups(pTypes.GroupParameter):
    def __init__(self, **opts):
        opts['type'] = 'bool'
        opts['value'] = True
        opts['expanded'] = True
        pTypes.GroupParameter.__init__(self, **opts)

        self.pSelectBoolItems = SelectBoolItems()

        self.addChildren([self.pSelectBoolItems])

        self.pSelectBoolItems.btnShowAll.sigActivated.connect(
            self.checkAllBools)
        self.pSelectBoolItems.btnHideAll.sigActivated.connect(
            self.unCheckAllBools)

    def checkAllBools(self):
        for plt in self.pSelectBoolItems.groupItems1:
            plt.setValue(True)
        for plt in self.pSelectBoolItems.groupItems2:
            plt.setValue(True)
        for plt in self.pSelectBoolItems.groupItems3:
            plt.setValue(True)

        # for test purposes
        global counter_check_all
        counter_check_all += 1
        print("counter_check_all = ", counter_check_all)

    def unCheckAllBools(self):
        for plt in self.pSelectBoolItems.groupItems1:
            plt.setValue(False)
        for plt in self.pSelectBoolItems.groupItems2:
            plt.setValue(False)
        for plt in self.pSelectBoolItems.groupItems3:
            plt.setValue(False)

        # for test purposes
        global counter_uncheck_all
        counter_uncheck_all += 1
        print("counter_uncheck_all = ", counter_uncheck_all)


def changes():
    # This function may only be called once, regardless of whether
    # only one or all values are changed (via checkAllBools/unCheckAllBools).

    # for test purposes
    global counter
    counter += 1
    print("counter = ", counter)


pParaTreeTest = BoolGroups(name='boolGroups')

p = Parameter.create(name='myParameter', type='group', children=pParaTreeTest)
p.sigTreeStateChanged.connect(changes)


# Create ParameterTree widget
t = ParameterTree()
t.setParameters(p, showTop=False)

win = QtGui.QWidget()
layout = QtGui.QGridLayout()
win.setLayout(layout)
layout.addWidget(t, 1, 0)
win.show()
win.resize(350, 600)

# Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

Reply via email to