Anyone tried mixing pygame with wx?
I should be pretty easy with just adding a pygame window, but I'd like to see a pygame embedded control
Anyone heard of such a creature or have a theory on how to implement it?
Matthew
Anyone tried mixing pygame with wx?
I should be pretty easy with just adding a pygame window, but I'd like to see a pygame embedded control
Anyone heard of such a creature or have a theory on how to implement it?
Matthew
Hi, ALL!
I'm using wxPython for some week.
I like very much the XML resource file; very good way to handle resource.
I have a little problem loading frames from XRC: if the panel contain a wxGrid class I get an error like this:
10.23.32: No handler found for XML node 'object', class 'wxGrid'!
10.23.32: Error in resource.
This is a snip from my code:
聽聽聽聽聽聽聽聽聽res = wxXmlResource("mainui.xrc")
聽聽聽聽聽聽聽聽聽聽res.InitAllHandlers()
聽聽聽聽聽聽聽聽聽p = res.LoadPanel(self,"mainUI")
Is it my fault or is a know problem?
Ciao!!______________
I dilettanti hanno costruito l'arca, i professionisti il Titanic. Passa a Linux!
http://dinogen.tripod.com : http://siena.linux.it
Hi,
Dinogen wrote:
10.23.32: No handler found for XML node 'object', class 'wxGrid'!
10.23.32: Error in resource.
...
Is it my fault or is a know problem?
wxGrid support is not (yet) implemented. There are two things you can
do about it:
1. implement wxGrid handler (preferably in C++, so that it can be
included in XRC), or
2. use the "unknown" pseudo-class:
Add
<object class="unknown" name="my_grid"/>
instead of <object class="wxGrid"> to your resource file and this code
to plug the grid into its place (warning: translating to wxPython
from memory):
wxXmlResource_Get().AttachUnknownControl("my_grid", wxGrid(...))
You can see it used in poEdit source code (poedit.sf.net; C++ code).
HTH,
Vaclav
Anyone tried mixing pygame with wx?
It's been done, but I don't know any details
I should be pretty easy with just adding a pygame window, but I'd like
to see a pygame embedded control
I think that is what was done.
Anyone heard of such a creature or have a theory on how to implement it?
Find the pygame API that lets you give a window handle for it to draw upon
and then in some wx derived class call it with self.GetHandle()
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
Matthew Sherborne wrote:
Anyone tried mixing pygame with wx?
I should be pretty easy with just adding a pygame window, but I'd like to see a pygame embedded control
Anyone heard of such a creature or have a theory on how to implement it?
Matthew
I played with this a long while ago (back when pygame was at version 0.5). I was curious whether my old code would still run under pygame 1.5, and it did after only minor modifications. For some reason, though, it doesn't exit cleanly...
Here's the code:
import os
from wxPython.wx import *
from Numeric import *
from pdk.Math.RandomNumbers import random
import pygame
from pygame import display,event,surfarray,time
class wxSDLWindow(wxFrame):
def __init__(self, parent, id, title = 'SDL window', **options):
options['style'] = wxDEFAULT_FRAME_STYLE | wxTRANSPARENT_WINDOW
wxFrame.__init__(*(self, parent, id, title), **options)
self._initialized = 0
self._resized = 0
self._surface = None
self.__needsDrawing = 1
EVT_IDLE(self, self.OnIdle)
def OnIdle(self, ev):
if not self._initialized or self._resized:
if not self._initialized:
# get the handle
hwnd = self.GetHandle()
os.putenv('SDL_WINDOWID', str(hwnd))
pygame.init()
EVT_SIZE(self, self.OnSize)
self._initialized = 1
else:
self._resized = 0
x,y = self.GetSizeTuple()
self._surface = display.set_mode((x,y))
if self.__needsDrawing:
self.draw()
def OnPaint(self, ev):
self.__needsDrawing = 1
def OnSize(self, ev):
self._resized = 1
ev.Skip()
def draw(self):
raise NotImplementedError('please define a .draw() method!')
def getSurface(self):
return self._surface
if __name__ == "__main__":
class GradientWindow(wxSDLWindow):
"simple random color gradient done with a NumPy array."
def draw(self):
surface = self.getSurface()
if not surface is None:
topcolor,bottomcolor = random.uniform_int_sample(0, 255, (2, 3))
diff = bottomcolor - topcolor
width,height = surface.get_size()
# create array from 0.0 to 1.0 triplets
column = arange(height, typecode=Float)/height
column = repeat(column[:, NewAxis], [3], 1)
# create a single column of gradient
column = topcolor + (diff * column).astype(Int)
# make the column a 3d image column by adding X
column = column.astype(UnsignedInt8)[NewAxis,:,:]
#3d array into 2d array
column = surfarray.map_array(surface, column)
# stretch the column into a full image
surfarray.blit_array(self._surface,
resize(column, (width, height)))
display.flip()
def gradienttest():
app = wxPySimpleApp()
sizeT = (640,480)
w = GradientWindow(None, -1, size = sizeT)
w.Show(1)
app.MainLoop()
# gradienttest()
--------------------------
F. Oliver Gathmann, Ph.D.
Cenix BioScience GmbH
Pfotenhauer Strasse 108
D-01307 Dresden, Germany
phone: +49 (351) 210-2735
fax: +49 (351) 210-1309
--------------------------