Last active
September 8, 2015 23:42
-
-
Save whoiscarlo/e9638b3663b5b420babd to your computer and use it in GitHub Desktop.
Testing a UI
This file contains hidden or 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
from PySide import QtGui, QtCore | |
# from PyQt4 import QtGui, QtCore | |
import sys | |
class MyFirstUI(QtGui.QDialog): | |
def __init__(self, *args, **kws): | |
parent = kws.get('parent', None) | |
super(MyFirstUI, self).__init__(parent=parent) | |
## Class variables | |
self.logic = Logic() | |
## Setup GUI | |
self._buildUI() | |
self._setupConnections() | |
def _buildUI(self): | |
''' | |
Purpose: Contains all window elements | |
''' | |
## Window Title | |
self.setWindowTitle('Zero Out') | |
## Main Layout | |
self._mainLayout = QtGui.QVBoxLayout() | |
self._mainLayout.setAlignment(QtCore.Qt.AlignCenter) | |
self.setLayout(self._mainLayout) | |
## Do Something button | |
self._thisLine = QtGui.QLineEdit() | |
self._mainLayout.addWidget(self._thisLine) | |
## Do Something button | |
self._doSomethingButton = QtGui.QPushButton('Do Something') | |
self._mainLayout.addWidget(self._doSomethingButton) | |
def _setupConnections(self): | |
''' | |
Purpose: Connect all GUI Elemenents to functions | |
''' | |
self._doSomethingButton.clicked.connect(self._doSomethingButton_clicked) | |
def _doSomethingButton_clicked(self): | |
value = str(self._thisLine.text()) | |
self.logic.alterString(value) | |
class Logic(): | |
def alterString(self, val): | |
''' | |
Alter string and carlo | |
@param val: String name | |
@type val: str | |
''' | |
print val+ ' :WAS PRINTED!!!' | |
def show_dialog(): | |
''' | |
Shows the dialog as a singleton | |
''' | |
global MyFirstUI_instance | |
try: | |
MyFirstUI_instance.close() | |
MyFirstUI_instance.deleteLater() | |
except: | |
pass | |
MyFirstUI_instance = MyFirstUI(parent=None) | |
MyFirstUI_instance.show() | |
return MyFirstUI_instance | |
def main(): | |
app = QtGui.QApplication(sys.argv) | |
# app.setStyle("DarkMojo") | |
show_dialog() | |
sys.exit(app.exec_()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment