I am writing a gui program that allows a user to resend a message to a phone number with a custom delay and the number of repetitions.
I used QT Designer to create gui, and now I'm trying to create code behind it. I am trying to get the program to start sending messages when the start button is pressed, but not to freeze gui.
I am trying to use gobject.timeout_add_seconds to check if new messages should be sent every 1 s, but when a segmentation error occurs.
queueMessages is called whenever a button is pressed to start sending messages, and sendMessages should be run every 1 second to send any necessary messages.
Let me know if there is an easier way to do this (e.g. threads). I am open to any other ideas.
Here is the applicable code. I can also include gui code if this were useful:
import sys, os
import time
import gobject
from PyQt4 import QtGui,QtCore
from smsBomb import *
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.btnSendMessages, QtCore.SIGNAL('clicked()'), self.queueMessages)
self.maintimer = gobject.timeout_add_seconds(1, self.sendMessages)
def queueMessages(self):
number = str(self.ui.txtNumber.text())
message = str(self.ui.txtMessage.text())
delay = int(self.ui.txtDelay.text())
repetitions = int(self.ui.txtRepetitions.text())
for i in range(repetitions):
os.system('dbus-send --dest=org.QGVDial.TextServer --session --print-reply /org/QGVDial/TextServer org.QGVDial.TextServer.Text array:string:"+1' + number + '" string:"' + message + '"')
def sendMessages(self):
print "Sending queued messages..."
return True
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
xur17 source
share