On 8 Nov, 2007, at 20:55, Mike Covill wrote:

I wanted to try using the NSDistributedNotificationCenter to pass
messages between two separate python programs running simultaneously,
so to learn about doing this I created this class:

FILE: listener.py
------------------------------------------------------------------------
-------------------------
import Foundation

class GetNotes(object):

    def __init__(self):
        '''register for an NSNotification'''
nc = Foundation.NSDistributedNotificationCenter.defaultCenter()
        nc.addObserver_selector_name_object_(self, 'getMyNotes:',
'myNote', None)

    def getMyNotes_(self, note):
        print 'got a note!:', note.object
------------------------------------------------------------------------
-------------------------

then I created an instance of this class and tried sending a
notification via the command line, expecting to see a print statement
that the notification was received:

import Foundation as F
import listener
gn = listener.GetNotes()
nc = F.NSDistributedNotificationCenter.defaultCenter()
nc.postNotificationName_object_('myNote', None)

So far, no such luck.  Any suggestions?

The delivery of notifications uses the runloop, it is basically just another source of events.

In a command-line tool you'll have to run the loop yourself, something like:

  loop = F.NSRunLoop.currentRunLoop()
  loop.run()

(That last call will run the eventloop and therefore "block" your script. It will also cause the notification to be delivered).

Ronald


Thanks,
Mike
_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to