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

Commit af501c3

Browse files
authored
Merge pull request #5 from HypoT/typewriter_bits
looks good
2 parents 692fb75 + d0f91b1 commit af501c3

File tree

11 files changed

+332
-183
lines changed

11 files changed

+332
-183
lines changed

jurassic-journalists/buttons.kv

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#:import Animation kivy.animation.Animation
2+
<TypeWriterButton@Button>:
3+
width: self.parent.width * 1/17
4+
height: self.parent.height * 1/23
5+
size_hint: None, None
6+
txt: ''
7+
background_normal: f'atlas://typewriter/{self.txt}' if self.txt else ''
8+
background_down: self.background_normal
9+
border: 0,0,0,0
10+
on_press: Animation(anim_y = self.anim_y - .005, d=.025, t='in_bounce').start(self); self.sound.play()
11+
# canvas.before:
12+
# Color:
13+
# rgba: (0,0,0,0) if self.state == 'normal' else (0,.7,.7,.1)
14+
# RoundedRectangle:
15+
# pos: self.pos
16+
# size: self.size
17+
# radius: 5,
18+
19+
<Row1@TypeWriterButton>:
20+
default_y: .175
21+
anim_y: .175
22+
23+
<Row2@TypeWriterButton>:
24+
default_y: .13
25+
anim_y: .13
26+
27+
<Row3@TypeWriterButton>:
28+
default_y: .08
29+
anim_y: .08
30+
31+
<PhoneButtons@Label>
32+
width: self.parent.width * 1/5
33+
height: self.parent.height * 1/10
34+
size_hint: None, None
35+

jurassic-journalists/click.wav

207 KB
Binary file not shown.
Lines changed: 10 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
#:import F kivy.factory.Factory
22
#:import Letter classes.Letter
3-
<TypeWriterButton@Button>:
4-
width: self.parent.width * 1/20
5-
height: self.parent.height * 1/20
6-
size_hint: None, None
7-
background_color: 0,0,0,0
8-
text_color: 0,0,0,0
9-
on_release: self.parent.typw.text += self.txt
10-
canvas.before:
11-
Color:
12-
rgba: (0,0,0,0) if self.state == 'normal' else (0,.7,.7,.1)
13-
RoundedRectangle:
14-
pos: self.pos
15-
size: self.size
16-
radius: 5,
3+
#:import random random.random
4+
#<Widget>:
5+
# canvas.after:
6+
# Color:
7+
# rgba: random(), random(), random()
8+
# Line:
9+
# rectangle: [self.x, self.y, self.width, self.height]
1710

18-
<PhoneButtons@Label>
19-
width: self.parent.width * 1/5
20-
height: self.parent.height * 1/10
21-
size_hint: None, None
22-
2311
<RoomScreen>:
2412
name: 'RoomScreen'
2513
canvas:
@@ -35,18 +23,15 @@
3523
Button:
3624
size_hint: None, None
3725
pos_hint: {'x': .7, 'y': .45}
38-
background_normal: 'paper.png'
39-
background_down: 'paper.png'
40-
on_release: F.TypeW().open()
26+
background_normal: 'typewriter.png'
27+
background_down: 'typewriter.png'
28+
on_release: F.TypeWriter().open()
4129

4230

4331
<MainScreen@ScreenManager>:
4432
RoomScreen
4533
PhoneScreen
4634

