thread

Hi wxPython user

               I have tried to capture image from usb webcam (using VideoCapture) and display it on BufferedCanvas. Image also send to server using python xmlrpc.
               The ploblem are how to manage drawing and transfering image, now I use wx timer and
performance is very bad! I think I may use thread for these job but don't khow how to do
               every comment and sugguestion is welcomed.

thank
chatchai

···

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement

Chatchai Nanudorn wrote:

Hi wxPython user

              I have tried to capture image from usb webcam (using VideoCapture) and display it on BufferedCanvas. Image also send to server using python xmlrpc.
              The ploblem are how to manage drawing and transfering image, now I use wx timer and
performance is very bad! I think I may use thread for these job but don't khow how to do
              every comment and sugguestion is welcomed.

Have you looked at the thread sample in the demo yet? Also there are some pages in the wiki dealing with threads and long running tasks. The key thing to remember is that you can't call any functions that manipulate the GUI from the context of a worker thread, but you can use wx.CallAfter to schedule a call to a function to happen in the GUI thread.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

import wx
import wx.lib.newevent

import threading

NewImage, EVT_NEW_IMAGE = wx.lib.newevent.NewEvent()

def _thread(rootw):
    while rootw:
        #get the image
        try:
            wx.PostEvent(rootw, NewImage(data=imagedata))
        except:
            #will break out of the loop after the upload is done
            pass
        #upload the image

def startthread(rootw):
    x = threading.Thread(target=_thread, args=(rootw,))
    #x.setDaemon(1)
    #uncomment the above if you want the thread to die
    #immediately after the GUI quits
    x.start()

class myFrame(wx.Frame):
    def __init__(self, ...):
        wx.Frame.__init__(self, ...)
        ...
        self.Bind(EVT_NEW_IMAGE, self.OnNewImage)
        ...
        startthread(self)
    def OnNewImage(self, evt):
        imagedata = evt.data
        #update the image/cause a refresh/etc.

- Josiah

···

"Chatchai Nanudorn" <elecstud@hotmail.com> wrote:

Hi wxPython user

               I have tried to capture image from usb webcam (using
VideoCapture) and display it on BufferedCanvas. Image also send to server
using python xmlrpc.
               The ploblem are how to manage drawing and transfering image,
now I use wx timer and
performance is very bad! I think I may use thread for these job but don't
khow how to do
               every comment and sugguestion is welcomed.