-
Notifications
You must be signed in to change notification settings - Fork 0
/
priscasms.py
executable file
·110 lines (88 loc) · 4.05 KB
/
priscasms.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
#!/usr/bin/env python3.1
# PriscaSMS (c) Tobias Quinn, <[email protected]>, GPLv3
# This will send an sms using gammu on a remote machine
# The remote machine must be set up to use passwordless ssh login and the remote
# user must be able to send SMS using gammu from the command line
# The phone to be used must be configured before hand to send SMS
import sys, re
from PyQt4 import QtCore, QtGui
from priscasms.ui.MainWindowUI import Ui_MainWindow
from priscasms.ui.CMSDialog import CMS
from priscasms.ui.PreferencesDialog import PreferencesDialog
# out max message length
MML = 160
class ValidatePhoneNumber(QtGui.QValidator):
def __init__(self):
QtGui.QValidator.__init__(self)
self.regexp = re.compile("^[\d+]\d*$")
def validate(self, qstr, pos):
# Blank is acceptable
if qstr == '': return QtGui.QValidator.Acceptable, qstr, pos
# match on a regexp
if self.regexp.match(qstr):
return QtGui.QValidator.Acceptable, qstr, pos
else:
return QtGui.QValidator.Invalid, qstr, pos
class Highlight160(QtGui.QSyntaxHighlighter):
def highlightBlock(self, message):
self.setFormat(MML, len(message), QtGui.QColor("red"))
class Main(QtGui.QMainWindow):
def _getNumber(self):
return self.ui.lineEditPhoneNumber.text()
def _getMessage(self):
return self.ui.textEditMessage.toPlainText()
def _updateSendButton(self, s=None):
# only allow send when more than 3 chars and a message is present
if len(self._getNumber()) < 3 or len(self._getMessage()) == 0:
self.ui.pushButtonSend.setEnabled(False)
else:
self.ui.pushButtonSend.setEnabled(True)
def _updateClearButton(self):
# update the text clear button and send button status
self.ui.pushButtonClear.setEnabled(len(self._getMessage()) != 0)
self._updateSendButton()
def _messageChanged(self):
# update the information about the message length and clear button
self.ui.label_chars_left.setText("%d" % (160 - len(self._getMessage())))
self._updateClearButton()
def _sendMessage(self):
cms = CMS(self, self._getNumber(), self._getMessage()[:MML])
if cms.exec():
print(" TO:%s\nMESS:%s" % (self._getNumber(), self._getMessage()[:MML]))
def _preferences(self):
# display our preferences dialog and take appropriate action
prefsd = PreferencesDialog(self)
prefsd.exec()
def __init__(self):
self.settings = QtCore.QSettings()
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.lineEditPhoneNumber.setValidator(ValidatePhoneNumber())
# self.setWindowFlags(Qt.Qt.Window | Qt.Qt.WindowMinimizeButtonHint)
self.connect(self.ui.lineEditPhoneNumber, QtCore.SIGNAL('textChanged(QString)'), self._updateSendButton)
self.connect(self.ui.textEditMessage, QtCore.SIGNAL('textChanged()'), self._messageChanged)
self.connect(self.ui.pushButtonSend, QtCore.SIGNAL('clicked()'), self._sendMessage)
# highlight text over 160 chars
self.hl = Highlight160(self.ui.textEditMessage.document())
# read our settings
self.ui.lineEditPhoneNumber.setText(self.settings.value("gui/number"))
self.ui.textEditMessage.setText(self.settings.value("gui/message"))
# menu bindings
self.connect(self.ui.actionPreferences, QtCore.SIGNAL('triggered()'), self._preferences)
self.connect(self.ui.actionQuit, QtCore.SIGNAL('triggered()'), self.close)
def __del__(self):
# write our settings
self.settings.setValue("gui/number", self._getNumber())
self.settings.setValue("gui/message", self._getMessage())
def main():
app = QtGui.QApplication(sys.argv)
app.setOrganizationName("tobiasquinn.com")
app.setApplicationName("priscasms")
#ss.setValue("sms/gateway", "tobias-debian32.local")
window = Main()
window.show()
# exit on window close
sys.exit(app.exec())
if __name__ == "__main__":
main()