47-
48-
<TextPaper@Image>
49-
5035
<PhoneScreen>:
5136
name: 'PhoneScreen'
5237
typw2: typw2
@@ -106,129 +91,3 @@
10691
text: ''
10792
pos_hint: {'x': .6, 'y':0}
10893
disabled: True
109-
110-
111-
<TypeW@Popup>
112-
canvas.before:
113-
Color:
114-
rgba: 0,0,0,0
115-
Rectangle:
116-
pos: self.pos
117-
size: self.size
118-
canvas.after:
119-
Color:
120-
rgba: 1,1,1,.5
121-
Rectangle:
122-
pos: self.pos
123-
size: self.size
124-
source: 'paper.png'
125-
title: ''
126-
separator_color: 0,0,0,0
127-
FloatLayout:
128-
typw: typw
129-
GestureSurface:
130-
on_gesture_complete: typw.text += '_b'
131-
TextPaper:
132-
id: typw
133-
source: 'blank.png'
134-
pos_hint: {'x': 0.2, 'y':.5}
135-
size_hint: .7, .5
136-
allow_stretch: True
137-
letters: []
138-
text: ''
139-
on_text:
140-
self.letters.append(Letter(self.text[-1], 32, '1942.ttf')) if '_' not in self.text[-2:] else self.escaped()
141-
on_letters: self.update()
142-
TypeWriterButton:
143-
txt: 'q'
144-
pos_hint: {'x': .16, 'y':.175}
145-
TypeWriterButton:
146-
txt: 'w'
147-
pos_hint: {'x': .235, 'y':.175}
148-
TypeWriterButton:
149-
txt: 'e'
150-
pos_hint: {'x': .31, 'y':.175}
151-
TypeWriterButton:
152-
txt: 'r'
153-
pos_hint: {'x': .385, 'y':.175}
154-
TypeWriterButton:
155-
txt: 't'
156-
pos_hint: {'x': .46, 'y':.175}
157-
TypeWriterButton:
158-
txt: 'y'
159-
pos_hint: {'x': .535, 'y':.175}
160-
TypeWriterButton:
161-
txt: 'u'
162-
pos_hint: {'x': .61, 'y':.175}
163-
TypeWriterButton:
164-
txt: 'i'
165-
pos_hint: {'x': .685, 'y':.175}
166-
TypeWriterButton:
167-
txt: 'o'
168-
pos_hint: {'x': .76, 'y':.175}
169-
TypeWriterButton:
170-
txt: 'p'
171-
pos_hint: {'x': .835, 'y':.175}
172-
TypeWriterButton:
173-
txt: 'a'
174-
pos_hint: {'x': .2, 'y':.125}
175-
TypeWriterButton:
176-
txt: 's'
177-
pos_hint: {'x': .275, 'y':.125}
178-
TypeWriterButton:
179-
txt: 'd'
180-
pos_hint: {'x': .35, 'y':.125}
181-
TypeWriterButton
182-
txt: 'f'
183-
pos_hint: {'x': .425, 'y':.125}
184-
TypeWriterButton
185-
txt: 'g'
186-
pos_hint: {'x': .5, 'y':.125}
187-
TypeWriterButton:
188-
txt: 'h'
189-
pos_hint: {'x': .575, 'y':.125}
190-
TypeWriterButton:
191-
txt: 'j'
192-
pos_hint: {'x': .65, 'y':.125}
193-
TypeWriterButton:
194-
txt: 'k'
195-
pos_hint: {'x': .725, 'y':.125}
196-
TypeWriterButton:
197-
txt: 'l'
198-
pos_hint: {'x': .8, 'y':.125}
199-
TypeWriterButton:
200-
txt: 'z'
201-
pos_hint: {'x': .2, 'y':.08}
202-
TypeWriterButton:
203-
txt: 'x'
204-
pos_hint: {'x': .275, 'y':.08}
205-
TypeWriterButton:
206-
txt: 'c'
207-
pos_hint: {'x': .35, 'y':.08}
208-
TypeWriterButton:
209-
txt: 'v'
210-
pos_hint: {'x': .425, 'y':.08}
211-
TypeWriterButton:
212-
txt: 'b'
213-
pos_hint: {'x': .5, 'y':.08}
214-
TypeWriterButton:
215-
txt: 'n'
216-
pos_hint: {'x': .575, 'y':.08}
217-
TypeWriterButton:
218-
txt: 'm'
219-
pos_hint: {'x': .65, 'y':.08}
220-
TypeWriterButton:
221-
txt: ';'
222-
pos_hint: {'x': .725, 'y':.08}
223-
TypeWriterButton:
224-
txt: ':'
225-
pos_hint: {'x': .8, 'y':.08}
226-
TypeWriterButton:
227-
pos_hint: {'x': .2, 'y':0}
228-
size_hint: .65, None
229-
height: self.parent.height * 1/20
230-
txt: ' '
231-
TypeWriterButton:
232-
pos_hint: {'x': .85, 'y': .4}
233-
size_hint: .15, .15
234-
txt: '_n'

