def finished(self): results = self.thread.result all_passed = True self.loading.close() if type(results) == None: return self.widgets.open_dialog( self.widgets.dialog_warning, self._("Troubleshooting Failed"), self. _("The troubleshooter for this backend is not available for this operating system." )) elif type(results) == str: return self.widgets.open_dialog( self.widgets.dialog_error, self._("Troubleshooting Failed"), self. _("An exception was thrown while running the troubleshooter. This is probably a bug." ), details=results) for result in results: item = QTreeWidgetItem() # "passed" must be either: True (Passed); False (Failed); None (Unknown) if result["passed"] is True: item.setText(0, self._("Passed")) item.setIcon(0, QIcon(common.get_icon("general", "success"))) elif result["passed"] is False: item.setText(0, self._("Failed")) item.setIcon(0, QIcon(common.get_icon("general", "serious"))) else: item.setText(0, self._("Unknown")) item.setIcon(0, QIcon(common.get_icon("general", "unknown"))) item.setText(1, result["test_name"]) item.copyable = False # Provide suggestions on failures if not result["passed"]: all_passed = False suggestions = result["suggestions"] for line in suggestions: subitem = QTreeWidgetItem() if line.startswith("$"): text = line subitem.setBackground(1, QBrush(Qt.black)) subitem.setForeground(1, QBrush(Qt.green)) subitem.copyable = True else: text = "• " + line subitem.setDisabled(True) subitem.setText(1, text) subitem.setToolTip(1, line) item.addChild(subitem) self.result_tree_root.addChild(item) self.result_tree.expandAll() self.result_window.findChild(QPushButton, "Close").clicked.connect( self._close_troubleshooter) self.result_tree.itemSelectionChanged.connect(self._item_changed) self.result_copy_btn.setHidden(True) self.result_copy_btn.clicked.connect(self._copy_to_clipboard) self.result_window.setWindowTitle( self._("Troubleshooter for []").replace("[]", self.human_name)) if all_passed: self.result_label.setText( self._("Everything appears to be in working order!")) self.dbg.stdout("Troubleshooting completed!", self.dbg.success, 1) self.result_window.open()
def _troubleshoot_complete(): _ = self.appdata._ results = self.thread.result self.loading.close() if type(results) == None: self.widgets.open_dialog( self.widgets.dialog_warning, _("Troubleshooting Failed"), _("The troubleshooter for this backend is not available for this operating system." )) return elif type(results) == str: self.widgets.open_dialog( self.widgets.dialog_error, _("Troubleshooting Failed"), _("An exception was thrown while running the troubleshooter. This is probably a bug." ), None, results) return self.result_window = shared.get_ui_widget(self.appdata, "troubleshooter", QDialog) label = self.result_window.findChild(QLabel, "Title") tree = self.result_window.findChild(QTreeWidget, "Results") column = tree.invisibleRootItem() btn_copy = self.result_window.findChild(QPushButton, "CopyToClipboard") if not self.appdata.system_qt_theme: self.result_window.findChild(QPushButton, "Close").setIcon( self.widgets.get_icon_qt("general", "close")) all_passed = True for result in results: item = QTreeWidgetItem() # "passed" must be either: True (Passed); False (Failed); None (Unknown) if result["passed"] is True: item.setText(0, _("Passed")) item.setIcon(0, QIcon(common.get_icon("general", "success"))) elif result["passed"] is False: item.setText(0, _("Failed")) item.setIcon(0, QIcon(common.get_icon("general", "serious"))) else: item.setText(0, _("Unknown")) item.setIcon(0, QIcon(common.get_icon("general", "unknown"))) item.setText(1, result["test_name"]) item.copyable = False # Provide suggestions on failures if not result["passed"]: all_passed = False suggestions = result["suggestions"] for line in suggestions: subitem = QTreeWidgetItem() if line.startswith("$"): text = line subitem.setBackground(1, QBrush(Qt.black)) subitem.setForeground(1, QBrush(Qt.green)) subitem.copyable = True else: text = "• " + line subitem.setDisabled(True) subitem.setText(1, text) subitem.setToolTip(1, line) item.addChild(subitem) column.addChild(item) # Commands can be copied to clipboard for convenience def _change_option(): selected = tree.selectedItems()[0] btn_copy.setHidden(selected.copyable == False) tree.itemSelectionChanged.connect(_change_option) def _copy_to_clipboard(): selected_text = tree.selectedItems()[0].text(1).replace( "$ ", "") QApplication.clipboard().setText(selected_text) btn_copy.setHidden(True) btn_copy.clicked.connect(_copy_to_clipboard) def _close_troubleshooter(): self.result_window.close() self.result_window.findChild( QPushButton, "Close").clicked.connect(_close_troubleshooter) tree.expandAll() self.result_window.setWindowTitle( _("Troubleshooter for []").replace("[]", self.human_name)) if all_passed: label.setText(_("Everything appears to be in working order!")) self.result_window.open()