Skip to content

Commit

Permalink
Add --nosortlabels option
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Mar 22, 2018
1 parent 1c9488f commit 300d1eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
19 changes: 14 additions & 5 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class MainWindow(QMainWindow, WindowMixin):
FIT_WINDOW, FIT_WIDTH, MANUAL_ZOOM = 0, 1, 2

def __init__(self, filename=None, output=None, store_data=True,
labels=None):
labels=None, sort_labels=True):
super(MainWindow, self).__init__()
self.setWindowTitle(__appname__)

Expand All @@ -104,7 +104,8 @@ def __init__(self, filename=None, output=None, store_data=True,
self.screencast = "screencast.ogv"

# Main widgets and related state.
self.labelDialog = LabelDialog(parent=self, labels=labels)
self.labelDialog = LabelDialog(parent=self, labels=labels,
sort_labels=sort_labels)

self.labelList = QListWidget()
self.itemsToShapes = []
Expand Down Expand Up @@ -963,8 +964,10 @@ def main():
parser.add_argument('filename', nargs='?', help='image or label filename')
parser.add_argument('--output', '-O', '-o', help='output label name')
parser.add_argument('--nodata', dest='store_data', action='store_false',
help='Stop storing image data to JSON file.')
parser.add_argument('--labels', help='Camma separated list of labels')
help='stop storing image data to JSON file')
parser.add_argument('--labels', help='comma separated list of labels')
parser.add_argument('--nosortlabels', dest='sort_labels',
action='store_false', help='stop sorting labels')
args = parser.parse_args()

if args.labels is not None:
Expand All @@ -973,7 +976,13 @@ def main():
app = QApplication(sys.argv)
app.setApplicationName(__appname__)
app.setWindowIcon(newIcon("app"))
win = MainWindow(args.filename, args.output, args.store_data, args.labels)
win = MainWindow(
filename=args.filename,
output=args.output,
store_data=args.store_data,
labels=args.labels,
sort_labels=args.sort_labels,
)
win.show()
win.raise_()
sys.exit(app.exec_())
11 changes: 9 additions & 2 deletions labelme/labelDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

class LabelDialog(QDialog):

def __init__(self, text="Enter object label", parent=None, labels=None):
def __init__(self, text="Enter object label", parent=None, labels=None,
sort_labels=True):
super(LabelDialog, self).__init__(parent)
self.edit = QLineEdit()
self.edit.setPlaceholderText(text)
Expand All @@ -53,8 +54,13 @@ def __init__(self, text="Enter object label", parent=None, labels=None):
layout.addWidget(bb)
# label_list
self.labelList = QListWidget()
self._sort_labels = sort_labels
if labels:
self.labelList.addItems(labels)
if self._sort_labels:
self.labelList.sortItems()
else:
self.labelList.setDragDropMode(QAbstractItemView.InternalMove)
self.labelList.currentItemChanged.connect(self.labelSelected)
layout.addWidget(self.labelList)
self.setLayout(layout)
Expand All @@ -63,7 +69,8 @@ def addLabelHistory(self, label):
if self.labelList.findItems(label, Qt.MatchExactly):
return
self.labelList.addItem(label)
self.labelList.sortItems()
if self._sort_labels:
self.labelList.sortItems()

def labelSelected(self, item):
self.edit.setText(item.text())
Expand Down

0 comments on commit 300d1eb

Please sign in to comment.