Update data pins intelligently, preserving connections when renaming
(self, new_pins_dict, direction)
| 605 | return [] |
| 606 | |
| 607 | def _update_data_pins(self, new_pins_dict, direction): |
| 608 | """Update data pins intelligently, preserving connections when renaming""" |
| 609 | # Get current pins of this direction and category |
| 610 | if direction == "input": |
| 611 | current_pins = [p for p in self.input_pins if p.pin_category == "data"] |
| 612 | else: |
| 613 | current_pins = [p for p in self.output_pins if p.pin_category == "data"] |
| 614 | |
| 615 | # Convert new_pins_dict to ordered list to match by position |
| 616 | new_pins_list = list(new_pins_dict.items()) # [(name, type), (name, type), ...] |
| 617 | |
| 618 | # Update existing pins by position, rename if needed |
| 619 | for i, (new_name, new_type) in enumerate(new_pins_list): |
| 620 | if i < len(current_pins): |
| 621 | # Pin exists at this position - update it |
| 622 | pin = current_pins[i] |
| 623 | name_changed = pin.name != new_name |
| 624 | type_changed = pin.pin_type != new_type |
| 625 | |
| 626 | if name_changed: |
| 627 | self.rename_pin(pin, new_name) |
| 628 | |
| 629 | # Update type if needed |
| 630 | if type_changed: |
| 631 | pin.pin_type = new_type |
| 632 | # Update label to reflect type change |
| 633 | if hasattr(pin, 'update_label_text'): |
| 634 | pin.update_label_text() |
| 635 | else: |
| 636 | # Need to add a new pin at this position |
| 637 | self.add_data_pin(new_name, direction, new_type) |
| 638 | |
| 639 | # Remove any extra pins that are no longer needed |
| 640 | for i in range(len(new_pins_list), len(current_pins)): |
| 641 | self.remove_pin(current_pins[i]) |
| 642 | |
| 643 | def update_pins_from_code(self): |
| 644 | new_data_inputs, new_data_outputs = {}, {} |
no test coverage detected