jurassic-journalists/main.py

Lines changed: 82 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
'''Jurassic Journalists'''
2+
from io import BytesIO
3+
from kivy.config import Config
4+
Config.set('graphics', 'resizable', False) # noqa
25
from kivy.app import App
36
from kivy.core.image import Image as CoreImage
47
from kivy.uix.screenmanager import ScreenManager, Screen
58
from kivy.uix.label import Label
9+
from kivy.uix.button import Button
610
from kivy.uix.image import Image
7-
from kivy.uix.widget import Widget
11+
from kivy.lang import Builder
12+
from kivy.properties import ListProperty, ObjectProperty, NumericProperty # noqa
13+
from kivy.core.window import Window
14+
from kivy.animation import Animation
15+
from kivy.core.audio import SoundLoader
816
from PIL import ImageDraw
917
from PIL import Image as Im
10-
from io import BytesIO
11-
from kivy.properties import ListProperty, ObjectProperty, NumericProperty
12-
from math import sin, cos, pi
13-
from kivy.core.window import Window
1418

15-
# Global Variable so there is no magic number.
16-
SCREEN_WIDTH = 720
17-
SCREEN_HEIGHT = 720
18-
PAPER_COLOR = (200, 200, 200, 0)
19-
STARTING_Y = SCREEN_HEIGHT - 150
2019

20+
# Global Variables
2121

22-
class JurassicJournalistApp(App):
23-
''' App Class '''
24-
def build(self):
25-
# Window.borderless = True
26-
return MainScreen()
22+
# Screen Dimensions
23+
SCREEN_WIDTH = 720
24+
SCREEN_HEIGHT = 1280
2725

26+
# Paper Dimensions
27+
STARTING_X = 50 # PAPER_WIDTH - 240
28+
STARTING_Y = 50 # PAPER_HEIGHT + 100
29+
PAPER_WIDTH = SCREEN_WIDTH * .7 - STARTING_X
30+
PAPER_HEIGHT = 720 # SCREEN_HEIGHT
2831

2932
class MainScreen(ScreenManager):
3033
''' ScreenManager '''
@@ -38,26 +41,42 @@ class PhoneScreen(Screen):
3841
''' Screen Two '''
3942

4043

44+
class TypeWriterButton(Button):
45+
sound = SoundLoader.load('click.wav')
46+
def on_release(self):
47+
self.parent.typw.text += self.txt
48+
if abs(self.anim_y - self.default_y) >= .01:
49+
Animation(anim_y = self.default_y, d=.025, t='out_bounce').start(self)
50+
else:
51+
Animation(anim_y = self.anim_y + .005, d=.025, t='out_bounce').start(self)
52+
53+
54+
4155
class TextPaper(Image):
4256
"""
43-
mesh_points = ListProperty([])
44-
mesh_texture = ObjectProperty(None)
45-
radius = NumericProperty(200)
46-
offset_x = NumericProperty(.5)
47-
offset_y = NumericProperty(.5)
48-
sin_wobble = NumericProperty(0)
49-
sin_wobble_speed = NumericProperty(0)
57+
TypeWriter Paper
5058
"""
5159
def __init__(self, *args, **kwargs):
5260
super().__init__(*args, **kwargs)
53-
61+
'''
62+
# actual screen size will be different, may need to adjust
63+
SCREEN_WIDTH, SCREEN_HEIGHT = Window.size
64+
PAPER_WIDTH = SCREEN_WIDTH * .7 - 50
65+
PAPER_HEIGHT = SCREEN_HEIGHT
66+
'''
5467
# Creating Blank Paper image to type on.
55-
self.img = Im.new("RGBA", (SCREEN_WIDTH, SCREEN_HEIGHT), PAPER_COLOR)
56-
68+
# self.img = Im.open("paper.png")
69+
# self.img.resize((int(SCREEN_WIDTH *.75), SCREEN_HEIGHT))
70+
self.img = Im.new('RGBA', (int(SCREEN_WIDTH *.75), PAPER_HEIGHT), (200,200,200,255))
71+
self.default_pos = 225, - (SCREEN_HEIGHT - PAPER_HEIGHT)//2 + STARTING_Y + 10
5772
# Type writer does not type from the top rather type from the bottom.
5873
self.txt = self.img.copy()
59-
self.head = {'x': 0, 'y': STARTING_Y}
74+
self.head = {'x': STARTING_X, 'y': STARTING_Y}
75+
self.pos = self.default_pos
76+
self.size = [PAPER_WIDTH, PAPER_HEIGHT]
6077

