-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
347 lines (295 loc) · 11.4 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
from PyQt5.QtWidgets import (
QApplication,
QMainWindow,
QWidget,
QVBoxLayout,
QPushButton,
QLabel,
QFrame,
QSizeGrip,
QMessageBox,
QGraphicsDropShadowEffect,
)
from PyQt5.QtCore import Qt, QPoint, QUrl, QTimer
from PyQt5.QtGui import QColor, QFontDatabase, QIcon, QDesktopServices
from ui.main_window import Ui_MainWindow
from ui import resources_rc
from ui.ui_splash_screen import Ui_SplashScreen
from ui.circular_progress import CircularProgress
import sys
import os
from tabs_functions.appbasic_info import BasicInfo
from tabs_functions.appdot_plot import DotPlot
from tabs_functions.applocal_align import LocalAlign
from tabs_functions.appglobal_align import GlobalAlign
# GLOBAL VARIABLE
counter = 0
class SplashScreen(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.ui = Ui_SplashScreen()
self.ui.setupUi(self)
# REMOVE TITLE BAR
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.progress = CircularProgress()
self.progress.width = 270
self.progress.height = 270
self.progress.value = 10
self.progress.move(15, 15)
self.progress.font_size = 35
self.progress.add_shadow(True)
self.progress.progress_width = 10
self.progress.bg_color = QColor(80, 250, 123, 140)
self.progress.setFixedSize(self.progress.width, self.progress.height)
self.progress.setParent(self.ui.centralwidget)
self.progress.show()
# ADD DROP SHADOW
self.shadow = QGraphicsDropShadowEffect(self)
self.shadow.setBlurRadius(15)
self.shadow.setXOffset(0)
self.shadow.setYOffset(0)
self.shadow.setColor(QColor(0, 0, 0, 80))
self.setGraphicsEffect(self.shadow)
# Q TIMER
self.timer = QTimer()
self.timer.timeout.connect(self.update)
self.timer.start(30)
self.show()
# UPDATE PROGRESS BAR
def update(self):
global counter
# SET VALUE TO PROGRESS BAR
self.progress.set_value(counter)
if counter >= 100:
self.timer.stop()
self.main = MyWindow()
self.main.show()
self.close()
counter += 1
class MyWindow(QMainWindow):
def __init__(self):
####===== Initialization Constructor ====###
super(MyWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
## ==================================####
## Style and Customizations of Main Window
## =================================####
self.stylesheet_file("static/style/style.qss")
QFontDatabase.addApplicationFont(
":/fonts/Lora-VariableFont/Lora-VariableFont_wght.ttf"
)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowMaximizeButtonHint)
self.setAttribute(Qt.WA_TranslucentBackground, True)
## ==================================####
## Resizing and Dragging Initial Objects
## =================================####
self.oldPos = None
QSizeGrip(self.ui.size_grip)
## ==================================####
## Customized min, max, and close button
## =================================####
self.max_btn = self.findChild(QPushButton, "max_btn")
self.max_btn.clicked.connect(lambda: self.toggle_max())
self.min_btn = self.findChild(QPushButton, "min_btn")
self.min_btn.clicked.connect(lambda: self.showMinimized())
self.close_btn = self.findChild(QPushButton, "close_btn")
self.close_btn.clicked.connect(lambda: self.close())
## =================================####
## Obtain the objects or pages(to launch in main_window)
## =================================####
self.basic_info_btn = self.ui.btn_1
self.dot_plot_btn = self.ui.btn_2
self.local_align_btn = self.ui.btn_3
self.global_align_btn = self.ui.btn_4
## ==================================####
## Create Dictionary for menu buttons and tab windows
## =================================####
self.menu_btns_dict = {
self.basic_info_btn: BasicInfo,
self.dot_plot_btn: DotPlot,
self.local_align_btn: LocalAlign,
self.global_align_btn: GlobalAlign,
}
## ==================================####
## Set Up Functions to Show Start Up Tab
## =================================####
self.show_home_window()
## ==================================####
## Signal and Slot Configuration
## =================================####
self.ui.tabWidget.tabCloseRequested.connect(self.close_tab)
self.basic_info_btn.clicked.connect(self.show_selected_window)
self.dot_plot_btn.clicked.connect(self.show_selected_window)
self.local_align_btn.clicked.connect(self.show_selected_window)
self.global_align_btn.clicked.connect(self.show_selected_window)
## ==================================####
## Developer's Info Label Signal
## =================================####
self.ui.devlabel.mousePressEvent = self.show_dev_popup
## ==================================####
## About Link Functions
## =================================####
def show_dev_popup(self, event):
"""Provides a popup mesage about the developer"""
msg = QMessageBox()
msg.setWindowTitle("About the Developer")
msg.setText("Hello! The developer of this GUI App is Bryan Castillo! ")
msg.setIcon(QMessageBox.Information)
msg.setStandardButtons(QMessageBox.Ok)
msg.setDetailedText(
f"""
This software was built to demonstrate my skills in bioinformatics and to promote data science in the field of computational biology. """
)
msg.setStyleSheet(self.popup_style())
msg.exec_()
def open_GitHub_repo(self):
"""Link to the GitHub Repository of this Project"""
QDesktopServices.openUrl(
QUrl("https://github.com/bryancastillo10/BioBytes-PairSync")
)
def open_paypal_donate(self):
"""Link to the Paypal Donation"""
QDesktopServices.openUrl(QUrl("https://paypal.me/BryanAngeloCastillo"))
## ==================================####
## Tab Functions
## =================================####
def show_home_window(self):
"""Function for showing home window
:return:
"""
result = self.open_tab_flag(self.basic_info_btn)
self.set_btn_checked(self.basic_info_btn)
if result[0]:
self.ui.tabWidget.setCurrentIndex(result[1])
else:
tab_title = self.basic_info_btn.text()
curIndex = self.ui.tabWidget.addTab(BasicInfo(), tab_title)
self.ui.tabWidget.setCurrentIndex(curIndex)
self.ui.tabWidget.setVisible(True)
def set_btn_checked(self, btn):
"""
Status of the selected button were checked and set other buttons' status off/unchecked
:param btn: button object
"""
for button in self.menu_btns_dict.keys():
if button != btn:
button.setChecked(False)
else:
button.setChecked(True)
def show_selected_window(self):
"""
Function for showing the currently selected window
:return:
"""
button = self.sender()
result = self.open_tab_flag(button.text())
self.set_btn_checked(button)
if result[0]:
self.ui.tabWidget.setCurrentIndex(result[1])
else:
tab_title = button.text()
curIndex = self.ui.tabWidget.addTab(
self.menu_btns_dict[button](), tab_title
)
self.ui.tabWidget.setCurrentIndex(curIndex)
self.ui.tabWidget.setVisible(True)
def close_tab(self, index):
"""
Function for closing a tab in tabWidget
:param index: index of tab
:return:
"""
self.ui.tabWidget.removeTab(index)
if self.ui.tabWidget.count() == 0:
self.ui.tabWidget.setCurrentIndex(0)
self.show_home_window()
def open_tab_flag(self, btn_text):
"""
To check if the selected window appears or not
:return: boolean and index
"""
open_tab_count = self.ui.tabWidget.count()
for i in range(open_tab_count):
tab_title = self.ui.tabWidget.tabText(i)
if tab_title == btn_text:
return True, i
else:
continue
return (False,)
## ==================================####
## QSS File Reading /Stylesheet
## =================================####
def stylesheet_file(self, style_path):
style_path = "static/style/style.qss"
with open(style_path, "r") as f:
style = f.read()
self.setStyleSheet(style)
def popup_style(self):
return """
QMessageBox{
background-color: rgb(54,54,54); /* charcoal gray*/
}
QMessageBox QLabel{
color: #fff;
}
QMessageBox QPushButton {
background-color: rgb(120,157,186); /* light blue */
border: 3px solid rgb(5,92,142);
border-radius:12px;
padding: 5px;
color: #000;
font-size:12px;
}
QMessageBox QPushButton::hover{
background-color: rgba(5,92,142,0.5); /* dark-blue */
color: #fff;
border-radius: 12px;
font-size:12px;
}
"""
## ==================================####
## Min, Max and Close Windows Function
## =================================####
def toggle_max(self):
if self.isFullScreen():
self.showNormal()
else:
self.showFullScreen()
def closeEvent(self, event):
"""Confirmation if the user wants to close the main window"""
close_msg = QMessageBox()
close_msg.setWindowTitle("The APP is about to Close")
close_msg.setText("Are you sure you want to terminate BioBytes APP?")
close_msg.setIcon(QMessageBox.Question)
close_msg.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel)
close_msg.setStyleSheet(self.popup_style())
response = close_msg.exec_()
if response == QMessageBox.Yes:
event.accept()
elif response == QMessageBox.Cancel:
event.ignore()
## ==================================####
## Default Event and Override Conditions
## =================================####
def mousePressEvent(self, event):
if event.button() == Qt.MouseButton.LeftButton:
self.oldPos = event.globalPos()
if self.ui.gitlabel.underMouse():
self.open_GitHub_repo()
elif self.ui.paypal_label.underMouse():
self.open_paypal_donate()
def mouseMoveEvent(self, event):
if self.oldPos is not None:
delta = event.globalPos() - self.oldPos
self.move(self.pos() + delta)
self.oldPos = event.globalPos()
def mouseReleaseEvent(self, event):
self.oldPos = None
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("static/icons/app_icon_dna_32.png"))
window = SplashScreen()
window.show()
sys.exit(app.exec())