class CurrentQuestion: id = 0 prompt = u'' response = u'' imgfn = u'' sndfn = u'' map = u'' answer_link = u'' import pygame from pygame.locals import * # the following line is not needed if pgu is installed import sys; sys.path.insert(0, "..") from pgu import gui cq = CurrentQuestion() class EditDialog(gui.Dialog): def __init__(self, editsave, cq): title = gui.Label("Edit Question") t = gui.Table() self.form = gui.Form() t.tr() t.td(gui.Label("Prompt: ")) t.td(gui.Input(name = 'prompt', value = cq.prompt),colspan=3) t.tr() t.td(gui.Label("Response: ")) t.td(gui.Input(name = 'response', value = cq.response),colspan=3) t.tr() t.td(gui.Label("Image: ")) t.td(gui.Input(name = 'image', value = cq.imgfn),colspan=3) t.tr() t.td(gui.Label("Sound: ")) t.td(gui.Input(name = 'sound', value = cq.sndfn),colspan=3) t.tr() t.td(gui.Label("Map: ")) t.td(gui.Input(name = 'map', value = cq.map),colspan=3) t.tr() t.td(gui.Label("Answer_link: ")) t.td(gui.Input(name = 'answer_link', value = cq.answer_link),colspan=3) t.tr() saveButton = gui.Button("Save") saveButton.connect(gui.CLICK, editsave) t.td(saveButton,colspan=3) gui.Dialog.__init__(self,title,t) class ImageQuizActivity: user_name = u"chris" def game(self): global edit_d global c clock = pygame.time.Clock() cq.prompt = "prompt" cq.response = "response" cq.imgfn = "image" cq.sndfn = "sound" cq.map = "map" cq.answer_link = "answerlink" app = gui.App() c = gui.Container(width = 100, height = 50) app.init(c) edit_d = EditDialog(self.editsave, cq) edit_d.open() # Pygame event loop. while True: clock.tick(20) app.paint(self.screen) pygame.display.update() for event in [ pygame.event.wait() ] + pygame.event.get( ): self.input(event) app.event(event) def editsave(cq): global edit_d global c print 'editsave' form = edit_d.form print 'items', len(form.items()), form.items() cq.prompt = form['prompt'].value cq.response = form['response'].value cq.imgfn = form['image'].value cq.sndfn = form['sound'].value cq.map = form['map'].value cq.answer_link = form['answer_link'].value print 'on save:' print 'prompt', cq.prompt print 'response', cq.response print 'image', cq.imgfn print 'sound', cq.sndfn print 'map', cq.map print 'answer_link', cq.answer_link app.close(edit_d) # Handle a pygame event def exit_all(self): global edit_d form = edit_d.form cq.prompt = form['prompt'].value cq.response = form['response'].value cq.imgfn = form['image'].value cq.sndfn = form['sound'].value cq.map = form['map'].value cq.answer_link = form['answer_link'].value print 'on exit:' print 'prompt', cq.prompt print 'response', cq.response print 'image', cq.imgfn print 'sound', cq.sndfn print 'map', cq.map print 'answer_link', cq.answer_link # plugger.close_plugins() # time.sleep(3) sys.exit(0) def input(self, event): if event.type == QUIT: self.exit_all() elif event.type == MOUSEBUTTONUP: #display.check_click(event.pos) pass elif event.type == KEYUP: if event.key == 113: # 'q' self.exit_all() elif event.key == 102: # 'f' pygame.display.toggle_fullscreen() # elif event.type == MOUSEMOTION: # pass # else: # x = event.type # display.show_tool_tip((200, 10), "%i" % int(x)) # pygame.display.update() def __init__(self): # Fire Up Display self.window = pygame.display.set_mode((1200, 825)) pygame.display.set_caption('PGU test') # Init Surface self.screen = pygame.display.get_surface() self.game() def main(): ImageQuiz = ImageQuizActivity() if __name__ == "__main__" or __name__ == "ImageQuiz": main()