Baby Language Lab Scripts
A collection of data processing tools.
 All Classes Namespaces Files Functions Variables Pages
C:/Users/Wayne/Documents/baby-lab/bll_app/launcher.py
Go to the documentation of this file.
1 ## @package launcher
2 # This module is the main entry point for all bll applications.
3 # It must be launched with a single command-line arg, the name of the module
4 # from the app/ directory that is to be run (i.e. which application to run).
5 # In addition, the BLL_APP_ROOT_DIR constant must be set to the absolute path to the bll_app/ directory.
6 
7 #must include trailing slash
8 BLL_APP_ROOT_DIR = 'C:/Users/Wayne/Documents/baby-lab/bll_app/'
9 
10 from app.app import App
11 import imp
12 import sys
13 #this will allow all modules to access bll classes
14 sys.path.append(BLL_APP_ROOT_DIR)
15 
16 if len(sys.argv) != 2:
17  print 'Launcher requires name of module to run (from app/ directory).'
18  exit(1)
19 
20 module_name = sys.argv[1]
21 module_path = '%sapp/%s.py' % (BLL_APP_ROOT_DIR, module_name)
22 #the name of the class we will instantiate is the module name, with underscores removed, in camel-case
23 cls_name = reduce(lambda accum, word: accum + word.capitalize(), module_name.split('_'), '')
24 
25 #attempt to dynamically import the module corresponding to the app we are launching
26 try:
27  module = imp.load_source(module_name, module_path)
28 
29 except Exception as err:
30  print 'Error loading launch module "%s": %s' % (module_name, err)
31  exit(2)
32 
33 #instantiate the app class, and call a few methods to get the app running
34 cls = getattr(module, cls_name)
35 cur_app = cls()
36 #do any required setup for the app
37 cur_app.start()
38 
39 if cur_app.app_type == App.APP_TYPES.GUI:
40  #start the UI (gtk+) event loop to accept input from the keyboard, mouse, etc.
41  cur_app.event_loop()
42