Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DictFeatWidget fails to initialize when keys are not explicitly set #64

Open
thibaudruelle opened this issue Apr 20, 2016 · 0 comments
Open

Comments

@thibaudruelle
Copy link

Context: I ran start_test_app on an instance of a custom driver which contained DictFeats initialized without specifying a keys=() argument. The following error shows up:

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\lantz\ui\widgets.py", line 528, in __init__
    feat_widget = LabeledFeatWidget(self, target, feat)
  File "C:\Anaconda3\lib\site-packages\lantz\ui\widgets.py", line 415, in __init__
    self._widget = DictFeatWidget(parent, target, feat)
  File "C:\Anaconda3\lib\site-packages\lantz\ui\widgets.py", line 340, in __init__
    wid.feat_key = self._keys[0]
AttributeError: 'DictFeatWidget' object has no attribute '_keys'

Probable origin: In that case, keys default to None so when the DictFeatWidget is created by start_test_app the _keys attribute is not set within the if feat.keys statement before wid.feat_key = self._keys[0] is run, leading to the error.

Probable fix: wid.feat_key = self._keys[0] should only be run when keys exist.

Proposed fix: rewrite DictFeatWidget.__init__ as

def __init__(self, parent, target, feat):
        super().__init__(parent)
        self._feat = feat

        layout = QtGui.QHBoxLayout(self)

        valwid = WidgetMixin.from_feat(feat)
        valwid.bind_feat(feat)
        valwid.lantz_target = target

        if feat.keys:
            keywid = QtGui.QComboBox()
            if isinstance(feat.keys, dict):
                self._keys = list(feat.keys.keys())
            else:
                self._keys = list(feat.keys)

            keywid .addItems([str(key) for key in self._keys])
            keywid .currentIndexChanged.connect(self._combobox_changed)

            valwid.feat_key = self._keys[0]
        else:
            keywid = QtGui.QLineEdit()
            keywid .textChanged.connect(self._lineedit_changed)

        layout.addWidget(keywid )
        self._key_widget = keywid 

        layout.addWidget(valwid )
        self._value_widget = valwid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant