From e5b726cbe6bcd5578e29a8ee19ef60904ac184ad Mon Sep 17 00:00:00 2001 From: DYefremov Date: Sun, 14 Oct 2018 16:01:05 +0300 Subject: [PATCH] little refactoring for the download dialog --- app/ftp.py | 1 - app/ui/download_dialog.py | 20 ++++++++++---------- app/ui/main_app_window.py | 10 +++++----- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/ftp.py b/app/ftp.py index d8428f15..8dc43693 100644 --- a/app/ftp.py +++ b/app/ftp.py @@ -59,7 +59,6 @@ def download_data(*, properties, download_type=DownloadType.ALL, callback=None): callback() -@run_task def upload_data(*, properties, download_type=DownloadType.ALL, remove_unused=False, profile=Profile.ENIGMA_2, callback=None): data_path = properties["data_dir_path"] diff --git a/app/ui/download_dialog.py b/app/ui/download_dialog.py index 87f5407c..2fa162e4 100644 --- a/app/ui/download_dialog.py +++ b/app/ui/download_dialog.py @@ -1,3 +1,5 @@ +from gi.repository import GLib + from app.commons import run_idle, run_task from app.ftp import download_data, DownloadType, upload_data from app.properties import Profile @@ -5,16 +7,10 @@ from .uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN from .dialogs import show_dialog, DialogType, get_message -def show_download_dialog(transient, options, open_data, profile=Profile.ENIGMA_2): - dialog = DownloadDialog(transient, options, open_data, profile) - dialog.run() - dialog.destroy() - - class DownloadDialog: - def __init__(self, transient, properties, open_data, profile): + def __init__(self, transient, properties, open_data_callback, profile=Profile.ENIGMA_2): self._properties = properties - self._open_data = open_data + self._open_data_callback = open_data_callback self._profile = profile handlers = {"on_receive": self.on_receive, @@ -40,6 +36,10 @@ class DownloadDialog: if profile is Profile.NEUTRINO_MP: self._webtv_radio_button.set_visible(True) + def show(self): + self._dialog.run() + self._dialog.destroy() + @run_idle def on_receive(self, item): self.download(True, self.get_download_type()) @@ -68,7 +68,7 @@ class DownloadDialog: def on_info_bar_close(self, bar=None, resp=None): self._info_bar.set_visible(False) - @run_idle + @run_task def download(self, download, d_type): """ Download/upload data from/to receiver """ try: @@ -86,7 +86,7 @@ class DownloadDialog: self.show_info_message(message, Gtk.MessageType.ERROR) else: if download and d_type is not DownloadType.SATELLITES: - self._open_data() + GLib.idle_add(self._open_data_callback) @run_idle def show_info_message(self, text, message_type): diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 6f5e0c18..d8a3a822 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -18,7 +18,7 @@ from .iptv import IptvDialog, SearchUnavailableDialog, IptvListConfigurationDial from .search import SearchProvider from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH, LOCKED_ICON, HIDE_ICON, IPTV_ICON, MOVE_KEYS from .dialogs import show_dialog, DialogType, get_chooser_dialog, WaitDialog, get_message -from .download_dialog import show_download_dialog +from .download_dialog import DownloadDialog from .main_helper import edit_marker, insert_marker, move_items, rename, ViewTarget, set_flags, locate_in_services, \ scroll_to, get_base_model, update_picons_data, copy_picon_reference, assign_picon, remove_picon, \ is_only_one_item_selected, gen_bouquets, BqGenType, get_iptv_url, append_picons, get_selection @@ -1017,10 +1017,10 @@ class MainAppWindow: self.on_play_stream() def on_download(self, item): - show_download_dialog(transient=self._main_window, - options=self._options.get(self._profile), - open_data=self.open_data, - profile=Profile(self._profile)) + DownloadDialog(transient=self._main_window, + properties=self._options.get(self._profile), + open_data_callback=self.open_data, + profile=Profile(self._profile)).show() def on_view_focus(self, view, focus_event): profile = Profile(self._profile)