-
Notifications
You must be signed in to change notification settings - Fork 0
/
BASE64_DECODER_GUI_RUN.py
61 lines (51 loc) · 1.95 KB
/
BASE64_DECODER_GUI_RUN.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
from PyQt5.QtCore import QEvent,QPoint
from PyQt5 import QtWidgets as qt
from PyQt5 import QtGui as gui
from PyQt5 import QtCore
from BASE64_DECODER_GUI_UI import Ui_Dialog as ui
from base64 import b64encode,b64decode
class Window(qt.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.ui = ui()
self.ui.setupUi(self) # Initalize UI
# Connect ButtonPress event to functions
self.ui.btnENC.clicked.connect(self.base64_encode)
self.ui.btnDEC.clicked.connect(self.base64_decode)
self.ui.btnCLEAR.clicked.connect(self.clearfields)
self.ui.btnCOPY.clicked.connect(self.copy_To_Clipboard)
def base64_encode(self):
varIN = self.ui.txtIN.text()
try:
self.ui.txtOut.setText(b64encode(bytes(varIN,'utf-8')).decode('utf-8'))
except Exception as e:
msg1 = qt.QMessageBox()
msg1.setIcon(qt.QMessageBox.Warning)
msg1.setText("Invalid input!")
msg1.setWindowTitle("Error")
msg1.setStandardButtons(qt.QMessageBox.Ok)
msg1.exec_()
def base64_decode(self):
varIN = self.ui.txtIN.text()
try:
self.ui.txtOut.setText(b64decode(bytes(varIN,'utf-8')).decode('utf-8'))
except Exception as e:
msg2 = qt.QMessageBox()
msg2.setIcon(qt.QMessageBox.Warning)
msg2.setText("Invalid base64 encoded string!")
msg2.setWindowTitle("Error")
msg2.setStandardButtons(qt.QMessageBox.Ok)
msg2.exec_()
def clearfields(self):
self.ui.txtIN.setText('')
self.ui.txtOut.setText('')
def copy_To_Clipboard(self):
import clipboard
copytext = self.ui.txtOut.text()
if len(copytext) > 0 :
clipboard.copy(copytext)
# Run Application
app = qt.QApplication([])
application = Window()
application.show()
app.exec()