-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainFrame.py
483 lines (387 loc) · 17.1 KB
/
MainFrame.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
"""
##########################################################################################
Improvised Version: DNA Cloud 3.14
Developers: Mihir Gohel, Natvar Prajapati, Shashank Upadhyay, Shivam Madlani, Vandan Bhuva
Mentor: Prof. Manish K Gupta
Website: www.guptalab.org/dnacloud
This file is the Main GUI file that is to be launched via command - python MainFrame.py.
##########################################################################################
Author: Aayush Kapadia,Suparshva Mehta
Project: DNA Cloud 3
Graduate Mentor: Dixita Limbachya
Mentor: Prof. Manish K Gupta
Website: www.guptalab.org/dnacloud
##########################################################################################
"""
from asyncio.windows_events import NULL
import sys
from PyQt5.QtWidgets import *
import os
import io
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from collections import deque
import GoldmanEncoding
import GoldmanDecoding
import golayEncoding
import GolayDecode
import EstimationUI
import webbrowser
# This object carries out encoding action of certain type
class EncodeThread(QThread):
# Used for indication how much percentage of action completed
signalStatus = pyqtSignal(str)
def __init__(self, fileName, typeOfAction, parent=None):
super(EncodeThread, self).__init__(parent)
self.fileName = fileName
# 0 for encodeGoldman , 1 for encodeGolay , 2 for decodeGoldman , 3 for decodeGolay
self.typeOfAction = typeOfAction
def run(self):
if self.typeOfAction == 0: # Goldman Encoding
GoldmanEncoding.encodeFile(self.fileName, self.signalStatus)
elif self.typeOfAction == 1: # Golay Encoding
golayEncoding.encodeFile(self.fileName, self.signalStatus)
self.signalStatus.emit('Idle.') # Indicating action is finished
# This object carries out decoding action of certain type
class DecodeThread(QThread):
# Used for indication how much percentage of action completed
signalStatus = pyqtSignal(str)
def __init__(self, fileName, typeOfAction, parent=None):
super(DecodeThread, self).__init__(parent)
self.fileName = fileName
# 0 for encodeGoldman , 1 for encodeGolay , 2 for decodeGoldman , 3 for decodeGolay
self.typeOfAction = typeOfAction
def run(self):
if self.typeOfAction == 2: # Goldman Decoding
GoldmanDecoding.decodeFile(self.fileName, self.signalStatus)
elif self.typeOfAction == 3: # Golay Decoding
GolayDecode.decodeFile(self.fileName, self.signalStatus)
self.signalStatus.emit('Idle.') # Indicating action is finished
# This object shows dialouge box for selecting encoding type
class EncodeSelection(QDialog):
def __init__(self, parent=None):
super(EncodeSelection, self).__init__(parent)
self.setWindowTitle("Encode")
self.initUI()
def initUI(self):
self.selectionComboBox = QComboBox()
encodings = ['Goldman', 'Golay']
self.selectionComboBox.addItems(encodings)
# OK and Cancel buttons
self.buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
layout = QVBoxLayout(self)
layout.addWidget(self.selectionComboBox)
layout.addWidget(self.buttons)
self.setLayout(layout)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
# This object shows dialouge box for selecting decoding type
class DecodeSelection(QDialog):
def __init__(self, parent=None):
super(DecodeSelection, self).__init__(parent)
self.setWindowTitle("Decode")
self.initUI()
def initUI(self):
self.selectionComboBox = QComboBox()
encodings = ['Goldman', 'Golay']
self.selectionComboBox.addItems(encodings)
# OK and Cancel buttons
self.buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
layout = QVBoxLayout(self)
layout.addWidget(self.selectionComboBox)
layout.addWidget(self.buttons)
self.setLayout(layout)
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
# Selects one of the type of encoding/decoding (Golay or Goldman)
def getActionType(typeOfAction, parent=None):
if typeOfAction == 'E': # Encoding Action
dialog = EncodeSelection(parent)
result = dialog.exec_()
if(result==1):
encodingType = str(dialog.selectionComboBox.currentText())
if encodingType == 'Goldman':
return 0
elif encodingType == 'Golay':
return 1
return -1
else:
return -1
else:
dialog = DecodeSelection(parent)
result = dialog.exec_()
if(result==1):
decodingType = str(dialog.selectionComboBox.currentText())
if decodingType == 'Goldman':
return 2
elif decodingType == 'Golay':
return 3
return -1
else:
return -1
# Used for identifying any action
class ActionIdentifierTuple():
def __init__(self, progressBar, fileName, encodingType):
self.progressBar = progressBar
self.fileName = fileName
self.encodingType = encodingType
# The Main GUI of any action
class ActionUI(QFrame):
def __init__(self, parent, actionType):
QFrame.__init__(self, parent)
self.actionType = actionType # 'E' for encoding , 'D' for decoding
self.noOfFiles = 0
self.processQueue = deque()
self.running = False
self.initUI()
def initUI(self):
self.layout = QGridLayout()
self.layout.setAlignment(Qt.AlignTop)
self.setLayout(self.layout)
self.setAcceptDrops(True)
self.setAutoFillBackground(False)
self.setStyleSheet("background-color: rgb(255,250,250); margin:5px; border:1px solid rgb(0, 0, 0);")
# This is called when any drag and drop event begins
def dragEnterEvent(self, e):
if e.mimeData().hasUrls:
e.accept()
else:
e.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
for url in event.mimeData().urls():
linkToFile = str(url.toLocalFile())
if os.path.isdir(linkToFile):
print('Folder Not Supported Yet')
continue
self.addLink(linkToFile)
else:
event.ignore()
def addLink(self, linkToFile):
if not os.path.isfile(linkToFile):
return
textView = QLabel(linkToFile)
textView.setStyleSheet("background-color: rgb(255,255,255); margin:5px; border:0px solid rgb(0, 0, 0);")
scroll = QScrollArea()
scroll.setWidget(textView)
scroll.setWidgetResizable(True)
scroll.setFixedWidth(250)
scroll.setFixedHeight(40)
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.progress = QProgressBar(self)
self.progress.setValue(0)
self.progress.setAlignment(Qt.AlignCenter)
self.layout.addWidget(scroll, self.noOfFiles, 0)
self.layout.addWidget(self.progress, self.noOfFiles, 1)
self.noOfFiles = self.noOfFiles + 1
self.addAction(self.progress, linkToFile, getActionType(self.actionType))
def addAction(self, progressBar, fileName, encodingType):
if len(self.processQueue) == 0:
self.processQueue.append(ActionIdentifierTuple(progressBar, fileName, encodingType))
self.startAction()
else:
self.processQueue.append(ActionIdentifierTuple(progressBar, fileName, encodingType))
def startAction(self):
fileName = self.processQueue[0].fileName
encodingType = self.processQueue[0].encodingType
if (encodingType <= 1):
self.thread = EncodeThread(fileName, encodingType)
else:
self.thread = DecodeThread(fileName, encodingType)
self.thread.signalStatus.connect(self.updateStatus)
self.thread.start()
def updateStatus(self, status):
if status != 'Idle.':
self.processQueue[0].progressBar.setValue(int(status))
else:
self.thread.wait()
self.processQueue.popleft()
if len(self.processQueue):
self.startAction()
# This object represents main UI which is collection of all actions (Here encoding window + decoding window)
class MainUI(QWidget):
def __init__(self, parent=None):
super(MainUI, self).__init__(parent)
self.initUI()
def initUI(self):
self.encodeUI = ActionUI(self, 'E')
self.decodeUI = ActionUI(self, 'D')
layout = QHBoxLayout()
layout.addWidget(self.encodeUI, 1)
layout.addWidget(self.decodeUI, 1)
self.setLayout(layout)
# This object represents main GUI of application will all menus like FILE,ABOUT etc...
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle('DNA 3.14')
self.setWindowIcon(QIcon("DNA_icon-8.png"))
self.initUI()
def initUI(self):
self.main_widget = MainUI()
self.setCentralWidget(self.main_widget)
self.statusBar() # for showing status bar in application
# for showing menu items like FILE,ABOUT etc..
menubar = self.menuBar()
# Actions for File menu
self.encodeAction = QAction('&Encode', self)
self.encodeAction.setShortcut('Ctrl+E')
self.encodeAction.setStatusTip('Encode file to DNA')
self.encodeAction.triggered.connect(self.encodeFile)
self.decodeAction = QAction('&Decode', self)
self.decodeAction.setShortcut('Ctrl+D')
self.decodeAction.setStatusTip('Decode file from DNA')
self.decodeAction.triggered.connect(self.decodeFile)
exitAction = QAction('&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(QApplication.quit)
# File menu creation
fileMenu = menubar.addMenu('&Files')
fileMenu.addAction(self.encodeAction)
fileMenu.addAction(self.decodeAction)
fileMenu.addAction(exitAction)
# Actions for Tools menu
self.storageEstimatorAction = QAction('&Storage Estimator', self)
self.storageEstimatorAction.setStatusTip('Estimates approximate encoded file size required on disk ')
self.storageEstimatorAction.triggered.connect(self.showMemoryEstimator)
self.costEstimatorAction = QAction('&Cost Estimator', self)
self.costEstimatorAction.setStatusTip('Predicts approximate cost to encode in DNA')
self.costEstimatorAction.triggered.connect(self.showCostEstimator)
# self.barcodeGeneratorAction = QAction('&Generate Barcode',self)
# self.barcodeGeneratorAction.setStatusTip('Generate Barcode')
# self.barcodeGeneratorAction.triggered.connect(self.showBarcode)
# Tools menu creation
toolsMenu = menubar.addMenu('&Tools')
toolsMenu.addAction(self.storageEstimatorAction)
toolsMenu.addAction(self.costEstimatorAction)
# toolsMenu.addAction(self.barcodeGeneratorAction)
# Actions for Follow us
self.Gupta_Lab = QAction('&Gupta Lab', self)
self.Gupta_Lab.setStatusTip('Gupta Lab')
self.Gupta_Lab.triggered.connect(self.showGupta_Lab)
self.Twitter = QAction('&Twitter', self)
self.Twitter.setStatusTip('Twitter')
self.Twitter.triggered.connect(self.showTwitter)
self.Gupta_Lab_GitHub = QAction('&GitHub', self)
self.Gupta_Lab_GitHub.setStatusTip('Gupta Lab Github')
self.Gupta_Lab_GitHub.triggered.connect(self.showGupta_Lab_GitHub)
self.Youtube_Channel = QAction('&YouTube', self)
self.Youtube_Channel.setStatusTip('Youtube Channel')
self.Youtube_Channel.triggered.connect(self.showYoutube_Channel)
self.LinkedIn= QAction('&LinkedIn', self)
self.LinkedIn.setStatusTip('LinkedIn')
self.LinkedIn.triggered.connect(self.showLinkedIn)
#About Follow us
AboutFollowUs = menubar.addMenu('&Follow Us')
AboutFollowUs.addAction(self.Gupta_Lab)
AboutFollowUs.addAction(self.Gupta_Lab_GitHub)
AboutFollowUs.addAction(self.LinkedIn)
AboutFollowUs.addAction(self.Twitter)
AboutFollowUs.addAction(self.Youtube_Channel)
#Actions for Contact us
self.Email_Id= QAction('&Email Id', self)
self.Email_Id.setStatusTip('Email Id')
self.Email_Id.triggered.connect(self.showEmail_Id)
self.Gupta_Lab1= QAction('&Gupta Lab', self)
self.Gupta_Lab1.setStatusTip('Gupta Lab Contact page')
self.Gupta_Lab1.triggered.connect(self.showGupta_Lab1)
#About Contact us
AboutContactUs = menubar.addMenu('&Contact Us')
AboutContactUs.addAction(self.Email_Id)
AboutContactUs.addAction(self.Gupta_Lab1)
#Actions for help menubar
self.User_Manual= QAction('&User Manual', self)
self.User_Manual.setStatusTip('User Manual')
self.User_Manual.triggered.connect(self.showUser_Manual)
self.Product_Demo= QAction('&Product Demo', self)
self.Product_Demo.setStatusTip('Product Demo')
self.Product_Demo.triggered.connect(self.showProduct_Demo)
self.Product_Feedback= QAction('&Product Feedback', self)
self.Product_Feedback.setStatusTip('Product Feedback')
self.Product_Feedback.triggered.connect(self.showProduct_Feedback)
self.Credits= QAction('&Credits', self)
self.Credits.setStatusTip('Credits')
self.Credits.triggered.connect(self.showCredits)
self.About_Us= QAction('&About Us', self)
self.About_Us.setStatusTip('About Us')
self.About_Us.triggered.connect(self.showAbout_Us)
#About Help
AboutHelp = menubar.addMenu('&Help')
AboutHelp.addAction(self.User_Manual)
AboutHelp.addAction(self.Product_Demo)
AboutHelp.addAction(self.Product_Feedback)
AboutHelp.addAction(self.Credits)
AboutHelp.addSeparator()
AboutHelp.addAction(self.About_Us)
# Actions for About menu
self.versionAction = QAction('&Version', self)
self.versionAction.setStatusTip('Version info')
self.versionAction.triggered.connect(self.showVersion)
# About menu creation
AboutMenu = menubar.addMenu('&About')
AboutMenu.addAction(self.versionAction)
self.statusBar().showMessage("Drag and drop on left to encode file or on right to decode file")
self.setStyleSheet("background-color: rgb(238,203,178)")
def getEncodeActionUI(self):
return self.main_widget.encodeUI
def getDecodeActionUI(self):
return self.main_widget.decodeUI
def encodeFile(self):
openfile = QFileDialog.getOpenFileName(self)[0]
encodeAction = self.getEncodeActionUI()
encodeAction.addLink(str(openfile))
def decodeFile(self):
openfile = QFileDialog.getOpenFileName(self)[0]
decodeAction = self.getDecodeActionUI()
decodeAction.addLink(str(openfile))
# def showBarcode(self) : # Not supported Yet
# return
def showMemoryEstimator(self):
est = EstimationUI.MemoryEstimation(self)
est.exec_()
def showCostEstimator(self):
est = EstimationUI.CostEstimation(self)
est.exec_()
def showVersion(self):
est = EstimationUI.Version(self)
est.exec_()
def showGupta_Lab(self):
webbrowser.open("https://guptalab.org/", new=2)
def showTwitter(self):
webbrowser.open("https://twitter.com/guptalab", new=2)
def showGupta_Lab_GitHub(self):
webbrowser.open("https://github.com/guptalab/", new=2)
def showYoutube_Channel(self):
webbrowser.open("https://www.youtube.com/c/ManishGuptamankg", new=2)
def showLinkedIn(self):
webbrowser.open("https://www.linkedin.com/company/guptalab/", new=2)
def showEmail_Id(self):
est = EstimationUI.Email_Id(self)
est.exec_()
def showGupta_Lab1(self):
webbrowser.open("https://www.guptalab.org/mainweb/contact.html", new=2)
def showUser_Manual(self):
webbrowser.open("https://drive.google.com/file/d/1Skru68vl41RhrLqnGBLq38NL-0ojp6m4/view", new=2)
def showProduct_Demo(self):
NULL
def showProduct_Feedback(self):
webbrowser.open("https://forms.gle/jTY8FcgKeWrosqZ1A", new=2)
def showCredits(self):
webbrowser.open("https://drive.google.com/file/d/1FNmoNd2rE4ChLR1-1nGbJd-CVq7vYAKV/view", new=2)
def showAbout_Us(self):
webbrowser.open("https://drive.google.com/file/d/1lXqpoG5tSoH7b8a04EQVWVk65HpqgdPc/view", new=2)
app = QApplication(sys.argv)
dna3Win = MainWindow()
dna3Win.showMaximized()
app.exec_()