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 __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)