from pgu import text pygame.font.init() screen = pygame.display.set_mode((640,480),SWSURFACE) fg = (0,0,0) bg = (0,192,255) screen.fill(bg) bg = (255,255,255) font = pygame.font.SysFont("default", 24) ##:: text.write(screen,font,(0,0),bg,"Hello World!") text.writec(screen,font,bg,"Centered Text") text.writepre(screen,font,pygame.Rect(160,48,320,100),fg,"""This is some preformatted t e x t""") text.writewrap(screen,font,pygame.Rect(160,268,320,100),fg,"""This is some text that will wrap automatically. This is some text that will wrap automatically. This is some text that will wrap automatically. This is some text that will wrap automatically.""") ## pygame.display.flip() _quit = 0 while not _quit: for e in pygame.event.get(): if e.type is QUIT: _quit = 1 pygame.time.wait(10)
def main(): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" global lines #Initialize Everything pygame.init() pygame.font.init() font = pygame.font.SysFont("default", 18) fontBig = pygame.font.SysFont("default", 24) fontSub = pygame.font.SysFont("default", 20) screen = pygame.display.set_mode(screenSize) pygame.display.set_caption('GUI Test - PGU') # create GUI object gui = pgui.App() textArea = pygame.Rect(370, 20, 250, 320) # layout using document lo = pgui.Container(width=350) # create page label #lo.block(align=-1) #lo.br(8) #lo.tr() title = pgui.Label("Pygame GUI Test Page - PGU", font=fontBig) lo.add(title,29,13) # create progress bar label # progress bar pbl = pgui.Label("Progress Bar Not Supported") lo.add(pbl,354,371) # create checkbuttons and add to gui cbt = pgui.Table() cb1 = pgui.Switch() cb1.connect(pgui.CHANGE, logCheckAction, (cb1, "Check Box 1")) cb1l = pgui.Label("Check Box 1") cbt.add(cb1) cbt.add(cb1l) cbt.tr() cb2 = pgui.Switch() cb2.connect(pgui.CHANGE, logCheckAction, (cb2, "Check Box 2")) cb2l = pgui.Label("Check Box 2") cbt.add(cb2) cbt.add(cb2l) cbt.tr() cb3 = pgui.Switch() cb3.connect(pgui.CHANGE, logCheckAction, (cb3, "Check Box 3")) cb3l = pgui.Label("Check Box 3") cbt.add(cb3) cbt.add(cb3l) lo.add(cbt,52,52) # create radio buttons, put in table, and add to gui rbt = pgui.Table() radio = pgui.Group() rb1 = pgui.Radio(radio, 1) rb1l = pgui.Label("Radio Button 1") rbt.add(rb1) rbt.add(rb1l) rbt.tr() rb2 = pgui.Radio(radio, 2) rb2l = pgui.Label("Radio Button 2") rbt.add(rb2) rbt.add(rb2l) rbt.tr() rb3 = pgui.Radio(radio, 3) rb3l = pgui.Label("Radio Button 3") rbt.add(rb3) rbt.add(rb3l) rbt.tr() lo.add(rbt,210,52) radio.connect(pgui.CHANGE, logRadioAction, (radio, "Radio Button 3")) # create txt box label txtl = pgui.Label("Text Box", font=fontSub) lo.add(txtl,30,127) # create text box txt = pgui.Input("next line of input", size=45) txt.connect(pgui.BLUR, logInputAction, txt) lo.add(txt,28,149) # add buttons, both regular and toggle btn1 = pgui.Button("Button 1") btn1.connect(pgui.CLICK, logButtonAction, ("Button 1 clicked")) lo.add(btn1,36,250) btn2 = pgui.Button("Button 2") btn2.connect(pgui.CLICK, logButtonAction, ("Button 2 clicked")) lo.add(btn2,133,250) btn3 = pgui.Button("Button 3") btn3.connect(pgui.CLICK, logButtonAction, ("Button 3 clicked")) lo.add(btn3,230,250) # create toggle button not avail label tbl = pgui.Label("Toggle Buttons Not Supported") lo.add(tbl,36,290) iml = pgui.Label("Image Map Not Supported") lo.add(iml,36,340) # create slider label sll = pgui.Label("Slider", font=fontSub) lo.add(sll,36,195) # create slider sl = pgui.HSlider(value=1,min=0,max=100,size=32,width=200,height=16) sl.connect(pgui.CHANGE, logSliderAction, sl) lo.add(sl,53,210) #, colspan=3) # make some insensitive btn2.style.disabled = True cb3.style.disabled = True # clear setup noise, and put initial content in lines = [] lines.append('top line of input') lines.append('second line of input') gui.init(lo) #Main Loop while 1: #Handle Input Events for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN and event.key == K_ESCAPE: return # pass event to gui gui.event(event) # 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) # Draw GUI gui.paint(screen) edText = "\n".join(lines) text.writepre(screen, font, textArea, (0,0,0), edText) pygame.display.flip()
# create slider label sll = pgui.Label("Slider",font=fontBig) lo.add(sll,36,195) # create slider sl = pgui.HSlider(value=1,min=0,max=100,size=32,width=200,height=16) sl.connect(pgui.CHANGE, logSliderAction, sl) lo.add(sl,53,210) #, colspan=3) # clear setup noise, and put initial content in lines = [] lines.append('top line of input') lines.append('second line of input') gui.init(lo) running = True while running: for event in pygame.event.get(): if event.type == QUIT: pygame.mouse.set_cursor(*pygame.cursors.arrow) running = False controller.handle_keystroke_event(event) model.update_model() view.draw() time.sleep(.01) # Draw GUI gui.paint(screen) edText = "\n".join(lines) text.writepre(screen, font, textArea, (0,0,0), edText) pygame.quit()
pygame.font.init() screen = pygame.display.set_mode((640, 480), SWSURFACE) fg = (0, 0, 0) bg = (0, 192, 255) screen.fill(bg) bg = (255, 255, 255) font = pygame.font.SysFont("default", 24) ##:: text.write(screen, font, (0, 0), bg, "Hello World!") text.writec(screen, font, bg, "Centered Text") text.writepre(screen, font, pygame.Rect(160, 48, 320, 100), fg, """This is some preformatted t e x t""") text.writewrap( screen, font, pygame.Rect(160, 268, 320, 100), fg, """This is some text that will wrap automatically. This is some text that will wrap automatically. This is some text that will wrap automatically. This is some text that will wrap automatically.""" ) ## pygame.display.flip() _quit = 0 while not _quit: for e in pygame.event.get(): if e.type == QUIT: _quit = 1
def setplayer(): global lines, txts pygame.init() pygame.font.init() font = pygame.font.SysFont("monospace", 18) # fontBig = pygame.font.SysFont("monospace", 18) # fontSub = pygame.font.SysFont("monospace", 18) screen = pygame.display.set_mode(screenSize) gui = pgui.App() textArea1 = pygame.Rect(370, 20, 250, 320) textArea2 = pygame.Rect(370, 30, 250, 320) textArea3 = pygame.Rect(370, 40, 250, 320) textArea4 = pygame.Rect(370, 50, 250, 320) # layout using document lo = pgui.Container(width=350) # create page label # lo.block(align=-1) #lo.br(8) #lo.tr() title = pgui.Label("CallBreak Player Name Setting", font=font) lo.add(title,29,13) # create txt box label txtl1 = pgui.Label("Ai1", font=font) lo.add(txtl1,1,151) txtl2 = pgui.Label("Ai2", font=font) lo.add(txtl2,1,170) txtl3 = pgui.Label("Ai3", font=font) lo.add(txtl3,1,190) txtl4 = pgui.Label("You", font=font) lo.add(txtl4,1,210) # create text box txt1 = pgui.Input(None, size=45) txt1.connect(pgui.BLUR, logInputAction, txt1) lo.add(txt1,35,149) # name.append(txt1) txts.append(txt1) txt2 = pgui.Input(None, size=45) txt2.connect(pgui.BLUR, logInputAction, txt2) lo.add(txt2,35,169) txts.append(txt2) # name.append(txt2) txt3 = pgui.Input(None, size=45) txt3.connect(pgui.BLUR, logInputAction, txt3) lo.add(txt3,35,189) txts.append(txt3) txt4 = pgui.Input(None, size=45) txt4.connect(pgui.BLUR, logInputAction, txt4) lo.add(txt4,35,209) txts.append(txt4) btn1 = pgui.Button("OK") btn1.connect(pgui.CLICK, lambda: btnOk()) lo.add(btn1,36,250) btn2 = pgui.Button("Cancel") btn2.connect(pgui.CLICK, btnCnl) lo.add(btn2,133,250) screen.fill(WHITE) gui.init(lo) while 1: #Handle Input Events time.sleep(0.03) for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN and event.key == K_ESCAPE: return # pass event to gui gui.event(event) # clear background screen.fill((250, 250, 250)) # Draw GUI gui.paint(screen) edText = "\n".join(lines) text.writepre(screen, font, textArea1, (0,0,0), edText) text.writepre(screen, font, textArea2, (1,1,1), edText) text.writepre(screen, font, textArea3, (2,2,2), edText) text.writepre(screen, font, textArea4, (3,3,3), edText) pygame.display.flip()
def main(): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" global lines #Initialize Everything pygame.init() pygame.font.init() font = pygame.font.SysFont("default",12) fontBig = pygame.font.SysFont("default",16) fontSub = pygame.font.SysFont("default",8) screen = pygame.display.set_mode(screenSize) pygame.display.set_caption('GUI Test - PGU') # create GUI object gui = pgui.App() textArea = pygame.Rect(500, 20, 250, 320) # layout using document lo = pgui.Container(width=350) # create page label #lo.block(align=-1) #lo.br(8) #lo.tr() title = pgui.Label("PygameTest Page - PGU", font=fontBig) lo.add(title,29,13) # create checkbuttons and add to gui cbt = pgui.Table() cb1 = pgui.Switch() cb1.connect(pgui.CHANGE, logCheckAction, (cb1, "Check Box 1")) cb1l = pgui.Label("Check1") cbt.add(cb1) cbt.add(cb1l) cbt.tr() cb2 = pgui.Switch() cb2.connect(pgui.CHANGE, logCheckAction, (cb2, "Check Box 2")) cb2l = pgui.Label("Check2") cbt.add(cb2) cbt.add(cb2l) cbt.tr() cb3 = pgui.Switch() cb3.connect(pgui.CHANGE, logCheckAction, (cb3, "Check Box 3")) cb3l = pgui.Label("Check3") cbt.add(cb3) cbt.add(cb3l) lo.add(cbt,52,52) # create radio buttons, put in table, and add to gui rbt = pgui.Table() radio = pgui.Group() rb1 = pgui.Radio(radio, 1) rb1l = pgui.Label("Mode 1") rbt.add(rb1) rbt.add(rb1l) rbt.tr() rb2 = pgui.Radio(radio, 2) rb2l = pgui.Label("Mode 2") rbt.add(rb2) rbt.add(rb2l) rbt.tr() rb3 = pgui.Radio(radio, 3) rb3l = pgui.Label("Mode 3") rbt.add(rb3) rbt.add(rb3l) rbt.tr() lo.add(rbt,210,52) radio.connect(pgui.CHANGE, logRadioAction, (radio, "Radio Button 3")) # create txt box label txtl = pgui.Label("Text", font=fontBig) lo.add(txtl,30,127) # create text box txt = pgui.Input("next of input", size=45) txt.connect(pgui.BLUR, logInputAction, txt) lo.add(txt,28,149) # add buttons, both regular and toggle btn1 = pgui.Button("Button 1") btn1.connect(pgui.CLICK, logButtonAction, ("Button 1 clicked")) lo.add(btn1,36,250) btn2 = pgui.Button("Button 2") btn2.connect(pgui.CLICK, logButtonAction, ("Button 2 clicked")) lo.add(btn2,133,250) btn3 = pgui.Button("Button 3") btn3.connect(pgui.CLICK, logButtonAction, ("Button 3 clicked")) lo.add(btn3,230,250) # create slider label sll = pgui.Label("Slider",font=fontBig) lo.add(sll,36,195) # create slider sl = pgui.HSlider(value=1,min=0,max=100,size=32,width=200,height=16) sl.connect(pgui.CHANGE, logSliderAction, sl) lo.add(sl,53,210) #, colspan=3) # clear setup noise, and put initial content in lines = [] lines.append('top line of input') lines.append('second line of input') gui.init(lo) #Main Loop while 1: #Handle Input Events for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN and event.key == K_ESCAPE: return # pass event to gui gui.event(event) # clear background, and draw clock-spinner screen.fill((250, 250, 250)) # Draw GUI gui.paint(screen) edText = "\n".join(lines) text.writepre(screen, font, textArea, (0,0,0), edText) pygame.display.flip()
def main(): """this function is called when the program starts. it initializes everything it needs, then runs in a loop until the function returns.""" global lines #Initialize Everything pygame.init() pygame.font.init() font = pygame.font.SysFont("default", 18) fontBig = pygame.font.SysFont("default", 24) fontSub = pygame.font.SysFont("default", 20) screen = pygame.display.set_mode(screenSize) pygame.display.set_caption('GUI Test - PGU') # create GUI object gui = pgui.App() textArea = pygame.Rect(370, 20, 250, 320) # layout using document lo = pgui.Container(width=350) # create page label #lo.block(align=-1) #lo.br(8) #lo.tr() title = pgui.Label("Pygame GUI Test Page - PGU", font=fontBig) lo.add(title, 29, 13) # create progress bar label # progress bar pbl = pgui.Label("Progress Bar Not Supported") lo.add(pbl, 354, 371) # create checkbuttons and add to gui cbt = pgui.Table() cb1 = pgui.Switch() cb1.connect(pgui.CHANGE, logCheckAction, (cb1, "Check Box 1")) cb1l = pgui.Label("Check Box 1") cbt.add(cb1) cbt.add(cb1l) cbt.tr() cb2 = pgui.Switch() cb2.connect(pgui.CHANGE, logCheckAction, (cb2, "Check Box 2")) cb2l = pgui.Label("Check Box 2") cbt.add(cb2) cbt.add(cb2l) cbt.tr() cb3 = pgui.Switch() cb3.connect(pgui.CHANGE, logCheckAction, (cb3, "Check Box 3")) cb3l = pgui.Label("Check Box 3") cbt.add(cb3) cbt.add(cb3l) lo.add(cbt, 52, 52) # create radio buttons, put in table, and add to gui rbt = pgui.Table() radio = pgui.Group() rb1 = pgui.Radio(radio, 1) rb1l = pgui.Label("Radio Button 1") rbt.add(rb1) rbt.add(rb1l) rbt.tr() rb2 = pgui.Radio(radio, 2) rb2l = pgui.Label("Radio Button 2") rbt.add(rb2) rbt.add(rb2l) rbt.tr() rb3 = pgui.Radio(radio, 3) rb3l = pgui.Label("Radio Button 3") rbt.add(rb3) rbt.add(rb3l) rbt.tr() lo.add(rbt, 210, 52) radio.connect(pgui.CHANGE, logRadioAction, (radio, "Radio Button 3")) # create txt box label txtl = pgui.Label("Text Box", font=fontSub) lo.add(txtl, 30, 127) # create text box txt = pgui.Input("next line of input", size=45) txt.connect(pgui.BLUR, logInputAction, txt) lo.add(txt, 28, 149) # add buttons, both regular and toggle btn1 = pgui.Button("Button 1") btn1.connect(pgui.CLICK, logButtonAction, ("Button 1 clicked")) lo.add(btn1, 36, 250) btn2 = pgui.Button("Button 2") btn2.connect(pgui.CLICK, logButtonAction, ("Button 2 clicked")) lo.add(btn2, 133, 250) btn3 = pgui.Button("Button 3") btn3.connect(pgui.CLICK, logButtonAction, ("Button 3 clicked")) lo.add(btn3, 230, 250) # create toggle button not avail label tbl = pgui.Label("Toggle Buttons Not Supported") lo.add(tbl, 36, 290) iml = pgui.Label("Image Map Not Supported") lo.add(iml, 36, 340) # create slider label sll = pgui.Label("Slider", font=fontSub) lo.add(sll, 36, 195) # create slider sl = pgui.HSlider(value=1, min=0, max=100, size=32, width=200, height=16) sl.connect(pgui.CHANGE, logSliderAction, sl) lo.add(sl, 53, 210) #, colspan=3) # make some insensitive btn2.style.disabled = True cb3.style.disabled = True # clear setup noise, and put initial content in lines = [] lines.append('top line of input') lines.append('second line of input') gui.init(lo) #Main Loop while 1: #Handle Input Events for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN and event.key == K_ESCAPE: return # pass event to gui gui.event(event) # 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) # Draw GUI gui.paint(screen) edText = "\n".join(lines) text.writepre(screen, font, textArea, (0, 0, 0), edText) pygame.display.flip()