~dreamsorcerer/simplegc/0.2

« back to all changes in this revision

Viewing changes to example/test.py

  • Committer: Sam Bull
  • Date: 2014-04-20 16:12:40 UTC
  • mfrom: (355.1.9 ProgressBar)
  • Revision ID: sam@sambull.org-20140420161240-gug8nz04rbffg0zh
Add ProgressBar widget.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
input_box = sgc.InputBox(label="Input Box", default="default text...")
64
64
input_box.config(pos=(30,120))
65
65
input_box.add(order=0)
 
66
# Create progress bar
 
67
progress_bar = sgc.ProgressBar()
 
68
progress_bar.config(pos=(400,120))
 
69
progress_bar.add()
66
70
# Change colour button, on_click event caught in event loop
67
71
button = sgc.Button(label="Change\ncolour", pos=(40,200))
68
72
# Create FPS counter
129
133
label.rect.midtop = title.rect.midbottom
130
134
label.add()
131
135
 
 
136
progress_fraction = 0.
 
137
 
132
138
while True:
133
139
    time = clock.tick(30)
134
140
    for event in pygame.event.get():
139
145
                print "Button event"
140
146
            if event.widget is button and event.gui_type == "click":
141
147
                button.config(col=[random.randrange(1,200) for x in range(3)])
 
148
                progress_fraction = 0. if progress_fraction is False else False
142
149
            elif event.widget is input_box:
143
150
                clear()
144
151
        elif event.type == KEYDOWN:
147
154
        elif event.type == QUIT:
148
155
            exit()
149
156
 
 
157
    if progress_fraction is not False:
 
158
        progress_fraction = (progress_fraction + .02) % 1
 
159
        progress_bar.set_fraction(progress_fraction)
 
160
    else:
 
161
        progress_bar.pulse()
 
162
 
150
163
    # Cleanup removed windows
151
164
    for widget in dialogs:
152
165
        if not widget.active():