-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthorizedialog.py
More file actions
67 lines (54 loc) · 2.14 KB
/
authorizedialog.py
File metadata and controls
67 lines (54 loc) · 2.14 KB
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
import sys, qrcode, logging, requests, time, os
from io import BytesIO
from PyQt5.QtWidgets import QDialog
from PyQt5.QtCore import pyqtSignal as Signal
from PyQt5.QtCore import QThread
from PyQt5.QtGui import QPixmap
from PyQt5 import uic
from authorization import Authorization
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger()
class AuthorizeDialog(QDialog):
authorize = None
def __init__(self, parent):
QDialog.__init__(self, parent)
self.parent = parent
self.ui = uic.loadUi(os.path.join(os.path.dirname(os.path.abspath(__file__)), "authorizedialog.ui"), self)
self.authorize = Authorization()
self.ui.cancelButton.clicked.connect(self.cancelAuth)
self.authorize.signalSetAuthLink.connect(self.setAuthLink)
self.authorize.signalDisplayError.connect(self.displayError)
self.authorize.signalAuthApproval.connect(super().hide)
def show(self):
logger.debug("show")
self.errorLabel.setText('')
super().show()
self.authorize.start()
def closeEvent(self, event):
logger.debug("exiting AuthorizeDialog...")
if self.authorize.isRunning():
self.authorize.terminate()
super().hide()
def cancelAuth(self):
logger.debug("cancel Authorization")
if self.authorize.isRunning():
self.authorize.terminate()
super().hide()
self.parent.setFocus()
self.parent.activateWindow()
def displayError(self, msg):
logger.debug(f"Error: {msg}")
error = f'<b style="color:red;">Error: {msg}</b>'
self.errorLabel.setText(error)
def setAuthLink(self, link):
logger.debug(f"authLink: {link}")
buf = BytesIO()
img = qrcode.make(link)
img.save(buf, "PNG")
pixmap = QPixmap()
pixmap.loadFromData(buf.getbuffer().tobytes())
self.ui.qrCode.setPixmap(pixmap)
self.ui.qrCode.setScaledContents(True)
self.ui.authorizationLink.setOpenExternalLinks(True)
link = f'<a href="{link}" target="_AUTHENIX">{link}</a>'
self.ui.authorizationLink.setText(link)