def __init__(self, strand: StrandT, new_idxs: SegmentT, update_segments: bool = True): super(ResizeCommand, self).__init__("resize strand") self.strand = strand self.old_indices = o_i = strand.idxs() self.new_idxs = new_idxs # an increase in length leads to positive delta self.delta = (new_idxs[1] - new_idxs[0]) - (o_i[1] - o_i[0]) # now handle insertion deltas oldInsertions = strand.insertionsOnStrand(*o_i) newInsertions = strand.insertionsOnStrand(*new_idxs) o_l = 0 for i in oldInsertions: o_l += i.length() n_l = 0 for i in newInsertions: n_l += i.length() self.delta += (n_l - o_l) self.update_segments = update_segments
def refreshInsertionItems(self, strand: StrandT): i_items = self.insertionItems() i_model = strand.insertionsOnStrand() was_in_use = set(i_items) in_use = set() # add in the ones supposed to be there for insertion in i_model: idx = insertion.idx() in_use.add(idx) if idx in i_items: pass else: i_items[insertion.idx()] = \ InsertionItem(self._virtual_helix_item, strand, insertion) # end for # remove all in items not_in_use = was_in_use - in_use for index in not_in_use: i_items[index].destroyItem() del i_items[index]