Re: runEventLoop() once.

Ben Artin <[email protected]>
Newsgroups gmane.comp.python.pyobjc.devel
Message-ID <[email protected]>
A working example is attached. Props to <http://cocoawithlove.com/2009/01/demystifying-nsapplication-by.html>.


-- 

<http://artins.org/ben>, <http://twitter.com/airbornemint>

"Cause of accident: lack of adhesive ducks" — Dr. Sheldon Cooper

------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly 
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus 
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d

_______________________________________________
Pyobjc-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
NSAppReplacement.py (text/x-python-script, 1.6 KB)
import sys, time, objc
from AppKit import *
from Foundation import *

class MyApplication(NSApplication):
	def init(self):
		self = super(MyApplication, self).init()
		self.shouldRun = True
		return self

	def run(self):
		self.finishLaunching()
		while self.shouldRun:
			print self.mainMenu()
			autoReleasePool = NSAutoreleasePool.alloc().init()
			event = self.nextEventMatchingMask_untilDate_inMode_dequeue_(NSAnyEventMask, NSDate.alloc().initWithTimeIntervalSinceNow_(0.5), NSDefaultRunLoopMode, True)
			self.sendEvent_(event)
			self.updateWindows()
			del autoReleasePool
			
	def terminate_(self, sender):
		self.shouldRun = False
	

def main():
	autoReleasePool = NSAutoreleasePool.alloc().init()
	app = MyApplication.sharedApplication()

	appMenu = NSMenu.alloc().initWithTitle_("App")
	quitItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Test', 'terminate:', '')
	appMenu.addItem_(quitItem)
	
	mainMenuBar = NSMenu.alloc().initWithTitle_("")

	appMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("App", None, "")
	mainMenuBar.addItem_(appMenuItem)
	mainMenuBar.setSubmenu_forItem_(appMenu, appMenuItem)
	
	app.setMainMenu_(mainMenuBar)

	statusbar = NSStatusBar.systemStatusBar()
	
	statusMenu = NSMenu.alloc().initWithTitle_("Test")
	statusMenu.addItem_(NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Test', 'terminate:', ''))
	
	statusitem = statusbar.statusItemWithLength_(NSVariableStatusItemLength)
	statusitem.setMenu_(statusMenu)
	statusitem.setToolTip_('Testing...')
	statusitem.setTitle_('Test')
	
	app.run()


if __name__ == '__main__':
	main()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.