Exemplo n.º 1
0
def askConfigPreferences(items,prefix=None,store=None):
    """Ask preferences stored in config variables.

    Items in list should only be keys. store is usually a dictionary, but
    can be any class that allow the setdefault method for lookup while
    setting the default, and the store[key]=val syntax for setting the
    value.
    If a prefix is given, actual keys will be 'prefix/key'. 
    The current values are retrieved from the store, and the type returned
    will be in accordance.
    If no store is specified, the global config GD.cfg is used.
    """
    if not store:
        store = GD.cfg
    if prefix:
        items = [ '%s/%s' % (prefix,i) for i in items ]
    itemlist = [ [ i,store.setdefault(i,'') ] for i in items ]
    res,accept = widgets.inputDialog(itemlist,'Config Dialog').process()
    if accept:
        for i,r in zip(itemlist,res):
            GD.debug("IN : %s\nOUT: %s" % (i,r))
            if type(i[1]) == str:
                store[r[0]] = r[1]
            else:
                store[r[0]] = eval(r[1])
    return accept
Exemplo n.º 2
0
def askItems(items,caption=None):
    """Ask the value of some items to the user. !! VERY EXPERIMENTAL!!

    Input is a dictionary of items or a list of [key,value] pairs.
    The latter is recommended, because a dictionary does not guarantee
    the order of the items.
    Returns a dictionary (maybe we should just return the list??)
    """
    if type(items) == dict:
        items = items.items()
    if type(caption) is str:
        w = widgets.inputDialog(items,caption)
    else:
        w = widgets.inputDialog(items)
    res,status = w.getResult()
    items = {}
    for r in res:
        items[r[0]] = r[1]
    return items
Exemplo n.º 3
0
def ask(question,choices=None,default=''):
    """Ask a question and present possible answers."""
    if choices:
        # this currently only supports 3 answers
        return info(question,choices)
    else:
        items = [ [question, default] ]
        res,accept = widgets.inputDialog(items,'Config Dialog').process()
        GD.gui.update()
        #print res
        if accept:
            return res[0][1]
        else:
            return default
Exemplo n.º 4
0
def newaskConfigPreferences(items,store):
    """Ask preferences stored in config variables.

    Items in list should only be keys. The current values are retrieved
    from the config.
    A config section name should be specified if the items are not in the
    top config level.
    """
    if not store:
        store = GD.cfg
    itemlist = [ [ i,store.setdefault(i,'') ] for i in items ]
    res,accept = widgets.inputDialog(itemlist,'Config Dialog').process()
    if accept:
        #print "ACCEPTED following values:"
        for r in res:
            #print r
            store[r[0]] = eval(r[1])
Exemplo n.º 5
0
def askConfigPreferences(items,section=None):
    """Ask preferences stored in config variables.

    Items in list should only be keys. The current values are retrieved
    from the config.
    A config section name should be specified if the items are not in the
    top config level.
    """
    if section:
        store = GD.cfg[section]
    else:
        store = GD.cfg
    # insert current values
    for it in items:
        it.insert(1,store.setdefault(it[0],''))
    res,accept = widgets.inputDialog(items,'Config Dialog').process()
    if accept:
        GD.prefsChanged = True
        #print "ACCEPTED following values:"
        for r in res:
            #print r
            store[r[0]] = eval(r[1])