Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
output_file = None
output_dir = None
if output is not None:
if output.endswith('.json'):
output_file = output
else:
output_dir = output
translator = QtCore.QTranslator()
translator.load(
QtCore.QLocale.system().name(),
osp.dirname(osp.abspath(__file__)) + '/translate'
)
app = QtWidgets.QApplication(sys.argv)
app.setApplicationName(__appname__)
app.setWindowIcon(newIcon('icon'))
app.installTranslator(translator)
win = MainWindow(
config=config,
filename=filename,
output_file=output_file,
output_dir=output_dir,
)
if reset_config:
logger.info('Resetting Qt config: %s' % win.settings.fileName())
win.settings.clear()
sys.exit(0)
win.show()
win.raise_()
parser.add_argument(
'--keep-prev',
action='store_true',
help='keep annotation of previous frame',
default=argparse.SUPPRESS,
)
parser.add_argument(
'--epsilon',
type=float,
help='epsilon to find nearest vertex on canvas',
default=argparse.SUPPRESS,
)
args = parser.parse_args()
if args.version:
print('{0} {1}'.format(__appname__, __version__))
sys.exit(0)
logger.setLevel(getattr(logging, args.logger_level.upper()))
if hasattr(args, 'flags'):
if os.path.isfile(args.flags):
with codecs.open(args.flags, 'r', encoding='utf-8') as f:
args.flags = [l.strip() for l in f if l.strip()]
else:
args.flags = [l for l in args.flags.split(',') if l]
if hasattr(args, 'labels'):
if os.path.isfile(args.labels):
with codecs.open(args.labels, 'r', encoding='utf-8') as f:
args.labels = [l.strip() for l in f if l.strip()]
else:
output_dir=None,
):
if output is not None:
logger.warning(
'argument output is deprecated, use output_file instead'
)
if output_file is None:
output_file = output
# see labelme/config/default_config.yaml for valid configuration
if config is None:
config = get_config()
self._config = config
super(MainWindow, self).__init__()
self.setWindowTitle(__appname__)
# Whether we need to save or not.
self.dirty = False
self._noSelectionSlot = False
# Main widgets and related state.
self.labelDialog = LabelDialog(
parent=self,
labels=self._config['labels'],
sort_labels=self._config['sort_labels'],
show_text_field=self._config['show_label_text_field'],
completion=self._config['label_completion'],
fit_to_content=self._config['fit_to_content'],
flags=self._config['label_flags']
)
def setClean(self):
self.dirty = False
self.actions.save.setEnabled(False)
self.actions.createMode.setEnabled(True)
self.actions.createRectangleMode.setEnabled(True)
self.actions.createCircleMode.setEnabled(True)
self.actions.createLineMode.setEnabled(True)
self.actions.createPointMode.setEnabled(True)
self.actions.createLineStripMode.setEnabled(True)
title = __appname__
if self.filename is not None:
title = '{} - {}'.format(title, self.filename)
self.setWindowTitle(title)
if self.hasLabelFile():
self.actions.deleteFile.setEnabled(True)
else:
self.actions.deleteFile.setEnabled(False)
def saveFileDialog(self):
caption = self.tr('%s - Choose File') % __appname__
filters = self.tr('Label files (*%s)') % LabelFile.suffix
if self.output_dir:
dlg = QtWidgets.QFileDialog(
self, caption, self.output_dir, filters
)
else:
dlg = QtWidgets.QFileDialog(
self, caption, self.currentPath(), filters
)
dlg.setDefaultSuffix(LabelFile.suffix[1:])
dlg.setAcceptMode(QtWidgets.QFileDialog.AcceptSave)
dlg.setOption(QtWidgets.QFileDialog.DontConfirmOverwrite, False)
dlg.setOption(QtWidgets.QFileDialog.DontUseNativeDialog, False)
basename = osp.basename(osp.splitext(self.filename)[0])
if self.output_dir:
default_labelfile_name = osp.join(
def setDirty(self):
if self._config['auto_save'] or self.actions.saveAuto.isChecked():
label_file = osp.splitext(self.imagePath)[0] + '.json'
if self.output_dir:
label_file_without_path = osp.basename(label_file)
label_file = osp.join(self.output_dir, label_file_without_path)
self.saveLabels(label_file)
return
self.dirty = True
self.actions.save.setEnabled(True)
self.actions.undo.setEnabled(self.canvas.isShapeRestorable)
title = __appname__
if self.filename is not None:
title = '{} - {}*'.format(title, self.filename)
self.setWindowTitle(title)
deleteFile,
None,
createMode,
editMode,
copy,
delete,
undo,
None,
zoomIn,
zoom,
zoomOut,
fitWindow,
fitWidth,
)
self.statusBar().showMessage(self.tr('%s started.') % __appname__)
self.statusBar().show()
if output_file is not None and self._config['auto_save']:
logger.warn(
'If `auto_save` argument is True, `output_file` argument '
'is ignored and output filename is automatically '
'set as IMAGE_BASENAME.json.'
)
self.output_file = output_file
self.output_dir = output_dir
# Application state.
self.image = QtGui.QImage()
self.imagePath = None
self.recentFiles = []
self.maxRecent = 7