Пример #1
0
    def set_tab(self):
        """
        Device tab opened. Populate the device and task lists, and open the
        properties for the first device (if applicable)
        """
        # Open all 'sidebar' tree branches
        self.SidebarTree.expandAll()

        # Populate sidebar
        tasks_branch = self.SidebarTree.invisibleRootItem().child(0)
        devices_branch = self.SidebarTree.invisibleRootItem().child(1)

        # Give IDs for fixed items
        tasks_branch.section = None
        devices_branch.section = None
        tasks_branch.child(0).section = "apply-to-all"

        # Recache the device list
        self.SidebarTree.parent().show()
        self.appdata.device_list = self.middleman.get_device_list()
        unknown_device_list = self.middleman.get_unsupported_devices()

        # Clear device entries
        devices_branch.takeChildren()
        for device_item in self.appdata.device_list:
            item = QTreeWidgetItem()
            item.setText(0, device_item["name"])
            item.setIcon(0, QIcon(device_item["form_factor"]["icon"]))
            item.section = "device"
            item.backend = device_item["backend"]
            item.uid = device_item["uid"]
            devices_branch.addChild(item)

        devices_branch.sortChildren(0, Qt.AscendingOrder)

        for device_item in unknown_device_list:
            item = QTreeWidgetItem()
            item.setText(0, device_item["name"])
            item.setIcon(0, QIcon(device_item["form_factor"]["icon"]))
            item.section = "device-unknown"
            item.backend = device_item["backend"]
            devices_branch.addChild(item)

        # Only show tasks when there are multiple devices present
        if len(self.appdata.device_list) > 1:
            tasks_branch.setHidden(False)
        else:
            tasks_branch.setHidden(True)

        # Backends loaded, but no usable devices
        if len(self.appdata.device_list) == 0 and len(unknown_device_list) > 0:
            devices_branch.child(0).setSelected(True)
            self.open_unknown_device(devices_branch.child(0).backend)

        # All backends failed to load
        elif len(self.middleman.backends) == 0 and len(self.middleman.import_errors) > 0:
            self._open_no_backend_found(1)

        # No backends are installed
        elif len(self.middleman.backends) == 0 and len(self.middleman.not_installed) > 0:
            self._open_no_backend_found(2)

        # Backends present, but no devices listed
        elif len(self.appdata.device_list) == 0:
            self._open_no_backend_found(0)

        # Open the first device initially
        if len(self.appdata.device_list) > 0:
            first_item = devices_branch.child(0)
            first_item.setSelected(True)
            self.open_device(first_item.backend, first_item.uid)