[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] pyui and other things



Riccardo Trocca wrote:
> I dled the last version from its website and found a few problems.
> No demo can work, because they are all looking for the pygame.locals 
> namespace. Of course renaming every pygame.locals.* to pygame.* works.

aren't the modules importing "pygame.locals"? i guess not. maybe the old 
pygame versions automatically imported the "locals" module, but i didn't 
think so and it doesn't work that way in 1.4. i'll have to check on that.


> I'm writing an application that extracts frames from an AVI file, then 
> puts them in a surface and blits them. One of the first version I made 
> (now lost, but I'll rewrite it) put the frames in a numeric array 
> (copying the data from a DIB) and then blitted them to a surface. The 
> only "small" problem is that the origin of the DIB environment is bottom 
> left, so images were blitted upside down, and that the RGB ordering is 
> reversed (BGR).

you can create Surfaces with any color ordering you need. you can call 
Surface and pass it the color masks to use for the image. for example:
	Surface(size, 0, (0xff0000, 0xff00, 0xff, 0)) #rgb
	Surface(size, 0, (0xff, 0xff00, 0xff0000, 0)) #bgr

the surfarray module also comes with a "blit_array" module which blits 
any formatted Numeric array to any formatted Surface. this will handle 
the RGB/BGR conversions for you, and might be faster overall?


flipping Numeric arrays is easy as well. you create a slice with a 
reverse increment. there's a small intro to surfarray that covers 
flipping and other little special effects, 
http://www.pygame.org/docs/tut/SurfarrayIntro.html. from the intro, 
here's how we flip an array:
	flipped_array = my_array[:, -1:0:-1]



> Some alternative UI for PyGame? 

nothing really standard now. there's several people working on something 
behind the scenes. but all their projects are still pretty early on.



> in pygame, which way do you think is better in order to implement the 
 > event handling code for a movie player?

the easiest way would be to just make a normal game like loop. single 
thread in a single loop. it checks for all events, then checks to see 
what the current frame should be. the avi likely has a constant 
framerate. record the time when the user hit play and the frame you 
started on. then:
     handle_all_events()
     now = pygame.time.get_ticks()
     current_frame = (now-time_start)/(avi_fps*1000.0)+frame_start
     if current_frame != drawn_frame and not paused_or_stopped:
         drawn_frame = current_frame
         avi_render_frame(drawn_frame)
     else:
         pygame.time.wait(10)

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org