2007-12-19
Cocoaセミナー中です。
となりに monospace の中の人がいます。
なぜか二人とも演習をすべて PyObjC でやっています。
セミナー無事終了
セミナーで出てきたものを取り合えず PyObjC にしてみます:^)
興味ある人はお試しくださいませ。
http://developer.apple.com/jp/documentation/Cocoa/Seminar/CocoaGraphics/CocoaGraphics.zip
ライセンス周りがよくわからないですが、ソースコードを PyObjC に移植しただけだから問題ない ... と思う。
つっこまれたら公開やめます。
一応すべてのサンプルを PyObjC にする予定です。
開発環境は IPython と VIM がメインです。 XCode はデバッガとして使っております。
動作確認済み
# vim: sts=4 sw=4 from objc import YES, NO, IBAction, IBOutlet from Foundation import * from AppKit import * class BrowerView(NSView): def initWithFrame_(self, frame): self = super(BrowerView, self).initWithFrame_(frame) if self: """ earthImage = [[NSImage alloc] initWithContentsOfFile: @"/Library/Desktop Pictures/Nature/Earth.jpg"]; """ ns_image = NSImage.alloc() self.earth_image = ns_image.initWithContentsOfFile_('/Library/Desktop Pictures/Nature/Earth.jpg') return self def drawRect_(self, rect): """ NSRect srcRect; srcRect.origin.x = 0; srcRect.origin.y = 0; srcRect.size = [earthImage size]; [earthImage drawInRect:rect fromRect:srcRect operation:NSCompositeCopy fraction:1.0f]; """ src_rect = NSRect() src_rect.origin.x = 0 src_rect.origin.y = 0 src_rect.size = self.earth_image.size(): self.earth_image.drawInRect_fromRect_operation_fraction_( rect, src_rect, NSCompositeCopy, 1.0) )
動作未確認
# vim: sts=4 sw=4 from objc import YES, NO, IBAction, IBOutlet from Foundation import * from AppKit import * from Quartz import * class Controller(NSObject): #image_view = = IBOutlet() image_view = IKImageView.alloc() def awakeFromNib(self): url = '/Library/Desktop Pictures/Nature/Aurora.jpg' image_view.setImageWithURL_(url) image_view.setAutoresizes_(YES)
動作確認済み
# vim: sts=4 sw=4 import os from objc import YES, NO, IBAction, IBOutlet from Foundation import * from AppKit import * class BrowserView(NSView): def initWithFrame_(self, frame): self = super(BrowserView, self).initWithFrame_(frame) if self: # initialization code here self.images = [] dir_path = '/Library/Desktop Pictures' for root, dirs, files in os.walk(dir_path): for f in files: subpath, ext = os.path.splitext(f) if ext == '.jpg': path = os.path.join(root, f) ns_image = NSImage.alloc() image = ns_image.initWithContentsOfFile_(path) self.images.append(image) return self def drawRect_(self, rect): # drawing code here width = 200 height = 200 margin = 20 src_rect = NSRect() dst_rect = NSRect() dst_rect.origin.x = margin dst_rect.origin.y = margin dst_rect.size.width = width dst_rect.size.height = height for image in self.images: src_rect.origin = NSZeroPoint src_rect.size = image.size() image.drawInRect_fromRect_operation_fraction_( dst_rect, src_rect, NSCompositeCopy, 1.0 ) dst_rect.origin.x += width + margin if NSMaxX(dst_rect) > rect.size.width: dst_rect.origin.x = margin dst_rect.origin.y += height + margin
追記
pateo さんがすさまじく素敵な「無駄」(ほめ言葉)をやってくれています。
トラックバック - http://d.hatena.ne.jp/Voluntas/20071219/1198049545
リンク元
- 2 http://www.google.co.jp/search?q=pyobjc+iboutlet&hl=ja&client=safari&rls=en&prmd=ivns&ei=mrRlTd6cBI6KuAPr4LCrBg&start=10&sa=N
- 2 http://www.google.co.jp/search?sourceid=chrome&ie=UTF-8&q=cocoaグラフィックセミナー
- 1 http://blog.monospace.jp/2007/12/
- 1 http://k.hatena.ne.jp/keywordblog/PyObjc?next=3673761993436774015
- 1 http://search.yahoo.co.jp/search?p=IKImageView+IBOutlet&aq=-1&oq=&ei=UTF-8&fr=top_ga1_sa&x=wrt
- 1 http://search.yahoo.co.jp/search?p=NSView+super&ei=UTF-8&fr=top_ga1_sa&x=wrt
- 1 http://translate.google.com/translate_p?hl=en&prev=/search?q=IKImageView+pyobjc&start=10&hl=en&safe=off&client=safari&sa=N&rls=en&biw=1156&bih=757&prmd=ivns&sl=ja&twu=1&u=http://d.hatena.ne.jp/Voluntas/mobile?da
- 1 http://www.google.cn/search?q=monospace+pyobjc&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:zh-CN:official&client=firefox-a
- 1 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja-JP-mac:official&hs=uSk&q=iboutlet+pyobjc&btnG=検索&lr=lang_ja
- 1 http://www.google.co.jp/search?hl=ja&client=safari&rls=en&q=Appkit+event+pyobjc&start=10&sa=N
