示例#1
0
 def testExecute(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._trace, "a", 0)
     button.executeCallable()
     time.sleep(0.1)
     self.assertListEqual(self._result, ["a"])
     self.waitForPendingOperations(button)
示例#2
0
 def testExecute(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._trace, "a", 0)
     button.executeCallable()
     time.sleep(0.1)
     self.assertListEqual(self._result, ["a"])
     self.qapp.processEvents()
示例#3
0
 def testSaturateThreadPool(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._trace, "a", 100)
     number = qt.silxGlobalThreadPool().maxThreadCount() * 2
     for _ in range(number):
         button.executeCallable()
     self.waitForPendingOperations(button)
     self.assertListEqual(self._result, ["a"] * number)
示例#4
0
 def testSaturateThreadPool(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._trace, "a", 100)
     number = qt.QThreadPool.globalInstance().maxThreadCount() * 2
     for _ in range(number):
         button.executeCallable()
     time.sleep(number * 0.1 + 0.1)
     self.assertListEqual(self._result, ["a"] * number)
     self.qapp.processEvents()
示例#5
0
 def testSuccess(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._compute)
     button.beforeExecuting.connect(lambda: self._result.append("be"))
     button.started.connect(lambda: self._result.append("s"))
     button.succeeded.connect(lambda r: self._result.append(r))
     button.failed.connect(lambda e: self.fail("Unexpected exception"))
     button.finished.connect(lambda: self._result.append("f"))
     button.executeCallable()
     self.qapp.processEvents()
     time.sleep(0.1)
     self.qapp.processEvents()
     self.assertListEqual(self._result, ["be", "s", "result", "f"])
示例#6
0
 def testFail(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._computeFail)
     button.beforeExecuting.connect(lambda: self._result.append("be"))
     button.started.connect(lambda: self._result.append("s"))
     button.succeeded.connect(lambda r: self.fail("Unexpected success"))
     button.failed.connect(lambda e: self._result.append(str(e)))
     button.finished.connect(lambda: self._result.append("f"))
     with TestLogging('silx.gui.widgets.ThreadPoolPushButton', error=1):
         button.executeCallable()
         self.qapp.processEvents()
         time.sleep(0.1)
         self.qapp.processEvents()
     self.assertListEqual(self._result, ["be", "s", "exception", "f"])
示例#7
0
 def testSuccess(self):
     listener = SignalListener()
     button = ThreadPoolPushButton()
     button.setCallable(self._compute)
     button.beforeExecuting.connect(listener.partial(test="be"))
     button.started.connect(listener.partial(test="s"))
     button.succeeded.connect(listener.partial(test="result"))
     button.failed.connect(listener.partial(test="Unexpected exception"))
     button.finished.connect(listener.partial(test="f"))
     button.executeCallable()
     self.qapp.processEvents()
     time.sleep(0.1)
     self.qapp.processEvents()
     result = listener.karguments(argumentName="test")
     self.assertListEqual(result, ["be", "s", "result", "f"])
示例#8
0
 def testFail(self):
     listener = SignalListener()
     button = ThreadPoolPushButton()
     button.setCallable(self._computeFail)
     button.beforeExecuting.connect(listener.partial(test="be"))
     button.started.connect(listener.partial(test="s"))
     button.succeeded.connect(listener.partial(test="Unexpected success"))
     button.failed.connect(listener.partial(test="exception"))
     button.finished.connect(listener.partial(test="f"))
     with TestLogging('silx.gui.widgets.ThreadPoolPushButton', error=1):
         button.executeCallable()
         self.qapp.processEvents()
         time.sleep(0.1)
         self.qapp.processEvents()
     result = listener.karguments(argumentName="test")
     self.assertListEqual(result, ["be", "s", "exception", "f"])
     listener.clear()