78+
self.first_letter = True
79+
self.font_size = None
6180
"""
6281
self.mesh_texture = CoreImage('paper.png').texture
6382
Clock.schedule_interval(self.update_points, 0)
@@ -83,22 +102,41 @@ def type(self, key):
83102
ImageDraw.Draw(self.txt).text((self.head["x"], self.head["y"]),
84103
key.char, font=key.font, fill=key.color)
85104
# Scrolling up
105+
106+
# Shoudln't move paper if it is the first letter of the line
107+
if self.first_letter:
108+
self.first_letter = False
109+
else:
110+
self.pos[0] -= (self.char_size)
111+
86112
self.font_size = key.font.getsize("l")[1]
87113
self.char_size = key.get_kerning()[0]
88114
self.head["x"] += self.char_size
89115

90-
if self.head["x"] + self.char_size >= SCREEN_WIDTH:
91-
self.head["x"] = 0
92-
self.head["y"] -= self.font_size
116+
if (self.head["x"] - STARTING_X) + self.char_size >= PAPER_WIDTH:
117+
self.head["x"] = STARTING_X
118+
self.head["y"] += self.font_size
119+
self.y += self.font_size
120+
#self.x = self.default_pos[0]
121+
122+
# 10 is to adjust the height. If you guys can investigate why it is not
123+
# matching the height and width of letter defined in kv file that would be great.
124+
line_height = self.head["y"] - STARTING_Y - 10
125+
self.pos = [self.default_pos[0], self.default_pos[1]+line_height]
126+
self.first_letter = True
93127

94128
def escaped(self):
95129
if not self.font_size:
96130
return
97131
if self.text[-2:] == '_b':
98132
self.head["x"] -= self.char_size
133+
self.x += self.char_size
99134
elif self.text[-2:] == '_n':
100-
self.head['y'] -= self.font_size
101-
self.head['x'] = 0
135+
self.head['y'] += self.font_size
136+
self.head['x'] = STARTING_X
137+
self.y += self.font_size
138+
self.x = self.default_pos[0]
139+
102140

103141
class PhoneButtons(Label):
104142
''' Phone Button/Label '''
@@ -123,4 +161,16 @@ def on_button_touch_down(self, touch):
123161
return True
124162

125163

126-
JurassicJournalistApp().run()
164+
class JurassicJournalistApp(App):
165+
''' App Class '''
166+
def build(self):
167+
Window.size = SCREEN_WIDTH, SCREEN_HEIGHT
168+
print(Window.size)
169+
Builder.load_file('buttons.kv')
170+
Builder.load_file('objects.kv')
171+
Window.borderless = True
172+
return MainScreen()
173+
174+
175+
if __name__ == '__main__':
176+
JurassicJournalistApp().run()

jurassic-journalists/nokia.png

511 KB
Loading

0 commit comments

Comments
 (0)