def execute_from_commandline(self, argv=None): """ TODO """ self.argv = argv or sys.argv[:] self.prog_name = os.path.basename(argv[0]) # Preprocess options to extract --settings and --pythonpath. # These options could affect the commands that are available, so they # must be processed early. parser = LaxOptionParser(usage=self.usage, version=VERSION, option_list=BaseCommand.option_list) try: options, args = parser.parse_args(self.argv) except: pass # Ignore any option errors at this point. # Initialize logging loglevel = (logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG)[int(options.verbosity)] logging.basicConfig( level=loglevel, format='%(asctime)s %(levelname)-8s %(name)-30s %(message)s' ) #, datefmt='%H:%M:%S.%m') # Disable PyQt log messages logging.getLogger("PyQt5").setLevel(logging.WARNING) # Handle options common for all commands # and initialize the labeltool object from # the configuration (default config if not specified) if options.pythonpath: sys.path.insert(0, options.pythonpath) self.init_from_config(options.config) # check for commands try: subcommand = args[1] except IndexError: subcommand = None # handle commands and command line arguments if subcommand == 'help': if len(args) > 2: self.fetch_command(args[2]).print_help(self.prog_name, args[2]) sys.exit(0) else: sys.stdout.write(self.main_help_text() + '\n') parser.print_lax_help() sys.exit(1) elif self.argv[1:] == ['--version']: # LaxOptionParser already takes care of printing the version. sys.exit(0) elif self.argv[1:] in (['--help'], ['-h']): sys.stdout.write(self.main_help_text() + '\n') parser.print_lax_help() sys.exit(0) elif subcommand in get_commands(): self.fetch_command(subcommand).run_from_argv(self.argv) sys.exit(0) else: # Setup GUI self._mainwindow = MainWindow(self) self._mainwindow.show() # Load plugins self.loadPlugins(config.PLUGINS) # check if args contain a labelfile filename to load if len(args) > 1: try: self.loadAnnotations(args[1], handleErrors=False) # goto to first image self.gotoNext() except Exception as e: LOG.fatal("Error loading annotations: %s" % e) if (int(options.verbosity)) > 1: raise else: sys.exit(1) else: self.clearAnnotations()
#!/usr/bin/env python import os, sys from PyQt4.QtGui import QApplication from sloth.gui import MainWindow from sloth.core.labeltool import LabelTool from sloth import APP_NAME, ORGANIZATION_NAME, ORGANIZATION_DOMAIN from pymodeltest.modeltest import ModelTest SAMPLE_DATA = os.path.join(os.path.dirname(__file__), 'data', 'example1_labels.json') if __name__ == '__main__': app = QApplication(sys.argv) app.setOrganizationName(ORGANIZATION_NAME) app.setOrganizationDomain(ORGANIZATION_DOMAIN) app.setApplicationName(APP_NAME) labeltool = LabelTool() if len(sys.argv) < 2: sys.argv.append(SAMPLE_DATA) labeltool.execute_from_commandline(sys.argv) labeltool.modeltest = ModelTest(labeltool._model, labeltool) wnd = MainWindow(labeltool) labeltool._mainwindow = wnd wnd.show() sys.exit(app.exec_())