示例#9
0
    def createTreeViewConfigurationPanel(self, parent, treeview):
        """Create a configuration panel to allow to play with widget states"""
        panel = qt.QWidget(parent)
        panel.setLayout(qt.QHBoxLayout())

        content = qt.QGroupBox("Create HDF5", panel)
        content.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(content)

        combo = qt.QComboBox()
        combo.addItem("Containing all types", get_hdf5_with_all_types)
        combo.activated.connect(self.__hdf5ComboChanged)
        content.layout().addWidget(combo)

        button = ThreadPoolPushButton(content, text="Create")
        button.setCallable(combo.itemData(combo.currentIndex()))
        button.succeeded.connect(self.__fileCreated)
        content.layout().addWidget(button)

        self.__hdf5Combo = combo
        self.__createHdf5Button = button

        content.layout().addStretch(1)

        option = qt.QGroupBox("Custom model", panel)
        option.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(option)

        button = qt.QPushButton("Original model")
        button.clicked.connect(self.__useOriginalModel)
        option.layout().addWidget(button)

        button = qt.QPushButton("Custom tooltips by composition")
        button.clicked.connect(self.__useCustomLabel)
        option.layout().addWidget(button)

        option.layout().addStretch(1)

        panel.layout().addStretch(1)
        return panel
 def testExecute(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._trace, "a", 0)
     button.executeCallable()
     time.sleep(0.1)
     self.assertListEqual(self._result, ["a"])
     self.qapp.processEvents()
示例#11
0
    def createTreeViewConfigurationPanel(self, parent, treeview):
        """Create a configuration panel to allow to play with widget states"""
        panel = qt.QWidget(parent)
        panel.setLayout(qt.QHBoxLayout())

        content = qt.QGroupBox("Create HDF5", panel)
        content.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(content)

        combo = qt.QComboBox()
        combo.addItem("Containing all types", get_hdf5_with_all_types)
        combo.activated.connect(self.__hdf5ComboChanged)
        content.layout().addWidget(combo)

        button = ThreadPoolPushButton(content, text="Create")
        button.setCallable(combo.itemData(combo.currentIndex()))
        button.succeeded.connect(self.__fileCreated)
        content.layout().addWidget(button)

        self.__hdf5Combo = combo
        self.__createHdf5Button = button

        content.layout().addStretch(1)

        option = qt.QGroupBox("Custom model", panel)
        option.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(option)

        button = qt.QPushButton("Original model")
        button.clicked.connect(self.__useOriginalModel)
        option.layout().addWidget(button)

        button = qt.QPushButton("Custom tooltips by composition")
        button.clicked.connect(self.__useCustomLabel)
        option.layout().addWidget(button)

        option.layout().addStretch(1)

        panel.layout().addStretch(1)
        return panel
 def testExecute(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._trace, "a", 0)
     button.executeCallable()
     time.sleep(0.1)
     self.assertListEqual(self._result, ["a"])
     self.waitForPendingOperations(button)
 def testSaturateThreadPool(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._trace, "a", 100)
     number = qt.silxGlobalThreadPool().maxThreadCount() * 2
     for _ in range(number):
         button.executeCallable()
     self.waitForPendingOperations(button)
     self.assertListEqual(self._result, ["a"] * number)
 def testSaturateThreadPool(self):
     button = ThreadPoolPushButton()
     button.setCallable(self._trace, "a", 100)
     number = qt.QThreadPool.globalInstance().maxThreadCount() * 2
     for _ in range(number):
         button.executeCallable()
     time.sleep(number * 0.1 + 0.1)
     self.assertListEqual(self._result, ["a"] * number)
     self.qapp.processEvents()
 def testSuccess(self):
     listener = SignalListener()
     button = ThreadPoolPushButton()
     button.setCallable(self._compute)
     button.beforeExecuting.connect(listener.partial(test="be"))
     button.started.connect(listener.partial(test="s"))
     button.succeeded.connect(listener.partial(test="result"))
     button.failed.connect(listener.partial(test="Unexpected exception"))
     button.finished.connect(listener.partial(test="f"))
     button.executeCallable()
     self.qapp.processEvents()
     time.sleep(0.1)
     self.qapp.processEvents()
     result = listener.karguments(argumentName="test")
     self.assertListEqual(result, ["be", "s", "result", "f"])
 def testFail(self):
     listener = SignalListener()
     button = ThreadPoolPushButton()
     button.setCallable(self._computeFail)
     button.beforeExecuting.connect(listener.partial(test="be"))
     button.started.connect(listener.partial(test="s"))
     button.succeeded.connect(listener.partial(test="Unexpected success"))
     button.failed.connect(listener.partial(test="exception"))
     button.finished.connect(listener.partial(test="f"))
     with TestLogging('silx.gui.widgets.ThreadPoolPushButton', error=1):
         button.executeCallable()
         self.qapp.processEvents()
         time.sleep(0.1)
         self.qapp.processEvents()
     result = listener.karguments(argumentName="test")
     self.assertListEqual(result, ["be", "s", "exception", "f"])
     listener.clear()
