Example #1
0
 def _removeClicked(self):
     indexes = self._ui.hostListView.selectedIndexes()
     rm_index = indexes.pop()
     item = self._model.itemFromIndex(rm_index)
     pmr_info = PMR()
     pmr_info.removeHost(item.text())
     self._model.removeRow(rm_index.row())
Example #2
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'))