Ejemplo n.º 1
0
    def mainloop(self):
        try:
            NSThread.mainThread().setThreadPriority_(1.0)
        except AttributeError:
            pass
        except:
            unhandled_exc_handler()

        threading.currentThread().signal_stop = self.exit_mainloop
        self.cocoa_ui_kit.mainloop()
Ejemplo n.º 2
0
def do_in_mainthread(f, wait=True):
	from AppKit import NSThread
	if NSThread.isMainThread():
		return f()

	try:
		NSObject = objc.lookUpClass("NSObject")
		class PyAsyncCallHelper(NSObject):
			def initWithArgs_(self, f):
				self.f = f
				self.ret = None
				self.exc = None
				return self
			def call_(self, o):
				try:
					self.ret = self.f()
				except (KeyboardInterrupt,SystemExit) as exc:
					self.exc = exc
				except:
					print "Exception in PyAsyncCallHelper call"
					sys.excepthook(*sys.exc_info())					
	except:
		PyAsyncCallHelper = objc.lookUpClass("PyAsyncCallHelper") # already defined earlier

	helper = PyAsyncCallHelper.alloc().initWithArgs_(f)
	helper.performSelectorOnMainThread_withObject_waitUntilDone_(helper.call_, None, wait)
	if wait and helper.exc:
		raise helper.exc
	return helper.ret
Ejemplo n.º 3
0
 def __init__(self, target=None, args=None, kwargs=None):
     self.target = target
     self.args = args
     self.kwargs = kwargs
     self.thread = NSThread.alloc().initWithTarget_selector_object_(self, "run:", None)
Ejemplo n.º 4
0
 def __init__(self, target=None, args=None, kwargs=None):
     self.target = target
     self.args = args
     self.kwargs = kwargs
     self.thread = NSThread.alloc().initWithTarget_selector_object_(
         self, "run:", None)