Skip to content
Snippets Groups Projects
Commit a5f02695 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Initial commit.

parents
No related branches found
No related tags found
No related merge requests found
*~
*.pyc
*.pyo
.idea
main.py 0 → 100644
from random import shuffle
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import BooleanProperty, ListProperty
from kivy.modules import inspector
from kivy.core.window import Window
GUI_QUESTIONS = [
('What are the fundamental building blocks of a GUI?',
('Buttons', 'Containers', 'Layout Managers', 'Widgets'), 'Widgets'),
('What kind of widget is used to organize other widgets?',
('Buttons', 'Containers', 'Layout Managers', 'Organizers'), 'Containers'),
('What math term describes a widget hierarchy?',
('Rooted Tree', 'Separation of Concerns', 'Shrubbery', 'Vertex'), 'Rooted Tree'),
('Which of the following is not a true widget property?',
('Color', 'Enabledness', 'ID', 'Visibility'), 'ID'),
('What process connects widgets to event handlers?',
('Event Handling', 'Invocation', 'Registration', 'Selection'), 'Registration'),
('Which of the following is mostly useless unless in a group of two or more?',
('Buttons', 'Checkboxes', 'Radio Buttons', 'Textboxes'), 'Radio Buttons'),
('Which of the following GUI frameworks uses an unflipped y axis?',
('HTML+CSS', 'JavaFX', 'Kivy', 'WPF'), 'Kivy'),
]
COLOR_QUESTIONS = [
('What of the following RGBA quadruples represents red?',
('(1, 0, 0, 1)', '(0, 1, 0, 1)', '(0, 1, 1, 0)', '(0, 0, 1, 1)'), '(1, 0, 0, 1)'),
('What of the following RGBA quadruples represents yellow?',
('(1, 0, 1, 1)', '(1, 1, 0, 1)', '(0, 1, 1, 1)', '(1, 1, 1, 1)'), '(1, 1, 0, 1)'),
('What of the following RGBA quadruples represents green?',
('(1, 0, 0, 1)', '(0, 1, 0, 1)', '(0, 1, 1, 0)', '(0, 0, 1, 1)'), '(0, 1, 0, 1)'),
('What of the following RGBA quadruples represents cyan?',
('(1, 0, 1, 1)', '(1, 1, 0, 1)', '(0, 1, 1, 1)', '(1, 1, 1, 1)'), '(0, 1, 1, 1)'),
('What of the following RGBA quadruples represents blue?',
('(1, 0, 0, 1)', '(0, 1, 0, 1)', '(0, 1, 1, 0)', '(0, 0, 1, 1)'), '(0, 0, 1, 1)'),
('What of the following RGBA quadruples represents magenta?',
('(1, 0, 1, 1)', '(1, 1, 0, 1)', '(0, 1, 1, 1)', '(1, 1, 1, 1)'), '(1, 0, 1, 1)'),
('What of the following RGBA quadruples represents white?',
('(1, 0, 1, 1)', '(1, 1, 0, 1)', '(0, 1, 1, 1)', '(1, 1, 1, 1)'), '(1, 1, 1, 1)'),
('What of the following RGBA quadruples represents black?',
('(0, 0, 0, 0)', '(0, 0, 0, 1)', '(0, 0, 1, 0)', '(0, 0, 1, 1)'), '(0, 0, 0, 1)'),
]
TREE_QUESTIONS = [
('If a widget X is directly inside a container Y, then Y is X\'s what?',
('Child', 'Descendant', 'Parent', 'Root'), 'Parent'),
('If a widget X is directly inside a container Y, then X is Y\'s what?',
('Ancestor', 'Child', 'Parent', 'Leaf'), 'Child'),
('If a container Y is not inside anything else, then Y is called what?',
('Child', 'Descendant', 'Parent', 'Root'), 'Root'),
('If a widget X is inside Y inside a container Z, then Z is X\'s what?',
('Ancestor', 'Child', 'Descendant', 'Parent'), 'Ancestor'),
('If a widget X is inside Y inside a container Z, then X is Z\'s what?',
('Ancestor', 'Child', 'Descendant', 'Parent'), 'Descendant'),
('If a widget X contains no other widgets, then X is called what?',
('Ancestor', 'Leaf', 'Parent', 'Root'), 'Leaf'),
('If the widgets W and X are directly inside a container Y, then W is X\'s what?',
('Child', 'Parent', 'Sibling', 'Tree'), 'Sibling'),
]
PAUSE_TIME = 0.75 # seconds
class QuizzerApp(App):
DEFAULT_QUESTION = ('What is your favourite color?', ('Blue', 'Blue', 'Blue', 'Blue'), 'Blue')
questions = ListProperty([])
paused = BooleanProperty(False)
correct = BooleanProperty(False)
def build(self):
inspector.create_inspector(Window, self)
def on_start(self):
self.reshuffle()
def reshuffle(self):
questions = []
if self.root.ids.gui.active:
questions += GUI_QUESTIONS
elif self.root.ids.color.active:
questions += COLOR_QUESTIONS
elif self.root.ids.tree.active:
questions += TREE_QUESTIONS
shuffle(questions)
self.questions = questions
def answer(self, answer):
question = self.questions[-1] if len(self.questions) > 0 else self.DEFAULT_QUESTION
self.paused = True
self.correct = answer == question[2]
Clock.schedule_once(lambda delta: self.unpause(), PAUSE_TIME)
def unpause(self):
self.paused = False
if len(self.questions) > 0:
self.questions.pop()
if len(self.questions) == 0:
self.reshuffle()
if __name__ == '__main__':
app = QuizzerApp()
app.run()
ScreenManager:
Screen:
name: 'settings'
BoxLayout:
orientation: 'vertical'
Label:
text: 'Choose a topic:'
font_size: sp(24)
BoxLayout:
orientation: 'horizontal'
Widget:
CheckBox:
id: gui
group: 'categories'
active: True
size_hint: (None, None)
size: (sp(32), gui_label.height)
on_active: app.reshuffle()
Label:
id: gui_label
text: 'Graphical User Interfaces'
size_hint: (None, 1.0)
size: self.texture_size
Widget:
BoxLayout:
orientation: 'horizontal'
Widget:
CheckBox:
id: color
group: 'categories'
active: False
size_hint: (None, None)
size: (sp(32), color_label.height)
on_active: app.reshuffle()
Label:
id: color_label
text: 'RGBA Quadruples'
size_hint: (None, 1.0)
size: self.texture_size
Widget:
BoxLayout:
orientation: 'horizontal'
Widget:
CheckBox:
id: tree
group: 'categories'
active: False
size_hint: (None, None)
size: (sp(32), tree_label.height)
on_active: app.reshuffle()
Label:
id: tree_label
text: 'Containment Hierarchies'
size_hint: (None, 1.0)
size: self.texture_size
Widget:
BoxLayout:
Widget:
Button:
text: 'Begin!'
size_hint: (None, None)
size: (self.texture_size[0] + 64, self.texture_size[1] + 64)
on_press:
root.transition.direction = 'left'
root.current = 'quiz'
Widget:
Widget:
size_hint: (1.0, 0.5)
Screen:
name: 'quiz'
BoxLayout:
orientation: 'vertical'
Button:
text: 'Change Topic'
size_hint: (1, 0.25)
disabled: app.paused
on_press:
root.transition.direction = 'right'
root.current = 'settings'
Label:
text: 'Do you know…'
font_size: sp(24)
size_hint: (1, None)
size: (self.texture_size[0] + 64, self.texture_size[1] + 64)
Label:
text: (app.questions[-1] if len(app.questions) > 0 else app.DEFAULT_QUESTION)[0] if not app.paused else ('Correct!' if app.correct else 'Incorrect!')
text_size: (self.width, None)
halign: 'center'
color: (0.0, 0.0, 0.75, 1.0) if not app.paused else ((0.0, 1.0, 0.0, 1.0) if app.correct else (0.5, 0.0, 0.0, 1.0))
GridLayout:
rows: 2
Button:
text: (app.questions[-1] if len(app.questions) > 0 else app.DEFAULT_QUESTION)[1][0]
disabled: app.paused
on_press: app.answer(self.text)
Button:
text: (app.questions[-1] if len(app.questions) > 0 else app.DEFAULT_QUESTION)[1][1]
disabled: app.paused
on_press: app.answer(self.text)
Button:
text: (app.questions[-1] if len(app.questions) > 0 else app.DEFAULT_QUESTION)[1][2]
disabled: app.paused
on_press: app.answer(self.text)
Button:
text: (app.questions[-1] if len(app.questions) > 0 else app.DEFAULT_QUESTION)[1][3]
disabled: app.paused
on_press: app.answer(self.text)
# All screens are white.
<Screen>:
canvas.before:
Color:
rgba: (1.0, 1.0, 1.0, 1.0)
Rectangle:
pos: self.pos
size: self.size
# All labels are blue.
<Label>:
color: (0.0, 0.0, 0.75, 1.0)
# All checkboxes are blue.
<CheckBox>:
canvas:
Color:
rgba: (0.0, 0.0, 0.75, 1.0)
Rectangle:
source: f'atlas://data/images/defaulttheme/checkbox{"_radio" if self.group else ""}{"_disabled" if self.disabled else ""}{"_on" if self.active else "_off"}'
size: sp(32), sp(32)
pos: int(self.center_x - sp(16)), int(self.center_y - sp(16))
# All buttons have white text.
<Button>:
color: (1.0, 1.0, 1.0, 1.0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment