Пример #1
0
    def transferModel(self):
        """
        Transfer the current status of the model into the PMR
        information object.
        """
        pmr_info = PMR()
        hosts = pmr_info.hosts()
        host_names_remove = [name for name in hosts]
        host_names_new = []
        active_host = None

        index = 0
        current_item = self._model.item(index)
        while current_item:
            current_host = current_item.text()
            if current_host in host_names_remove:
                host_names_remove.remove(current_host)
            else:
                host_names_new.append(current_host)

            if current_item.checkState() == QtCore.Qt.Checked:
                active_host = current_host

            index += 1
            current_item = self._model.item(index)

        pmr_info.setActiveHost(active_host)
        for host in host_names_remove:
            pmr_info.removeHost(host)
        for host in host_names_new:
            pmr_info.addHost(host)
    def testPMR(self):
        info = PMR()
        host = info.host()

        self.assertIsInstance(host, unicode)

        self.assertTrue(info.addHost('garbage'))
        self.assertIn('garbage', info._instances)

        self.assertFalse(info.setActiveHost('rubbish'))
        self.assertTrue(info.setActiveHost('garbage'))


        self.assertTrue(info.removeHost('garbage'))
        self.assertTrue(info.host() is None)
        self.assertFalse(info.removeHost('garbage'))
Пример #3
0
    def _hostChanged(self, item):
        pmr_info = PMR()
        if not item.checkState():
            pmr_info.setActiveHost(None)
            self.hostChanged.emit(item.row())
            return

        index = 0
        current_item = self._model.item(index)
        self.blockSignals(True)
        while current_item:
            if current_item.checkState() and (current_item.row() !=
                                              item.row()):
                current_item.setCheckState(QtCore.Qt.Unchecked)
            index += 1
            current_item = self._model.item(index)

        self.blockSignals(False)
        pmr_info.setActiveHost(item.text())
        self.hostChanged.emit(item.row())