示例#17
0
    def createTreeViewConfigurationPanel(self, parent, treeview):
        """Create a configuration panel to allow to play with widget states"""
        panel = qt.QWidget(parent)
        panel.setLayout(qt.QHBoxLayout())

        content = qt.QGroupBox("Create HDF5", panel)
        content.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(content)

        combo = qt.QComboBox()
        combo.addItem("Containing all types", get_hdf5_with_all_types)
        combo.addItem("Containing all links", get_hdf5_with_all_links)
        combo.addItem("Containing 1000 datasets", get_hdf5_with_1000_datasets)
        combo.addItem("Containing 10000 datasets",
                      get_hdf5_with_10000_datasets)
        combo.addItem("Containing 100000 datasets",
                      get_hdf5_with_100000_datasets)
        combo.addItem("Containing recursive links",
                      get_hdf5_with_recursive_links)
        combo.addItem("Containing external recursive links",
                      get_hdf5_with_external_recursive_links)
        combo.addItem("Containing NXdata groups", get_hdf5_with_nxdata)
        combo.activated.connect(self.__hdf5ComboChanged)
        content.layout().addWidget(combo)

        button = ThreadPoolPushButton(content, text="Create")
        button.setCallable(combo.itemData(combo.currentIndex()))
        button.succeeded.connect(self.__fileCreated)
        content.layout().addWidget(button)

        self.__hdf5Combo = combo
        self.__createHdf5Button = button

        asyncload = qt.QCheckBox("Async load", content)
        asyncload.setChecked(self.__asyncload)
        asyncload.toggled.connect(
            lambda: self.useAsyncLoad(asyncload.isChecked()))
        content.layout().addWidget(asyncload)

        content.layout().addStretch(1)

        content = qt.QGroupBox("Create EDF", panel)
        content.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(content)

        combo = qt.QComboBox()
        combo.addItem("Containing all types", get_edf_with_all_types)
        combo.addItem("Containing 100000 datasets", get_edf_with_100000_frames)
        combo.activated.connect(self.__edfComboChanged)
        content.layout().addWidget(combo)

        button = ThreadPoolPushButton(content, text="Create")
        button.setCallable(combo.itemData(combo.currentIndex()))
        button.succeeded.connect(self.__fileCreated)
        content.layout().addWidget(button)

        self.__edfCombo = combo
        self.__createEdfButton = button

        content.layout().addStretch(1)

        option = qt.QGroupBox("Tree options", panel)
        option.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(option)

        sorting = qt.QCheckBox("Enable sorting", option)
        sorting.setChecked(
            treeview.selectionMode() == qt.QAbstractItemView.MultiSelection)
        sorting.toggled.connect(
            lambda: treeview.setSortingEnabled(sorting.isChecked()))
        option.layout().addWidget(sorting)

        multiselection = qt.QCheckBox("Multi-selection", option)
        multiselection.setChecked(
            treeview.selectionMode() == qt.QAbstractItemView.MultiSelection)
        switch_selection = lambda: treeview.setSelectionMode(
            qt.QAbstractItemView.MultiSelection if multiselection.isChecked(
            ) else qt.QAbstractItemView.SingleSelection)
        multiselection.toggled.connect(switch_selection)
        option.layout().addWidget(multiselection)

        filedrop = qt.QCheckBox("Drop external file", option)
        filedrop.setChecked(treeview.findHdf5TreeModel().isFileDropEnabled())
        filedrop.toggled.connect(lambda: treeview.findHdf5TreeModel().
                                 setFileDropEnabled(filedrop.isChecked()))
        option.layout().addWidget(filedrop)

        filemove = qt.QCheckBox("Reorder files", option)
        filemove.setChecked(treeview.findHdf5TreeModel().isFileMoveEnabled())
        filemove.toggled.connect(lambda: treeview.findHdf5TreeModel().
                                 setFileMoveEnabled(filedrop.isChecked()))
        option.layout().addWidget(filemove)

        option.layout().addStretch(1)

        option = qt.QGroupBox("Header options", panel)
        option.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(option)

        autosize = qt.QCheckBox("Auto-size headers", option)
        autosize.setChecked(treeview.header().hasAutoResizeColumns())
        autosize.toggled.connect(lambda: treeview.header().
                                 setAutoResizeColumns(autosize.isChecked()))
        option.layout().addWidget(autosize)

        columnpopup = qt.QCheckBox("Popup to hide/show columns", option)
        columnpopup.setChecked(treeview.header().hasHideColumnsPopup())
        columnpopup.toggled.connect(lambda: treeview.header(
        ).setEnableHideColumnsPopup(columnpopup.isChecked()))
        option.layout().addWidget(columnpopup)

        define_columns = qt.QComboBox()
        define_columns.addItem("Default columns",
                               treeview.findHdf5TreeModel().COLUMN_IDS)
        define_columns.addItem("Only name and Value", [
            treeview.findHdf5TreeModel().NAME_COLUMN,
            treeview.findHdf5TreeModel().VALUE_COLUMN
        ])
        define_columns.activated.connect(lambda index: treeview.header(
        ).setSections(define_columns.itemData(index)))
        option.layout().addWidget(define_columns)

        option.layout().addStretch(1)

        panel.layout().addStretch(1)

        return panel
