Python Cocoa

2007年10月31日(水) 00:00

Leopardをcore duoなmacbookにインストールして、「軽くなった」「Stacksも軽い」「Spacesも軽い」と浮かれています。


Ruby Cocoaばっかりが脚光を浴びている訳だけど、リリースされてみればPython Cocoaも標準搭載されているんですよっと。

今までもPythonからObjectiveCをたたくのに使っていたPyObjCがデフォで入ったというイメージなのかな?よくわからんけど。


動画になってたようなやつをPythonで書くとこんな感じ。自動でできるなんちゃらDelegate.pyに書いて、MainMenu.xibをインターフェースビルダで開いて、アウトレットとかをつなげばオケ。


from AppKit import NSSpeechSynthesizer, NSLog, NSObject

import objc

class sayAppDelegate(NSObject):
    def applicationDidFinishLaunching_(self, sender):
        NSLog("Application did finish launching.")

    textfield = objc.IBOutlet()

    @objc.IBAction
    def say_(self, sender):
        voice = NSSpeechSynthesizer.defaultVoice()
        speech = NSSpeechSynthesizer.alloc().initWithVoice_(voice)
        speech.startSpeakingString_(self.textfield.stringValue())

動画をとろうと思ったけど、風邪の治りかけでメールをみようと試みた瞬間にこんなことをして反省モードのため自粛。


 
ponybadge

Powered by

Feedbacks

Tweets

Tags

Calendar