fix download dialog
This commit is contained in:
parent
5b75a64e84
commit
fe33c3889c
|
@ -8,7 +8,7 @@ from izzylib.path import Path
|
|||
from .base import BuilderBase
|
||||
from .config import scriptpath
|
||||
from .enums import FileChooserAction, FileChooserResponse
|
||||
from .functions import connect, set_image
|
||||
from .functions import connect, run_in_gui_thread, set_image
|
||||
|
||||
|
||||
class Download(BuilderBase):
|
||||
|
@ -21,7 +21,7 @@ class Download(BuilderBase):
|
|||
download_dir = s.get_config('download_dir')
|
||||
|
||||
self.download = download
|
||||
self.cancel = False
|
||||
self.cancel = None
|
||||
self.data = DotDict(
|
||||
filename = None,
|
||||
path = download_dir,
|
||||
|
@ -36,7 +36,7 @@ class Download(BuilderBase):
|
|||
self.connect('download-filename-set', 'clicked', self.handle_dialog_set_filename)
|
||||
self.connect('download-cancel', 'clicked', self.handle_dialog_close, True)
|
||||
self.connect('download-save', 'clicked', self.handle_dialog_close, False)
|
||||
self.connect('download-window', 'delete-event', self.handle_dialog_close, False)
|
||||
self.connect('download-window', 'delete-event', self.handle_dialog_close, True)
|
||||
|
||||
# Connect download signals
|
||||
connect(download, 'decide-destination', self.handle_download_decide_destination, original_args=True)
|
||||
|
@ -80,11 +80,12 @@ class Download(BuilderBase):
|
|||
|
||||
|
||||
def handle_dialog_close(self, cancel):
|
||||
self['download-window'].hide()
|
||||
|
||||
if self.cancel != None:
|
||||
return
|
||||
|
||||
self.cancel = cancel
|
||||
self.destroy()
|
||||
|
||||
|
||||
def handle_dialog_change_filename(self):
|
||||
|
@ -120,6 +121,8 @@ class Download(BuilderBase):
|
|||
else:
|
||||
download.set_destination(self.target_path())
|
||||
|
||||
self.destroy()
|
||||
|
||||
|
||||
def handle_download_failed(self, download, error):
|
||||
if error.code == 400:
|
||||
|
@ -136,15 +139,11 @@ class Download(BuilderBase):
|
|||
logging.debug(data.to_json(4))
|
||||
self.window.notification(f'Download failed: {self.target_path(False)}', system=True)
|
||||
|
||||
self.destroy
|
||||
|
||||
|
||||
def handle_download_finish(self):
|
||||
if not self.cancel:
|
||||
self.window.notification(f'Download finished: {self.target_path(False)}', system=True)
|
||||
|
||||
self.destroy()
|
||||
|
||||
|
||||
class FileChooser(BuilderBase):
|
||||
valid_response_types = [FileChooserResponse.OK, FileChooserResponse.CANCEL]
|
||||
|
|
Reference in a new issue