[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pygame+threading+windows



> >
> >> In general you must use pygame on the main thread. The same is true
> >> with any cross-platform GUI. You should start other threads for the
> >> other tasks your application is doing.
> >
> > This implies, that all user interfacing is done in the main thread.
> > What is the usual way to deal with this in an object oriented  
> > approach?
> >
> > My plan was to have several classes that inherit from "Thread" and are
> > each responsible for a certain part of the GUI. This way I have the
> > possibility to easily switch one part of my GUI on or off by
> > instantiating resp. deleting an object of the responsible class.
> > Learning that one cannot delete Threads and that all GUI-event- 
> > handling
> > should be done in the main Thread disappointed me little. What is the
> > usual structure, if I want to have a highly configurable framework,
> > with different GUI-Windows, not present in every application?
> 
> Why do you think you need threads? Nothing you've said implies a need  
> or want for threads at all.

I would like to explain my thoughts using a specific example of my
project:

I need to get frames from a camera and display them on the screen. At
the same time, I have to do some other stuff. I wrote a "Camera"-class
which has a "getFrame" method, returning a frame in a numpy-array. Now I
also have a "CamWindow"-Class (that inherits from "Thread") which will
know which camera's frames are to be displayed. It works like this:

myCam = Camera(...various options...)

myCamWindow = CamWindow(myCam)

myCamWindow.start()

Now the myCamWindow-Thread calls the "getFrame"-method of "myCam" and
displays the data, using pygame. The "run"-method of "CamWindow"
contains a "while 1"-loop with a "sleep"-command inside. If "CamWindow"
would not be a "Thread", program excecution would stop when this loop is
entered. That's why I wanted a "Thread".

I would like to be able to use all these objects in Python's interactive
mode, since I don't want to make a GUI for every little thing I would
like to try out.

Thanks for every comment

Lars


-- 
Dipl.-Ing. Lars Friedrich
Optical Measurement Technology
Department of Microsystems Engineering -- IMTEK
University of Freiburg
Georges-KÃhler-Allee 102
D-79110 Freiburg
Germany

phone: +49-761-203-7531
fax:   +49-761-203-7537
room:  01 088
email: lfriedri@xxxxxxxx