Search code examples
pythonuser-interfacewxpythonwxwidgets

Vibrate window in wxPython


How would I vibrate a window in wxPython. I'd like some way of specifying how long to do it for and distance and stuff like that.

Is there a builtin function I'm not noticing or would I have to code it myself?
(I'm thinking of moving the window sideways a few times but I'd rather have a builtin function that might be faster.)


Solution

  • I don't think there is any such function, but you can easily do it using win.SetPosition

    e.g. click inside frame to vibrate

    import wx
    
    def vibrate(win, count=20, delay=50):
        if count == 0: return
        x, y = win.GetPositionTuple()
        dx = 2*count*(.5-count%2)
        win.SetPosition((x+dx,y))
        wx.CallLater(delay, vibrate, win, count-1, delay)
    
    app = wx.PySimpleApp()
    frame = wx.Frame(None, title="Vibrator")
    frame.Show()
    frame.Bind(wx.EVT_LEFT_DOWN, lambda e:wx.CallAfter(vibrate, frame))
    app.SetTopWindow(frame)
    app.MainLoop()