11'''Jurassic Journalists'''
2+ from io import BytesIO
3+ from kivy .config import Config
4+ Config .set ('graphics' , 'resizable' , False ) # noqa
25from kivy .app import App
36from kivy .core .image import Image as CoreImage
47from kivy .uix .screenmanager import ScreenManager , Screen
58from kivy .uix .label import Label
9+ from kivy .uix .button import Button
610from 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
816from PIL import ImageDraw
917from 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
2932class 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+
4155class 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
103141class 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 ()
0 commit comments