473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1190

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sarah Mount | last post by:
Hi everyone. I'm trying to create an exe for a simple pygame app on Win XP. I think I've got the latest (python, py2exe, pygame) and my setup.py file looks like this: | from distutils.core...
3
by: Kenneth McDonald | last post by:
If this is not an appropriate newsgroup for this type of posting, please let me know and (if possible) suggest an alternative. I've done a fair bit of research on the net, but information is...
1
by: Terry | last post by:
Hi, could someone please exmaplin to me what dynamic method dispatching is and how it's connected to virtual methods? Thanks Terry
1
by: Tony Benham | last post by:
I have been getting to grips with css recently (very slowly), and one area I have a problem is when to use class selectors or id selectors. Are there any guidelines when to use each type ? The key...
0
by: Edson Tadeu | last post by:
I was thinking in a way to do static dispatching on enumerations, in a way similar to dispatching on integral constants using Loki's Int2Type<> or Boost.MPL's int_<>, i.e, creating types based on...
3
by: Hallvard B Furuseth | last post by:
I'm wondering how to design this: An API to let a request/response LDAP server be configured so a user-defined Python module can handle and/or modify some or all incoming operations, and later...
6
by: =?ISO-8859-1?Q?Une_B=E9vue?= | last post by:
i'd like to intercept the window.onload event in order to distribute it, as needed, to several methods. example : suppose i have several methods doing unlinked initialisations: ...
0
by: Horace Enea | last post by:
I'm trying to use Python on a Mac running OSX 10.4.9. I installed Python 2.5 along with Idle. My problem is that Xcode no longer works with PyObjC. It gives an error message: ImportError: No module...
1
by: flyfree | last post by:
I got an error during making a python application with xcode 3.0 in OS X Leopard. (KeyError: 'NSUnknownKeyException - : this class is not key value coding-compliant for the key calculatedMean.')...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.