示例#18
0
 def createThreadPoolPushButton(self):
     widget = ThreadPoolPushButton(text="Compute 2^16")
     widget.setCallable(self.takesTimeToComputePow, 2, 16)
     widget.succeeded.connect(self.printResult)
     widget.failed.connect(self.printError)
     return widget
 def createThreadPoolPushButton(self):
     widget = ThreadPoolPushButton(text="Compute 2^16")
     widget.setCallable(self.takesTimeToComputePow, 2, 16)
     widget.succeeded.connect(self.printResult)
     widget.failed.connect(self.printError)
     return widget
示例#20
0
    def createTreeViewConfigurationPanel(self, parent, treeview):
        """Create a configuration panel to allow to play with widget states"""
        panel = qt.QWidget(parent)
        panel.setLayout(qt.QHBoxLayout())

        content = qt.QGroupBox("Create HDF5", panel)
        content.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(content)

        combo = qt.QComboBox()
        combo.addItem("Containing all types", get_hdf5_with_all_types)
        combo.addItem("Containing all links", get_hdf5_with_all_links)
        combo.addItem("Containing 1000 datasets", get_hdf5_with_1000_datasets)
        combo.addItem("Containing 10000 datasets", get_hdf5_with_10000_datasets)
        combo.addItem("Containing 100000 datasets", get_hdf5_with_100000_datasets)
        combo.addItem("Containing recursive links", get_hdf5_with_recursive_links)
        combo.addItem("Containing external recursive links", get_hdf5_with_external_recursive_links)
        combo.activated.connect(self.__hdf5ComboChanged)
        content.layout().addWidget(combo)

        button = ThreadPoolPushButton(content, text="Create")
        button.setCallable(combo.itemData(combo.currentIndex()))
        button.succeeded.connect(self.__fileCreated)
        content.layout().addWidget(button)

        self.__hdf5Combo = combo
        self.__createHdf5Button = button

        asyncload = qt.QCheckBox("Async load", content)
        asyncload.setChecked(self.__asyncload)
        asyncload.toggled.connect(lambda: self.useAsyncLoad(asyncload.isChecked()))
        content.layout().addWidget(asyncload)

        content.layout().addStretch(1)

        if fabio is not None:
            content = qt.QGroupBox("Create EDF", panel)
            content.setLayout(qt.QVBoxLayout())
            panel.layout().addWidget(content)

            combo = qt.QComboBox()
            combo.addItem("Containing all types", get_edf_with_all_types)
            combo.addItem("Containing 100000 datasets", get_edf_with_100000_frames)
            combo.activated.connect(self.__edfComboChanged)
            content.layout().addWidget(combo)

            button = ThreadPoolPushButton(content, text="Create")
            button.setCallable(combo.itemData(combo.currentIndex()))
            button.succeeded.connect(self.__fileCreated)
            content.layout().addWidget(button)

            self.__edfCombo = combo
            self.__createEdfButton = button

            content.layout().addStretch(1)

        option = qt.QGroupBox("Tree options", panel)
        option.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(option)

        sorting = qt.QCheckBox("Enable sorting", option)
        sorting.setChecked(treeview.selectionMode() == qt.QAbstractItemView.MultiSelection)
        sorting.toggled.connect(lambda: treeview.setSortingEnabled(sorting.isChecked()))
        option.layout().addWidget(sorting)

        multiselection = qt.QCheckBox("Multi-selection", option)
        multiselection.setChecked(treeview.selectionMode() == qt.QAbstractItemView.MultiSelection)
        switch_selection = lambda: treeview.setSelectionMode(
            qt.QAbstractItemView.MultiSelection if multiselection.isChecked()
            else qt.QAbstractItemView.SingleSelection)
        multiselection.toggled.connect(switch_selection)
        option.layout().addWidget(multiselection)

        filedrop = qt.QCheckBox("Drop external file", option)
        filedrop.setChecked(treeview.findHdf5TreeModel().isFileDropEnabled())
        filedrop.toggled.connect(lambda: treeview.findHdf5TreeModel().setFileDropEnabled(filedrop.isChecked()))
        option.layout().addWidget(filedrop)

        filemove = qt.QCheckBox("Reorder files", option)
        filemove.setChecked(treeview.findHdf5TreeModel().isFileMoveEnabled())
        filemove.toggled.connect(lambda: treeview.findHdf5TreeModel().setFileMoveEnabled(filedrop.isChecked()))
        option.layout().addWidget(filemove)

        option.layout().addStretch(1)

        option = qt.QGroupBox("Header options", panel)
        option.setLayout(qt.QVBoxLayout())
        panel.layout().addWidget(option)

        autosize = qt.QCheckBox("Auto-size headers", option)
        autosize.setChecked(treeview.header().hasAutoResizeColumns())
        autosize.toggled.connect(lambda: treeview.header().setAutoResizeColumns(autosize.isChecked()))
        option.layout().addWidget(autosize)

        columnpopup = qt.QCheckBox("Popup to hide/show columns", option)
        columnpopup.setChecked(treeview.header().hasHideColumnsPopup())
        columnpopup.toggled.connect(lambda: treeview.header().setEnableHideColumnsPopup(columnpopup.isChecked()))
        option.layout().addWidget(columnpopup)

        define_columns = qt.QComboBox()
        define_columns.addItem("Default columns", treeview.findHdf5TreeModel().COLUMN_IDS)
        define_columns.addItem("Only name and Value", [treeview.findHdf5TreeModel().NAME_COLUMN, treeview.findHdf5TreeModel().VALUE_COLUMN])
        define_columns.activated.connect(lambda index: treeview.header().setSections(define_columns.itemData(index)))
        option.layout().addWidget(define_columns)

        option.layout().addStretch(1)

        panel.layout().addStretch(1)

        return panel