Connect a feature from a given driver to a widget. Calling this function also patches the widget is necessary. If applied two times with the same widget, it will connect to the target provided in the second call. This behaviour can be useful to change the connection target without r
(widget, target, feat_name=None, feat_key=MISSING)
| 619 | |
| 620 | |
| 621 | def connect_feat(widget, target, feat_name=None, feat_key=MISSING): |
| 622 | """Connect a feature from a given driver to a widget. Calling this |
| 623 | function also patches the widget is necessary. |
| 624 | |
| 625 | If applied two times with the same widget, it will connect to the target |
| 626 | provided in the second call. This behaviour can be useful to change the |
| 627 | connection target without rebuilding the whole UI. Alternative, after |
| 628 | connect has been called the first time, widget will have a property |
| 629 | `lantz_target` that can be used to achieve the same thing. |
| 630 | |
| 631 | :param widget: widget instance. |
| 632 | :param target: driver instance. |
| 633 | :param feat_name: feature name. If None, connect using widget name. |
| 634 | :param feat_key: For a DictFeat, this defines which key to show. |
| 635 | """ |
| 636 | |
| 637 | logger.debug('Connecting {} to {}, {}, {}'.format(widget, target, feat_name, feat_key)) |
| 638 | |
| 639 | if not isinstance(target, Driver): |
| 640 | raise TypeError('Connect target must be an instance of lantz.Driver, not {}'.format(target)) |
| 641 | |
| 642 | if not feat_name: |
| 643 | feat_name = widget.objectName() |
| 644 | |
| 645 | #: Reconnect |
| 646 | if hasattr(widget, '_feat.name') and widget._feat.name == feat_name: |
| 647 | widget.lantz_target = target |
| 648 | return |
| 649 | |
| 650 | feat = target.feats[feat_name] |
| 651 | |
| 652 | WidgetMixin.wrap(widget) |
| 653 | widget.bind_feat(feat) |
| 654 | widget.feat_key = feat_key |
| 655 | |
| 656 | widget.lantz_target = target |
| 657 | |
| 658 | |
| 659 | def connect_driver(parent, target, *, prefix='', sep='__'): |
no test coverage detected