forked from ryanwlb/Robot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunAPI7.py
674 lines (577 loc) · 28.2 KB
/
RunAPI7.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#
#
# 带水印 定制版
#
#
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QApplication, QWidget, QPushButton, QLabel,QLineEdit,QGroupBox,QListWidget,QListWidgetItem,QCheckBox,QDateTimeEdit
from PyQt5.QtMultimedia import QSound
from PyQt5.QtGui import QIcon,QPixmap,QFont
import PyQt5.QtCore as QtCore
import qdarkstyle
import sys
import queue
from fcoin3 import Fcoin
import random
import time
import datetime
import json
import sms_send
import re
import codecs
def catch_exceptions(t, val, tb):
print(t,val,tb)
old_hook(t, val, tb)
old_hook = sys.excepthook
sys.excepthook = catch_exceptions
class workThread(QtCore.QThread):
logSignal = QtCore.pyqtSignal(dict)
def __init__(self):
super(workThread,self).__init__()
def run(self):
self.work()
def work(self):
global gIniQueue
self.printLog('软件启动!')
file=open('./ini.json')
dic=json.loads( file.read())
apikey=dic['apikey']
apisecret=dic['apisecret']
file.close()
while gFlag:
try:
try:
ini=gIniQueue.get(block=False)
except:
pass
else:
str1=ini[0]
str2=ini[1]
num=ini[2]
str3=ini[3]
myTime=ini[4]
num2=ini[5]
buyFlag=ini[6]
tel=ini[7]
myTime2=ini[8]
num3=ini[9]
# test
self.printLog(str(ini))
# file = open('./mytxt.txt', 'a+')
fcoin = Fcoin()
# 主号
# fcoin.auth('', '')
# 刷号
fcoin.auth(apikey,apisecret,tel)
# os.system('fskl.mp3')
# 获取账户资产
data=fcoin.get_balance()
self.printLog('交易对:%s'%(str3))
level= fcoin.get_market_depth('L20',str3)
if ('data' not in data.keys()) or (not data['data']):
continue
for i in data['data']:
if i['currency']==str1:
my_usdt=i['balance']
self.printLog(str1+'余额: '+my_usdt)
if i['currency']==str2:
my_ft=i['balance']
self.printLog(str2+'余额: '+my_ft)
nowBids=level['data']['bids'][0]
sumBids=0
for i in range(0,len(level['data']['bids'])):
if (i%2)==0:
nowBids=level['data']['bids'][i]
self.printLog('本次价格:%s'%(nowBids))
else:
temp_Num2=sumBids
sumBids+=level['data']['bids'][i]
self.printLog('买盘 本次数量总和:%s 本次数量:%s 上次数量总和:%s 总数量:%s'%(sumBids,level['data']['bids'][i],temp_Num2,num3))
if sumBids>num3: #num3是输入的数
if i!=0:
sumBids=temp_Num2
self.printLog('本次数量总和:%s'%(sumBids))
if i>0:
nowBids=level['data']['bids'][i-1]
self.printLog('买盘本次价格:%s' % (nowBids))
break
elif sumBids==num3:
break
nowAsks=level['data']['asks'][0]
sumAsks=0
for i in range(0,len(level['data']['asks'])):
if(i%2)==0:
nowAsks=level['data']['asks'][i]
self.printLog('本次价格:%s'%(nowAsks))
else:
temp_Num2=sumAsks
sumAsks+=level['data']['asks'][i]
self.printLog('卖盘 本次数量总和:%s 本次数量:%s 上次数量总和:%s 总数量:%s'%(sumAsks,level['data']['asks'][i],temp_Num2,num3)) #sumAsks+temp_Num2 这是什么意思
if sumAsks>num3: #num3是输入的数
if i!=0:
sumAsks=temp_Num2
self.printLog('本次数量总和:%s'%(sumAsks))
if i>0:
nowAsks=level['data']['asks'][i-1]
self.printLog('卖盘本次价格:%s' % (nowAsks))
break
elif sumAsks==num3:
break
self.printLog('价格小数:%s'%(num2))
nowResult=round((round(nowAsks,num2)+round(nowBids,num2))/2,num2)
logStr=str(data)
# self.printLog(logStr)
# file.write(logStr+ '\n')
nowtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
resultstr = fcoin.get_market_ticker(str3)
logStr=str(resultstr)
# self.printLog(logStr)
# file.write(logStr+ '\n')
wantstr = resultstr["data"]["ticker"]
# a是买一价 b是卖一价
a, b = wantstr[2], wantstr[4]
# result = round(random.uniform(a, b), num2)
result=nowResult
logStr="random price is:" + str(result) + "now time:" + nowtime
# self.printLog(logStr)
# file.write(logStr+ '\n')
#卖
if num<float(my_ft):
sellop = fcoin.sell(str3, result, str(round(num,2)))
if (sellop is not None ) and (sellop['status']==0):
logStr=r'限价卖出成功 限价卖出%s个%s 卖出价格是%s 当前时间是%s'%(num,str2,result,nowtime)
self.printLog(logStr)
else:
self.printLog(sellop['msg'])
elif (num>float(my_ft)) :
if buyFlag:
buyop = fcoin.buy_market(str3,round(float(num)*float(result)-float(my_ft)*float(result),2))
tempFlag=False
if (buyop is not None) and (buyop['status']==3014):
tempFlag=True
temp_num = int(re.search(r'\d+$', buyop['msg']).group(0))
buyop = fcoin.buy_market(str3, str(temp_num))
#
# if (buyop is not None) and (buyop['status'] == 0):
# # print(num-float(my_ft))*(result/float(my_usdt))
# logStr = r'市价补仓买入成功 市价买入%s个%s的%s 当前时间是%s' % (
# str(round((num - float(my_ft)) * b + (((num - float(my_ft)) * b) * 0.1), 2)), str1,
# str2, nowtime)
# self.printLog(logStr)
# continue
# file.write(logStr+ '\n')
# else:
# self.printLog(buyop['msg'])
# continue
# buyop = fcoin.buy(str3, result,str(float(num-float(my_ft))*(result/float(my_usdt))))
# buyop = fcoin.buy(str3, b, str(round(num-float(my_ft)+((num-float(my_ft))*0.1),2)))
if (buyop is not None) and (buyop['status']==0):
# print(num-float(my_ft))*(result/float(my_usdt))
if not tempFlag:
logStr=r'市价补仓买入成功 市价买入%s个%s的%s 当前时间是%s'%(str(round(float(num)*float(result)-float(my_ft)*float(result),2)),str1,str2,nowtime)
else:
logStr=r'市价补仓买入成功 市价买入%s个%s的%s 当前时间是%s'%(temp_num,str1,str2,nowtime)
self.printLog(logStr)
continue
# file.write(logStr+ '\n')
else:
self.printLog(buyop['msg'])
continue
# time.sleep(60*?)
# buyrecord = buyop["data"]
# sellop = fcoin.sell(str3, result, str(num))
# if (sellop is not None) and (sellop['status']==0):
# logStr = r'限价卖出成功 卖出%s个s% 卖出价格是%s 当前时间是%s' % (num, str2,result, nowtime)
# self.printLog(logStr)
# # file.write(logStr+ '\n')
# else:
# self.printLog(sellop['msg'])
# if sellop:
# sellrecord = sellop["data"]
else:
smsResult=sms_send.send('您当前交易对数量不足,请及时处理', tel, '44060')
#在这等15分钟
logStr = r'因为交易对数量不足程序已停止,30分钟后重新启动'
time.sleep(60 * 30)
#买
if num< float(my_usdt):
buyop = fcoin.buy(str3, result, str(round(num,2)))
if (buyop is not None) and (buyop['status']==0):
logStr=r'限价买入成功 限价买入%s个%s 买入价格是%s 当前时间是%s'%(num,str2,result,nowtime)
self.printLog(logStr)
# file.write(logStr+ '\n')
else:
self.printLog(buyop['msg'])
# buyrecord = buyop["data"]
elif num> float(my_usdt):
if buyFlag:
# sell正常卖 sell_market非正常卖
# sellop = fcoin.sell_market(str3, str(round(num-float(my_ft)+((num-float(my_ft))*0.1),2)))
sellop = fcoin.sell_market(str3, round((float(num)*float(result)-float(my_usdt)),2))
# sellop = fcoin.sell_market(str3, num+(num*result)*0.01)
tempFlag = False
if (sellop is not None) and (sellop['status'] == 3014):
tempFlag = True
temp_num = int(re.search(r'\d+$', sellop['msg']).group(0))
sellop = fcoin.buy_market(str3, str(temp_num))
# sellop =fcoin.sell(str3, round(a,num2), str(round(num-float(my_ft)+((num-float(my_ft))*0.1),2)))
if (sellop is not None) and (sellop['status']==0):
if not tempFlag:
logStr=r'市价补仓卖出成功 市价卖出%s个%s,当前时间是%s'%(str(round((float(num)*float(result)-float(my_usdt)))),str2,nowtime)
else:
logStr=r'市价补仓卖出成功 市价卖出%s个%s,当前时间是%s'%(temp_num+temp_num*0.1,str2,nowtime)
self.printLog(logStr)
continue
# file.write(logStr+ '\n')
else:
self.printLog(sellop['msg'])
continue
# if sellop:
# sellrecord = sellop["data"]
# buyop = fcoin.buy(str3, result, str(num))
# if (buyop is not None) and (buyop['status']==0):
# logStr = r'限价买入成功 限价买入%s个%s 买入价格是%s 当前时间是%s' % (num,str2, result, nowtime)
# self.printLog(logStr)
# # file.write(logStr+ '\n')
# else:
# self.printLog(buyop['msg'])
# # buyrecord = buyop["data"]
else:
smsResult=sms_send.send('您当前交易对数量不足,请及时处理', tel, '44060')
logStr = r'因为交易对数量不足程序已停止,30分钟后重新启动'
time.sleep(60 * 30)
time.sleep(myTime)
# 获取订单列表
if buyFlag:
rol = fcoin.list_orders(str3, 'submitted,partial_filled')
if ('data' not in rol.keys()) or (not rol['data']):
continue
lastTime=rol['data'][len(rol['data'])-1]['created_at']
lastTime=int(re.sub(r'\d{3}$','',str(lastTime)))
nowTime=int(time.time())
if not buyFlag:
if (nowTime-lastTime) >(myTime):
smsResult=sms_send.send('您当前有超过5分钟未成交的订单,请及时处理', tel, '44060')
else:
# 这里加not true的else
if buyFlag:
for p in rol["data"]:
if p["side"] == "buy":
lastTime = p['created_at']
lastTime = int(re.sub(r'\d{3}$', '', str(lastTime)))
nowTime = int(time.time())
if (nowTime-lastTime) >(myTime2):
# 市价卖
sellamount = round(float(p["amount"]) - float(p["filled_amount"]), 2)
temptemp_result = fcoin.cancel_order(p["id"])
if (temptemp_result is None) or (temptemp_result['status'] != 0):
logStr = "检测到有超过" + str(
myTime2) + "秒未完成订单 限价买入订单取消失败,因为已取消,现在时间是:" + nowtime
else:
logStr = "检测到有超过" + str(myTime2) + "秒未完成订单 限价买入订单取消成功,现在时间是:" + nowtime
self.printLog(logStr)
file.write(logStr + '\n')
temptemp_result1 = fcoin.buy_market(str3, sellamount)
if (temptemp_result1 is None) or (temptemp_result1['status']!=0):
logStr="检测到有超过"+str(myTime2)+"秒未完成订单 限价买入订单取消失败,因为已取消,现在时间是:" + nowtime
else:
logStr="检测到有超过"+str(myTime2)+"秒未完成订单 限价买入订单取消成功,现在时间是:" + nowtime
self.printLog(logStr)
# file.write(logStr+ '\n')
elif p["side"] == "sell":
lastTime = p['created_at']
lastTime = int(re.sub(r'\d{3}$', '', str(lastTime)))
nowTime = int(time.time())
if (nowTime - lastTime) > (myTime2):
# 市价卖
sellamount = round(float(p["amount"]) - float(p["filled_amount"]), 2)
temptemp_result=fcoin.cancel_order(p["id"])
if (temptemp_result is None) or (temptemp_result['status']!=0):
logStr="检测到有超过"+str(myTime2)+"秒未完成订单 限价卖出订单取消失败,因为已取消,现在时间是:" + nowtime
else:
logStr="检测到有超过"+str(myTime2)+"秒未完成订单 限价卖出订单取消成功,现在时间是:" + nowtime
self.printLog(logStr)
file.write(logStr+ '\n')
temptemp_result=fcoin.sell_market(str3,sellamount)
if (temptemp_result is None) or (temptemp_result['status']!=0):
logStr="检测到有超过"+str(myTime2)+"秒未完成订单 市价卖出结果失败,因为已取消,现在时间是:" + nowtime
else:
logStr="检测到有超过"+str(myTime2)+"秒未完成订单 市价卖出结果成功,现在时间是:" + nowtime
self.printLog(logStr)
file.write(logStr+ '\n')
# elif ['side']=='buy':
# lastTime = p['created_at']
# lastTime = int(re.sub(r'\d{3}$', '', str(lastTime)))
# nowTime = int(time.time())
# if (nowTime - lastTime) > (myTime2):
# # 市价买
# sellamount = round(float(p["amount"]) - float(p["filled_amount"]), 2)
# temptemp_result = fcoin.buy_market(str3, sellamount)
# if (temptemp_result is None) or (temptemp_result['status'] != 0):
# logStr = "检测到有超过" + str(myTime2) + "秒未完成订单 市价买入结果失败,因为已取消,现在时间是:" + nowtime
# else:
# logStr = "检测到有超过" + str(myTime2) + "秒未完成订单 市价买入结果成功,现在时间是:" + nowtime
# self.printLog(logStr)
# file.write(logStr + '\n')
# file.write(logStr+ '\n')
# isemprol = fcoin.list_orders('ftusdt', 'submitted,partial_filled')
# print(isemprol)
# time.sleep(myTime)
# if len(isemprol["data"]) != 0:
# flag = False
# # os.system('fskl.mp3')
# file.close()
# # 执行完等3秒继续循
# time.sleep(1)
except Exception as e:
raise e
time.sleep(myTime)
self.printLog('软件结束!')
def printLog(self,str):
self.logSignal.emit({'msg':str})
class timerThread(QtCore.QThread):
startSignal=QtCore.pyqtSignal()
endSignal=QtCore.pyqtSignal()
def __init__(self):
super(timerThread,self).__init__()
def run(self):
while True:
if gTimeFlag and (gStartTime is not None) and (gEndTime is not None) and (not gWorkRunFlag):
nowTime=datetime.datetime.now()
if (nowTime>=gStartTime) and (nowTime<gEndTime) and (gFlag==False):
self.startSignal.emit()
elif nowTime>=gEndTime:
self.endSignal.emit()
break
time.sleep(0.5)
class OWO(QWidget):
def __init__(self):
super(QWidget,self).__init__()
tempTime=datetime.datetime.now()
tempTime=tempTime.strftime(r'%Y-%m-%d %H %M %S')
self.logFile=codecs.open('./log/'+str(tempTime)+'日志'+'.html','w','utf-8')
self.htmlPart1="""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Log</title>
</head>
<body>
<table>
"""
self.htmlPart2="""
</table>
</body>
</html>
"""
self.logFile.write(self.htmlPart1)
vBox = QVBoxLayout()
logG=QGroupBox()
logG.setTitle('信息')
hBox=QHBoxLayout()
self.logList=QListWidget()
hBox.addWidget(self.logList)
logG.setLayout(hBox)
iniG=QGroupBox()
iniG.setTitle('设置')
vBox2 = QVBoxLayout()
hBox1 = QHBoxLayout()
mylable1=QLabel('交易对1:')
self.input1=QLineEdit()
self.input1.setText('usdt')
hBox1.addWidget(mylable1)
hBox1.addWidget(self.input1)
vBox2.addLayout(hBox1)
hBox2 = QHBoxLayout()
mylable2 = QLabel('交易对2:')
self.input2 = QLineEdit()
self.input2.setText('ft')
hBox2.addWidget(mylable2)
hBox2.addWidget(self.input2)
vBox2.addLayout(hBox2)
hBox3 = QHBoxLayout()
mylable3 = QLabel('交易数量:')
self.input3 = QLineEdit()
self.input3.setText('10')
hBox3.addWidget(mylable3)
hBox3.addWidget(self.input3)
vBox2.addLayout(hBox3)
hBox4 = QHBoxLayout()
mylable4 = QLabel('交易对:')
self.input4 = QLineEdit()
self.input4.setText('ftusdt')
hBox4.addWidget(mylable4)
hBox4.addWidget(self.input4)
vBox2.addLayout(hBox4)
hBox6=QHBoxLayout()
mylable6=QLabel('交易时间:')
self.input6=QLineEdit()
self.input6.setText('10')
hBox6.addWidget(mylable6)
hBox6.addWidget(self.input6)
vBox2.addLayout(hBox6)
hBox7 = QHBoxLayout()
mylable6 = QLabel('价格小数:')
self.input7 = QLineEdit()
self.input7.setText('6')
hBox7.addWidget(mylable6)
hBox7.addWidget(self.input7)
vBox2.addLayout(hBox7)
hBox11 = QHBoxLayout()
mylable11 = QLabel('输入数值!:')
self.input11 = QLineEdit()
self.input11.setText('0')
hBox11.addWidget(mylable11)
hBox11.addWidget(self.input11)
vBox2.addLayout(hBox11)
hBox5=QHBoxLayout()
self.input8 = QCheckBox()
self.input8.setText('当余额不足是否市价增补仓')
mylable7=QLabel('输入手机号:')
self.input8.setChecked(True)
self.input9 = QLineEdit()
mylable9=QLabel('请输入多久取消订单(秒):')
self.input10=QLineEdit()
self.input10.setText('5')
submitBtn=QPushButton(' 提交 ')
submitBtn.clicked.connect(self.submitFn)
hBox5.addWidget(self.input8)
hBox5.addSpacing(8)
hBox5.addWidget(mylable7)
hBox5.addWidget(self.input9)
hBox5.addSpacing(8)
hBox5.addWidget(mylable9)
hBox5.addWidget(self.input10)
hBox5.addStretch()
hBox5.addWidget(submitBtn)
# hBox5.addStretch()
vBox2.addLayout(hBox5)
iniG.setLayout(vBox2)
vBox.addWidget(logG)
vBox.addWidget(iniG)
hBox7=QHBoxLayout()
self.startBtn=QPushButton(' 运行 ')
self.startBtn.clicked.connect(self.startBtnClick)
self.stopBtn=QPushButton(' 停止 ')
self.stopBtn.clicked.connect(self.stopBtnClick)
mylable8=QLabel('JC软件工作室 微信:jcccccccc1991')
font=QFont('微软雅黑')
font.setPixelSize(18)
mylable8.setFont(font)
mylable8.setStyleSheet("""
QLabel{color:#FF0000}
""")
hBox7.addWidget(self.startBtn)
hBox7.addStretch()
hBox7.addWidget(mylable8)
hBox7.addStretch()
hBox7.addWidget(self.stopBtn)
hBox8 = QHBoxLayout()
tempNowTime = QtCore.QDateTime.currentDateTime()
self.timerC = QCheckBox()
self.timerC.setText('启用定时运行 ')
self.timerC.stateChanged.connect(self.timerClicked)
startLab = QLabel('开始时间:')
self.startTimeEdit = QDateTimeEdit()
self.startTimeEdit.setDateTime(tempNowTime)
self.startTimeEdit.setStyleSheet("""
QDateTimeEdit{width:110px}
""")
endLab = QLabel('<--> 结束时间:')
self.endTimeEdit = QDateTimeEdit()
self.endTimeEdit.setDateTime(tempNowTime)
self.endTimeEdit.setStyleSheet("""
QDateTimeEdit{width:110px}
""")
hBox8.addWidget(self.timerC)
hBox8.addWidget(startLab)
hBox8.addWidget(self.startTimeEdit)
hBox8.addWidget(endLab)
hBox8.addWidget(self.endTimeEdit)
hBox8.addStretch()
vBox.addLayout(hBox8)
vBox.addLayout(hBox7)
self.stopBtn.setEnabled(False)
icon=QIcon()
icon.addPixmap(QPixmap('./JC.ico'),QIcon.Normal)
self.setWindowIcon(icon)
self.setLayout(vBox)
self.setWindowTitle('JC全自动挖矿交易软件')
self.resize(700,500)
self.show()
def submitFn(self,click):
self.sendIni()
def sendIni(self):
global gIniQueue
myList = [
str(self.input1.text()),
str(self.input2.text()),
float(self.input3.text()),
str(self.input4.text()),
int(self.input6.text()),
int(self.input7.text()),
bool(self.input8.isChecked()),
str(self.input9.text()),
int(self.input10.text()),
int(self.input11.text())
]
gIniQueue.put(myList)
def printLog(self,dic):
item=QListWidgetItem(dic['msg'])
self.logList.addItem(item)
self.logList.setCurrentRow(self.logList.count()-1)
self.logFile.write(r'<tr><td>'+dic['msg']+r'</td></tr>')
if self.logList.count()>1000:
item=self.logList.takeItem(0)
del item
def startBtnClick(self,click):
self.startBtn.setEnabled(False)
self.stopBtn.setEnabled(True)
if not gTimeFlag:
self.runWorkTh()
elif gTimeFlag:
self.runTimerTh()
def runTimerTh(self):
global gStartTime
global gEndTime
gStartTime=self.startTimeEdit.dateTime().toPyDateTime()
gEndTime=self.endTimeEdit.dateTime().toPyDateTime()
self.timerTh=timerThread()
self.timerTh.startSignal.connect(self.runWorkTh)
self.timerTh.endSignal.connect(self.stopBtnClick)
self.timerTh.start()
self.printLog({'msg':'启动定时器'})
def runWorkTh(self):
global gFlag
gFlag = True
self.sendIni()
self.myTh = workThread()
self.myTh.logSignal.connect(self.printLog)
self.myTh.start()
self.printLog({'msg': '正在启动软件'})
def stopBtnClick(self,click=None):
global gFlag
self.startBtn.setEnabled(True)
self.stopBtn.setEnabled(False)
gFlag = False
self.printLog({'msg':'正在关闭软件'})
def closeEvent(self, QCloseEvent):
global gFlag
self.logFile.write(self.htmlPart2)
self.logFile.close()
gFlag=False
QCloseEvent.accept()
def timerClicked(self,status):
global gTimeFlag
gTimeFlag=status
if __name__=='__main__':
gTimeFlag = False
gStartTime = None
gEndTime = None
gWorkRunFlag = False
gFlag=False
gIniQueue=queue.Queue()
app=QApplication(sys.argv)
owo=OWO()
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
sys.exit(app.exec_())