def set(self, current_task_id: TaskID, monotonic_device_time: Decimal): self._task_display.set( get_human_friendly_task_name(current_task_id, short=True)) self._task_display.setToolTip(str(current_task_id).split('.')[-1]) self._task_display.setStatusTip(self._task_display.toolTip()) self._monotonic_time_display.set( _duration_to_string(monotonic_device_time)) self.set_icon(get_icon_name_for_task_id(current_task_id))
def on_general_status_update(self, timestamp: float, s: GeneralStatusView): w = self._task_id_to_widget_mapping[s.current_task_id] self._ensure_widget_active(w) # noinspection PyBroadException try: w.on_general_status_update(timestamp, s) except Exception: _logger.exception( f'Task-specific widget update failed; ' f'task ID {s.current_task_id!r}, widget {type(w)!r}') self.set_icon(get_icon_name_for_task_id(s.current_task_id)) title = f'{get_human_friendly_task_name(s.current_task_id)} task status information' if title != self.title(): self.setTitle(title)
def on_general_status_update(self, timestamp: float, s: GeneralStatusView): tssr = self._get_task_specific_status_report(TaskSpecificStatusReport.Fault, s) if tssr == self._last_displayed: return self._last_displayed = tssr pixmap = get_icon_pixmap( get_icon_name_for_task_id(tssr.failed_task_id), self._line_height ) self._task_icon_display.setPixmap(pixmap) self._task_name_display.setText(str(tssr.failed_task_id).split(".")[-1]) self._task_name_display.setToolTip( get_human_friendly_task_name(tssr.failed_task_id) ) self._error_code_dec.setText(f"{tssr.failed_task_exit_code}") self._error_code_hex.setText(f"0x{tssr.failed_task_exit_code:02X}") self._error_code_bin.setText(f"0b{tssr.failed_task_exit_code:08b}") file_name = get_absolute_path( "view", "main_window", "telega_control_widget", "task_specific_status_widget", f"error_codes.yml", check_existence=True, ) with open(file_name, "r") as f: error_codes = yaml.safe_load(f) failed_task_name = str(tssr.failed_task_id).split(".")[-1] error = error_codes[failed_task_name].get( tssr.failed_task_exit_code, "unknown error" ) error_description = ( error.get("description", "unknown error") if isinstance(error, dict) else error ) error_comment = error.get("comment", "") if isinstance(error, dict) else "" self._error_description_display.setText(error_description) self._error_comment_display.setText(error_comment)
def on_general_status_update(self, timestamp: float, s: GeneralStatusView): tssr = self._get_task_specific_status_report( TaskSpecificStatusReport.Fault, s) if tssr == self._last_displayed: return self._last_displayed = tssr pixmap = get_icon_pixmap( get_icon_name_for_task_id(tssr.failed_task_id), self._line_height) self._task_icon_display.setPixmap(pixmap) self._task_name_display.setText( str(tssr.failed_task_id).split('.')[-1]) self._task_name_display.setToolTip( get_human_friendly_task_name(tssr.failed_task_id)) self._error_code_dec.setText(f'{tssr.failed_task_exit_code}') self._error_code_hex.setText(f'0x{tssr.failed_task_exit_code:02X}') self._error_code_bin.setText(f'0b{tssr.failed_task_exit_code:08b}') file_name = get_absolute_path('view', 'main_window', 'telega_control_widget', 'task_specific_status_widget', f'error_codes.yml', check_existence=True) with open(file_name, 'r') as f: error_codes = yaml.safe_load(f) failed_task_name = str(tssr.failed_task_id).split('.')[-1] error = error_codes[failed_task_name].get(tssr.failed_task_exit_code, 'unknown error') error_description = error.get('description', 'unknown error') if isinstance( error, dict) else error error_comment = error.get('comment', '') if isinstance(error, dict) else '' self._error_description_display.setText(error_description) self._error_comment_display.setText(error_comment)
def headerData(self, section: int, orientation: int, role=None): if role == Qt.DisplayRole: if orientation == Qt.Horizontal: return self.COLUMNS[section][0] else: task_enum = list(self._data.entries.keys())[section] return get_human_friendly_task_name(task_enum, short=True) if role in (Qt.ToolTipRole, Qt.StatusTipRole): if orientation == Qt.Horizontal: return self.COLUMNS[section][1] else: task_enum = list(self._data.entries.keys())[section] return get_human_friendly_task_name(task_enum) if role == Qt.DecorationRole: if orientation == Qt.Vertical: task_enum = list(self._data.entries.keys())[section] try: icon_name = get_icon_name_for_task_id(task_enum) except KeyError: pass else: return get_icon_pixmap(icon_name, self._icon_size) if role == Qt.TextAlignmentRole: return Qt.AlignCenter if role == Qt.FontRole: if orientation == Qt.Vertical: if (list(self._data.entries.keys())[section] == self._get_running_task_id()): font = QFont() font.setBold(True) return font return QVariant()