-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
219 lines (176 loc) · 6.14 KB
/
main.py
File metadata and controls
219 lines (176 loc) · 6.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/env python3
"""
@author: dodo
"""
import sys
# Importieren des PySide Moduls
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
# Das backend wird importiert
from backend import *
try:
from twitter import tweet_job
except ImportError:
twitter_integration = False
else:
twitter_integration = True
rating_strings = ("Easy", "Normal", "Hard", "Impossible")
# So können Argumente für Qt5 dem Programm übergeben werden
app = QApplication(sys.argv)
# Das Fenster wird erstellt
main_window = QWidget()
rate_window = QWidget()
# Gitter Layout
layout = QGridLayout()
# Bewertungsfenster Layout:
rate_layout = QVBoxLayout()
# 1. Label "Schreibe"
write_label = QLabel("Schreibe")
# 2. Label "in"
in_label = QLabel("in")
# Hauptfenster:
# 1. Textfeld: Projekt
project = QLineEdit(main_window)
project.setFixedWidth(300)
# 2. Textfeld: Programmiersprache
language = QLineEdit(main_window)
language.setFixedWidth(300)
# 3. Textfeld: Herausforderung
constraint = QLineEdit(main_window)
constraint.setFixedWidth(300)
# 1. Checkbox: Projekt fixieren
project_checkbox = QCheckBox("Fix?")
# 2. Checkbox: Sprache fixieren
language_checkbox = QCheckBox("Fix?")
# 3. Checkbox: Hürde fixieren
constraint_checkbox = QCheckBox("Fix?")
# Die Knöpfe werden initialisiert
new_button = QPushButton("New", main_window)
save_button = QPushButton("Save", main_window)
load_button = QPushButton("Load", main_window)
rate_button = QPushButton("Rate", main_window)
if twitter_integration:
tweet_button = QPushButton("Tweet", main_window)
# Bewertungsfenster:
# Radiobuttons für die Bewertung
easy_rButton = QRadioButton("Easy")
normal_rButton = QRadioButton("Normal")
hard_rButton = QRadioButton("Hard")
impossible_rButton = QRadioButton("Impossible")
# Button zum Beenden der Bewertung:
rate_quit_button = QPushButton("Rate")
# Funktion zum Anzeigen eines Ergebnises in einer
# Messagebox
def job_messagebox(job):
mb = QMessageBox(QMessageBox.Information, "Aufgabe", job, QMessageBox.Ok, main_window)
mb.show()
def get_current_job():
# Funktion um die aktuelle Aufgabe zu erhalten
current_project = project.text().strip("\n")
current_language = language.text().strip("\n")
current_constraint = constraint.text().strip("\n")
return (current_project, current_language, current_constraint)
# Die Aktionen beim Drücken der Knöpfe werden definiert
def onClick_new():
if project_checkbox.checkState():
project_str = project.text()
else:
project_str = get_project()
project.setText(project_str)
if language_checkbox.checkState():
language_str = language.text()
else:
language_str = get_language()
language.setText(language_str)
if constraint_checkbox.checkState():
constraint_str = constraint.text()
else:
constraint_str = get_constraint()
constraint.setText(constraint_str)
result_str = get_job(project_str, language_str, constraint_str)
job_messagebox(result_str)
def onClick_save():
project_str = project.text()
language_str = language.text()
constraint_str = constraint.text()
job = get_job(project_str, language_str, constraint_str)
save_job(job)
def onClick_load():
job = load_rating()
current_project = job[0]
current_language = job[1]
current_constraint = job[2]
current_rating = job[3]
job_str = get_job(current_project, current_language, current_constraint)
rating_str = rating_strings[int(current_rating) - 1]
mb = QMessageBox(QMessageBox.Information, rating_str, job_str, QMessageBox.Ok, main_window)
mb.show()
def onClick_rate():
rate_window.show()
def onClick_tweet():
project_str = project.text()
language_str = language.text()
constraint_str = constraint.text()
job = get_job(project_str, language_str, constraint_str)
if twitter_integration:
result = tweet_job(job)
mb = QMessageBox(QMessageBox.Information, "Twitter Feedback", "Der Tweet wurde gesendet", QMessageBox.Ok, main_window)
if not result:
mb = QMessageBox(QMessageBox.Information, "Twitter Feedback", "Der Tweet war zu lang", QMessageBox.Ok, main_window)
mb.show()
def onClick_rate_quit():
rating = 0
if easy_rButton.isChecked():
rating = 1
elif normal_rButton.isChecked():
rating = 2
elif hard_rButton.isChecked():
rating = 3
elif impossible_rButton.isChecked():
rating = 4
current_job = get_current_job()
current_project = current_job[0]
current_language = current_job[1]
current_constraint = current_job[2]
current_rating = rating
save_rating(current_project, current_language, current_constraint, current_rating)
mb = QMessageBox(QMessageBox.Information, "Bewertung erfolgreich", "Deine Bewertung wurde gespeichert.", QMessageBox.Ok, main_window)
mb.show()
rate_window.close()
# Den Knöpfen werden ihre Aktionen zugeordnet
new_button.clicked.connect(onClick_new)
save_button.clicked.connect(onClick_save)
load_button.clicked.connect(onClick_load)
rate_button.clicked.connect(onClick_rate)
if twitter_integration:
tweet_button.clicked.connect(onClick_tweet)
rate_quit_button.clicked.connect(onClick_rate_quit)
# Die Elemente werden in das Hauptlayout hinzugefügt:
layout.addWidget(write_label, 0, 0)
layout.addWidget(project, 0, 1)
layout.addWidget(project_checkbox, 0, 2)
layout.addWidget(in_label, 1, 0)
layout.addWidget(language, 1, 1)
layout.addWidget(language_checkbox, 1, 2)
layout.addWidget(constraint, 2, 1)
layout.addWidget(constraint_checkbox, 2, 2)
layout.addWidget(new_button, 3, 0)
layout.addWidget(save_button, 3, 1)
layout.addWidget(load_button, 3, 2)
layout.addWidget(rate_button, 4, 0)
if twitter_integration:
layout.addWidget(tweet_button, 4, 1)
# Die Elemente werden in das Bewertungslayout hinzugefügt:
rate_layout.addWidget(easy_rButton)
rate_layout.addWidget(normal_rButton)
rate_layout.addWidget(hard_rButton)
rate_layout.addWidget(impossible_rButton)
rate_layout.addWidget(rate_quit_button)
# Das Layout wird zum Fenster hinzugefügt
main_window.setLayout(layout)
rate_window.setLayout(rate_layout)
# Fenster anzeigen
main_window.show()
# App ausführen
app.exec_()