little refactoring for the download dialog

This commit is contained in:
DYefremov
2018-10-14 16:01:05 +03:00
parent fcfac6c20b
commit e5b726cbe6
3 changed files with 15 additions and 16 deletions

View File

@@ -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"]

View File

@@ -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):

View File

@@ -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)