/
gui.py
176 lines (153 loc) · 6.04 KB
/
gui.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
from PyQt5.QtWidgets import QStyle, QWidget, QPushButton, QFrame, QLabel, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout, QGridLayout
from PyQt5 import QtGui, QtCore
import sys
import linphone
class Dialer(QWidget):
def __init__(self, sip):
super(Dialer, self).__init__()
self.sip = sip
self.call = None
self.call_state = 0
self.left = 380
self.top = 600
self.width = 320
self.height = 200
self.initUI()
def initUI(self):
self.setGeometry(self.left, self.top, self.width, self.height)
self.button_size = QtCore.QSize()
self.button_size.setHeight(80)
self.button_size.setWidth(80)
self.createGridLayout()
self.windowLayout = QVBoxLayout()
self.windowLayout.addWidget(self.horizontalGroupBox)
self.setLayout(self.windowLayout)
self.show()
#self.showFullScreen()
def createGridLayout(self):
self.horizontalGroupBox = QGroupBox()
layout = QGridLayout()
#layout.setColumnStretch(1, 4)
#layout.setColumnStretch(2, 4)
#lcd = QLCDNumber(self)
self.ui_font = QtGui.QFont("Arial", 35, QtGui.QFont.Bold)
self.num_to_dial = []
self.num_bar = QLabel(''.join(self.num_to_dial), self)
self.num_bar.setAlignment(QtCore.Qt.AlignRight)
self.num_bar.setFont(self.ui_font)
self.num_bar.setWordWrap(True)
self.num_bar.setMaximumWidth(370)
self.cursor = QtGui.QCursor(QtCore.Qt.BlankCursor)
layout.addWidget(self.num_bar, 0,0,1,3, self.num_bar.alignment())
button1 = QPushButton('1', self)
button1.setMinimumSize(120,80)
layout.addWidget(button1,1,0)
button2 = QPushButton('2', self)
button2.setMinimumSize(120,80)
layout.addWidget(button2,1,1)
button3 = QPushButton('3', self)
button3.setMinimumSize(120,80)
layout.addWidget(button3,1,2)
button4 = QPushButton('4', self)
button4.setMinimumSize(80,80)
layout.addWidget(button4,2,0)
button5 = QPushButton('5', self)
button5.setMinimumSize(80,80)
layout.addWidget(button5,2,1)
button6 = QPushButton('6', self)
button6.setMinimumSize(80,80)
layout.addWidget(button6,2,2)
button7 = QPushButton('7', self)
button7.setMinimumSize(80,80)
layout.addWidget(button7,3,0)
button8 = QPushButton('8', self)
button8.setMinimumSize(80,80)
layout.addWidget(button8,3,1)
button9 = QPushButton('9', self)
button9.setMinimumSize(80,80)
layout.addWidget(button9,3,2)
button_astr = QPushButton('*', self)
button_astr.setMinimumSize(80,80)
layout.addWidget(button_astr,4,0)
button0 = QPushButton('0', self)
button0.setMinimumSize(80,80)
layout.addWidget(button0,4,1)
button_hash = QPushButton('#', self)
button_hash.setMinimumSize(80,80)
layout.addWidget(button_hash,4,2)
self.buttonCall = QPushButton("Call", self)
self.buttonCall.setMinimumSize(80,80)
layout.addWidget(self.buttonCall,5,2)
self.buttonClear = QPushButton("Clear", self)
self.buttonClear.setMinimumSize(80,80)
layout.addWidget(self.buttonClear,5,0)
button1.clicked.connect(self.on_button_click)
button2.clicked.connect(self.on_button_click)
button3.clicked.connect(self.on_button_click)
button4.clicked.connect(self.on_button_click)
button5.clicked.connect(self.on_button_click)
button6.clicked.connect(self.on_button_click)
button7.clicked.connect(self.on_button_click)
button8.clicked.connect(self.on_button_click)
button9.clicked.connect(self.on_button_click)
button0.clicked.connect(self.on_button_click)
button_astr.clicked.connect(self.on_button_click)
button_hash.clicked.connect(self.on_button_click)
self.buttonCall.clicked.connect(self.call_handler)
self.buttonClear.clicked.connect(self.clear)
self.horizontalGroupBox.setLayout(layout)
def on_button_click(self, pressed):
sender = self.sender()
self.num_to_dial.append(sender.text())
dial = ''.join(self.num_to_dial)
self.num_bar.setText(dial)
self.num_bar.adjustSize()
if self.call_state == 6:
#self.sip.start_dtmf_stream()
self.sip.play_dtmf(int(sender.text()), 1000)
#print (int(sender.text()))
#self.sip.stop_dtmf_stream()
def make_call(self):
self.call = self.sip.invite("sip:" + self.num_bar.text() + "@shookke.fl.3cx.us")
self.buttonCall.setText('End')
def answer_call(self):
self.sip.accept_call(self.call)
self.buttonCall.setText('End')
self.buttonClear.setText('Clear')
def end_call(self):
self.sip.terminate_call(self.call)
self.call = None
self.call_state = 0
self.clear()
self.buttonCall.setText('Call')
def decline_call(self):
self.sip.decline_call(self.call, linphone.Reason.Declined)
def clear(self):
sender = self.sender()
if sender.text() == 'Ignore':
self.decline_call()
self.num_bar.setText('')
self.num_to_dial = []
def call_incoming(self, call):
self.call = call
self.call_state = self.call.state
self.num_bar.setText(self.call.user_data)
self.num_bar.adjustSize()
self.buttonClear.setText('Ignore')
self.buttonCall.setText('Answer')
def incoming_terminated(self):
self.call = None
self.call_state = 0
self.buttonCall.setText('Call')
self.buttonClear.setText('Clear')
def call_handler(self):
if self.call_state == 1:
self.answer_call()
elif self.call_state == 0 and self.num_bar != '':
self.make_call()
elif self.call_state == 3:
self.end_call()
elif self.call_state == 6:
self.end_call()
else:
return