Added notification dialogs
This commit is contained in:
parent
7f790a2e82
commit
70ae74dcbb
76
GUI/NotificationDialog.ui
Normal file
76
GUI/NotificationDialog.ui
Normal file
@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>150</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>ACHTUNG!</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>../icon.ico</normaloff>../icon.ico</iconset>
|
||||
</property>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>30</y>
|
||||
<width>331</width>
|
||||
<height>61</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Century Gothic</family>
|
||||
<pointsize>16</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="indent">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>280</x>
|
||||
<y>100</y>
|
||||
<width>81</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Cooper Black</family>
|
||||
<pointsize>14</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>OK!</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Return</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@ -63,6 +63,9 @@
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>BusyCursor</cursorShape>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
|
||||
@ -16,17 +16,16 @@ class GUI(QMainWindow):
|
||||
super().__init__()
|
||||
loadUi('GUI/MainWindow.ui',self)
|
||||
self.dlbtn.clicked.connect(self.download)
|
||||
self.inprocess=False
|
||||
|
||||
def download(self):
|
||||
self.inprocess=True
|
||||
# Validating input
|
||||
songID=self.input.text()
|
||||
page=parse(load(f'https://www.newgrounds.com/audio/listen/{songID}').text,'html.parser')
|
||||
if page.find(id='pageerror') is not None:
|
||||
self.input.clear()
|
||||
self.notification=NotificationDialog('Incorrect input or the song doesn\'t exist!')
|
||||
self.notification.exec()
|
||||
return
|
||||
songTitle=page.find('title').text
|
||||
self.songTitle=page.find('title').text
|
||||
# Getting download link
|
||||
link='http://audio.ngfiles.com/'
|
||||
page=str(page)
|
||||
@ -35,23 +34,21 @@ class GUI(QMainWindow):
|
||||
if page[i]!='\\': link+=page[i]
|
||||
i+=1
|
||||
# Locating file
|
||||
dist=QFileDialog.getSaveFileName(self,'Save File',
|
||||
self.dist=QFileDialog.getSaveFileName(self,'Save File',
|
||||
link.split('/')[-1],
|
||||
'MP3 Audio File (*.mp3)')[0]
|
||||
if not dist: return
|
||||
if not self.dist: return
|
||||
# Downloading
|
||||
file=load(link,stream=True)
|
||||
global progress
|
||||
progress.label.setText(f'Downloading "{songTitle}"...')
|
||||
progress.setWindowTitle(f'Downloading "{songTitle}"...')
|
||||
progress.bar.setValue(0)
|
||||
progress.show()
|
||||
self.thread=DownloadThread(file,dist)
|
||||
self.thread.got_chunk.connect(lambda done:progress.bar.setValue(done))
|
||||
self.thread.finished.connect(self.thread.finish)
|
||||
self.thread.start()
|
||||
self.input.clear()
|
||||
self.inprocess=False
|
||||
self.file=load(link,stream=True)
|
||||
self.progress=ProgressDialog()
|
||||
self.progress.label.setText(f'Downloading "{self.songTitle}"...')
|
||||
self.progress.setWindowTitle(f'Downloading "{self.songTitle}"...')
|
||||
self.progress.bar.setValue(0)
|
||||
self.progress.exec()
|
||||
|
||||
def keyPressEvent(self,event):
|
||||
if event.key()==16777216:
|
||||
self.close()
|
||||
|
||||
|
||||
class ProgressDialog(QDialog):
|
||||
@ -59,37 +56,52 @@ class ProgressDialog(QDialog):
|
||||
super().__init__()
|
||||
loadUi('GUI/ProgressDialog.ui',self)
|
||||
self.setWindowFlags(self.windowFlags()&~QtCore.Qt.WindowCloseButtonHint)
|
||||
self.thread=DownloadThread()
|
||||
self.thread.got_chunk.connect(lambda done:self.bar.setValue(done))
|
||||
self.thread.finished.connect(self.thread.finish)
|
||||
self.thread.start()
|
||||
|
||||
|
||||
class DownloadThread(QThread):
|
||||
got_chunk=pyqtSignal(object)
|
||||
|
||||
def __init__(self,file,dist):
|
||||
super().__init__()
|
||||
self.file,self.dist=file,dist
|
||||
def __init__(self): super().__init__()
|
||||
|
||||
def run(self):
|
||||
global progress
|
||||
total=self.file.headers.get('content-length')
|
||||
total=ngad.file.headers.get('content-length')
|
||||
if total is None: total=-1
|
||||
else: total=int(total)
|
||||
downloaded=0
|
||||
with open(self.dist,'wb') as out:
|
||||
for data in self.file.iter_content(chunk_size=max(total//100,1024)):
|
||||
with open(ngad.dist,'wb') as out:
|
||||
for data in ngad.file.iter_content(chunk_size=max(total//100,1024)):
|
||||
downloaded+=len(data)
|
||||
out.write(data)
|
||||
self.got_chunk.emit(100*downloaded//total)
|
||||
|
||||
def finish(self):
|
||||
global progress
|
||||
progress.hide()
|
||||
global ngad
|
||||
ngad.progress.hide()
|
||||
ngad.notification=NotificationDialog(f'"{ngad.songTitle}" has been downloaded successfully!')
|
||||
ngad.notification.exec()
|
||||
self.deleteLater()
|
||||
|
||||
|
||||
class NotificationDialog(QDialog):
|
||||
def __init__(self,msg):
|
||||
super().__init__()
|
||||
loadUi('GUI/NotificationDialog.ui',self)
|
||||
self.label.setText(msg)
|
||||
self.setWindowFlags(self.windowFlags()&~QtCore.Qt.WindowCloseButtonHint)
|
||||
self.btn.clicked.connect(self.accept)
|
||||
|
||||
def accept(self):
|
||||
ngad.input.clear()
|
||||
self.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from sys import argv
|
||||
app=QApplication(argv)
|
||||
ngad=GUI()
|
||||
progress=ProgressDialog()
|
||||
ngad.show()
|
||||
sys.exit(app.exec_())
|
||||
@ -22,4 +22,8 @@ It's easy as pie. You just run the downloader, enter your song ID and your file
|
||||
|
||||

|
||||
|
||||

|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
Reference in New Issue
Block a user