471,348 Members | 1,428 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Dispatching a method using PyobjC Selectors/Methods

Hi,
I am writing a SIMBL plugin for Mail.app, so far it loads and the
correct method has been swizzled. However, i would like to call the
original method and that is where the problem lies.

If you could see the code(below), in console.app, i get the following
error because of old(x)
"
2007-06-26 03:42:04.053 Mail[2600] *** NSRunLoop ignoring exception
'exceptions.TypeError: 'int' object is not callable' that raised
during posting of delayed perform with target 5bd1b10 and selector
'_finalSetup'
"

#saved as MailDump.py
import objc
from Foundation import *
from AppKit import *
WebMessageEditor = objc.lookUpClass('WebMessageEditor')
old=1
swizzled = {}
#http://end.com/svn/BionicDOM/tags/1.0/
BionicDOMPalette.py
def swizzle(cls, SEL, func):
NSLog(cls)
oldIMP = cls.instanceMethodForSelector_(SEL)
oldMethod = objc.selector(oldIMP.__call__,
selector=oldIMP.selector, signature=oldIMP.signature)
newMethod = objc.selector(func, selector=oldIMP.selector,
signature=oldIMP.signature)
objc.classAddMethod(cls, 'OLD'+SEL, oldMethod)
objc.classAddMethod(cls, SEL, newMethod)
swizzled[(cls, SEL, func)] = (oldMethod, newMethod, oldIMP)
return(oldMethod)
def updateContentsToShowSignature_(self,x):
NSLog("OHMYGOD")
old(x)
class MWM(NSObject):
plugin = None # We will retain a pointer to the plugin to prevent
it being garbage-collected
@classmethod
def sharedInstance(cls): # not strictly necessary, but we only
need one instance of our object
if not cls.plugin:
cls.plugin = cls.alloc().init()
return cls.plugin

@classmethod
def initialize(cls):
old=swizzle(WebMessageEditor,
'updateContentsToShowSignature:', updateContentsToShowSignature_)
#setup.py
# from distutils.core import setup
# import py2app
# plist = dict(
# NSPrincipalClass='MWM',
# CFBundleName='MWM',
# SIMBLTargetApplications=[dict(BundleIdentifier='com.apple.mail',
MinBundleVersion='000', MaxBundleVersion='999920')],
# )

# setup(
# plugin=['MailDump.py'],
# options=dict(py2app=dict(
# extension='.bundle',
# plist=plist,
# )),
# )
#Run the following
#python2.4 setup.py py2app -A
#and copy the dist/MailDump.bundle to ~/Library/Application Support/
SIMBL/Plugins/

Jun 26 '07 #1
0 1107

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Sarah Mount | last post: by
3 posts views Thread by Kenneth McDonald | last post: by
1 post views Thread by Terry | last post: by
1 post views Thread by Tony Benham | last post: by
reply views Thread by Edson Tadeu | last post: by
3 posts views Thread by Hallvard B Furuseth | last post: by
6 posts views Thread by =?ISO-8859-1?Q?Une_B=E9vue?= | last post: by
reply views Thread by Horace Enea | last post: by
1 post views Thread by flyfree | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.