Hi, Thanks for the suggestion and Im trying it out with pgu. Now Im having problems with the pgu interface. Can anyone help me? I've attached my test code. Its basically a button or event that brings up a text entry dialog. So far its fine, as soon as the dialog is closed, it wont close. Any ideas? Cheers Stan René Dudfield wrote: hi, Lamina allows you to use any pygame 2d gui with opengl. http://pitchersduel.python-hosting.com/browser/branches/Lamina/ It's fairly easy to use, and comes with demos for ocempgui and pgu. cheers, On Wed, Jun 18, 2008 at 2:58 PM, Astan Chee <stanc@xxxxxxxxx> wrote:Hi, I was wondering if there is a way to get a simple text entry dialog on a pygame+opengl surface. I've tried several and all of them seem to dislike doing a .blit on a opengl surface and crash badly whenever I do anything on it. Are there simple alternatives? Thanks Astan -- "Formulations of number theory: Complete, Consistent, Non-trivial. Choose two." Animal Logic http://www.animallogic.com Please think of the environment before printing this email. This email and any attachments may be confidential and/or privileged. If you are not the intended recipient of this email, you must not disclose or use the information contained in it. Please notify the sender immediately and delete this document if you have received it in error. We do not guarantee this email is error or virus free. -- "Formulations of number theory: Complete, Consistent, Non-trivial. Choose two." Please think of the environment before printing this email. This email and any attachments may be confidential and/or privileged.
If you are not the intended recipient of this email, you must not disclose or use the information |
#!/usr/bin/env python # demo of laminar.PanelOverlaySurface, by # David Keeney 2006 # based on version of Nehe's OpenGL lesson04 # by Paul Furber 2001 - m@xxxxxxxxxxxx # you need pgu to be installed, and you need a copy of the default theme directory # as 'test_theme', and you need the accompanying config.txt in that test_theme dir. import sys sys.path.insert( 0, '..' ) from OpenGL.GL import * from OpenGL.GLU import * import pygame from pygame.locals import * # import gui stuff try: from pgu import gui as pgui except ImportError: print "PGU GUI must be installed in order to run this demo. " print "PGU can be obtained from: " print " https://sourceforge.net/project/showfiles.php?group_id=145281" sys.exit() import lamina rtri = rquad = 0.0 triOn = quadOn = True zoomAngle = 45 open_d = None class OpenDialog(pgui.Dialog): def __init__(self,**params): title = pgui.Label("Input Position") t = pgui.Table() self.value = pgui.Form() t.tr() t.td(pgui.Label("Position: ")) t.td(pgui.Input(name="pos"),colspan=3) t.tr() e = pgui.Button("Ok") e.connect(pgui.CLICK,self.send,pgui.CHANGE) t.td(e,colspan=2) e = pgui.Button("Cancel") e.connect(pgui.CLICK,self.close,None) t.td(e,colspan=2) pgui.Dialog.__init__(self,title,t) def resize((width, height)): if height==0: height=1 glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(zoomAngle, 1.0*width/height, 0.1, 100.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() def init(): glShadeModel(GL_SMOOTH) glClearColor(0.0, 0.5, 0.0, 0.0) glClearDepth(1.0) glEnable(GL_DEPTH_TEST) glDepthFunc(GL_LEQUAL) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) def draw(): glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(-1.5, 0.0, -6.0) # draw triangle global rtri glRotatef(rtri, 0.0, 1.0, 0.0) glBegin(GL_TRIANGLES) glColor3f(1.0, 0.0, 0.0) glVertex3f(0.0, 1.0, 0.0) glColor3f(0.0, 1.0, 0.0) glVertex3f(-1.0, -1.0, 0) glColor3f(0.0, 0.0, 1.0) glVertex3f(1.0, -1.0, 0) glEnd() # draw quad glLoadIdentity() glTranslatef(1.5, 0.0, -6.0) global rquad glRotatef(rquad, 1.0, 0.0, 0.0) glColor3f(0.5, 0.5, 1.0) glBegin(GL_QUADS) glVertex3f(-1.0, 1.0, 0) glVertex3f(1.0, 1.0, 0) glVertex3f(1.0, -1.0, 0) glVertex3f(-1.0, -1.0, 0) glEnd() # draw gui glLoadIdentity() global gui_screen gui_screen.display() def main(): global rtri, rquad, gui_screen, open_d video_flags = OPENGL|DOUBLEBUF pygame.init() pygame.display.set_mode((640,480), video_flags) font = pygame.font.SysFont("default", 18) fontBig = pygame.font.SysFont("default", 24) fontSub = pygame.font.SysFont("default", 20) theme = pgui.Theme('test_theme'); resize((640,480)) init() # create PanelOverlaySurface # gui_screen = lamina.LaminaPanelSurface((640,480), (-3.3, 2.5, 6.6, 5)) gui_screen = lamina.LaminaScreenSurface() gui = pgui.App(theme=theme) gui._screen = gui_screen.surf # func to toggle triangle spin def triTog(): global triOn triOn = not triOn # func to toggle quad spin def quadTog(): global quadOn quadOn = not quadOn # func to toggle zoom def zoomTog(): global zoomAngle if zoomAngle == 45: zoomAngle = 30 else: zoomAngle = 45 resize((640,480)) gui_screen.refreshPosition() gui.repaint(gui_screen.surf) def action_open(meme): global open_d open_d.close() fname = open_d.value['pos'] print fname.value # create page # layout using document lo = pgui.Container(width=640) # create page label title = pgui.Label("Lamina Demo : PGU", font=fontBig) lo.add(title,29,13) # create triangle button, connect to triTog handler function, # and install in gui btn1 = pgui.Button("Stop/Start Triangle") btn1.connect(pgui.CLICK, triTog) lo.add(btn1,120,440) btn2 = pgui.Button("Stop/Start Quad") btn2.connect(pgui.CLICK, quadTog) lo.add(btn2,420,440) # create zoom button, connect to zoomTog handler function, # and install in gui btn3 = pgui.Button('Zoom') btn3.connect(pgui.CLICK, zoomTog) lo.add(btn3,300,440) open_d = OpenDialog() open_d.connect(pgui.CHANGE,action_open,None) btn4 = pgui.Button('Ask') btn4.connect(pgui.CLICK, open_d.open) lo.add(btn4,300,240) gui.init(lo) frames = 0 ticks = pygame.time.get_ticks() while 1: event = pygame.event.poll() if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): break # handle gui events and raster updating gui.event((event)) chg = gui.update(gui_screen.surf) if chg: gui_screen.refresh(chg) # draw all objects draw() # update rotation counters if triOn: rtri += 0.2 if quadOn: rquad+= 0.2 # make changes visible pygame.display.flip() frames = frames+1 print "fps: %d" % ((frames*1000)/(pygame.time.get_ticks()-ticks)) pygame.quit() if __name__ == '__main__': main()