Pythonのプログラムを配布可能なアプリケーションを作成する方法について扱います。
コンピュータが理解できるのは突き詰めると、0と1だけです。そのため、プログラムを実行するには「プログラミング言語で書かれたテキストのプログラム」を0と1に変換する必要があります。そのやり方には2つあり、ひとつはコンパイラを使うもので、もうひとつはインタプリタを使うものです。
以下に両者の違いについて記載します。
| m = 'stdout: think different' | |
| t = '\n' | |
| u = $.NSUTF8StringEncoding | |
| d = $(m+t).dataUsingEncoding(u) | |
| $.NSFileHandle.fileHandleWithStandardOutput.writeData(d) |
| app = Application.currentApplication() | |
| app.includeStandardAdditions = true | |
| path = app.pathTo("desktop",{from:"user domain"})+"/read_write.txt" | |
| // write | |
| contents = new Date() + " 本日は晴天なり" | |
| try { | |
| f = app.openForAccess(path, {writePermission:true}) | |
| app.setEof(f, {to:0}) |
| ObjC.import('Cocoa') | |
| function Url(str) { | |
| return $.NSURL.URLWithString(str) | |
| } | |
| function Req(url) { | |
| return $.NSURLRequest.requestWithURL(url) | |
| } |
| eval($.NSString.stringWithContentsOfFileEncodingError($('~/Library/Script Libraries/AppletKit.js').stringByStandardizingPath.js,$.NSUTF8StringEncoding,$()).js) | |
| ObjC.import('Cocoa') | |
| controls = {} | |
| UtilityWindow('AppWindow', { | |
| setup() { | |
| this.setFrameDisplayAnimate($.NSMakeRect(0, 0, 200, 200), false, false) | |
| this.center |
| # -*- coding: utf-8 -*- | |
| import os | |
| from urlparse import urlparse | |
| from urllib import unquote | |
| from ScriptingBridge import SBApplication | |
| def finder_frontmost_visible_window_path(): | |
| finder = SBApplication.applicationWithBundleIdentifier_('com.apple.Finder') | |
| windows = filter(lambda x:x.visible()==True, finder.windows()) | |
| if windows: |
| #!/usr/bin/python2.6 | |
| # -*- coding: utf-8 -*- | |
| import objc | |
| from Foundation import * | |
| from AppKit import * | |
| from PyObjCTools import AppHelper | |
| NSWindowDelegate = objc.protocolNamed("NSWindowDelegate") |
| ObjC.import('Cocoa') | |
| ObjC.import('WebKit') | |
| var webViewRect = $.NSMakeRect(0, 0, 1024, 560) | |
| var webViewConf = $.WKWebViewConfiguration.alloc.init | |
| webViewConf.preferences.plugInsEnabled = true | |
| var webView = $.WKWebView.alloc.initWithFrameConfiguration(webViewRect, webViewConf) | |
| var url = $.NSURL.URLWithString('http://www.youtube.com/') | |
| var req = $.NSURLRequest.requestWithURL(url) |
| ObjC.import('Cocoa') | |
| ObjC.import('WebKit') | |
| App = Application.currentApplication() | |
| App.includeStandardAdditions = true | |
| MyAction = SimpleSubclass('Action', { | |
| quit(sender) { | |
| App.quit() | |
| }, |