PyUI2's init function, in pygame2d mode, sets up the pygame screen. In order to draw on the screen through pygame functions, we need the pygame screen object.
How do we get the screen from PyUI2, or do we set up the screen before and provide it to PyUI2 somehow?
Thanks in advance
David
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm sorry I've taken so long to get back to you. Getting set up after moving back to Oz has taken quite a bit longer than I expected.
You should be able to use the pygame.display.get_surface function to get the current display surface. This display surface needs to be set up using the set_mode function first, or get_surface will return None. PyUI2, as you observed, does this. So all you need to do in your background drawing function is use the get_surface function.
I hope this helps.
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been evaluating the various Pygame GUIs and publishing the reports on my weblog 'pitchersduel.iuplog.com'. I expect to be posting a report on PyUI2 in the next ten days.
David
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Could you provide me a bit more advice on PyUI2 coding?
This code runs, and draws everything, but flickers enormously. How do I instruct the PyUI2 draw() and update() functions to not clear the background?
I appreciate your assistance
David Keeney
==============
# As part of the Pitcher's Duel Project, I am
# conducting a comparative
# analysis of pygame GUI modules, and publishing
# the results on my blog.
# The comparison consists of implementing the same
# sample interface on
# each of the various GUIs.
#
# This source code is the work of David Keeney,
# dkeeney at travelbyroad dot net
#Import Modules
import pygame
from pygame.locals import *
import time
import math
# import gui stuff
import pyui2
screenSize = (642, 429)
screen = None;
def main():
"""this function is called when the program starts.
it initializes everything it needs, then runs in
a loop until the function returns."""
#Initialize Everything
global screen
pygame.init()
pyui2.init(screenSize[0], screenSize[1], "2d", 0, 'GUI Test - PyUI2')
screen = pygame.display.get_surface()
# create GUI object
newFrame = pyui2.widgets.Frame(1, 1, 200, 200, "requisite window")
newFrame.setLayout(pyui2.layouts.AbsoluteLayoutManager(*screenSize))
newLabel = pyui2.widgets.Label("this is a label")
The most obvious thing that I can see wrong here is that you are calling the pyui2 update and draw functions, then drawing your background and then calling pygame.display.update again. If you trace the code down (when using pygame) pyui2.draw actually calls the pygame.display.update function when it draws. So what you are doing is telling pyui2 to draw the gui, then drawing the background over the top. This will cause pretty bad flicker.
Try calling the background function between the update and draw functions, and don't bother calling the pygame update as this is already done. What this will do is draw your background, and then the gui.
I think that doing this will fix most of your flicker.
I hope this helps.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just had a bit of a closer look and I think there might be a bug here. While you still need to change your code to what I describe above, there seems to be an issue with the presenter also clearing the background. I'll have to look closer at this.
I'll get back to you on it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
PyUI2's init function, in pygame2d mode, sets up the pygame screen. In order to draw on the screen through pygame functions, we need the pygame screen object.
How do we get the screen from PyUI2, or do we set up the screen before and provide it to PyUI2 somehow?
Thanks in advance
David
Hi David,
I'm sorry I've taken so long to get back to you. Getting set up after moving back to Oz has taken quite a bit longer than I expected.
You should be able to use the pygame.display.get_surface function to get the current display surface. This display surface needs to be set up using the set_mode function first, or get_surface will return None. PyUI2, as you observed, does this. So all you need to do in your background drawing function is use the get_surface function.
I hope this helps.
John
Thank you, John.
I have been evaluating the various Pygame GUIs and publishing the reports on my weblog 'pitchersduel.iuplog.com'. I expect to be posting a report on PyUI2 in the next ten days.
David
No worries David.
I look forward to reading it.
John:
Could you provide me a bit more advice on PyUI2 coding?
This code runs, and draws everything, but flickers enormously. How do I instruct the PyUI2 draw() and update() functions to not clear the background?
I appreciate your assistance
David Keeney
==============
# As part of the Pitcher's Duel Project, I am
# conducting a comparative
# analysis of pygame GUI modules, and publishing
# the results on my blog.
# The comparison consists of implementing the same
# sample interface on
# each of the various GUIs.
#
# This source code is the work of David Keeney,
# dkeeney at travelbyroad dot net
#Import Modules
import pygame
from pygame.locals import *
import time
import math
# import gui stuff
import pyui2
screenSize = (642, 429)
screen = None;
def main():
"""this function is called when the program starts.
it initializes everything it needs, then runs in
a loop until the function returns."""
#Initialize Everything
global screen
pygame.init()
pyui2.init(screenSize[0], screenSize[1], "2d", 0, 'GUI Test - PyUI2')
screen = pygame.display.get_surface()
# create GUI object
newFrame = pyui2.widgets.Frame(1, 1, 200, 200, "requisite window")
newFrame.setLayout(pyui2.layouts.AbsoluteLayoutManager(*screenSize))
newLabel = pyui2.widgets.Label("this is a label")
newFrame.addChild(newLabel, (50, 50))
newFrame.pack()
#Main Loop
while 1:
#Handle Input Events
queue = []
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN and event.key == K_ESCAPE:
return
else:
queue.append(event)
# pass events to gui
for e in queue:
pygame.event.post(e)
queue = [];
pyui2.update()
pyui2.draw()
background()
pygame.display.update()
pyui2.quit()
def background():
# clear background, and draw clock-spinner
screen.fill((250, 250, 250))
radius = 30
spinPos = 240, 362
sp2 = spinPos[0]+1, spinPos[1]
progressAngle = int(time.time() % 15 * 24 - 90) #60
pygame.draw.circle(screen, (180, 180, 180), spinPos, radius, 0)
for angle in range(-90, progressAngle):
a = angle*math.pi/180
tgt = radius*math.cos(a)+spinPos[0], \ radius*math.sin(a)+spinPos[1]
pygame.draw.line(screen, (254,254,254), spinPos, tgt, 2)
pygame.draw.circle(screen, (0,0,0), spinPos, radius, 2)
pygame.draw.circle(screen, (0,0,0), spinPos, radius+1, 3)
pygame.draw.circle(screen, (0,0,0), sp2, radius, 2)
pygame.draw.circle(screen, (0,0,0), sp2, radius+1, 3)
pygame.draw.line(screen, (0,0,0), spinPos, tgt, 2)
tgt = spinPos[0], spinPos[1]-radius
pygame.draw.line(screen, (0,0,0), spinPos, tgt, 2)
main()
Hi David,
The most obvious thing that I can see wrong here is that you are calling the pyui2 update and draw functions, then drawing your background and then calling pygame.display.update again. If you trace the code down (when using pygame) pyui2.draw actually calls the pygame.display.update function when it draws. So what you are doing is telling pyui2 to draw the gui, then drawing the background over the top. This will cause pretty bad flicker.
Try calling the background function between the update and draw functions, and don't bother calling the pygame update as this is already done. What this will do is draw your background, and then the gui.
I think that doing this will fix most of your flicker.
I hope this helps.
Just had a bit of a closer look and I think there might be a bug here. While you still need to change your code to what I describe above, there seems to be an issue with the presenter also clearing the background. I'll have to look closer at this.
I'll get back to you on it.