Skip to content
This repository was archived by the owner on Mar 31, 2020. It is now read-only.

Commit bcb5271

Browse files
committed
Splash layout
1 parent f6b55a5 commit bcb5271

File tree

3 files changed

+81
-50
lines changed

3 files changed

+81
-50
lines changed

src/animate.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,17 @@ def get_bounce(self):
146146
x1, y1, x2, y2 = self.canvas.bbox(self.id)
147147
bounce = Coord(0, 0)
148148
if x1 <= self.bound_x1:
149-
print('x1', x1, self.bound_x1)
149+
# print('x1', x1, self.bound_x1)
150150
bounce += Direction.RIGHT
151-
if y1 >= self.bound_y1:
152-
print('y1', y1, self.bound_y1)
153-
bounce += Direction.UP
151+
if y1 <= self.bound_y1:
152+
# print('y1', y1, self.bound_y1)
153+
bounce += Direction.DOWN
154154
if x2 >= self.bound_x2:
155-
print('x2', x2, self.bound_x2)
155+
# print('x2', x2, self.bound_x2)
156156
bounce += Direction.LEFT
157157
if y2 >= self.bound_y2:
158-
print('y2', y2, self.bound_y2)
159-
bounce += Direction.DOWN
158+
# print('y2', y2, self.bound_y2)
159+
bounce += Direction.UP
160160
return bounce
161161

162162
@property

src/splash.py

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,82 @@
55
from . import widget, DOCS
66

77

8-
class Question(widget.PrimaryFrame):
8+
class Splash(widget.PrimaryFrame):
99

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)
1312

14-
self.options = []
13+
def init(self):
14+
self.intro = Intro(self)
15+
self.intro.pack(fill='both', expand=True)
1516

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)
2119

22-
frame.pack()
23-
check.pack(side='left')
24-
val.pack(side='left')
20+
self.bounce(bouncer)
2521

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)
2828

29+
def next(self):
30+
pass
2931

30-
class Splash(widget.PrimaryFrame):
3132

33+
class Intro(widget.PrimaryFrame):
3234
intro = (DOCS / 'intro.txt').read_text()
33-
with (DOCS / 'questions.json').open() as fp:
34-
questions = json.load(fp)
3535

3636
def init(self):
3737
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'
4147
)
4248
self.intro = View(
4349
self.window,
4450
text=self.intro,
45-
width=self.window.winfo_reqwidth(),
51+
width=width,
4652
font=('sys', 12), justify='center'
4753
)
48-
self.window.set_view(self.intro)
54+
self.update()
4955

50-
self.btn_confirm = widget.PrimaryButton(self.window, command=self.begin, text='Okay')
56+
self.after(0, self.build)
5157

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+
)
5565

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)
6266

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)

src/view.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ def init(self):
1717
def __coord(self, id):
1818
return Coord(*self.coords(id))
1919

20-
def __set(self, view: View, coord: Coord):
21-
wid = view.draw(coord, anchor='nw')
20+
def __set(self, view: View, end: Coord):
21+
wid = view.draw(end, anchor='nw')
2222
self.current = view
2323
self.views[view] = wid
2424
return wid
2525

26-
def set_view(self, view: View, coord: Coord = None):
27-
return self.__set(view, coord or self.origin)
26+
def set_view(self, view: View, end: Coord = None):
27+
return self.__set(view, end or self.origin)
2828

2929
def move_view(self, view: View, end: Coord):
3030
wid = self.views.get(view)
@@ -33,11 +33,11 @@ def move_view(self, view: View, end: Coord):
3333
wid, end, speed=self.animation_speed
3434
)
3535

36-
def move_in(self, view: View, direction: Direction):
36+
def move_in(self, view: View, direction: Direction, end: Coord = None):
3737
distance = self.get_distance(direction)
3838
start = self.origin + distance
3939
wid = self.__set(view, start)
40-
self.move_view(view, self.origin)
40+
self.move_view(view, end or self.origin)
4141
return wid
4242

4343
def move_out(self, view: View, direction: Direction):
@@ -82,10 +82,19 @@ def active(self):
8282
def origin(self):
8383
return Coord(self.canvasx(0), self.canvasy(0))
8484

85+
@property
86+
def centery(self):
87+
self.update()
88+
return self.origin.midpoint(Coord(0, self.winfo_reqheight()))
89+
90+
@property
91+
def centerx(self):
92+
self.update()
93+
return self.origin.midpoint(Coord(self.winfo_reqwidth(), 0))
94+
8595
@property
8696
def center(self):
87-
br = self.origin + Coord(self.winfo_reqwidth(), self.winfo_reqheight())
88-
return self.origin.midpoint(br)
97+
return self.centerx + self.centery
8998

9099

91100
class DrawType(Enum):

0 commit comments

Comments
 (0)