Re: [Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?
On 11/2/07, Darran Edmundson [EMAIL PROTECTED] wrote: Now that we have a proof-of-concept Objective-C framework, I'm trying to port a simple test application to python. Keep in mind that I didn't write either of these. I'm a complete neophyte in terms of Mac development and ObjectiveC; all I have going for me is a lot of python experience on Windows. Issues I'm having: - In a terminal, 'python' still gives me Apple's native 2.3 rather than MacPython 2.4. Do I uninstall Apple's version or simply ensure that the MacPython version comes earlier in the system path? Just make sure python2.5 comes earlier in your path. Never uninstall Apple's version--your computer uses it for system operations. - The pyObjC online docs discuss XCode templates and a distutils approach. Is the latter deprecated, or still a reasonable approach? I would use the distutils (actually, I think it is setuptools now) approach. The XCode templates have been fixed in Leopard (or so I have heard), but I don't think they were very helpful in Tiger. You can easy_install setuptools and py2app. Below is a bare-bones setup.py that you can customize by replacing variables with the word YOUR in them. Sorry about the over-abundance of ALL CAPS. I have this set up so I can re-use it quickly, so there are a bunch of semi-constants I use in all caps, then I added more for your customization. Let me know if it is confusing. ''' Minimal setup.py example, run with: % python setup.py py2app ''' from distutils.core import setup import py2app NAME = 'YOUR_APP_NAME' SCRIPT = 'YOUR_PYTHON_SCRIPT.py' VERSION = 'YOUR_VERSION' ICON = '' ID = 'A_UNIQUE_STRING COPYRIGHT = 'Copyright 2007 YOUR_NAME' DATA_FILES = ['English.lproj'] # This is needed if you use nib files to define your UI plist = dict( CFBundleIconFile= ICON, CFBundleName= NAME, CFBundleShortVersionString = ' '.join([NAME, VERSION]), CFBundleGetInfoString = NAME, CFBundleExecutable = NAME, CFBundleIdentifier = 'org.YOUR_DOMAIN.examples.%s' % ID, NSHumanReadableCopyright= COPYRIGHT ) app_data = dict(script=SCRIPT, plist=plist) py2app_opt = dict(frameworks=['YOUR_FRAMEWORK_HERE.framework'],) options = dict(py2app=py2app_opt,) setup( data_files = DATA_FILES, app = [app_data], options = options, ) ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?
On 11/2/07, Darran Edmundson [EMAIL PROTECTED] wrote: The bare minimum you need is: import objc objc.loadBundle('MyBundle', globals(), bundle_path='/my/bundle/path/MyBundle.framework') One more thing. While the above is a bare minimum from the command line or to work with the framework locally, you'll need a skintch more to get the file paths to work when the framework is packaged into your application bundle. Below is an example I use to package Tim Omernick's CocoaSequenceGrabber framework, and it works both from the command line and in the app bundle. I have this saved as PySight/__init__.py and can then use all the framework objects and methods by simply importing PySight in my project. Again, if any of this is not clear, or you're not sure how to customize this to your project, just let me know. import objc, AppKit, Foundation, os if 'site-packages.zip' in __file__: base_path = os.path.join(os.path.dirname(os.getcwd()), 'Frameworks') else: base_path = '/Library/Frameworks' bundle_path = os.path.abspath(os.path.join(base_path, 'CocoaSequenceGrabber.fram ework')) objc.loadBundle('CocoaSequenceGrabber', globals(), bundle_path=bundle_path) del objc, AppKit, Foundation, os, base_path, bundle_path --Dethe ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?
Dethe Elza wrote: If you write an Objective-C framework, the python code to wrap it using PyObjC is very short. Here is an example I use to expose Tim Omernick's CocoaSequenceGrabber framework to capture images from the iSight camera ... The bare minimum you need is: import objc objc.loadBundle('MyBundle', globals(), bundle_path='/my/bundle/path/MyBundle.framework') Now that we have a proof-of-concept Objective-C framework, I'm trying to port a simple test application to python. Keep in mind that I didn't write either of these. I'm a complete neophyte in terms of Mac development and ObjectiveC; all I have going for me is a lot of python experience on Windows. Issues I'm having: - In a terminal, 'python' still gives me Apple's native 2.3 rather than MacPython 2.4. Do I uninstall Apple's version or simply ensure that the MacPython version comes earlier in the system path? - The pyObjC online docs discuss XCode templates and a distutils approach. Is the latter deprecated, or still a reasonable approach? - Following Dethe's advice, I can successfully obj.loadBundle('EDMDisplayController', ...) from within IDLE. I'm not at all clear on how to proceed from here ;-) It seems there's some infrastructure required even for the simplest of applications, correct? I.e., I can't just expect to create a single python script callable from the command line ... As much as I like independent learning, I could really do with someone to walk me through this one-on-one. Anyone interested in a few hours of consulting? If so, just email me a rate and availability over the next week. I can give you SVN access to our code, and we can chat on the phone or Skype. Cheers, Darran. -- Darran Edmundson [EMAIL PROTECTED] http://www.edmstudio.com ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?
If you write an Objective-C framework, the python code to wrap it using PyObjC is very short. Here is an example I use to expose Tim Omernick's CocoaSequenceGrabber framework to capture images from the iSight camera: example import objc, AppKit, Foundation, os if 'site-packages.zip' in __file__: base_path = os.path.join(os.path.dirname(os.getcwd()), 'Frameworks') else: base_path = '/Library/Frameworks' bundle_path = os.path.abspath(os.path.join(base_path, 'CocoaSequenceGrabber.fram ework')) objc.loadBundle('CocoaSequenceGrabber', globals(), bundle_path=bundle_path) del objc, AppKit, Foundation, os, base_path, bundle_path /example I have that saved as PySight/__init__.py so I can import * from PySight to get all the objects and methods from the framework. It would be shorter, but I have some path manipulation so that it works from the command line and from within an application bundle built with py2app. The bare minimum you need is: import objc objc.loadBundle('MyBundle', globals(), bundle_path='/my/bundle/path/MyBundle.framework') Writing a bundle in Python that can be imported by an Objective-C application is similarly easy. I have some blog posts on that topic if you ever decide to try that direction. The application just needs to take Objective-C bundles as plugins, it does not have to plan for, or even know about, Python in the bundle implementation. HTH --Dethe ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?
On 27-Oct-2007, at 02:55 , Darran Edmundson wrote: I've recommended that Douglas join this mailing list and ask questions. My only concern is that most people coming to this list are probably python users (like myself) who want to write Mac apps. Douglas is coming from the opposite tack - he's a hardcore Cocoa developer who doesn't know python at all. With this in mind, do you have any pointers in designing a library that is easily called from python? There are some things you can do in ObjC that are difficult to expose to Python, but as they're so unusual I've never come across them I've also conveniently forgotten what they are:-) Oh yes, I think if you pass a C structure you have to do some massaging (excpe tif PyObjC already knows about that structure, such as for NSPoint and such, then the work has already been done for you). I wondered, for example, if he wrote the Objective C library and a separate Objective C test application to exercise the code, if the test app could then simply be ported to pyObjC? This way Douglas wouldn't need to worry about python at all ... If you do this very early during development, i.e. when the library API has only a couple of calls you have the ObjC programmer write a minimal test script which you then port to Python, you could give this back to the ObjC developer. There's a very good chance this'll teach them enough Python to continue the testing directly in Python. -- Jack Jansen, [EMAIL PROTECTED], http://www.cwi.nl/~jack If I can't dance I don't want to be part of your revolution -- Emma Goldman ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
[Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?
I have a couple of Cocoa/Quicktime developers working on a small custom application. These guys are very capable at OS X programming but don't have any python experience. I, on the other hand, have a lot of python experience but virtually no Mac development experience. I could really do with some advice from someone able to see the big picture. A bit of background ... We are working on a museum exhibit where a large 65 1920x1080 screen attached to a Mac Pro is electronically positioned on a 4m industrial slide-track via a physical interface device. Each millimeter of track corresponds to a different image in a 4000 frame photo-jpeg-encoded Quicktime. The user tweaks the interface device, the screen moves, the image changes appropriately - that's the basic plan. I have a python program on the Mac that determines, among other things, the screen location. The OS X developers are going to write a full-screen Cocoa application that handles the display side of things (along with some tricks like: change to a new movie; tweak the opacity; add a second layer movie; etc.) The question then: how to join these two codes? Options (that I can think of, probably more worthy of discussion): 1) Get the Mac guys to write their application as a library that can be wrapped in pyObjC and invoked by my python program. In this scenario, the result is only one process/program with no network issues. 2) Add networking code to both the python and cocoa apps in order to communicate (binary socket, XML over http, Bonjour, etc.). Easy in python via Twisted, no doubt less so in cocoa. As always, any advice is much appreciated. Cheers, Darran. -- Darran Edmundson [EMAIL PROTECTED] http://www.edmstudio.com ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?
If I understand the architecture correctly I would go with option 1. And get the Mac guys to write their code in a reusable way, i.e. have them export enough low-level functionality in their API. This should be easy enough in ObjC. It'll allow tweaking from the Python side, and if you're lucky during the project they'll see the advantage of Python and all jump on the bandwagon:-) BTW: there's a potential third architecture that I can see: write a Cocoa app with a Python module embedded. This is similar to option 1, but depending on which technologies you use it may be easier to structure things with ObjC in charge in stead of Python. But if you also structure your Python code well it shouldn't be much of a problem to switch from design 1 to design 3 later in the development process. On 26-okt-2007, at 9:01, Darran Edmundson wrote: I have a couple of Cocoa/Quicktime developers working on a small custom application. These guys are very capable at OS X programming but don't have any python experience. I, on the other hand, have a lot of python experience but virtually no Mac development experience. I could really do with some advice from someone able to see the big picture. A bit of background ... We are working on a museum exhibit where a large 65 1920x1080 screen attached to a Mac Pro is electronically positioned on a 4m industrial slide-track via a physical interface device. Each millimeter of track corresponds to a different image in a 4000 frame photo-jpeg-encoded Quicktime. The user tweaks the interface device, the screen moves, the image changes appropriately - that's the basic plan. I have a python program on the Mac that determines, among other things, the screen location. The OS X developers are going to write a full-screen Cocoa application that handles the display side of things (along with some tricks like: change to a new movie; tweak the opacity; add a second layer movie; etc.) The question then: how to join these two codes? Options (that I can think of, probably more worthy of discussion): 1) Get the Mac guys to write their application as a library that can be wrapped in pyObjC and invoked by my python program. In this scenario, the result is only one process/program with no network issues. 2) Add networking code to both the python and cocoa apps in order to communicate (binary socket, XML over http, Bonjour, etc.). Easy in python via Twisted, no doubt less so in cocoa. As always, any advice is much appreciated. Cheers, Darran. -- Darran Edmundson [EMAIL PROTECTED] http://www.edmstudio.com ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig -- Jack Jansen, [EMAIL PROTECTED], http://www.cwi.nl/~jack If I can't dance I don't want to be part of your revolution -- Emma Goldman ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?
Darran Edmundson wrote: I have a python program on the Mac that determines, among other things, the screen location. The OS X developers are going to write a full-screen Cocoa application [...] The question then: how to join these two codes? 1) Get the Mac guys to write their application as a library that can be wrapped in pyObjC and invoked by my python program. In this scenario, the result is only one process/program with no network issues. 2) Add networking code to both the python and cocoa apps in order to communicate (binary socket, XML over http, Bonjour, etc.). Easy in python via Twisted, no doubt less so in cocoa. Jack's already given advice on #1 and suggested embedding Python as a third option. As for the IPC option, you're pretty well covered there too. The two high-level approaches I'd recommend investigating are: 1. Apple events using appscript/aem on the client side and OS X's Cocoa Scripting framework on the server side (although there are other options available as well). 2. Cocoa's Distributed Objects system, using PyObjC on the client side. HTH has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Python control/integration of a Cocoa/Quicktime application?
Jack and Has, thanks very much for the valuable advice. This weekend one of the developers is going to have a first crack at implementing option 1, namely a library that we can invoke from python. I've recommended that Douglas join this mailing list and ask questions. My only concern is that most people coming to this list are probably python users (like myself) who want to write Mac apps. Douglas is coming from the opposite tack - he's a hardcore Cocoa developer who doesn't know python at all. With this in mind, do you have any pointers in designing a library that is easily called from python? I wondered, for example, if he wrote the Objective C library and a separate Objective C test application to exercise the code, if the test app could then simply be ported to pyObjC? This way Douglas wouldn't need to worry about python at all ... As always, any advice is much appreciated. Cheers, Darran. -- Darran Edmundson [EMAIL PROTECTED] http://www.edmstudio.com ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig