Last active
April 13, 2019 05:08
-
-
Save pudquick/7100e0902e1ead6a7a5807b0a4af1990 to your computer and use it in GitHub Desktop.
Example of using nibbler to make an annoying window that re-focuses itself to the front every second
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nibbler import * | |
from Foundation import NSTimer, NSObject | |
from AppKit import NSApplication | |
n = Nibbler('/Users/frogor/Desktop/sweet.nib') | |
def test2(): | |
print "hi (politely quit)" | |
n.quit() | |
class doStuffController(NSObject): | |
def doTheThing_(self, timer_obj): | |
print "I am re-activating to the foreground" | |
# use .userInfo on the timer object to get a reference back to the main Nibbler object which we passed in | |
n = timer_obj.userInfo()["nibbler_obj"] | |
# Move the application to the front | |
NSApplication.sharedApplication().activateIgnoringOtherApps_(True) | |
# Move the main window to the front | |
# Nibbler objects have a .win property (...should probably be .window) that contains a reference to the first NSWindow it finds | |
n.win.makeKeyAndOrderFront_(None) | |
n.timer_controller = doStuffController.alloc().init() | |
NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(1.0, n.timer_controller, 'doTheThing:', {"nibbler_obj": n}, True) | |
n.attach(test2, 'quitnow') | |
n.hidden = True | |
n.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment