472,983 Members | 2,509 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 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 1169

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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.