python 3.7 - I try to close the thread without closing the GUI is it possible?
alon.najman at gmail.com
alon.najman at gmail.com
Fri Sep 14 03:09:44 EDT 2018
python 3.7 - I try to close the thread without closing the GUI is it possible?
here is my code, sorry I'm am new with python and generally with code XD .
thanks all
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'AlonStockMarket.ui'
#
# Created by: PyQt5 UI code generator 5.11.2
#
# WARNING! All changes made in this file will be lost!
import time
import sys
import requests
from lxml import html
import requests
import urllib.request, urllib.error, urllib.parse
import _thread
from PyQt5 import QtCore, QtGui, QtWidgets
from multiprocessing import Pool
global flag
import threading
import time
exitFlag = 0
class myThread (threading.Thread):
def __init__(self, threadID, name, counter):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
def run(self):
print ("Starting " + self.name)
print_time(self.name, self.counter, 5)
print ("Exiting " + self.name)
def print_time(threadName, delay, counter):
print("hello, world")
while True:
time.sleep(15)
f=open("flag.txt", "r")
if f.mode == 'r':
flag =f.read()
timeHour = int(time.strftime('%H'))
print("keep alive")
print (time.strftime('%H:%M:%S'))
while ((timeHour>16) and (timeHour<23)):
print(time.strftime('%H:%M:%S'))
price=get_quote('evok')
time.sleep(5)
if flag!=time.strftime("%d/%m/%Y") and price>4:
print ("send SMS")
import requests
requests.post('https://textbelt.com/text', {
'phone': '+972546233257',
'message': "Hi Alon Najman,EVOK value: "+Price,
'key': 'secret',
})
#write to file
with open("flag.txt", "w") as text_file:
text_file.write(format(time.strftime("%d/%m/%Y")))
#read from file
f=open("flag.txt", "r")
if f.mode == 'r':
flag =f.read()
# Create new threads
thread1 = myThread(1, "Thread-1", 1)
# Start new Threads
def get_quote(str):
url="https://api.iextrading.com/1.0/stock/"+str+"/price"
resource = urllib.request.urlopen(url)
content = resource.read().decode(resource.headers.get_content_charset())
print (content)
content=float(content)
return content
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(666, 571)
self.radioButton = QtWidgets.QRadioButton(Dialog)
self.radioButton.setGeometry(QtCore.QRect(80, 190, 191, 24))
font = QtGui.QFont()
font.setPointSize(14)
self.radioButton.setFont(font)
self.radioButton.setObjectName("radioButton")
self.buttonGroup_2 = QtWidgets.QButtonGroup(Dialog)
self.buttonGroup_2.setObjectName("buttonGroup_2")
self.buttonGroup_2.addButton(self.radioButton)
self.checkBox = QtWidgets.QCheckBox(Dialog)
self.checkBox.setGeometry(QtCore.QRect(290, 450, 131, 17))
font = QtGui.QFont()
font.setPointSize(14)
self.checkBox.setFont(font)
self.checkBox.setObjectName("checkBox")
self.checkBox_2 = QtWidgets.QCheckBox(Dialog)
self.checkBox_2.setGeometry(QtCore.QRect(290, 480, 141, 17))
font = QtGui.QFont()
font.setPointSize(14)
self.checkBox_2.setFont(font)
self.checkBox_2.setObjectName("checkBox_2")
self.textEdit = QtWidgets.QTextEdit(Dialog)
self.textEdit.setGeometry(QtCore.QRect(130, 20, 321, 41))
self.textEdit.setObjectName("textEdit")
self.radioButton_2 = QtWidgets.QRadioButton(Dialog)
self.radioButton_2.setGeometry(QtCore.QRect(300, 190, 186, 24))
font = QtGui.QFont()
font.setPointSize(14)
self.radioButton_2.setFont(font)
self.radioButton_2.setObjectName("radioButton_2")
self.buttonGroup_2.addButton(self.radioButton_2)
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(60, 460, 72, 31))
font = QtGui.QFont()
font.setPointSize(14)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.radioButton_3 = QtWidgets.QRadioButton(Dialog)
self.radioButton_3.setGeometry(QtCore.QRect(80, 250, 191, 24))
font = QtGui.QFont()
font.setPointSize(14)
self.radioButton_3.setFont(font)
self.radioButton_3.setObjectName("radioButton_3")
self.buttonGroup = QtWidgets.QButtonGroup(Dialog)
self.buttonGroup.setObjectName("buttonGroup")
self.buttonGroup.addButton(self.radioButton_3)
self.radioButton_4 = QtWidgets.QRadioButton(Dialog)
self.radioButton_4.setGeometry(QtCore.QRect(300, 250, 186, 24))
font = QtGui.QFont()
font.setPointSize(14)
self.radioButton_4.setFont(font)
self.radioButton_4.setObjectName("radioButton_4")
self.buttonGroup.addButton(self.radioButton_4)
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(30, 20, 72, 31))
font = QtGui.QFont()
font.setPointSize(14)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.textEdit_4 = QtWidgets.QTextEdit(Dialog)
self.textEdit_4.setGeometry(QtCore.QRect(310, 383, 221, 38))
font = QtGui.QFont()
font.setPointSize(16)
self.textEdit_4.setFont(font)
self.textEdit_4.setObjectName("textEdit_4")
self.textEdit_5 = QtWidgets.QTextEdit(Dialog)
self.textEdit_5.setGeometry(QtCore.QRect(310, 340, 221, 38))
font = QtGui.QFont()
font.setPointSize(16)
self.textEdit_5.setFont(font)
self.textEdit_5.setObjectName("textEdit_5")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(150, 80, 111, 16))
font = QtGui.QFont()
font.setPointSize(14)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(410, 80, 131, 16))
font = QtGui.QFont()
font.setPointSize(14)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(160, 350, 121, 20))
font = QtGui.QFont()
font.setPointSize(14)
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(140, 390, 171, 20))
font = QtGui.QFont()
font.setPointSize(14)
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.splitter = QtWidgets.QSplitter(Dialog)
self.splitter.setGeometry(QtCore.QRect(80, 120, 512, 31))
self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName("splitter")
self.textEdit_2 = QtWidgets.QTextEdit(self.splitter)
self.textEdit_2.setObjectName("textEdit_2")
self.textEdit_3 = QtWidgets.QTextEdit(self.splitter)
self.textEdit_3.setObjectName("textEdit_3")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.pushButton.clicked.connect(self.printMessage)
self.pushButton_2.clicked.connect(self.printMessage2)
def printMessage(self):
print ("what a great day!")
thread1.start()
def printMessage2(self):
thread1._Thread_stop()
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.radioButton.setText(_translate("Dialog", "Above Price (x>)"))
self.checkBox.setText(_translate("Dialog", "SMS ALERT"))
self.checkBox_2.setText(_translate("Dialog", "GMAIL ALERT"))
self.textEdit.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:18pt;\">Alon Stock Market (alerts)</span></p></body></html>"))
self.radioButton_2.setText(_translate("Dialog", "Bellow Price (x<)"))
self.pushButton.setText(_translate("Dialog", "START"))
self.radioButton_3.setText(_translate("Dialog", "get alert once a day"))
self.radioButton_4.setText(_translate("Dialog", "get alert every time"))
self.pushButton_2.setText(_translate("Dialog", "EXIT"))
self.textEdit_4.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:16pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt;\">Password of Gmail</span></p></body></html>"))
self.textEdit_5.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:16pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:14pt;\">User of Gmail</span></p></body></html>"))
self.label.setText(_translate("Dialog", "SYMBOL"))
self.label_2.setText(_translate("Dialog", "PRICE VALUE"))
self.label_3.setText(_translate("Dialog", "User of Gmail:"))
self.label_4.setText(_translate("Dialog", "Password of Gmail:"))
self.textEdit_2.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">STOCK SYMBOL</p></body></html>"))
self.textEdit_3.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">STOCK SYMBOL</p></body></html>"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
More information about the Python-list
mailing list