@@ -165,6 +165,15 @@ def __init__(self, config=None, filename=None, output=None):
165
165
self .labelListContainer = QtWidgets .QWidget ()
166
166
self .labelListContainer .setLayout (listLayout )
167
167
168
+ self .flag_dock = self .flag_widget = None
169
+ self .flag_dock = QtWidgets .QDockWidget ('Flags' , self )
170
+ self .flag_dock .setObjectName ('Flags' )
171
+ self .flag_widget = QtWidgets .QListWidget ()
172
+ if config ['flags' ]:
173
+ self .loadFlags ({k : False for k in config ['flags' ]})
174
+ self .flag_dock .setWidget (self .flag_widget )
175
+ self .flag_widget .itemChanged .connect (self .setDirty )
176
+
168
177
self .uniqLabelList = EscapableQListWidget ()
169
178
self .uniqLabelList .setToolTip (
170
179
"Select label to start annotating for it. "
@@ -214,6 +223,7 @@ def __init__(self, config=None, filename=None, output=None):
214
223
215
224
self .setCentralWidget (scrollArea )
216
225
226
+ self .addDockWidget (Qt .RightDockWidgetArea , self .flag_dock )
217
227
self .addDockWidget (Qt .RightDockWidgetArea , self .labelsdock )
218
228
self .addDockWidget (Qt .RightDockWidgetArea , self .dock )
219
229
self .addDockWidget (Qt .RightDockWidgetArea , self .filedock )
@@ -686,6 +696,14 @@ def loadLabels(self, shapes):
686
696
shape .fill_color = QtGui .QColor (* fill_color )
687
697
self .loadShapes (s )
688
698
699
+ def loadFlags (self , flags ):
700
+ self .flag_widget .clear ()
701
+ for key , flag in flags .items ():
702
+ item = QtWidgets .QListWidgetItem (key )
703
+ item .setFlags (item .flags () | Qt .ItemIsUserCheckable )
704
+ item .setCheckState (Qt .Checked if flag else Qt .Unchecked )
705
+ self .flag_widget .addItem (item )
706
+
689
707
def saveLabels (self , filename ):
690
708
lf = LabelFile ()
691
709
@@ -698,13 +716,26 @@ def format_shape(s):
698
716
points = [(p .x (), p .y ()) for p in s .points ])
699
717
700
718
shapes = [format_shape (shape ) for shape in self .labelList .shapes ]
719
+ flags = {}
720
+ for i in range (len (self .flag_widget )):
721
+ item = self .flag_widget .item (i )
722
+ key = item .text ()
723
+ flag = item .checkState () == Qt .Checked
724
+ flags [key ] = flag
701
725
try :
702
726
imagePath = os .path .relpath (
703
727
self .imagePath , os .path .dirname (filename ))
704
728
imageData = self .imageData if self ._config ['store_data' ] else None
705
- lf .save (filename , shapes , imagePath , imageData ,
706
- self .lineColor .getRgb (), self .fillColor .getRgb (),
707
- self .otherData )
729
+ lf .save (
730
+ filename = filename ,
731
+ shapes = shapes ,
732
+ imagePath = imagePath ,
733
+ imageData = imageData ,
734
+ lineColor = self .lineColor .getRgb (),
735
+ fillColor = self .fillColor .getRgb (),
736
+ otherData = self .otherData ,
737
+ flags = flags ,
738
+ )
708
739
self .labelFile = lf
709
740
# disable allows next and previous image to proceed
710
741
# self.filename = filename
@@ -880,6 +911,8 @@ def loadFile(self, filename=None):
880
911
self .canvas .loadPixmap (QtGui .QPixmap .fromImage (image ))
881
912
if self .labelFile :
882
913
self .loadLabels (self .labelFile .shapes )
914
+ if self .labelFile .flags is not None :
915
+ self .loadFlags (self .labelFile .flags )
883
916
self .setClean ()
884
917
self .canvas .setEnabled (True )
885
918
self .adjustScale (initial = True )
@@ -1243,16 +1276,9 @@ def main():
1243
1276
output = config_from_args .pop ('output' )
1244
1277
config_file = config_from_args .pop ('config_file' )
1245
1278
# drop the default config
1246
- if not config_from_args ['auto_save' ]:
1247
- config_from_args .pop ('auto_save' )
1248
- if config_from_args ['store_data' ]:
1249
- config_from_args .pop ('store_data' )
1250
- if not config_from_args ['labels' ]:
1251
- config_from_args .pop ('labels' )
1252
- if not config_from_args ['sort_labels' ]:
1253
- config_from_args .pop ('sort_labels' )
1254
- if not config_from_args ['validate_label' ]:
1255
- config_from_args .pop ('validate_label' )
1279
+ for k , v in list (config_from_args .items ()):
1280
+ if v is None :
1281
+ config_from_args .pop (k )
1256
1282
config = get_config (config_from_args , config_file )
1257
1283
1258
1284
app = QtWidgets .QApplication (sys .argv )
0 commit comments