[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] pygame ingration with wxpython
Hi,
I am trying to get pygame window in wxPython - wxFrame window. My
requirement is to set wxframe as pygame window and nextstep is i should be
able to use scrolling of wxframe to show/scroll the surface of pygame, which
is larger than wxframe size
I followed some information/examples available in internet fro wxpython and
pygame ingeration. Following is one such link.
http://wiki.wxpython.org/IntegratingPyGame
<http://wiki.wxpython.org/IntegratingPyGame>
<http://wiki.wxpython.org/IntegratingPyGame
<http://wiki.wxpython.org/IntegratingPyGame> >
But this sample didn't work as the environment variable SDL_WINDOWID is not
effective when we start pygame even in a child thread.
soI tried creating pygame stuff as a seperate process so that the envronment
variable become effective and it worked.
following are the two scripts i have written . I am using pygame 1.8 version
and wxpython 2.8.7 version
------------------------------sample1.py-------------------
import wx
import os
import subprocess
class MyFrame(wx.Frame):
def __init__(self, parent, ID, strTitle, tplSize):
wx.Frame.__init__(self, parent, ID, strTitle,
size=tplSize,style=wx.DEFAULT_FRAME_STYLE|wx.VSCROLL|wx.HSCROLL)
os.environ['SDL_VIDEODRIVER'] = 'windib'
os.environ['SDL_WINDOWID'] = str(self.GetHandle())
app = wx.PySimpleApp()
frame = MyFrame(None, wx.ID_ANY, "SDL Frame", (1000,800))
subprocess.Popen(['c:\python25\python','sample2.py'])
frame.Show()
app.MainLoop()
--------------------------------------------------------------
-------------------------------sampl2.py--------------------
import sys
import pygame # this has to happen after setting the environment variables.
pygame.display.init()
s = pygame.Surface((4892,3164))
s.fill((255,255,255))
pygame.draw.lines(s,(0,0,0),True,[(3000,2500),(3192,2500),(3192,2648),(3000,
2648)],1)
w = pygame.display.set_mode((1000,750))
s1 = pygame.transform.rotozoom(s,0,0.25)
w.blit(s1,(0,0))
pygame.display.flip()
def input(events):
for event in events:
if event.type == pygame.QUIT:
sys.exit(0)
elif event.type == pygame.KEYDOWN:
sys.exit(0)
else:
pass
while True:
input(pygame.event.get())
--------------------------------------------------------------------
Now the problem is how to manage window and pygame events?
Thanks for any idea/help in solving this issue.
Regards,
Madhubala