1
1
'''Jurassic Journalists'''
2
+ from io import BytesIO
3
+ from kivy .config import Config
4
+ Config .set ('graphics' , 'resizable' , False ) # noqa
2
5
from kivy .app import App
3
6
from kivy .core .image import Image as CoreImage
4
7
from kivy .uix .screenmanager import ScreenManager , Screen
5
8
from kivy .uix .label import Label
9
+ from kivy .uix .button import Button
6
10
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
8
16
from PIL import ImageDraw
9
17
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
14
18
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
20
19
20
+ # Global Variables
21
21
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
27
25
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
28
31
29
32
class MainScreen (ScreenManager ):
30
33
''' ScreenManager '''
@@ -38,26 +41,42 @@ class PhoneScreen(Screen):
38
41
''' Screen Two '''
39
42
40
43
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
+
41
55
class TextPaper (Image ):
42
56
"""
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
50
58
"""
51
59
def __init__ (self , * args , ** kwargs ):
52
60
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
+ '''
54
67
# 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
57
72
# Type writer does not type from the top rather type from the bottom.
58
73
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 ]
60
77
78
+ self .first_letter = True
79
+ self .font_size = None
61
80
"""
62
81
self.mesh_texture = CoreImage('paper.png').texture
63
82
Clock.schedule_interval(self.update_points, 0)
@@ -83,22 +102,41 @@ def type(self, key):
83
102
ImageDraw .Draw (self .txt ).text ((self .head ["x" ], self .head ["y" ]),
84
103
key .char , font = key .font , fill = key .color )
85
104
# 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
+
86
112
self .font_size = key .font .getsize ("l" )[1 ]
87
113
self .char_size = key .get_kerning ()[0 ]
88
114
self .head ["x" ] += self .char_size
89
115
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
93
127
94
128
def escaped (self ):
95
129
if not self .font_size :
96
130
return
97
131
if self .text [- 2 :] == '_b' :
98
132
self .head ["x" ] -= self .char_size
133
+ self .x += self .char_size
99
134
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
+
102
140
103
141
class PhoneButtons (Label ):
104
142
''' Phone Button/Label '''
@@ -123,4 +161,16 @@ def on_button_touch_down(self, touch):
123
161
return True
124
162
125
163
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 ()
0 commit comments