def __init__(self, handler=None): super().__init__() self._handler = handler self._downloader = downloader.Downloader(self) self._download_finished_filenames = [] self._filemanager_proxy = Gio.DBusProxy.new_for_bus_sync( Gio.BusType.SESSION, Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES | Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS | Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION, None, 'org.freedesktop.FileManager1', '/org/freedesktop/FileManager1', 'org.freedesktop.FileManager1') bind_property(self, 'download-dir', self, 'download-dir-abs', expand_path) self.actions = Gio.SimpleActionGroup.new() self.actions.add_action_entries([ ('download', lambda *_: self.set_property('state', 'download')), ('cancel', lambda *_: self.set_property('state', 'cancel')), ('back', lambda *_: self.set_property('state', 'start')), ('open-download-dir', self._open_download_dir) ]) bind_property(self, 'url', self.actions.lookup_action('download'), 'enabled', bool) bind_property(self, 'state', self, 'prev-state', self._state_transition) bind_property(self, 'state', self.actions.lookup_action('cancel'), 'enabled', lambda s: s == 'download')
def start(self): assert self.page.get() == "main" assert self.downloader is None self.error.set("") self.cancelled = False self.download_playlist_index.set(0) self.download_playlist_count.set(0) self.download_filename.set("") self.download_progress.set(-1) self.download_bytes.set(-1) self.download_bytes_total.set(-1) self.download_speed.set(-1) self.download_eta.set(-1) self.page.set("download") self.downloader = downloader.Downloader(self) self.downloader.start()