Last active
December 17, 2015 13:39
-
-
Save Rurik/5618772 to your computer and use it in GitHub Desktop.
Basic Python GUI framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from PyQt4.QtCore import * | |
from PyQt4.QtGui import * | |
import base64 | |
def main(): | |
app = QApplication(sys.argv) | |
w = MyWindow() | |
w.show() | |
sys.exit(app.exec_()) | |
class MyWindow(QWidget): | |
def __init__(self, *args): | |
QWidget.__init__(self, *args) | |
self.setWindowTitle("@BBaskin Decoders") | |
# create objects | |
HelpMsg = QLabel(self.tr("Enter text to decode")) | |
OutputTitle = QLabel(self.tr("Output")) | |
ErrorTitle = QLabel(self.tr("Errors")) | |
self.textInput = QLineEdit() | |
self.outputWindow = QTextEdit() | |
self.errorWindow = QTextEdit() | |
Base64Btn = QPushButton("Base64 Decode", self) | |
ReverseBtn = QPushButton("String Reverse", self) | |
ClearBtn = QPushButton("Clear", self) | |
# layout | |
layout = QVBoxLayout(self) | |
layout.addWidget(HelpMsg) | |
layout.addWidget(self.textInput) | |
layout.addWidget(Base64Btn) | |
layout.addWidget(ReverseBtn) | |
layout.addWidget(ClearBtn) | |
#layout.addWidget(quitBtn) | |
layout.addWidget(OutputTitle) | |
layout.addWidget(self.outputWindow) | |
layout.addWidget(ErrorTitle) | |
layout.addWidget(self.errorWindow) | |
Base64Btn.clicked.connect(self.Base64decode) | |
ReverseBtn.clicked.connect(self.Reversedecode) | |
ClearBtn.clicked.connect(self.ClearOutput) | |
self.setGeometry(300,300,280,170) | |
self.setLayout(layout) | |
self.connect(self.textInput, SIGNAL("returnPressed(void)"), | |
self.Reversedecode) | |
def ClearOutput(self): | |
self.outputWindow.clear() | |
self.errorWindow.clear() | |
def Base64decode(self): | |
self.outputWindow.clear() | |
self.errorWindow.clear() | |
text = str(self.textInput.text()) | |
try: | |
decoded = base64.b64decode(text) | |
self.outputWindow.setText(decoded) | |
except TypeError: | |
decoded = text + " Bad" | |
self.errorWindow.setText(decoded) | |
def Reversedecode(self): | |
self.outputWindow.clear() | |
self.errorWindow.clear() | |
text = str(self.textInput.text()) | |
reversetext = text[::-1] | |
self.outputWindow.setText(reversetext) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment