Skip to content
Snippets Groups Projects

#73 Fjernet main.py og test_main.py

Merged Anders H. Rebner requested to merge fjern-main-og-test_main into master
2 files
+ 0
169
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 0
63
"""Applikasjon basert på popups.
Bare her for å ha noe å teste mens vi setter opp repo.
"""
import sys
from PySide2 import QtWidgets
class CoolWidget(QtWidgets.QWidget):
"""Enkel widget for å ha noe å teste.
Placeholderbeskrivelse.
"""
def __init__(self, text, *args, **kwargs):
super(CoolWidget, self).__init__(*args, **kwargs)
# settings this to None is only useful for one of the testing methods
# described in test_main.py
self.dlg_input = None
# only here to conform to pylint. see above comment
self.dlg_msg = None
layout = QtWidgets.QHBoxLayout()
self.qlabel = QtWidgets.QLabel(text)
self.button = QtWidgets.QPushButton("Change text")
self.button.clicked.connect(self.clickfunc)
layout.addWidget(self.qlabel)
layout.addWidget(self.button)
self.setLayout(layout)
def clickfunc(self):
"""Pop-up for å endre tekst. Koblet til knapp."""
# try-finally to set dialog to None is only useful for one of the
# testing methods described in test_main.py
try:
self.dlg_input = QtWidgets.QInputDialog(self)
text, ok = self.dlg_input.getText(
self,
"Change text",
"Please type something",
QtWidgets.QLineEdit.Normal,
)
if ok:
self.qlabel.setText(text)
else:
self.dlg_msg = QtWidgets.QMessageBox()
self.dlg_msg.setText("Operation cancelled")
self.dlg_msg.exec_()
finally:
self.dlg_input = None
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
WIDGET = CoolWidget("Custom text")
WIDGET.show()
app.exec_()
Loading