pythoncard: what's wrong in my code?

Kevin Altis altis at semi-retired.com
Sun Jan 12 12:58:15 EST 2003


Hi, first of all questions like this should be directed to the
pythoncard-users mailing list since you are much more likely to get a timely
response there.

http://lists.sourceforge.net/lists/listinfo/pythoncard-users

It is generally not legal to have a thread other than the main one for the
GUI access the GUI windows and controls of your app. There are several
methods for getting around this that have been covered on the wxPython-users
mailing list and pythoncard-users fairly recently. See the archives at:

http://aspn.activestate.com/ASPN/Mail/?topic=Python

You might also look at long running tasks in the wxPython wiki

http://wiki.wxpython.org/index.cgi/FrontPage

One solution is to post custom wxPython event messages from your other
thread and then handle that in your main event loop. My preferred way is to
use the Queue module, you share a Queue instance between your threads, push
the message onto the Queue, call wxWakeUpIdle() and then handle the message
in an idle handler in the GUI, something like this.

    def on_idle(self, event):
        if not self.msgQueue.empty():
            msg = self.msgQueue.get()
            self.doDisplayMsgReceived(msg)
            event.RequestMore()

When you want to update the display of a control before an event finishes,
call Update() after setting the value.

ka

"Riccardo Galli" <riccardo at Togli_Quest0sideralis.net> wrote in message
news:pan.2003.01.12.16.45.28.368632 at Togli_Quest0sideralis.net...
> This little program start a thread, which every 1 second modify a text
> widget.
> The problem is that, often, when I run it the text is written ON the old
> text, without changing the old text value. It's like to write always on
the
> same paper: in a short time the paper is completely black
>
> The real program is bigger, of course, but this is the minimum code which
> can produce the error
>
> if someone can help me....
> Thanks,
> Riccardo
>
> class Retriever(Thread):
> def __init__(self,components):
> Thread.__init__(self)
> self.components=components #this is a dirty trick I use to see
self.components of the main apllication
>
> def run(self):
> seconds=0
> while 1:
> self.components.counterStText.text=str(seconds)
> seconds+=1
> time.sleep(1)
>
> class myclass(model.Background):
> def on_openBackground(self, event):
> aThread=Retriever(self.components)
> aThread.start()
>
> if __name__ == '__main__':
>     app=model.PythonCardApp(myclass)
>     app.MainLoop()
>
>
>
> --
> -=Riccardo Galli=-
>
>  _,e.
> s~  ``
>  ~@.   ideralis Programs
> .   ol
>  `**~  http://www.sideralis.net
>






More information about the Python-list mailing list