Example #1
0
 def open_database(back, db_dir=None):
     # File -> Open Database
     try:
         # Use the same args in a new (opened) database
         args = back.hs.args
         if db_dir is None:
             msg = 'Select (or create) a database directory.'
             db_dir = guitools.select_directory(msg)
         print('[*back] user selects database: ' + db_dir)
         # Try and load db
         args.dbdir = db_dir
         hs = HotSpotterAPI.HotSpotter(args=args, db_dir=db_dir)
         hs.load(load_all=False)
         # Write to cache and connect if successful
         io.global_cache_write('db_dir', db_dir)
         back.connect_api(hs)
         #back.layout_figures()
     except Exception as ex:
         import traceback
         print(traceback.format_exc())
         back.user_info('Aborting open database')
         print('aborting open database')
         print(ex)
         if back.hs.args.strict:
             raise
     print('')
Example #2
0
 def open_database(back, db_dir=None):
     # File -> Open Database
     try:
         # Use the same args in a new (opened) database
         args = back.hs.args
         if db_dir is None:
             msg = 'Select (or create) a database directory.'
             db_dir = guitools.select_directory(msg)
         print('[*back] user selects database: ' + db_dir)
         # Try and load db
         args.dbdir = db_dir
         hs = HotSpotterAPI.HotSpotter(args=args, db_dir=db_dir)
         hs.load(load_all=False)
         # Write to cache and connect if successful
         io.global_cache_write('db_dir', db_dir)
         back.connect_api(hs)
         #back.layout_figures()
     except Exception as ex:
         import traceback
         print(traceback.format_exc())
         back.user_info('Aborting open database')
         print('aborting open database')
         print(ex)
         if back.hs.args.strict:
             raise
     print('')
Example #3
0
def _user_option(parent, msg, title='options', options=['No', 'Yes'], use_cache=False):
    'Prompts user with several options with ability to save decision'
    print('[*guitools] _user_option:\n %r: %s' + title + ': ' + msg)
    # Recall decision
    print('[*guitools] asking user: %r %r' % (msg, title))
    cache_id = helpers.hashstr(title + msg)
    if use_cache:
        reply = io.global_cache_read(cache_id, default=None)
        if reply is not None:
            return reply
    # Create message box
    msgBox = _newMsgBox(msg, title, parent)
    _addOptions(msgBox, options)
    if use_cache:
        dontPrompt = _cacheReply(msgBox)
    # Wait for output
    optx = msgBox.exec_()
    if optx == QtGui.QMessageBox.Cancel:
        return None
    try:
        reply = options[optx]
    except Exception as ex:
        print('[*guitools] USER OPTION EXCEPTION !')
        print('[*guitools] optx = %r' % optx)
        print('[*guitools] options = %r' % options)
        print('[*guitools] ex = %r' % ex)
        raise
    # Remember decision
    if use_cache and dontPrompt.isChecked():
        io.global_cache_write(cache_id, reply)
    del msgBox
    return reply
Example #4
0
def select_directory(caption='Select Directory', directory=None):
    print(caption)
    if directory is None:
        directory = io.global_cache_read('select_directory')
    qdlg = PyQt4.Qt.QFileDialog()
    qopt = PyQt4.Qt.QFileDialog.ShowDirsOnly
    qdlg_kwargs = dict(caption=caption, options=qopt, directory=directory)
    dpath = str(qdlg.getExistingDirectory(**qdlg_kwargs))
    print('Selected Directory: %r' % dpath)
    io.global_cache_write('select_directory', split(dpath)[0])
    return dpath
Example #5
0
def select_files(caption='Select Files:', directory=None, name_filter=None):
    'Selects one or more files from disk using a qt dialog'
    print(caption)
    if directory is None:
        directory = io.global_cache_read('select_directory')
    qdlg = PyQt4.Qt.QFileDialog()
    qfile_list = qdlg.getOpenFileNames(caption=caption, directory=directory, filter=name_filter)
    file_list = map(str, qfile_list)
    print('Selected %d files' % len(file_list))
    io.global_cache_write('select_directory', directory)
    return file_list
