-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
262 lines (230 loc) · 11 KB
/
app.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import logging
import os
import time
from PySide2.QtCore import Slot
from PySide2.QtGui import QPixmap, QGuiApplication, QCloseEvent, QIcon
from PySide2.QtWidgets import QApplication, QMainWindow, QFileDialog, QMessageBox
from hashcalc import HashingMethods
from infoManager import informationManger
from ui.ui_mainwindow import Ui_MainWindow
from updateManager import updateManager
logging.basicConfig(level=logging.DEBUG,
format='%(name)s:%(levelname)s:%(message)s')
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.__hashCalculator: HashingMethods
# Setting fixed window size to disable full screen ↓
self.setFixedWidth(self.size().width())
self.setFixedHeight(self.minimumSizeHint().height())
# ↓
self.__main()
def __main(self):
# Making window centered ↓
self.__makeWindowCenter()
# Window customizing ↓
self.setWindowTitle('Free Hash Checker')
# Clipboard setup ↓
self.__clipboard = QApplication.clipboard()
self.__clipboard.clear(mode=self.__clipboard.Clipboard)
# Resetting progress bar ↓
self.ui.progressBarHashCaclulation.reset()
# Updating about information ↓
self.__aboutInformationSetter()
# Default Button's Behaviour Set ↓
self.ui.buttonSelectFile.clicked.connect(self.__buttonSelectFile_Func)
self.ui.buttonHashCalculate.clicked.connect(
self.__buttonHashCalculate__Func)
self.ui.buttonClearHashBox.clicked.connect(
self.__buttonClearHashBox_Func)
self.ui.buttonCopyToClipboard.clicked.connect(
self.__buttonCopyToClipboard_Func)
self.ui.buttonCheckHash.clicked.connect(self.__buttonCheckHash_Func)
# Default ToolTip Information Setter ↓
self.__toolTipInfoSetter()
# Set License Text ↓
self.ui.licenseTextBrowser.setText(informationManger().getLicense())
# Hiding Menu Bar and Status Bar ↓
self.ui.menubar.hide()
self.ui.statusbar.hide()
# Showing application update ↓
# self.__updateMessageBox()
def __updateMessageBox(self):
appUpdates = updateManager()
if appUpdates.haveUpdate() is True:
updateData = appUpdates.getUpdateData()
message: str = """<html><head/><body><p>Version: {0}</p><p>Go to download page,
<a style=\"text-decoration: none\" href=\"{1}\">Click Here</a></p></body></html>""".format(
updateData['version'], updateData['update'])
QMessageBox.information(self, 'New update!', message,
QMessageBox.Ok, QMessageBox.Ok)
else:
pass
# For launching windows in center ↓
def __makeWindowCenter(self):
qtRectangle = self.frameGeometry()
centerPoint = QGuiApplication.primaryScreen().geometry().center()
qtRectangle.moveCenter(centerPoint)
self.move(qtRectangle.topLeft())
# Close button behaviour ↓
# noinspection PyCallingNonCallable
@Slot(QCloseEvent)
def closeEvent(self, event: QCloseEvent):
buttonReply = QMessageBox.question(self, 'Warning', "Sure to exit?",
QMessageBox.Ok | QMessageBox.Cancel,
QMessageBox.Cancel)
if buttonReply == QMessageBox.Ok:
try:
self.__hashCalculator.terminateThread()
except AttributeError:
pass
event.accept()
else:
event.ignore()
def __aboutInformationSetter(self):
info = informationManger()
self.ui.developerName.setText(info.developerName)
self.ui.developerEmail.setText(info.developerEmail)
self.ui.logoCreditName.setText(info.logoCreditName)
self.ui.logoCreditEmail.setText(info.logoCreditEmail)
self.ui.icons8Credit.setText(info.icons8Credit)
self.ui.sourceCodeLink.setText(info.sourceCodeLink)
self.ui.applicationVersion.setText(info.applicationVersion)
# Default ToolTip Information Setter↓
def __toolTipInfoSetter(self):
self.ui.buttonSelectFile.setToolTip('Click to select file.')
self.ui.buttonHashCalculate.setToolTip('Start calculation.')
self.ui.buttonClearHashBox.setToolTip('Clear all.')
self.ui.buttonClearCheckHashBox.setToolTip('C')
self.ui.buttonCopyToClipboard.setToolTip('Copy hash to the clipboard.')
self.ui.buttonCheckHash.setToolTip(
'Paste & Check hash matching result.')
self.ui.lineEditFileExplore.setToolTip(
'Selected file location will be shown here.')
self.ui.lineEditHashBox.setToolTip(
'Calculated hash will be shown here.')
self.ui.progressBarHashCaclulation.setToolTip(
'Calculation\'s progress will be shown here.')
self.ui.buttonClearCheckHashBox.setToolTip('Clear pasted hash.')
self.ui.lineEditCheckHashBox.setToolTip(
'Pasted hash will be shown here for matching.')
self.ui.developerName.setToolTip(informationManger().developerName)
info = informationManger()
self.ui.developerName.setToolTip(info.developerNameTooltip)
self.ui.developerEmail.setToolTip(info.developerEmailTooltip)
self.ui.logoCreditName.setToolTip(info.logoCreditNameTooltip)
self.ui.logoCreditEmail.setToolTip(info.logoCreditEmailTooltip)
self.ui.icons8Credit.setToolTip(info.icons8CreditTooltip)
self.ui.sourceCodeLink.setToolTip(info.sourceCodeLinkTooltip)
self.ui.applicationVersion.setToolTip(info.applicationVersionTooltip)
self.ui.licenseTextBrowser.setToolTip(info.licenseTextBrowserTooltip)
def __buttonSelectFile_Func(self):
dialog = QFileDialog(self)
dialog.setFileMode(QFileDialog.AnyFile)
# noinspection PyTypeChecker
fileName = dialog.getOpenFileName(self, self.tr(u"Select a File"),
str(), self.tr(u"All Files (*)"))
fileName = fileName[0]
if fileName:
self.ui.lineEditFileExplore.clear()
self.ui.lineEditFileExplore.setText(fileName)
self.ui.labelFileExplore.setPixmap(QPixmap(":ok/ok.png"))
logging.info('File selected "{0}"'.format(fileName))
try:
self.ui.buttonHashCalculate.clicked.disconnect()
except RuntimeError:
pass
self.ui.buttonHashCalculate.clicked.connect(
self.__buttonHashCalculate__Func)
def __buttonHashCalculate__Func(self):
if not os.path.isfile(self.ui.lineEditFileExplore.text()):
# noinspection PyTypeChecker
QMessageBox().warning(None, 'Warning',
'Please select a file to continue!',
QMessageBox.Ok)
else:
self.__hashCalculator = HashingMethods()
self.__hashCalculator.setHashName(
self.ui.comboBoxHashChoices.currentText())
self.__hashCalculator.setFileLoc(
self.ui.lineEditFileExplore.text())
self.__hashCalculator.signalEmitter.calculatedHash.connect(
self.__on_finished_hash_calculation)
self.__hashCalculator.signalEmitter.progressBarValue.connect(
self.__on_going_progressbar)
self.__hashCalculator.start()
if self.__hashCalculator.isRunning():
self.ui.progressBarHashCaclulation.setFormat('%p%')
self.ui.buttonHashCalculate.setText('Cancel')
self.ui.buttonHashCalculate.setIcon(
QIcon(':/cancel/cancel.png'))
self.ui.buttonHashCalculate.clicked.disconnect()
self.ui.buttonHashCalculate.clicked.connect(
self.__btnHashCalculatorThreadCanceler_Func)
# noinspection PyCallingNonCallable
@Slot(str)
def __on_finished_hash_calculation(self, calculatedHash):
self.ui.lineEditHashBox.setText(calculatedHash)
self.ui.buttonHashCalculate.setText('Calculate')
self.ui.buttonHashCalculate.setIcon(
QIcon(':/calculate/drawing-compass.png'))
self.ui.buttonHashCalculate.clicked.disconnect()
self.ui.buttonHashCalculate.clicked.connect(
self.__buttonHashCalculate__Func)
logging.info('Response received: ' + calculatedHash)
while self.__hashCalculator.isFinished() is False:
time.sleep(0.5)
logging.info('Hash Calculator Thread Finished')
# noinspection PyTypeChecker,PyCallingNonCallable
@Slot(int)
def __on_going_progressbar(self, value):
self.ui.progressBarHashCaclulation.setValue(value)
def __btnHashCalculatorThreadCanceler_Func(self):
buttonReply = QMessageBox.question(self, 'Confirmation',
"Are you sure to cancel?",
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if buttonReply == QMessageBox.Yes:
self.__hashCalculator.terminateThread()
self.ui.buttonHashCalculate.clicked.disconnect()
self.ui.buttonHashCalculate.setText('Calculate')
self.ui.buttonHashCalculate.setIcon(
QIcon(':/calculate/drawing-compass.png'))
self.ui.progressBarHashCaclulation.reset()
self.ui.buttonHashCalculate.clicked.connect(
self.__buttonHashCalculate__Func)
else:
pass
def __buttonClearHashBox_Func(self):
self.ui.lineEditFileExplore.clear()
self.ui.labelFileExplore.setPixmap(
QPixmap(u":/folder/opened-folder.png"))
self.ui.lineEditHashBox.clear()
self.ui.progressBarHashCaclulation.reset()
try:
if self.__hashCalculator.isRunning() is True:
self.__btnHashCalculatorThreadCanceler_Func()
except AttributeError:
pass
try:
self.ui.buttonHashCalculate.clicked.disconnect()
except RuntimeError:
pass
self.ui.buttonHashCalculate.clicked.connect(
self.__buttonHashCalculate__Func)
def __buttonCopyToClipboard_Func(self):
self.__clipboard.setText(self.ui.lineEditHashBox.text())
def __buttonCheckHash_Func(self):
if not self.ui.lineEditHashBox.text().strip():
return
elif self.ui.lineEditHashBox.text().strip(
) == self.ui.lineEditCheckHashBox.text().strip():
QMessageBox.information(self, 'Result', "Good news! It's Matched!",
QMessageBox.Ok, QMessageBox.Ok)
else:
QMessageBox.information(self, 'Result', "Bad news! Not Matched!",
QMessageBox.Ok, QMessageBox.Ok)
if __name__ == "__main__":
print('Hello World')