Exemple #1
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
Exemple #2
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
Exemple #3
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
Exemple #4
0
def show_open_db_dlg(parent=None):
    # OLD
    from _frontend import OpenDatabaseDialog
    if not '-nc' in sys.argv and not '--nocache' in sys.argv:
        db_dir = io.global_cache_read('db_dir')
        if db_dir == '.':
            db_dir = None
    print('[*guitools] cached db_dir=%r' % db_dir)
    if parent is None:
        parent = PyQt4.QtGui.QDialog()
    opendb_ui = OpenDatabaseDialog.Ui_Dialog()
    opendb_ui.setupUi(parent)
    #opendb_ui.new_db_but.clicked.connect(create_new_database)
    #opendb_ui.open_db_but.clicked.connect(open_old_database)
    parent.show()
    return opendb_ui, parent
Exemple #5
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
Exemple #6
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