-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.py
77 lines (67 loc) · 2.63 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright (C) 2009-2021 AG Projects. See LICENSE for details.
#
debug_memory = False # turn it on to enable tracing some of the memory leaks
# this import has to come first
if debug_memory:
import memory_debug
del memory_debug
import os
import sys
import signal
import mimetypes
import traceback
import Foundation
from PyObjCTools import AppHelper
from Foundation import NSBundle
assert Foundation.NSThread.isMultiThreaded()
# Don't load Python modules from system paths
remove_paths = list(path for path in sys.path if 'site-packages' in path or path.startswith('/Library/Frameworks/'))
for path in remove_paths:
sys.path.remove(path)
# Make mimetypes use our copy of the file in order to work with sandboxing
resource_path = str(Foundation.NSBundle.mainBundle().resourcePath())
mime_path = os.path.join(resource_path, "mime.types")
mimetypes.init(files=[mime_path])
class NSLogger(object):
closed = False
encoding = 'UTF-8'
mode = 'w'
name = '<NSLogger>'
newlines = None
softspace = 0
def close(self): pass
def flush(self): pass
def fileno(self): return -1
def isatty(self): return False
def __next__(self): raise IOError("cannot read from NSLogger")
def read(self): raise IOError("cannot read from NSLogger")
def readline(self): raise IOError("cannot read from NSLogger")
def readlines(self): raise IOError("cannot read from NSLogger")
def readinto(self, buf): raise IOError("cannot read from NSLogger")
def seek(self, offset, whence=0): raise IOError("cannot seek in NSLogger")
def tell(self): raise IOError("NSLogger does not have position")
def truncate(self, size=0): raise IOError("cannot truncate NSLogger")
def write(self, text):
pool = Foundation.NSAutoreleasePool.alloc().init()
if isinstance(text, str):
text = text.rstrip()
elif not isinstance(text, buffer):
raise TypeError("write() argument must be a string or read-only buffer")
Foundation.NSLog("%@", text)
del pool
def writelines(self, lines):
pool = Foundation.NSAutoreleasePool.alloc().init()
for line in lines:
if isinstance(line, str):
line = line.rstrip()
elif not isinstance(line, buffer):
raise TypeError("writelines() argument must be a sequence of strings")
Foundation.NSLog("%@", line)
del pool
sys.stdout = NSLogger()
sys.stderr = NSLogger()
# import modules containing classes required to start application and load MainMenu.nib
import BlinkAppDelegate
import ContactWindowController
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
AppHelper.runEventLoop()