Re: [Pyobjc-dev] Problem with NSText:setString
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2011-06-14 05:05:51
|
On 13 Jun, 2011, at 14:07, Daniel Luis dos Santos wrote: > Hello, > > I have a GUI application built with interface builder. One of the windows has a NSTextView in it. I connected it to an object also referenced in the interface builder file. > The goal is to write to the NSTextView from a background trhead that does some task. I launch the thread with a call to > > NSThread.alloc().initWithTarget_selector_object_() > > The behaviour I am getting is erratic. Most times it blocks on the call to the NSTextView's setString_() method and the application hangs. If I run the code on the main thread it runs fine. > > How do I do this from a background thread ? The idea is to keep the application responsive. You cannot call methods of GUI classes from a thread that is not the main thread (that is, AppKit is not thread-safe). You need to look into methods like, "-performSelectorOnMainThread:withObject:waitUntilDone:". The basic pattern is that you launch your long running task in a secondary thread and use performSelectorOnMainThread... to call a method that updates the GUI. This should keep the application responsive as the GUI updating code should be simple and not take a lot of time. Ronald > > I am on : > snow leopard (10.6.7) > pyObjc (I think it is 2.2b3 (can you tell me how to really check the version ?)) > > Many thanks > ------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |