def PartialProgress(f1, f2, progress_callback):
    """Often a function accepting a progress callback needs to call
    sub-functions to perform the task. By wrapping the given callback
    with this function before passing it on, correct progress will be
    sent upwards.

    Like so:
    
    def LongRunningTask(progress_callback):
        DoSomeStuff(PartialProgress(0.0, 0.5, progress_callback))
        DoSomeMoreStuff(PartialProgress(0.5, 1.0, progress_callback))
        return

    The original progress callback will now see only a monotonously
    increasing progress from 0 to 100%.
    """
    assert 0.0 <= f1 <= f2 <= 1.0
    def wrapped_callback(f):
        progress_callback(f1 + (f2 - f1) * f)
    return wrapped_callback