diff options
author | Avery Pennarun <apenwarr@gmail.com> | 2011-01-22 16:49:19 -0800 |
---|---|---|
committer | Avery Pennarun <apenwarr@gmail.com> | 2011-01-22 16:49:21 -0800 |
commit | 668441adb68d015e6ad452651756b3bee7d44383 (patch) | |
tree | 3a582615d9aa056892d1fa2ad516e1bceccdfbf2 /ui-macos/my.py | |
parent | 415be935d4e2ba5cfbcf245a3e5d6ffcaeddbfd6 (diff) | |
parent | d4ccd30c24b717113f1e94c440c0b60cff14f63d (diff) |
Merge branch 'macapp'sshuttle-0.45
A cute little GUI for sshuttle on MacOS, written using pyobjc.
* macapp:
ui-macos: call the main binary MacOS/Sshuttle.
ui-macos/git-export.do: write the generated app to a branch.
ui-macos/default.app.do: get rid of some duplicated files.
ui-macos: Actually prompt for passwords instead of assuming a default.
ui-macos: Don't enable connecting for hosts with Custom but zero subnets.
ui-macos: Smoother log messages in the log window.
ui-macos: Notice when we've connected; make debug logs optional.
ui-macos: Much better connection status reporting.
ui-macos/run.do: a shortcut for running debug.app.
ui-macos/*: "a series of unfortunate events."
Diffstat (limited to 'ui-macos/my.py')
-rw-r--r-- | ui-macos/my.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/ui-macos/my.py b/ui-macos/my.py new file mode 100644 index 0000000..cd701eb --- /dev/null +++ b/ui-macos/my.py @@ -0,0 +1,62 @@ +import sys, os +from AppKit import * +import PyObjCTools.AppHelper + + +def bundle_path(name, typ): + if typ: + return NSBundle.mainBundle().pathForResource_ofType_(name, typ) + else: + return os.path.join(NSBundle.mainBundle().resourcePath(), name) + + +# Load an NSData using a python string +def Data(s): + return NSData.alloc().initWithBytes_length_(s, len(s)) + + +# Load a property list from a file in the application bundle. +def PList(name): + path = bundle_path(name, 'plist') + return NSDictionary.dictionaryWithContentsOfFile_(path) + + +# Load an NSImage from a file in the application bundle. +def Image(name, ext): + bytes = open(bundle_path(name, ext)).read() + img = NSImage.alloc().initWithData_(Data(bytes)) + return img + + +# Return the NSUserDefaults shared object. +def Defaults(): + return NSUserDefaults.standardUserDefaults() + + +# Usage: +# f = DelayedCallback(func, args...) +# later: +# f() +# +# When you call f(), it will schedule a call to func() next time the +# ObjC event loop iterates. Multiple calls to f() in a single iteration +# will only result in one call to func(). +# +def DelayedCallback(func, *args, **kwargs): + flag = [0] + def _go(): + if flag[0]: + print 'running %r (flag=%r)' % (func, flag) + flag[0] = 0 + func(*args, **kwargs) + def call(): + flag[0] += 1 + PyObjCTools.AppHelper.callAfter(_go) + return call + + +def atoi(s): + try: + return int(s) + except ValueError: + return 0 |