/
GUI4_Portrait.py
2839 lines (2406 loc) · 125 KB
/
GUI4_Portrait.py
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3
#coding = utf-8
import tkinter as tk
import pitalk
import picamera
import datetime
import math
import calendar
import logging
from PIL import Image, ImageTk
import subprocess
import shlex
import time
import os
import sys
############################## Icon ##########################################
class Icon:
def __init__(self):
try:
for file in sorted(os.listdir(path+'/Icons')):
icons.append(tk.PhotoImage(file=path + "/Icons/" + file))
except:
pass
################################## MainApp ###################################
class MainApp(pitalk.PiTalk, tk.Tk):
"""
This is a class for Creating Frames, Key Press Handling, Flags Checking,
Network Update and Call/SMS Logs
"""
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.ws = tk.Tk.winfo_screenwidth(self)
self.hs = tk.Tk.winfo_screenheight(self)
self.w = 480 #screen width
self.h = 800 #screen height
self.bar_width = 30 #width of the signal bar
self.bar_height = 20 #height of the signal bar
self.x = (self.ws/2) - (self.w/2) # x coordinate of the screen edge
self.y = (self.hs/2) - (self.h/2)
self.Fl_incoming = False
self.Fl_Auto_Answer = False
self.Fl_initialize = False
self.networkName = None
self.imei = None
self.geometry("%dx%d+%d+%d" %(self.w, self.h, self.x, self.y))
self.title("PiTalk")
if not self.ws > self.w:
self.attributes('-fullscreen', True)
self.config(cursor="none")
self.Topframe = tk.Frame(self, bg = "black")
self.Topframe.pack(side='top', fill = 'x', anchor = 'w')
for i in range(8):
self.Topframe.grid_columnconfigure(i, weight = 1)
self.networkLabel = tk.Label(self.Topframe, text ="",bg = "black",
fg = "OliveDrab1", font = ("Helvetica",14))
self.networkLabel.grid(row = 0, column = 0, columnspan = 3 ,
sticky = "w")
self.timeLabelTop = tk.Label(self.Topframe, text = "",bg = "black",
fg = "tomato", font = ("Helvetica",14))
self.timeLabelTop.grid(row = 0, column = 3, columnspan = 3,
padx = (0, 70))
self.callLabelTop = tk.Label(self.Topframe,bg = "black")
self.callLabelTop.place(x=350, y=0)
self.msgLabelTop = tk.Label(self.Topframe, bg = "black")
self.msgLabelTop.place(x=390,y=0)
self.signal = tk.Canvas(self.Topframe, width=self.bar_width,
height=self.bar_height, bg= "black",
highlightthickness=0, bd=0)
self.signal.grid(row = 0, column = 7, sticky = "e")
container = tk.Frame(self,height=800, width=480, bg = "black")
container.pack(fill = 'both', expand = True)
container.grid_rowconfigure(0, weight = 1)
container.grid_columnconfigure(0, weight = 1)
Icon()
self.messageData=[]
self.frames = {}
for F in (HomeFrame, Menu1Frame, Menu2Frame, CallFrame,
CallIncomingFrame, CamFrame, MessageFrame, InboxBodyFrame,
InboxFrame, CreateSMSFrame,DeleteSMSFrame, StopwatchFrame,
SettingsFrame, GUIRotateFrame, CallSettingFrame,
CalendarFrame, AudioFrame, AboutFrame, SIMFrame, GalleryFrame,
CalculatorFrame, SensorFrame, PiFrame, InternetFrame,
ShutdownFrame, HDMIFrame, LogFrame, LocationFrame,
TemplateFrame):
frame_name = F.__name__
frame = F(parent = container, controller = self)
self.frames[frame_name] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("HomeFrame")
self.logframe = self.get_frame("LogFrame")
self.update_network()
self.check_flags()
def show_frame(self, frame_name):
"""
This function raise the frame on Top
Args:
frame_name: Name of the Frame
"""
global Gframename
Gframename = frame_name
frame = self.frames[frame_name]
frame.tkraise()
def get_frame(self, frame_name):
"""
This function returns the address of given frame
Args:
frame_name: Name of the Frame
Return:
Address of frame_name
"""
return self.frames[frame_name]
def check_flags(self):
""" This function handles incoming call, call disconnect and SMS """
if phone.incomingCall == True:
self.Fl_incoming = True
self.retFrame = self.get_frame("CallIncomingFrame")
self.retFrame.number.config(text = phone.callerID)
self.show_frame("CallIncomingFrame")
if phone.callConnected == True and self.Fl_Auto_Answer == True:
self.Fl_Auto_Answer = False
frame = self.get_frame("CallIncomingFrame")
frame.call_connect()
elif phone.callDisconnected and self.Fl_incoming:
self.retFrame.Fl_incoming_call_start = False
self.retFrame.timer.config(text="00:00:00")
self.retFrame.hour = 0
self.retFrame.min = 0
self.retFrame.second = 0
self.retFrame.connect.config(state = "normal")
phone.callDisconnected = False
self.Fl_incoming = False
self.show_frame("HomeFrame")
elif (phone.flag_newSMS):
phone.flag_newSMS = False
self.messageData.append(phone.messageList)
self.retFrame = self.get_frame("InboxFrame")
self.retFrame.update_inbox()
self.msgLabelTop.configure(image = icons[26])
self.Fl_newSMS = True
phone.messageList = []
else:
pass
self.after(1000, self.check_flags)
def update_network(self):
""" Update network and status bar after every 5 seconds"""
if self.Fl_initialize == False and phone.alive == False:
phone.connect()
self.signal.config(bg="black")
if self.Fl_initialize == False and phone.alive == True:
self.networkName = phone.networkName()
self.networkLabel.config(text = self.networkName)
self.imei = int(phone.imei())
self.Fl_initialize = True
if self.Fl_initialize == True and phone.alive == False:
self.networkLabel.config(text="No Power", fg="tomato")
self.signal.config(bg="red4")
self.Fl_initialize = False
elif self.Fl_initialize == True:
network = phone.signalStrength()
if int(network) >= 2 and int(network) <= 9:
signal = [1]
elif int(network) >= 10 and int(network) <= 14:
signal = [1, 2]
elif int(network) >= 15 and int(network) <= 19:
signal = [1, 2, 3]
elif int(network) >= 20 and int(network) <= 24:
signal = [1, 2, 3, 4]
elif int(network) >= 25 and int(network) <= 30:
signal = [1, 2, 3, 4, 5]
y_stretch = 4
y_gap = 1
x_stretch = 2
x_width = 5
x_gap = 1
for x, y in enumerate (signal):
x0 = x * x_stretch + x * x_width + x_gap
y0 = self.bar_height - (y * y_stretch + y_gap)
x1 = x * x_stretch + x * x_width + x_width + x_gap
y1 = self.bar_height - y_gap
self.signal.create_rectangle(x0, y0, x1, y1, fill="OliveDrab1")
self.after(5000, self.update_network)
def call_log(self, logPath, data):
""" This function make the call logs """
if self.logframe.Fl_logs:
file = open(logPath,"a")
width = (1,15,14,22)
data = ('\n', data, time.strftime('%H:%M:%S'),
time.strftime('%A %d/%m/%Y'))
number = "".join("%*s" % i for i in zip(width,data))
file.write(number)
file.close()
def message_log(self, logPath, data):
""" This function make the SMS logs """
if self.logframe.Fl_logs:
file = open(logPath,"a")
file.write(data[0] + '\t\t')
file.write(data[1] + '\n')
file.write(data[2])
file.write('\n\n\n')
file.close()
################################### HomeFrame #################################
class HomeFrame(tk.Frame):
""" This class handles HomeFrame, Clock update and color change of box """
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
tk.Frame.config(self, bg="black")
self.controller = controller
self.index = 0
self.COLOR = ['RoyalBlue1', 'gray60', 'violet', 'cyan2']
self.canvas = tk.Canvas(self,bg="black",width = 480, height = 480,
highlightthickness=0,bd=0)
self.circle = self.canvas.create_rectangle(99,140,370,350,
outline="tomato",width=7)
self.canvas.grid(row = 0, column = 0, rowspan = 3,columnspan = 3)
for i in range(3):
self.grid_rowconfigure(i, weight = 1)
self.grid_columnconfigure(i, weight = 1)
self.dateLabel = tk.Text(self,bg = "black", fg = "yellow" ,height = 8,
width = 25, bd = 0, highlightthickness = 0,
font = 20)
self.dateLabel.grid(row = 1, column = 1, padx = (7,0), pady = (13,0))
self.call = tk.Button(self, text = "Call", image=icons[4],bg = "black",
fg = "white", font = ("bold", 15), bd = 0,
highlightbackground = "black", compound="top",
activebackground = "black",
activeforeground = "white",
command = lambda:
controller.show_frame("CallFrame"))
self.call.grid(row = 3, column = 0, pady=(0,5))
self.menu = tk.Button(self, image=icons[22],text = "Menu",bg = "black",
fg = "white",font = ("bold", 15), bd = 0,
highlightbackground = "black",compound="top",
activebackground = "black",
activeforeground = "white",
command = lambda:
controller.show_frame("Menu1Frame"))
self.menu.grid(row=3, column = 1,pady=(0,5))
self.camera = tk.Button(self,image=icons[8], text = "Camera",
bg = "black", fg = "white", font = ("bold", 15),
bd = 0, highlightbackground = "black",
compound="top", activebackground = "black",
activeforeground = "white",
command =lambda:
controller.show_frame("CamFrame"))
self.camera.grid(row = 3, column = 2, pady=(0,5))
self.update_Clock()
self.update_color()
'''
@ Func: update_Clock
@ Desc: Updates the clock per second
'''
def update_Clock(self):
timeNow = time.strftime('%H:%M:%S')
if Gframename != "HomeFrame":
self.controller.timeLabelTop.configure(text= timeNow)
else:
self.controller.timeLabelTop.configure(text="")
dateNow = time.strftime('%A\n %d/%m/%Y')
self.dateLabel.delete(1.0, "end")
self.dateLabel.insert(1.0, "\n"+timeNow+"\n\n"+dateNow)
self.dateLabel.tag_add("time", "2.0", "2.12")
self.dateLabel.tag_config("time" ,foreground = "tomato",
background = "black",font = ("bold",30),
justify = "center")
self.dateLabel.tag_add("date", "3.0", "end")
self.dateLabel.tag_config("date" ,justify = "center",
foreground = "gold", font = ("bold",15))
self.after(1000, self.update_Clock)
def update_color(self):
""" Update color after every 10 seconds """
self.canvas.itemconfig(self.circle, outline=self.COLOR[self.index])
self.index += 1
if self.index >= len(self.COLOR):
self.index = 0
self.after(10000, self.update_color)
#################################### Menu1Frame ##############################
class Menu1Frame(tk.Frame):
""" This class handle Menu1 Frame """
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
BUTTON = [# Text Image Frame Row Col
("Call", icons[4], "CallFrame" , 0, 0),
("Message", icons[17], "MessageFrame" , 0, 1),
("Camera", icons[8], "CamFrame" , 0, 2),
("Internet", icons[19], "InternetFrame" , 1, 0),
("Gallery", icons[13], "GalleryFrame" , 1, 1),
("Settings", icons[32], "SettingsFrame" , 1, 2),
("Stopwatch", icons[38], "StopwatchFrame" , 2, 0),
("Location", icons[14], "LocationFrame" , 2, 1),
("Calculator", icons[2], "CalculatorFrame" , 2, 2),
("<<", None, "HomeFrame" , 3, 0),
(None, icons[16], "HomeFrame" , 3, 1),
(">>", None, "Menu2Frame" , 3, 2),
]
for i in range(4):
self.grid_rowconfigure(i, weight = 1)
if i <= 2:
self.grid_columnconfigure(i, weight = 1)
for b in range(len(BUTTON)):
cmd = lambda x=BUTTON[b][2]: controller.show_frame(x)
tk.Button(self, text = BUTTON[b][0],bg = "white", fg = "black",
font = ("Helvetica", 15), bd = 0,
highlightbackground = "white",activebackground = "white",
activeforeground = "black", image = BUTTON[b][1],
compound = 'top',
command = cmd).grid(row = BUTTON[b][3],
column = BUTTON[b][4],
sticky ="nsew",ipadx = 0, ipady = 0)
############################### Menu2Frame ###################################
class Menu2Frame(tk.Frame):
""" This class handle Menu2 Frame """
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
tk.Frame.config(self, bg="white")
BUTTON = [# Text Image Frame Row Col
("Audio", icons[1], "AudioFrame", 0, 0),
("Sensor", icons[50], "SensorFrame", 0, 1),
("Inside Pi", icons[18], "PiFrame", 0, 2),
("Calendar", icons[3], "CalendarFrame", 1, 0),
("SIM Info", icons[33], "SIMFrame", 1, 1),
("About Us", icons[0], "AboutFrame", 1, 2),
("Your Apps", icons[45], "TemplateFrame", 2, 0),
("<<", None, "Menu1Frame", 3, 0),
(None, icons[16], "HomeFrame", 3, 1),
(">>", None, "Menu2Frame", 3, 2),
]
for i in range(4):
self.grid_rowconfigure(i, weight = 1)
if i <= 2:
self.grid_columnconfigure(i, weight = 1)
for b in range(len(BUTTON)):
cmd = lambda x=BUTTON[b][2]: controller.show_frame(x)
tk.Button(self, text = BUTTON[b][0],bg = "white", fg = "black",
font = ("Helvetica", 15), bd = 0,
highlightbackground = "white",activebackground = "white",
activeforeground = "black", image = BUTTON[b][1],
compound = 'top',
command = cmd).grid(row = BUTTON[b][3],
column = BUTTON[b][4],
sticky ="nsew" ,ipadx = 0, ipady = 0)
################################## CallFrame #################################
class CallFrame(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
tk.Frame.config(self, bg="black")
self.controller = controller
self.buttons = []
BUTTON = [# text anchor row col
("1", "e", 1, 0), ("2", "center", 1, 1), ("3", "w", 1, 2),
("4", "e", 2, 0), ("5", "center", 2, 1), ("6", "w", 2, 2),
("7", "e", 3, 0), ("8", "center", 3, 1), ("9", "w", 3, 2),
("*", "e", 4, 0), ("0", "center", 4, 1), ("#", "w", 4, 2)]
for i in range(6):
self.grid_rowconfigure(i, weight = 1)
if i <= 2:
self.grid_columnconfigure(i, weight = 1)
self.diallednumber = tk.Entry(self, font = ('bold', 30),
justify="right",fg='RoyalBlue1')
self.diallednumber.grid(row = 0, column = 0, columnspan =3,
sticky = "nsew")
for b in range(12):
cmd = lambda x=BUTTON[b][0]: self.dial_Entry(x)
self.buttons.append(tk.Button(self,text=BUTTON[b][0],
font=('bold',20),
highlightbackground="black",
activebackground = "black",
anchor = BUTTON[b][1],
activeforeground="white",
bg="black",fg="white",bd=0,
command = cmd))
self.buttons[b].grid(row=BUTTON[b][2],column=BUTTON[b][3],
sticky="nsew")
self.buttons.append(tk.Button(self, image = icons[5],bd=0,
bg = "black", fg = "white",
highlightbackground = "black",
activebackground = "black",
activeforeground = "white",
command = self.outgoing_Call))
self.buttons[-1].grid(row = 5, column = 0, sticky ="nsew", pady=(0,10))
self.buttons.append(tk.Button(self, image = icons[16],bd=0,bg = "black",
fg = "white",
highlightbackground = "black",
activebackground = "black",
activeforeground = "white",
command = lambda:
controller.show_frame("HomeFrame")))
self.buttons[-1].grid(row = 5, column = 1, sticky ="nsew", pady=(0,10))
self.buttons.append(tk.Button(self, image = icons[11],bd=0,bg = "black",
fg = "white",highlightbackground = "black",
activebackground = "black",
activeforeground = "white",
command = self.dial_Delete))
self.buttons[-1].grid(row = 5, column = 2, sticky ="nsew", pady=(0,10))
def dial_Entry(self, args):
''' Enables the entry widget to get values from the dialpad '''
self.diallednumber.insert("end", args)
def dial_Delete(self):
''' deletes a single character in the dialler entry '''
self.txt=self.diallednumber.get()[:-1]
self.diallednumber.delete(0,"end")
self.diallednumber.insert(0,self.txt)
def outgoing_Call(self):
""" This function handle outgoing call and logging of outgoing call """
global Fl_outgoing_Call
if len(self.diallednumber.get()):
self.number = self.diallednumber.get()
self.diallednumber.delete(0,"end")
self.diallednumber.grid_remove()
for index in range(len(self.buttons)):
self.buttons[index].grid_remove()
tk.Frame.config(self, bg="white")
phone.dial(int(self.number))
self.controller.callLabelTop.config(image = icons[52])
self.outgoingcall = tk.Label(self, text = "Outgoing Call",
font = ("bold",25), fg = "tomato",
bg = "white")
self.outgoingcall.grid(row = 0, column = 0, columnspan = 7,
sticky = "s")
self.dialnumber = tk.Label(self, text = self.number,
font = ("normal",20), fg = "gray30",
bg = "white")
self.dialnumber.grid(row = 1, column = 0, columnspan = 7,padx=50,
pady=20, sticky = "n")
self.hangup = tk.Button(self, image = icons[6],bd=0,bg = "white",
fg = "black",highlightbackground = "white",
activebackground = "white",
activeforeground = "white",
command = self.call_Hangup)
self.hangup.grid(row = 3, column = 0, pady = (0, 20))
self.headfone = tk.Button(self,image = icons[15],bd=0, bg = "white",
fg = "black",highlightbackground = "white",
activebackground = "white",
activeforeground = "white",
command = lambda: self.audio_mode(1))
self.headfone.grid(row = 3, column = 1, pady = (0, 20))
self.speaker = tk.Button(self, image = icons[34],bd=0, bg = "white",
fg = "black",highlightbackground = "white",
activebackground = "white",
activeforeground = "white",
command = lambda :self.audio_mode(2))
self.speaker.grid(row = 3, column = 2,pady = (0, 20))
self.controller.call_log(path + '/Logs/Call/Outgoing.txt', self.number)
self.label = tk.Label(self, text = "", fg = "white", bg = "white",
font=("Helvetica", 15))
self.label.place(x = 170, y =600 )
def audio_mode(self, args):
""" Handle audio mode selection during outgoing call """
if args == 1:
self.label.place(x = 170, y =600 )
phone.jackMode()
self.label.config(text = "Headphone Mode", fg = "gold3")
self.label.after(1000, self.label.place_forget)
else:
self.label.place(x = 170, y =600 )
phone.speakerMode()
self.label.config(text = "Speaker Mode", fg = "green")
self.label.after(1000, self.label.place_forget)
def call_Hangup(self):
""" Disconnect the outgoing call and go back to HomeFrame """
phone.hangup()
self.controller.callLabelTop.config(image = "")
Fl_outgoing_Call = False
self.outgoingcall.grid_forget()
self.dialnumber.grid_forget()
self.hangup.grid_forget()
self.headfone.grid_forget()
self.speaker.grid_forget()
self.label.grid_forget()
tk.Frame.config(self, bg="black")
self.diallednumber.grid()
for index in range(len(self.buttons)):
self.buttons[index].grid()
self.controller.show_frame("HomeFrame")
##################################### CallIncomingFrame ######################
class CallIncomingFrame(tk.Frame):
""" This class handle the Incoming Calls and Logging of Incoming Call """
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
tk.Frame.config(self, bg="black")
self.controller = controller
self.hour = 00
self.minute = 00
self.second = 00
self.Fl_incoming_call_start = False
for j in range (5):
self.grid_columnconfigure(j, weight = 1)
if j <= 4:
self.grid_rowconfigure(j, weight = 1)
self.incominglabel = tk.Label(self, text = "Incoming Call", fg = "gold3",
bg = "black", font = ("bold",20))
self.incominglabel.grid(row = 0, column = 0, columnspan = 5)
self.number = tk.Label(self, text = "",fg = "red4", bg = "black" ,
font = ("bold", 22))
self.number.grid(row = 1, column = 0, columnspan = 5)
self.timer = tk.Label(self, text = "00:00:00", font = ("bold",18),
bg = "black", fg = "white")
self.timer.grid(row = 2, column = 0, columnspan =5)
self.hangup = tk.Button(self, image = icons[6],bg = "black",fg = "black",
bd = 0, highlightbackground = "black",
activebackground = "black",
command = self.call_hangup)
self.hangup.grid(row = 4, column = 4)
self.headfone = tk.Button(self,image = icons[15],bd=0, bg = "black",
fg = "black",highlightbackground = "black",
activebackground = "black",
activeforeground = "black",
command = lambda: self.audio_mode(1))
self.headfone.grid(row = 4, column = 1)
self.speaker = tk.Button(self, image = icons[34],bd=0, bg = "black",
fg = "black",highlightbackground = "black",
activebackground = "black",
activeforeground = "black",
command = lambda :self.audio_mode(2))
self.speaker.grid(row = 4, column = 3)
self.connect = tk.Button(self, image = icons[51],bg = "black",
fg = "black", bd = 0,
highlightbackground = "black",
activebackground = "black",
command = self.call_connect)
self.connect.grid(row = 4, column = 0)
self.label = tk.Label(self, text = "", fg = "black", bg = "black",
font=("Helvetica", 15))
self.label.place(x = 170, y =600 )
def audio_mode(self, args):
""" Handle audio mode selection during Incoming Call """
if args == 1:
self.label.place(x = 170, y =600 )
phone.jackMode()
self.label.config(text = "Headphone Mode", fg = "gold3")
self.label.after(1000, self.label.place_forget)
else:
self.label.place(x = 170, y =600 )
phone.speakerMode()
self.label.config(text = "Speaker Mode", fg = "Deep sky blue")
self.label.after(1000, self.label.place_forget)
def call_hangup(self):
""" Disconnect the Incoming Call and back to HomeFrame """
phone.hangup()
phone.incomingCall = False
self.Fl_incoming_call_start = False
self.timer.config(text="00:00:00")
self.hour = 00
self.minute = 00
self.second = 00
self.connect.config(state = "normal")
self.controller.show_frame("HomeFrame")
def call_connect(self):
""" Function connec the incoming call and make log """
self.Fl_incoming_call_start = True
self.connect.config(state = "disable")
phone.connectCall()
self.call_time_counter()
self.controller.call_log(path+'/Logs/Call/Incoming.txt',phone.callerID)
def call_time_counter(self):
""" Call time counter """
if(self.Fl_incoming_call_start):
self.timer.configure(text="%02d:%02d:%02d"\
%(self.hour,self.minute, self.second))
self.second=self.second+1
if self.second == 60:
self.minute=self.minute+1 ; self.second = 0
elif self.minute == 60:
self.hour = self.hour + 1; self.minute = 0
self.after(999, self.call_time_counter)
else:
self.hour = 00
self.minute = 00
self.second = 00
################################# MessageFrame ###############################
class MessageFrame(tk.Frame):
""" This class handle Message Frame and makes buttons """
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
tk.Frame.config(self, bg="white")
self.controller = controller
self.grid_columnconfigure(0, weight = 1)
for i in range(6):
self.grid_rowconfigure(i, weight = 1)
BUTTON = [# Text Image Frame Row Col
("Create New", icons[20], "CreateSMSFrame", 0, 0),
("Inbox", icons[23], "InboxFrame", 1, 0),
("Sent Message", icons[25], "PiFrame", 2, 0),
("Delete", icons[21], "DeleteSMSFrame", 3, 0),
]
for b in range(len(BUTTON)):
cmd = lambda x=BUTTON[b][2]: controller.show_frame(x)
tk.Button(self,text=BUTTON[b][0],bg="white", fg = "black",bd = 0,\
highlightbackground = "white", activebackground = "white",\
activeforeground="black",image=BUTTON[b][1],
compound = 'left',anchor = "w",font=("Helvetica", 15),
command = cmd).grid(row = BUTTON[b][3],
column=BUTTON[b][4], sticky ="nsew")
home=tk.Button(self,bg="white",fg="white",bd=0,
highlightbackground="white",
activebackground="white",
activeforeground="black",
command=lambda:
controller.show_frame("HomeFrame"),
image=icons[16])
home.grid(row=5,column=0,sticky="new")
################################### InboxFrame ###############################
class InboxFrame(tk.Frame):
""" This class handle Inbox messages and make log """
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
tk.Frame.config(self,bg="black")
self.controller = controller
self.canvas = tk.Canvas(self, bg = "black", borderwidth = 0)
canvas = self.canvas
self.frame = tk.Frame(canvas, bg = "black")
self.vsb = tk.Scrollbar(self, orient = "vertical",
command = canvas.yview, width = 20)
canvas.configure(yscrollcommand = self.vsb.set)
self.vsb.pack(side = "right", fill = "y")
canvas.pack(side = "left", fill = "both", expand = True)
canvas.create_window((0,0), window = self.frame, width = 480,
anchor = "nw")
self.frame.bind("<Configure>", lambda event, canvas = canvas:
self.onFrameConfigure(canvas))
self.index = 0
self.incomingSMS = []
self.frame.grid_columnconfigure(0, weight = 1)
self.home = tk.Button(self.frame,image=icons[16],bg="black",
anchor="center",bd = 0,
highlightbackground = "black",
activeforeground = "black",
activebackground = "black",
command = lambda:
controller.show_frame("HomeFrame"))
self.home.grid(row = self.index+1, column = 0)
self.textframe = self.controller.get_frame("InboxBodyFrame")
def onFrameConfigure(self, canvas):
""" Scrolling of messages """
canvas.configure(scrollregion = canvas.bbox("all"))
def update_inbox(self):
""" Update inbox list and make log """
self.controller.message_log(path + '/Logs/Message/Inbox.txt',
self.controller.messageData[-1])
self.incomingSMS.append(tk.Button(self.frame,font = ("Helvetica", 15),
bg = "gold2",fg = "black",
activeforeground = "white",
activebackground = "black",
text = self.controller.messageData\
[self.index][0]+"\t "+\
self.controller.messageData\
[self.index][1],
command = lambda index=self.index:
self.textframe.open_sms(index)))
self.incomingSMS[-1].grid(row = self.index, column = 0, sticky = "nsew")
self.home.grid(row = self.index+1, column = 0, sticky = "nsew")
self.index = self.index+1
################################### InboxBodyFrame ###########################
class InboxBodyFrame(tk.Frame):
""" This class handle reading of Inbox SMS """
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
tk.Frame.config(self,bg="black")
self.controller = controller
self.index = 0
for i in range(4):
self.grid_rowconfigure(i, weight = 1)
if i < 3:
self.grid_columnconfigure(i, weight = 1)
def open_sms(self, args):
""" Open message text, Number and date-time """
self.controller.show_frame("InboxBodyFrame")
inbox = self.controller.get_frame("InboxFrame")
inbox.incomingSMS[args].config(fg = "white", bg = "black")
self.numberSMS = tk.Label(self, text = self.controller.messageData[args][0],\
bg = "black", fg= "DarkGoldenrod3", font = ("bold",18))
self.numberSMS.grid(row = 0, column = 0,columnspan = 3,sticky = "nsew")
self.datetime=tk.Label(self,text=self.controller.messageData[args][1],
bg = "black", fg= "tomato", font = ("bold",14))
self.datetime.grid(row = 1, column = 0,columnspan = 3,sticky = "nsew")
self.bodySMS = tk.Text(self,bg = "white", fg= "black", height = 10,
width = 35,font = ("Helvetica", 10))
self.bodySMS.delete(1.0, "end")
self.bodySMS.insert(1.0, self.controller.messageData[args][2])
self.bodySMS.grid(row = 2, column = 0, columnspan = 3,
padx=40, sticky = "nsew")
self.reply = tk.Button(self,text = "Reply",font= ("bold", 15),
bg = "white",bd = 0,highlightbackground="white",
activeforeground = "black",
activebackground = "white",command=lambda
args=args: self.reply_msg(args))
self.reply.grid(row = 3, column = 1)
self.back = tk.Button(self, bg="black",bd=0,highlightbackground="black",
activeforeground="black",activebackground="black",
image = icons[30], command = lambda :
self.controller.show_frame("InboxFrame"))
self.back.grid(row = 3, column = 0)
self.backtohome = tk.Button(self, image = icons[16], bg="black",bd = 0,
highlightbackground = "black",
activeforeground = "black",
activebackground = "black",
command = lambda:
self.controller.show_frame("HomeFrame"))
self.backtohome.grid(row = 3, column = 2)
self.controller.msgLabelTop.configure(image = "")
def reply_msg(self, args):
reply = self.controller.get_frame("CreateSMSFrame")
reply.recipient.insert("end", self.controller.messageData[args][0])
self.controller.show_frame("CreateSMSFrame")
############################## CreateSMSFrame ################################
class CreateSMSFrame(tk.Frame):
""" This class create new SMS and make qwerty keypad """
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.buttonData = []
self.buttonCharData = []
self.buttonCapsData = []
self._buttoncount = 0
self._buttonCharcount = 0
self.letter = ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p",
"a", "s", "d", "f", "g", "h", "j", "k", "l", ":",
".", "z", "x", "c", "v", "b", "n", "m", "$", ","]
self.letterCaps = ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
"A", "S", "D", "F", "G", "H", "J", "K", "L", ":",
".", "Z", "X", "C", "V", "B", "N", "M", "$", ","]
self.specialChar = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
"~", "!", "@", "#", "%", "^", "&", "(", ")", ":",
'"', "+", "=", "/", ";", "[", "]", "?", "<", ">"]
for j in range(10):
self.grid_columnconfigure(j, weight = 1)
if j <= 5:
self.grid_rowconfigure(j, weight = 1)
self.Label = tk.Label(self, font = ('bold', 18),text = "To: ")
self.Label.grid(row = 0, column = 0)
self.recipient = tk.Entry(self, justify="right",font = ('bold', 18),
width = 25)
self.recipient.grid(row = 0, column = 1, columnspan = 6,sticky = "nsew")
self.recipient.bind("<FocusIn>", self.remember_Focus)
self.recipient.focus()
self.messageSend = tk.Button(self, text = "SEND",font = ('bold', 20),
fg = "gold",bg = "green4",
command = self.send_Message)
self.messageSend.grid(row = 0, column = 8, columnspan = 2,
sticky = "nsew")
self.messageBody = tk.Text(self,font = ('Helvetica', 16),
height = 15, width = 35)
self.messageBody.grid(row = 1, column = 0, columnspan = 10,
sticky = "nsew")
self.messageBody.bind("<FocusIn>", self.remember_Focus)
c = 0
r = 2
for k in range(30):
self.buttonCharData.append(0)
self.buttonCapsData.append(0)
self.buttonData.append(0)
self.buttonCharData[k] = tk.Button(self,font = ('Helvetica', 14),
text = self.specialChar[k],
command = lambda k=k:
self.messageEntry
(self.specialChar[k]))
self.buttonCapsData[k] = tk.Button(self, font = ('Helvetica',14),
text = self.letterCaps[k],
command = lambda k=k:
self.messageEntry
(self.letterCaps[k]))
self.buttonData[k] = tk.Button(self, font=('Helvetica',14),
text=self.letter[k],command=lambda
k=k:self.messageEntry(self.letter[k]))
self.buttonCharData[k].grid(row = r, column = c, sticky = "nsew")
self.buttonCapsData[k].grid(row = r , column = c, sticky = "nsew")
self.buttonData[k].grid(row = r , column = c, sticky = "nsew")
c = c + 1
if(c == 10):
r = r + 1
c = 0
home = tk.Button(self, text = "HOME", fg = "Deep Sky Blue",font=("bold",10),
command = lambda: controller.show_frame("HomeFrame"))
home.grid(row = 5, column = 0, columnspan = 2 , sticky = "nsew")
capital_char = tk.Button(self, text = "UP",font=("bold",10),
command = self.capitalLetters)
capital_char.grid(row = 5, column = 2 ,sticky = "nsew")
space = tk.Button(self, text = "space", bg = "gray60",font=("bold",10),
command = lambda:self.messageEntry(" "))
space.grid(row = 5, column = 3, columnspan = 4, sticky = "nsew")
symbols = tk.Button(self, text = "SYM",font=("bold",10),
command = self.specialCharacters)
symbols.grid(row = 5, column = 7,sticky = "nsew")
delete = tk.Button(self, text = "DEL",fg="red4",font=("bold",10),
command = self.single_Char_Delete)
delete.grid(row = 5, column = 8, columnspan = 2 ,sticky = "nsew")
def remember_Focus(self,event):
""" Keeps the focussed widget global for the keyboard to input values in """
self.focused_entry = event.widget
def single_Char_Delete(self):
""" Deletes a single character in the focussed widget """
if(self.focused_entry == self.recipient):
self.num=self.recipient.get()[:-1]
self.recipient.delete(0,"end")
self.recipient.insert(0,self.num)
else:
self.messageBody.delete("%s-1c"% 'insert', 'insert')
def messageEntry(self, args):
""" Message Entry """
self.focused_entry.insert("end", args)
def specialCharacters(self):
""" Enables numbers(0-9) and special characters on the keyboard """
self._buttonCharcount = self._buttonCharcount+1
if(self._buttonCharcount == 1):
for i in range(30):
self.buttonData[i].grid_remove()
self.buttonCapsData[i].grid_remove()
self.buttonCharData[i].grid()
else:
for j in range(30):
self.buttonCharData[j].grid_remove()
self.buttonData[j].grid()
self._buttonCharcount = 0
def capitalLetters(self):
""" Enables Capital Letters on the keyboard """
self._buttoncount = self._buttoncount+1
if(self._buttoncount == 1):
for i in range(30):
self.buttonData[i].grid_remove()
self.buttonCapsData[i].grid()
else:
for j in range(30):
self.buttonCapsData[j].grid_remove()
self.buttonData[j].grid()
self._buttoncount = 0
def send_Message(self):
""" This fucntion is used for Sending SMS """
label = tk.Label(self)
label.grid(row = 0, column = 7)
if self.recipient.get():
status = phone.sendSMS(self.recipient.get(),
self.messageBody.get(1.0, "end") )
if status[-1] == 'OK\r\n':
print ("han ho guya")
self.recipient.delete(0,"end")
self.messageBody.delete(1.0, "end")
label.config(text = "Sent")
label.after(1000, label.grid_forget)
else:
label.config(text = "Error", bg = "red")
label.after(1000, label.grid_forget)