gusmueller
Thursday, December 30th, 2004

PyObjC 1.2 was released last night. And here's the first VoodooPad plugin written in it. Talk about super easy to do...

import objc
objc.registerPlugin('PPlugin')
VPPlugin = objc.lookUpClass('VPPlugin')
  
class PPlugin (VPPlugin):
  __bundle_hack__ = True
  
  def pluginCall_(self, pluginWindowController):
    textStorage = pluginWindowController.textView().textStorage()
    textStorage.mutableString().insertString_atIndex_(u"Hello World!", 0)

  def didRegister(self):
    pluginManager = self.pluginManager()

    #imagine this was on one line:
    pluginManager.addPluginsMenuTitle_withSuperMenuTitle
    _target_action_keyEquivalent_keyEquivalentModifierMask_(
      u"Say Hello World",
      u"Python",
      self,
      "pluginCall:",
      "",
      0
    )


download the source, type "python setup.py py2app" in the terminal to build. Double click the plugin to install.

(Updated to use unicode strings- hint via Bob Ippolito)

comments (2)   # posted 10:21 am (uct-6)