PyObjC tutorial without Xcode

I am writing a small cross-platform wxPython application, however on each platform I need to use some platform-specific API. On Mac OS, this can be done using PyObjC.

I am looking for a tutorial on how to use PyObjC. However, all I have found so far are tutorials with Xcode. I want my application to be able to run on mac / win / lin without change, and I don't want to develop it in Xcode. Is there any way?

UPD. To be more specific, I need to access some tablet events from Mac OS X, and I wanted to use PyObjC for this (I don't see other ways).

+7
source share
3 answers

You can import Foundation and AppKit modules, and then subclass NSApplication. But perhaps this is not what you are looking for if your pyobjc code is not an entry point for your code. Could you give more details about what you are trying to do with pyobjc?

Here is a quick example of using pyobjc to create a simple status window, without using xcode:

import objc from Foundation import * from AppKit import * from PyObjCTools import AppHelper class MyApp(NSApplication): def finishLaunching(self): # Make statusbar item statusbar = NSStatusBar.systemStatusBar() self.statusitem = statusbar.statusItemWithLength_(NSVariableStatusItemLength) self.icon = NSImage.alloc().initByReferencingFile_('icon.png') self.icon.setScalesWhenResized_(True) self.icon.setSize_((20, 20)) self.statusitem.setImage_(self.icon) #make the menu self.menubarMenu = NSMenu.alloc().init() self.menuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Click Me', 'clicked:', '') self.menubarMenu.addItem_(self.menuItem) self.quit = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '') self.menubarMenu.addItem_(self.quit) #add menu to statusitem self.statusitem.setMenu_(self.menubarMenu) self.statusitem.setToolTip_('My App') def clicked_(self, notification): NSLog('clicked!') if __name__ == "__main__": app = MyApp.sharedApplication() AppHelper.runEventLoop() 

Then you can use py2app to make it redistributable:

 from distutils.core import setup import py2app NAME = 'myapp' SCRIPT = 'myapp.py' VERSION = '0.1' ID = 'myapp' plist = dict( CFBundleName = NAME, CFBundleShortVersionString = ' '.join([NAME, VERSION]), CFBundleGetInfoString = NAME, CFBundleExecutable = NAME, CFBundleIdentifier = 'com.yourdn.%s' % ID, LSUIElement = '1', #makes it not appear in cmd-tab task list etc. ) app_data = dict(script=SCRIPT, plist=plist) setup( app = [app_data], options = { 'py2app':{ 'resources':[ ], 'excludes':[ ] } } ) 
+11
source

What is Xcode for? If you need this for windows / gui files (* .nib, * .xib), you should probably look for "create * .nib, * xib without Xcode". This is just a hint to search and the lack of a satisfactory answer.

0
source
-one
source

All Articles