I have a question regarding the use of PyUI2 with Pygame. I am trying to add PyUI2 into an existing Pygame project, but I am not sure how to tell PyUI2 to draw itself without erasing everything else.
My main problem at the moment is that pyui2.draw() fills the screen with a black background, which overwrites anything else on the screen. Do I need to reimplement draw, can I make this background transparent, or is there another way to wrap PyUI2 around my existing project?
You don't need to reimplement draw, PyUI2 has the functionality already there to let you do this.
The renderers allow you to set a background drawing method. By default this is set to self.clear which simply erases the background. What you need to do, is to create a method with one parameter and during initialisation call the renderers setBackMethod function.
from pyui2.desktop import getRenderer
pyui2.init(width, height, "2d", 0, "MyApp")
That should be all there is to it. If you have any more problems please let me know.
Thanks for the prompt response! I got it to work, although I have one more problem now. PyUI2 intercepts Pygame's events, so I cannot intercept mouse clicks. Is there a way to pass these events on to a function, while still allowing PyUI2 to read them?
You should be able to register an event through the desktop and attach a handler to get the mouseclick. Try this.
def onMouseDown(self, event):
# Event handling here
Give that a try. I haven't done this myself yet, but looking at the code, and the old PyUI docs, I think it should work.
Let me know how you go.
Oops. Cut and paste error. Unfortunately you can't edit these posts.
pyui.locals should be pyui2.locals.
It worked! Thanks again for the help.
Log in to post a comment.