Example #6
0
def main(defaultdb='NAUTS', usedbcache=False, default_load_all=True):
    import matplotlib
    matplotlib.use('Qt4Agg')
    imports()
    from hscom import argparse2
    from hscom import helpers
    from hotspotter import HotSpotterAPI as api
    args = argparse2.parse_arguments(defaultdb=defaultdb)
    # Parse arguments
    args = argparse2.fix_args_with_cache(args)
    if usedbcache:
        load_all, cids = preload_args_process(args)
    else:
        args = argparse2.fix_args_shortnames(args)
        load_all = helpers.get_flag('--load-all', default_load_all)

    # Preload process args
    if args.delete_global:
        from hscom import fileio as io
        io.delete_global_cache()

    # --- Build HotSpotter API ---
    hs = api.HotSpotter(args)
    setcfg = args.setcfg
    if setcfg is not None:
        import experiment_harness
        print('[main] setting cfg to %r' % setcfg)
        varried_list = experiment_harness.get_varried_params_list([setcfg])
        cfg_dict = varried_list[0]
        #print(cfg_dict)
        hs.prefs.query_cfg.update_cfg(**cfg_dict)
        hs.prefs.save()
        #hs.prefs.printme()
        # load default preferences
        hs.default_preferences()

    # Load all data if needed now, otherwise be lazy
    try:
        hs.load(load_all=load_all)
        from hscom import fileio as io
        #imported from wrong module
        #from hotspotter import fileio as io
        db_dir = hs.dirs.db_dir
        io.global_cache_write('db_dir', db_dir)
    except ValueError as ex:
        print('[main] ValueError = %r' % (ex, ))
        if hs.args.strict:
            raise
    return hs
Example #7
0
def main(defaultdb='NAUTS', usedbcache=False, default_load_all=True):
    import matplotlib
    matplotlib.use('Qt4Agg')
    imports()
    from hscom import argparse2
    from hscom import helpers
    from hotspotter import HotSpotterAPI as api
    args = argparse2.parse_arguments(defaultdb=defaultdb)
    # Parse arguments
    args = argparse2.fix_args_with_cache(args)
    if usedbcache:
        load_all, cids = preload_args_process(args)
    else:
        args = argparse2.fix_args_shortnames(args)
        load_all = helpers.get_flag('--load-all', default_load_all)

    # Preload process args
    if args.delete_global:
        from hscom import fileio as io
        io.delete_global_cache()

    # --- Build HotSpotter API ---
    hs = api.HotSpotter(args)
    setcfg = args.setcfg
    if setcfg is not None:
        import experiment_harness
        print('[main] setting cfg to %r' % setcfg)
        varried_list = experiment_harness.get_varried_params_list([setcfg])
        cfg_dict = varried_list[0]
        #print(cfg_dict)
        hs.prefs.query_cfg.update_cfg(**cfg_dict)
        hs.prefs.save()
        #hs.prefs.printme()
        #hs.default_preferences()

    # Load all data if needed now, otherwise be lazy
    try:
        hs.load(load_all=load_all)
        from hotspotter import fileio as io
        db_dir = hs.dirs.db_dir
        io.global_cache_write('db_dir', db_dir)
    except ValueError as ex:
        print('[main] ValueError = %r' % (ex,))
        if hs.args.strict:
            raise
    return hs
Example #8
0
 def get_work_directory(back, use_cache=True):
     # TODO: This should go in api (or higher level main?)
     cache_id = 'work_directory_cache_id'
     if use_cache:
         work_dir = io.global_cache_read(cache_id, default='.')
         if work_dir is not '.' and exists(work_dir):
             return work_dir
     msg_dir = 'Work directory not currently set. Select a work directory'
     work_dir = guitools.select_directory(msg_dir)
     if not exists(work_dir):
         msg_try = 'Directory %r does not exist.' % work_dir
         opt_try = ['Try Again']
         try_again = back.user_option(msg_try, 'get work dir failed',
                                      opt_try, False)
         if try_again == 'Try Again':
             return back.get_work_dir(use_cache)
     io.global_cache_write(cache_id, work_dir)
     return work_dir
