Created
March 19, 2013 12:38
-
-
Save adamw523/5195751 to your computer and use it in GitHub Desktop.
Simple Cocoa app in Python. Using XIB for UI. https://github.com/adamw523/simple_pyobjc_cocoa_xib
This file contains hidden or 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 Cocoa import * | |
from Foundation import NSObject | |
class SimpleXibDemoController(NSWindowController): | |
counterTextField = objc.IBOutlet() | |
def windowDidLoad(self): | |
NSWindowController.windowDidLoad(self) | |
# Start the counter | |
self.count = 0 | |
@objc.IBAction | |
def increment_(self, sender): | |
self.count += 1 | |
self.updateDisplay() | |
@objc.IBAction | |
def decrement_(self, sender): | |
self.count -= 1 | |
self.updateDisplay() | |
def updateDisplay(self): | |
self.counterTextField.setStringValue_(self.count) | |
if __name__ == "__main__": | |
app = NSApplication.sharedApplication() | |
# Initiate the contrller with a XIB | |
viewController = SimpleXibDemoController.alloc().initWithWindowNibName_("SimpleXibDemo") | |
# Show the window | |
viewController.showWindow_(viewController) | |
# Bring app to top | |
NSApp.activateIgnoringOtherApps_(True) | |
from PyObjCTools import AppHelper | |
AppHelper.runEventLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment