Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pgutest.py
blob: 0ec71915052baa6e35db5144b0f72f6f0f0f9e31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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()