-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
76 lines (64 loc) · 1.98 KB
/
main.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
import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5 import uic, QtCore, QtTest
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import QThread
from TOTP import *
from time import sleep
class AddCode(QThread):
def __init__(self, name:str, secret:str):
QThread.__init__(self)
self.name = name
self.secret = secret
def run(self):
if self.secret != "_":
ACCOUNT_ADD(self.name, self.secret)
else:
ACCOUNT_REMOVE(self.name)
class ShowCodes(QThread):
codesShow = QtCore.pyqtSignal(str)
def __init__(self):
QThread.__init__(self)
def run(self):
while True:
LIST = ""
CODEs = SHOW_ALL_CODES()
if CODEs != None:
for label, key in sorted(list(CODEs.items())):
try:
LIST += (f"{label}: {get_totp_token(key)}\n")
except:
LIST += (f"{label}: ______\n")
else:
pass
self.codesShow.emit(f"{LIST}")
sleep(0.1)
class App(QWidget):
def __init__(self):
QWidget.__init__(self)
self.set()
def set(self):
self.w_root = uic.loadUi('root.ui', self)
self.runShow()
self.pushButton.clicked.connect(self.runFunc)
self.w_root.show()
def setTextBrowser(self, val):
self.w_root.textBrowser.setText(val)
def runShow(self):
self.ShowCODE = ShowCodes()
self.ShowCODE.codesShow.connect(self.setTextBrowser)
self.ShowCODE.start()
def runFunc(self):
try:
name = str(self.nameEdit.text())
secret = str(self.secretEdit.text())
if name == "" or secret == "":
raise ValueError
self.AddCODE = AddCode(name, secret)
self.AddCODE.start()
except:
pass
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
app.exec_()