-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApplication.py
More file actions
469 lines (355 loc) · 13.2 KB
/
Application.py
File metadata and controls
469 lines (355 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
#kivy modules
from kivy.uix.label import Label
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.popup import Popup
from kivy.uix.image import Image as Imag
from kivy.core.window import Window
from kivy.graphics import Color,Rectangle
import time
from kivy.clock import Clock
from fpdf import FPDF
from kivy.uix.dropdown import DropDown
from kivy.uix.scrollview import ScrollView
from kivy.uix.filechooser import FileChooserIconView
import pickle
import os
from PIL import Image
#For Screen colour
Window.clearcolor=(1,1,1,1)
#variable for different screens
w,h=Window.size
BG = Image.open("Font/base.png")
sizeOfSheet = BG.width
gap, _ = 0, 0
allowedChars = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM,.-?!() 1234567890'
def writee(char):
global gap, _
if char == '\n':
pass
else:
char.lower()
cases = Image.open("Font/%s.png" % char)
BG.paste(cases, (gap, _))
size = cases.width
gap += size
del cases
def letterwrite(word):
global gap, _
if gap > sizeOfSheet - 95 * (len(word)):
gap = 0
_ += 200
for letter in word:
if letter in allowedChars:
if letter.islower():
pass
elif letter.isupper():
letter = letter.lower()
letter += 'upper'
elif letter == '.':
letter = "fullstop"
elif letter == '!':
letter = 'exclamation'
elif letter == '?':
letter = 'question'
elif letter == ',':
letter = 'comma'
elif letter == '(':
letter = 'braketopn'
elif letter == ')':
letter = 'braketcls'
elif letter == '-':
letter = 'hiphen'
writee(letter)
def worddd(Input):
wordlist = Input.split(' ')
for i in wordlist:
letterwrite(i)
writee('space')
def pdf_creation(PNG_FILE, flag=False):
global name
rgba = Image.open(PNG_FILE)
rgb = Image.new('RGB', rgba.size, (255, 255, 255)) # white background
rgb.paste(rgba, mask=rgba.split()) # paste using alpha channel as mask
rgb.save(name+'.pdf',append=flag)
def needle(*args):
global f,s_y,n,yh,yg,sa,name
if n%2==0:
z=0
else:
z=0.5
if n>10 and n%2==0:
s_y+=0.18
sa.size_hint=(1,s_y)
yt=0.16
num=1
for i in btnlist:
i.size_hint_y=0.1/s_y
i.pos_hint=({"y":(s_y-yt)/s_y})
if num%2==0:
yt+=0.17
num+=1
yz=0.2
num=1
for j in lbllist:
j.size_hint_y=0.05/s_y
j.pos_hint=({"y":(s_y-yz)/s_y})
if num%2==0:
yz+=0.17
num+=1
if n%2==0 and n!=0:
yh+=0.17
yg+=0.17
nam=name+".pdf"
s_yy=s_y
lab1=Label(color=(0,0,0,1),text=nam,size_hint=(0.5,0.05/s_yy),pos_hint={'x':z,'y':(s_yy-yh)/s_yy})
sa.add_widget(lab1)
lbllist.append(lab1)
but=Button(background_normal= "Icon/pdf.png",size_hint=(0.2,0.1/s_yy),pos_hint={'x':z+0.15,'y':(s_yy-yg)/s_yy})
sa.add_widget(but)
btnlist.append(but)
n+=1
#scrren of logo(first)
class LOGO(FloatLayout):
def __init__(self,*args,**kwargs):
super().__init__(*args)
self.img=Imag(source="Icon/T2H.png",size=(w,h),pos=(0,0))
self.add_widget(self.img)
Clock.schedule_once(self.ss,5/1)
def ss(self,instance):
s.current = "2"
#screen for new pdf
class FIRST(FloatLayout):
def __init__(self,*args,**kwargs):
super().__init__(*args)
with self.canvas:
Color(0,0.5,1,1)
Rectangle(pos=(0,h*0.95),size=(w,h*0.05))
self.ti=TextInput(hint_text="Enter yout text here",size_hint=(0.7,0.5),pos_hint={'x':0.15,'y':0.4})
self.add_widget(self.ti)
self.bt=Button(font_size=30,text="Generate",size_hint=(0.4,0.07),pos_hint={'x':0.15,'y':0.27},background_normal="Icon/button.png")
self.add_widget(self.bt)
self.bt.bind(on_press=self.pop)
self.btt5=Button(font_size=30,text="Select",size_hint=(0.4,0.07),pos_hint={'x':0.45,'y':0.27},background_normal="Icon/button.png")
self.add_widget(self.btt5)
self.bt3=Button(size_hint=(0.1,0.05),pos_hint={'x':0.9,'y':0.95},background_normal="Icon/list.png")
self.add_widget(self.bt3)
self.img1=Imag(source="Icon/banner.png",size=(w,h*0.4),pos=(0,-0.37*h))
self.add_widget(self.img1)
self.bt5=Button(size_hint=(0.1,0.05),pos_hint={'x':0,'y':0.95},background_normal="Icon/info.png")
self.add_widget(self.bt5)
self.bt3.bind(on_press=self.shift)
self.bt5.bind(on_press=self.popinfo)
self.btt5.bind(on_press=self.openfile)
def shift(self,*args):
s.current="3"
def popinfo(self,*args):
f2=FloatLayout()
self.label=Label(markup=True,halign="center",valign="top",font_size=0.0185*h,text=""" [b][u]To use this application[/u]:-[/b]
-> Copy the text from source and paste in the "enter
text" window on the home screen.
-> Click on the generate button and name your PDF
file and save.
-> Your PDF will be generated along with picture of
every page in your gallery.
-> Or alternatively you can upload a txt file with text
in it and can get a PDF generated.
[u][b]Created by[/u]:-[/b]
Rahul Gothwal, Yugam Sachdeva
[b][u] Note[/u]:- [/b]
If you face any issue feel free to report issue at:
[b]https://bit.ly/T2H-RIS[/b]""",color=(0,0,0,1),size_hint=(1,1),pos_hint={'x':0,'y':0})
f2.add_widget(self.label)
pop1=Popup(title_color=(0,0.5,1,1),background="Icon/white.jpeg",content=f2,title="Information",size_hint=(0.8,0.8),pos_hint={'x':0.1,'y':0.1})
pop1.open()
def pop(self,instance):
global f,pop,d,pop4,pop3
try:
self.remove_widget(pop4)
self.remove_widget(pop3)
except:
pass
d=instance.text
if d=="Yes":
if file_text=='':
try:
self.remove_widget(self.llb)
except:
pass
self.lb=Label(text="File format is wrong or file is empty!",color=(0,0,0,1),size_hint=(1,0.05),pos_hint={'x':0,'y':0.33})
self.add_widget(self.lb)
else:
self.naming()
else:
try:
self.remove_widget(self.lb)
except:
pass
if self.ti.text=='':
self.llb=Label(text="Empty PDF can't be generated!",color=(0,0,0,1),size_hint=(1,0.05),pos_hint={'x':0,'y':0.33})
self.add_widget(self.llb)
else:
self.naming()
def naming(self,*args):
global pop,ff
ff=FloatLayout()
self.ti1=TextInput(hint_text="Enter PDF name",size_hint=(0.8,0.2),pos_hint={'x':0.1,'y':0.6})
ff.add_widget(self.ti1)
self.bt1=Button(text="Done",size_hint=(0.4,0.3),pos_hint={'x':0.3,'y':0.08},background_normal="Icon/button.png")
ff.add_widget(self.bt1)
self.bt1.bind(on_press=self.pdfgene)
pop=Popup(auto_dismiss=False,title_color=(0,0.5,1,1),background="Icon/white.jpeg",content=ff,title="Save PDF",size_hint=(0.8,0.3),pos_hint={'x':0.1,'y':0.3})
pop.open()
def openfile(self,*args):
global pop3
self.filechoose=FileChooserIconView(path=".")
pop3=Popup(title="File Manager",content=self.filechoose,size_hint=(1,1),pos_hint={'x':0,'y':0})
self.add_widget(pop3)
self.filechoose.bind(on_submit=self.pk)
def pk(self,a,path,b):
global pop3,file_text,pop4
f=FloatLayout()
self.ll=Label(color=(0,0,0,1),text="Do you want to covert this Doc into PDF?",size_hint=(1,0.5),pos_hint={'x':0,'y':0.5})
f.add_widget(self.ll)
self.yes=Button(text="Yes",font_size=30,size_hint=(0.4,0.25),pos_hint={'x':0.1,'y':0.2}, background_normal="Icon/button.png")
f.add_widget(self.yes)
self.yes.bind(on_press=self.pop)
self.no=Button(text="No",font_size=30,size_hint=(0.4,0.25),pos_hint={'x':0.5,'y':0.2}, background_normal="Icon/button.png")
f.add_widget(self.no)
self.no.bind(on_press=self.denied)
pop4=Popup(background="Icon/white.jpeg",title="Confirmation",title_color=(0,0.5,1,1),content=f,size_hint=(0.8,0.3),pos_hint={'x':0.1,'y':0.35})
self.add_widget(pop4)
for i in [".txt"]:
if path[0].endswith(i):
files=open(path[0],"r")
file_text=files.read()
else:
file_text=''
def denied(self,*args):
global pop4,name
self.remove_widget(pop4)
def pdfgene(self,instance):
global BG,sizeofSheet,allowedChars,gap,name,sa,d,pop
c=instance.text
daty=os.listdir('.')
pdf=self.ti1.text+".pdf"
if len(self.ti1.text)==0 or pdf in daty:
self.lb1=Label(text="Name is empty or already exist!",color=(0,0,0,1),size_hint=(1,0.05),pos_hint={'x':0,'y':0.38})
ff.add_widget(self.lb1)
else:
pop.dismiss()
try:
self.remove_widget(self.lb)
except:
pass
try:
if d=="Yes":
date=file_text
else:
date=self.ti.text
data = date.replace('\n', '')
name=self.ti1.text
with open(name+".pdf", 'w') as file:
pass
l = len(data)
nn = len(data) // 600
chunks, chunk_size = len(data), len(data) // (nn + 1)
p = [data[i:i + chunk_size] for i in range(0, chunks, chunk_size)]
for i in range(0, len(p)):
worddd(p[i])
writee('\n')
BG.save('%doutput.png' % i)
BG1 = Image.open("Font/base.png")
BG = BG1
gap = 0
_ = 0
except ValueError as E:
print("{}\nTry again".format(E))
imagelist = []
for i in range(0, len(p)):
imagelist.append('%doutput.png' % i)
try:
pdf_creation(imagelist.pop(0)[20])
for PNG_FILE in imagelist:
pdf_creation(PNG_FILE, flag=True)
except:
pass
needle()
self.ti.text=""
s.current="3"
#screen for list of pdf
class PDFLIST(FloatLayout):
def __init__(self,*args,**kwargs):
global s_y,n,yh,yg,sa,btnlist,lbllist
btnlist=[]
lbllist=[]
super().__init__(*args)
sel=ScrollView()
self.add_widget(sel)
dat=os.listdir('.')
data=[]
for item in range(len(dat)):
if dat[item].endswith(".pdf"):
data.append(dat[item])
n=len(data)
sa=FloatLayout()
s_y=1.02
if n<11:
pass
else:
s_y=s_y+(n-10)/11
sa.size_hint=(1,s_y)
with self.canvas:
Color(0,0.5,1,1)
Rectangle(pos=(0,0.95*h),size=(w,h*0.05))
self.bt2=Button(size_hint=(0.1,0.05),pos_hint={'x':0.9,'y':0.95},background_normal="Icon/add.png")
self.add_widget(self.bt2)
self.bt2.bind(on_press=self.change)
sel.do_scroll_x: False
sel.do_scroll_y: True
sel.scroll_y=1
sel.bar_width=5
sel.size=Window.size
sel.add_widget(sa)
yh=0.2
for i in range(n):
if i%2==0:
z=0
else:
z=0.5
lb=Label(color=(0,0,0,1),text=data[i],size_hint=(0.5,0.05/s_y),pos_hint={'x':z,'y':(s_y-yh)/s_y})
sa.add_widget(lb)
if i%2!=0:
yh=yh+0.17
lbllist.append(lb)
yg=0.16
for i in range(n):
if i%2==0:
z=0.15
else:
z=0.65
btn=Button(background_normal= "Icon/pdf.png",size_hint=(0.2,0.1/s_y),pos_hint={'x':z,'y':(s_y-yg)/s_y})
sa.add_widget(btn)
if i%2!=0:
yg=yg+0.17
btnlist.append(btn)
def change(self,*args):
s.current="2"
#main class
class profileapp(App):
def build(self):
return s
s=ScreenManager()
s1=Screen(name="1")
s1.add_widget(LOGO())
s2=Screen(name="2")
s2.add_widget(FIRST())
s3=Screen(name="3")
s3.add_widget(PDFLIST())
s.add_widget(s1)
s.add_widget(s2)
s.add_widget(s3)
profileapp().run()