Example #9
0
 def get_work_directory(back, use_cache=True):
     # TODO: This should go in api (or higher level main?)
     cache_id = 'work_directory_cache_id'
     if use_cache:
         work_dir = io.global_cache_read(cache_id, default='.')
         if work_dir is not '.' and exists(work_dir):
             return work_dir
     msg_dir = 'Work directory not currently set. Select a work directory'
     work_dir = guitools.select_directory(msg_dir)
     if not exists(work_dir):
         msg_try = 'Directory %r does not exist.' % work_dir
         opt_try = ['Try Again']
         try_again = back.user_option(msg_try, 'get work dir failed',
                                      opt_try, False)
         if try_again == 'Try Again':
             return back.get_work_dir(use_cache)
     io.global_cache_write(cache_id, work_dir)
     return work_dir
Example #10
0
def main(defaultdb='cache', preload=False, app=None):
    from hscom import fileio as io
    from hscom import params
    from hotspotter import HotSpotterAPI as api
    from hsgui import guitools
    from hsgui import guiback
    if app is True:
        app, is_root = guitools.init_qtapp()
    args = parse_arguments(defaultdb, defaultdb == 'cache')
    # --- Build HotSpotter API ---
    if app is None:
        hs = api.HotSpotter(args)
    else:
        back = guiback.make_main_window(app)
        hs = back.open_database(args.dbdir)
    setcfg = args.setcfg
    if setcfg is not None:
        # FIXME move experiment harness to hsdev
        import experiment_harness
        print('[tapi.main] setting cfg to %r' % setcfg)
        varied_list = experiment_harness.get_varied_params_list([setcfg])
        cfg_dict = varied_list[0]
        hs.prefs.query_cfg.update_cfg(**cfg_dict)
        hs.prefs.save()
        hs.prefs.printme()
    # Load all data if needed now, otherwise be lazy
    try:
        load_all = preload
        hs.load(load_all=load_all)
        db_dir = hs.dirs.db_dir
        io.global_cache_write('db_dir', db_dir)
    except ValueError as ex:
        print('[tapi.main] ValueError = %r' % (ex, ))
        if params.args.strict:
            raise
    if app is not None:
        return hs, back
    else:
        from hsgui import guitools
        app, is_root = guitools.init_qtapp()
        hs.app = app
    return hs
Example #11
0
def open_database(db_dir=None):
    # File -> Open Database
    try:
        # Use the same args in a new (opened) database
        args = params.args
        # Try and load db
        if args is not None:
            args.dbdir = db_dir
        hs = HotSpotterAPI.HotSpotter(args=args, db_dir=db_dir)
        hs.load(load_all=False)
        # Write to cache and connect if successful
        io.global_cache_write('db_dir', db_dir)
        #back.layout_figures()
    except Exception as ex:
        import traceback
        import sys
        print(traceback.format_exc())
        print('aborting open database')
        print(ex)
        if '--strict' in sys.argv:
            raise
        raise
    print('')
    return hs
Example #12
0
    roi = np.array(xywh, dtype=np.int32)

    return roi


#%%
# =============================================================================
#     Initialization -  dataset
# =============================================================================
db_dir = join(dpath, new_db)

#------ function:[hsgui]-[guitools]- def select_directory
caption = 'Select Directory'
print('Selected Directory: %r' % dpath)
io.global_cache_write('select_directory', split(dpath)[0])
print('[*back] valid new_db_dir = %r' % db_dir)
io.global_cache_write('db_dir', db_dir)
helpers.ensurepath(db_dir)

if Flag_new_db & 1:
    if exists(db_dir):
        shutil.rmtree(db_dir)

defaultdb = None
preload = False

args = parse_arguments(defaultdb, defaultdb == 'cache')
# --- Build HotSpotter API ---
hs = open_database(db_dir)