def add_protocol_label(self, start: int, end: int, refblock: int, type_index: int, restrictive: bool, name=None, color_ind=None) -> \ ProtocolLabel: if refblock >= self.num_blocks: refblock = 0 name = "Label {0:d}".format(len(self.labels) + 1) if not name else name used_colors = [p.color_index for p in self.labels] avail_colors = [i for i, _ in enumerate(constants.LABEL_COLORS) if i not in used_colors] if color_ind is None: if len(avail_colors) > 0: color_ind = avail_colors[random.randint(0, len(avail_colors)-1)] else: color_ind = random.randint(0, len(constants.LABEL_COLORS) - 1) proto_label = ProtocolLabel(name, start, end, refblock, type_index, color_ind, restrictive) try: proto_label.reference_bits = self.decoded_bits_str[refblock][proto_label.start:proto_label.end] except IndexError: return None proto_label.signals.apply_decoding_changed.connect(self.handle_plabel_apply_decoding_changed) proto_label.find_block_numbers(self.decoded_bits_str) self.labels.append(proto_label) self.labels.sort() return proto_label
def refresh_label(self, lbl: ProtocolLabel): if lbl not in self.labels: print("Label {0} is not in Group {1}".format(lbl.name, self.name), file=sys.stderr) return lbl.find_block_numbers(self.decoded_bits_str)