-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
172 lines (137 loc) · 7.15 KB
/
main.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
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
# EdupageClient - Open-source desktop Edupage Client for students
# Copyright (C) MMXXI Tomáš Lovrant & Adam Vlčko
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from PyQt5.QtWidgets import QGridLayout, QSizePolicy, QLineEdit, QMessageBox
from edupage_api import Edupage, BadCredentialsException, LoginDataParsingException, EduStudent
from PyQt5 import QtWidgets, QtCore, QtGui
import sys
import pygame
class EdupageClient:
def __init__(self):
self.app = QtWidgets.QApplication(sys.argv)
self.login_formular = QtWidgets.QWidget()
self.login_layout = QtWidgets.QVBoxLayout()
#740x532
self.login_formular.setGeometry(300, 200, 740/2 - 25, 532/2 - 25)
self.login_formular.setFixedSize(self.login_formular.size())
self.login_formular.setWindowTitle("Edupage Client: Login ")
# Widgety
self.text = QtWidgets.QLabel("Edupage Client - Login to your account", parent=self.login_formular)
self.text.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.text.setAlignment(QtCore.Qt.AlignCenter)
self.domain_edit = QtWidgets.QLineEdit()
self.domain_label = QtWidgets.QLabel(".edupage.org")
self.user_label = QtWidgets.QLabel("Username: ")
self.user_edit = QtWidgets.QLineEdit()
self.pass_label = QtWidgets.QLabel("Password: ")
self.pass_edit = QtWidgets.QLineEdit()
self.pass_edit.setEchoMode(QLineEdit.Password)
self.pass_edit.show()
self.submit_button = QtWidgets.QPushButton("Login")
self.submit_button.clicked.connect(self.login)
self.about_button = QtWidgets.QPushButton("About")
self.about_button.clicked.connect(self.about)
# Layouty
self.login_grid = QGridLayout()
self.domain_box = QtWidgets.QHBoxLayout()
self.user_box = QtWidgets.QHBoxLayout()
self.pass_box = QtWidgets.QHBoxLayout()
self.submit_box = QtWidgets.QHBoxLayout()
self.about_box = QtWidgets.QHBoxLayout()
# Maintain main layout
self.login_layout.addLayout(self.login_grid)
self.login_layout.addStretch()
self.login_layout.addLayout(self.domain_box)
# self.login_layout.addStretch()
self.login_layout.addLayout(self.user_box)
self.login_layout.addLayout(self.pass_box)
self.login_layout.addStretch()
self.login_layout.addLayout(self.submit_box)
# self.login_layout.addStretch()
self.login_layout.addLayout(self.about_box)
# Add widgets
self.login_grid.addWidget(self.text, 0, 0)
self.domain_box.addWidget(self.domain_edit)
self.domain_box.addWidget(self.domain_label)
self.user_box.addWidget(self.user_label)
self.user_box.addWidget(self.user_edit)
self.pass_box.addWidget(self.pass_label)
self.pass_box.addWidget(self.pass_edit)
self.submit_box.addWidget(self.submit_button)
self.about_box.addWidget(self.about_button)
self.login_formular.setLayout(self.login_layout)
self.login_formular.show()
sys.exit(self.app.exec_())
def login(self):
# 1. self.domain_edit 2. self.user_edit 3. self.pass_edit
domain = self.domain_edit.text()
user = self.user_edit.text()
password = self.pass_edit.text()
try:
self.edu = Edupage(domain, user, password)
try:
self.edu.login()
self.login_formular.hide()
eci = EdupageClientIndex(self)
eci.index_formular.show()
except BadCredentialsException:
self.render_err("Bad credentials", "Check login credentials (username/password)!")
except LoginDataParsingException:
self.render_err("Login data parsing", "Check internet connection, try again later or contact server "
"administrators!")
except UnicodeError:
return
except IndexError:
self.render_err("Indexing error", "Check entered domain, if correct then check internet connection or est!")
def about(self):
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText("EdupageClient Version: 0.1\n\nEdupageClient Copyright (C) MMXXI \nTomáš Lovrant & Adam "
"Vlčko\n\nThis program comes "
"with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under "
"the terms of the GNU General Public License as published by "
"the Free Software Foundation, either version 3 of the License, or "
"(at your option) any later version.\nSee: https://www.gnu.org/licenses/\n\nClick on Show Details "
"... for more information.")
msg.setDetailedText("THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT "
"WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE "
"PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, "
"BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A "
"PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS "
"WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY "
"SERVICING, REPAIR OR CORRECTION.")
msg.setWindowTitle("About EdupageClient")
msg.setStandardButtons(QMessageBox.Ok)
msg.setEscapeButton(QMessageBox.Ok)
msg.exec_()
def render_err(self, title, description):
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
msg.setText(description)
msg.setWindowTitle(title)
msg.setStandardButtons(QMessageBox.Retry)
msg.setEscapeButton(QMessageBox.Retry)
msg.exec_()
class EdupageClientIndex:
def __init__(self, edupageclient):
#self.edupageclient = edupageclient
self.index_formular = QtWidgets.QWidget()
self.index_layout = QtWidgets.QVBoxLayout()
self.index_formular.setWindowTitle("Edupage Client: Main")
self.index_formular.setGeometry(300, 200, 345, 245)
self.index_formular.setFixedSize(self.index_formular.size())
self.index_formular.setLayout(self.index_layout)
# sys.exit(self.edupageclient.app.exec_())
EdupageClient()