Skip to content

Commit

Permalink
Add label_completion config key
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Jul 31, 2018
1 parent ee6933f commit 06f52e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(self, config=None, filename=None, output=None):
labels=self._config['labels'],
sort_labels=self._config['sort_labels'],
show_text_field=self._config['show_label_text_field'],
completion=self._config['label_completion'],
)

self.labelList = LabelQListWidget()
Expand Down
3 changes: 3 additions & 0 deletions labelme/config/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ labels: null
file_search: null
sort_labels: true
validate_label: null

# label_dialog
show_label_text_field: true
label_completion: startswith

epsilon: 11.0

Expand Down
13 changes: 10 additions & 3 deletions labelme/widgets/label_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def keyPressEvent(self, e):
class LabelDialog(QtWidgets.QDialog):

def __init__(self, text="Enter object label", parent=None, labels=None,
sort_labels=True, show_text_field=True):
sort_labels=True, show_text_field=True,
completion='startswith'):
super(LabelDialog, self).__init__(parent)
self.edit = LabelQLineEdit()
self.edit.setPlaceholderText(text)
Expand Down Expand Up @@ -64,8 +65,14 @@ def __init__(self, text="Enter object label", parent=None, labels=None,
self.setLayout(layout)
# completion
completer = QtWidgets.QCompleter()
completer.setFilterMode(QtCore.Qt.MatchContains)
completer.setCompletionMode(QtWidgets.QCompleter.PopupCompletion)
if completion == 'startswith':
completer.setFilterMode(QtCore.Qt.MatchStartsWith)
completer.setCompletionMode(QtWidgets.QCompleter.InlineCompletion)
elif completion == 'contains':
completer.setFilterMode(QtCore.Qt.MatchContains)
completer.setCompletionMode(QtWidgets.QCompleter.PopupCompletion)
else:
raise ValueError('Unsupported completion: {}'.format(completion))
completer.setModel(self.labelList.model())
self.edit.setCompleter(completer)

Expand Down

0 comments on commit 06f52e0

Please sign in to comment.