|
5 | 5 | from . import widget, DOCS |
6 | 6 |
|
7 | 7 |
|
8 | | -class Question(widget.PrimaryFrame): |
| 8 | +class Splash(widget.PrimaryFrame): |
9 | 9 |
|
10 | | - def init(self): |
11 | | - self.title = widget.PrimaryLabel(self) |
12 | | - self.choices = widget.SecondaryFrame(self) |
| 10 | + with (DOCS / 'questions.json').open() as fp: |
| 11 | + questions = json.load(fp) |
13 | 12 |
|
14 | | - self.options = [] |
| 13 | + def init(self): |
| 14 | + self.intro = Intro(self) |
| 15 | + self.intro.pack(fill='both', expand=True) |
15 | 16 |
|
16 | | - def load(self, choices): |
17 | | - for question in questions: |
18 | | - frame = widget.SecondaryFrame(self.choices) |
19 | | - check = widget.PrimaryCheckbutton(frame) |
20 | | - val = widget.SecondaryLabel(frame, text=question) |
| 17 | + self.btn_confirm = widget.PrimaryButton(self.intro.window, command=self.next, text='Okay') |
| 18 | + bouncer = View(self.intro.window, window=self.btn_confirm) |
21 | 19 |
|
22 | | - frame.pack() |
23 | | - check.pack(side='left') |
24 | | - val.pack(side='left') |
| 20 | + self.bounce(bouncer) |
25 | 21 |
|
26 | | - self.title.pack(fill='both', expand=True) |
27 | | - self.choices.pack(fill='both', expand=True) |
| 22 | + def bounce(self, view): |
| 23 | + start = view.master.center + (Direction.LEFT * 175) + (Direction.DOWN * 100) |
| 24 | + wid = view.master.set_view(view, start) |
| 25 | + motion = BounceBall(view.master, wid, view.master.origin, speed=6) |
| 26 | + motion.kick(Direction.UP) |
| 27 | + self.after(0, view.master.run, motion) |
28 | 28 |
|
| 29 | + def next(self): |
| 30 | + pass |
29 | 31 |
|
30 | | -class Splash(widget.PrimaryFrame): |
31 | 32 |
|
| 33 | +class Intro(widget.PrimaryFrame): |
32 | 34 | intro = (DOCS / 'intro.txt').read_text() |
33 | | - with (DOCS / 'questions.json').open() as fp: |
34 | | - questions = json.load(fp) |
35 | 35 |
|
36 | 36 | def init(self): |
37 | 37 | self.window = Window(self, bg='gray') |
38 | | - self.title = widget.PrimaryLabel( |
39 | | - self, text=self.master.master.title(), |
40 | | - font=('Courier', 17), wraplength=300 |
| 38 | + self.window.pack(fill='both', expand=True) |
| 39 | + self.update() |
| 40 | + |
| 41 | + width = self.winfo_reqwidth() |
| 42 | + self.title = View( |
| 43 | + self.window, |
| 44 | + text=self.master.master.master.title(), # yikes |
| 45 | + font=('Courier', 17), |
| 46 | + width=width, justify='center' |
41 | 47 | ) |
42 | 48 | self.intro = View( |
43 | 49 | self.window, |
44 | 50 | text=self.intro, |
45 | | - width=self.window.winfo_reqwidth(), |
| 51 | + width=width, |
46 | 52 | font=('sys', 12), justify='center' |
47 | 53 | ) |
48 | | - self.window.set_view(self.intro) |
| 54 | + self.update() |
49 | 55 |
|
50 | | - self.btn_confirm = widget.PrimaryButton(self.window, command=self.begin, text='Okay') |
| 56 | + self.after(0, self.build) |
51 | 57 |
|
52 | | - self.title.pack(fill='both') |
53 | | - self.window.pack(fill='both') |
54 | | - self.bounce() |
| 58 | + def build(self): |
| 59 | + self.window.set_view(self.title) |
| 60 | + adjust = (Direction.LEFT * 175) + (Direction.DOWN * 100) |
| 61 | + self.window.set_view( |
| 62 | + self.intro, |
| 63 | + self.window.center + adjust |
| 64 | + ) |
55 | 65 |
|
56 | | - def bounce(self): |
57 | | - bouncer = View(self.window, window=self.btn_confirm) |
58 | | - wid = self.window.set_view(bouncer, self.window.center) |
59 | | - motion = BounceBall(self.window, wid, self.window.origin, speed=6) |
60 | | - motion.kick(Direction.DOWN) |
61 | | - self.after(0, self.window.run, motion) |
62 | 66 |
|
63 | | - def begin(self): |
64 | | - pass |
| 67 | +class Question(widget.PrimaryFrame): |
| 68 | + |
| 69 | + def init(self): |
| 70 | + self.title = widget.PrimaryLabel(self) |
| 71 | + self.choices = widget.SecondaryFrame(self) |
| 72 | + |
| 73 | + self.options = [] |
| 74 | + |
| 75 | + def load(self, choices): |
| 76 | + for question in questions: |
| 77 | + frame = widget.SecondaryFrame(self.choices) |
| 78 | + check = widget.PrimaryCheckbutton(frame) |
| 79 | + val = widget.SecondaryLabel(frame, text=question) |
| 80 | + |
| 81 | + frame.pack() |
| 82 | + check.pack(side='left') |
| 83 | + val.pack(side='left') |
| 84 | + |
| 85 | + self.title.pack(fill='both', expand=True) |
| 86 | + self.choices.pack(fill='both', expand=True) |
0 commit comments