Esempio n. 1
0
def move_smoothly(win, position, oldpos=None, time=200, interval=10):
    '''Moves a window to a new position smoothly.

    Optionally specify an old position.'''

    if hasattr(win, '_timer'):
        win._timer.stop()

    if oldpos is None:
        oldpos = vector(win.Rect[:2])

    if vector(oldpos) == vector(position):
        return

    def cb(p):
        try:
            win.SetRect(RectPS(p, win.Size))
        except wx.PyDeadObjectError:
            win._timer.stop()
            del win._timer

    win._timer = InterpTimer(cb,
                             oldpos,
                             position,
                             time=time,
                             interval=interval)
    win._newpos = position
    return win._timer
Esempio n. 2
0
def resize_smoothly(win, newsize, oldsize = None, on_tick=None, set_min = False, method=None, time=150):
    'Resizes a window smoothly. Optionally specify an old size.'

    if hasattr(win, '_resizetimer'):
        win._resizetimer.stop()

    win.SetAutoLayout(False)

    if oldsize is None:
        oldsize = vector(win.Size)
    else:
        assert len(oldsize) == 2
        oldsize = vector(oldsize)

    if set_min:
        def mysize(*a):
            #win.SetMinSize(*a)
            win.SetLA
            win.SetSize(*a)
            win.Refresh()
    else:
        def mysize(*a):
            p = win.Rect
            win.SetRect(wx.Rect(p[0], p[1], *a[0]))

    try:
        win._resizetimer = InterpTimer(mysize, oldsize, newsize, time=time,
                                       on_tick=on_tick, on_done = lambda: (win.SetAutoLayout(True), win.Layout(), win.Refresh()),
                                       method = method)
        return win._resizetimer
    except wx.PyDeadObjectError:
        pass
Esempio n. 3
0
def resize_smoothly(win,
                    newsize,
                    oldsize=None,
                    on_tick=None,
                    set_min=False,
                    method=None,
                    time=150):
    'Resizes a window smoothly. Optionally specify an old size.'

    if hasattr(win, '_resizetimer'):
        win._resizetimer.stop()

    win.SetAutoLayout(False)

    if oldsize is None:
        oldsize = vector(win.Size)
    else:
        assert len(oldsize) == 2
        oldsize = vector(oldsize)

    if set_min:

        def mysize(*a):
            #win.SetMinSize(*a)
            win.SetLA
            win.SetSize(*a)
            win.Refresh()
    else:

        def mysize(*a):
            p = win.Rect
            win.SetRect(wx.Rect(p[0], p[1], *a[0]))

    try:
        win._resizetimer = InterpTimer(
            mysize,
            oldsize,
            newsize,
            time=time,
            on_tick=on_tick,
            on_done=lambda:
            (win.SetAutoLayout(True), win.Layout(), win.Refresh()),
            method=method)
        return win._resizetimer
    except wx.PyDeadObjectError:
        pass
Esempio n. 4
0
    def Notify(self):
        '''
        Invoked by the wxTimer.

        Decides how much to move, and if it is time to stop.
        '''
        if not self: return
        if not self.window: return
        winrect = self.window.ScreenRect
        w, pos, target = self.window, vector(winrect[:2]), vector(self.target)
        move = lambda newpos: w.SetRect((newpos[0], newpos[1], winrect.width, winrect.height))

        if pos.to(target) < self.stop_threshold:
            move(self.target)
            self.Stop()
        else:
            move( pos + (target - pos) * self.dampen )
Esempio n. 5
0
    def Notify(self):
        '''
        Invoked by the wxTimer.

        Decides how much to move, and if it is time to stop.
        '''
        if not self: return
        if not self.window: return
        winrect = self.window.ScreenRect
        w, pos, target = self.window, vector(winrect[:2]), vector(self.target)
        move = lambda newpos: w.SetRect(
            (newpos[0], newpos[1], winrect.width, winrect.height))

        if pos.to(target) < self.stop_threshold:
            move(self.target)
            self.Stop()
        else:
            move(pos + (target - pos) * self.dampen)
Esempio n. 6
0
def interpolate_gen(total_ticks, p1, p2, func=None):
    '''
    Will yield [total_ticks] points between p1 and p2, based on the given
    interpolation function.
    '''

    if func is None or func not in globals():
        posfunc = better_logistic
    else:
        posfunc = globals()[func] if not callable(func) else func
    diff = vector(p2) - vector(p1)
    normal, total_distance = diff.normal, diff.length

    for n in xrange(total_ticks):
        d = total_distance * posfunc(n / total_ticks)
        yield p1 + normal * d

    yield p2  # make sure we end on the destination
Esempio n. 7
0
def interpolate_gen(total_ticks, p1, p2, func = None):
    '''
    Will yield [total_ticks] points between p1 and p2, based on the given
    interpolation function.
    '''


    if func is None or func not in globals():
        posfunc = better_logistic
    else:
        posfunc = globals()[func] if not callable(func) else func
    diff = vector(p2) - vector(p1)
    normal, total_distance = diff.normal, diff.length

    for n in xrange(total_ticks):
        d = total_distance * posfunc(n / total_ticks)
        yield p1 + normal * d

    yield p2 # make sure we end on the destination
Esempio n. 8
0
def move_smoothly(win, position, oldpos = None, time = 200, interval = 10):
    '''Moves a window to a new position smoothly.

    Optionally specify an old position.'''

    if hasattr(win, '_timer'):
        win._timer.stop()

    if oldpos is None:
        oldpos = vector(win.Rect[:2])

    if vector(oldpos) == vector(position):
        return

    def cb(p):
        try:
            win.SetRect(RectPS(p, win.Size))
        except wx.PyDeadObjectError:
            win._timer.stop()
            del win._timer

    win._timer  = InterpTimer(cb, oldpos, position, time = time, interval = interval)
    win._newpos = position
    return win._timer