From a8bc81fb132e502b3136054b1d4bf5aa7c2cc882 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Tue, 6 Nov 2018 21:21:47 +0300 Subject: [PATCH] simple output during data transferring --- app/ui/download_dialog.glade | 689 ++++++++++++++++++++++--------- app/ui/download_dialog.py | 69 +++- app/ui/main_app_window.py | 2 +- app/ui/new_download_dialog.glade | 689 ------------------------------- app/ui/new_download_dialog.py | 126 ------ app/ui/settings_dialog.py | 4 +- 6 files changed, 545 insertions(+), 1034 deletions(-) delete mode 100644 app/ui/new_download_dialog.glade delete mode 100644 app/ui/new_download_dialog.py diff --git a/app/ui/download_dialog.glade b/app/ui/download_dialog.glade index 1e40ba87..0a0ae0e7 100644 --- a/app/ui/download_dialog.glade +++ b/app/ui/download_dialog.glade @@ -33,50 +33,192 @@ Author: Dmitriy Yefremov - - 480 + + 500 False False True - True + center-on-parent mail-send-receive - dialog + True + True + center True False - FTP-transfer - 2 + 5 + True - - 85 + True - True - True - Receive - + False + 2 - + + 48 + True + True + True + Receive + + + + True + False + gtk-goto-bottom + + + + + False + True + 0 + + + + + 48 + True + True + True + Send + + + + True + False + gtk-goto-top + + + + + False + True + 1 + + + + + + + True + False + 5 + 2 + vertical + 5 + + True False - gtk-goto-bottom + FTP-transfer + + False + True + 0 + + + + + True + False + 5 + 5 + + + True + False + 0 + + + False + True + 0 + + + + + All + True + True + False + True + satellites_radio_button + + + False + True + 1 + + + + + Bouquets + True + True + False + True + satellites_radio_button + + + False + True + 2 + + + + + Satellites + True + True + False + True + all_radio_button + + + False + True + 3 + + + + + WebTV + True + False + True + all_radio_button + + + False + True + 4 + + + + + False + True + 1 + - - 85 + + 48 True True True - Send - + Options + - + True False - gtk-goto-top + gtk-properties @@ -87,69 +229,45 @@ Author: Dmitriy Yefremov - - cancel_download_dialog_button - - - + + + True False - 2 - 2 + 1 + 1 + 1 vertical 2 - - - False - end - - - gtk-close - True - True - True - True - - - True - True - 0 - - - - - False - False - 0 - - - + True False - vertical - 2 + 5 + 5 + 5 + 0.019999999552965164 + in - + True False - 0.019999999552965164 - in + 5 + 5 + 5 + vertical - + True False - Receive - 5 - 5 - 5 - 5 + 2 + 2 True True False Receiver IP: - 0 + 0.10000000149011612 0 @@ -176,7 +294,7 @@ Author: Dmitriy Yefremov True False Current data path: - 0 + 0.10000000149011612 1 @@ -198,40 +316,27 @@ Author: Dmitriy Yefremov + + False + True + 0 + - - - True - False - Current settings: - - - - - True - True - 0 - - - - - True - False - 0.019999999552965164 - in - + True False 5 5 - 5 - 5 + 5 - + + Remove unused bouquets True - False - 0 + True + False + True + True False @@ -240,92 +345,204 @@ Author: Dmitriy Yefremov - - All + True - True - False - True - satellites_radio_button - - - False - True - 1 - - - - - Bouquets - True - True - False - True - satellites_radio_button + False + 2 + + + True + False + Use HTTP + + + False + True + 1 + + + + + True + True + Use http to reload data in the receiver. + True + + + False + True + 2 + + False True + end 2 - - - Satellites - True - True - False - True - all_radio_button - - - False - True - 3 - - - - - WebTV - True - False - True - all_radio_button - - - False - True - 4 - - - - - - - True - False - Data: + + False + True + 2 + - - False - True - 1 - + + + + + + False + True + 0 + + + + + True + False + 5 + 5 + 5 + 5 + 0.019999999552965164 + in - + + True + False + + + 5 + 5 + 5 + 2 + 2 + + + True + False + Login: + 0.10000000149011612 + + + 0 + 0 + + + + + True + True + root + False + avatar-default-symbolic + + + 0 + 1 + + + + + True + False + Password: + 0.10000000149011612 + + + 1 + 0 + + + + + True + True + False + + root + emblem-readonly + password + + + 1 + 1 + + + + + True + False + Port: + 0.10000000149011612 + + + 2 + 0 + + + + + True + True + False + 8 + 21 + False + network-workgroup-symbolic + + + 2 + 1 + + + + + True + True + False + 8 + False + alarm-symbolic + digits + + + 3 + 1 + + + + + True + False + Timeout: + + + 3 + 0 + + + + + + True False - - Remove unused bouquets + + FTP True True False True - True + False + telnet_radio_button + False @@ -333,77 +550,143 @@ Author: Dmitriy Yefremov 0 + + + HTTP + True + True + False + False + telnet_radio_button + + + + False + True + 1 + + + + + Telnet + True + True + False + False + ftp_radio_button + + + + False + True + 2 + + + + + + + False + True + 1 + + + + + True + True + 1 + 1 + 1 + True + + + 120 + True + True + in + + + True + True + False + 5 + 5 + + + + + + + True + False + Extra: + + + + + False + True + 3 + + + + + False + 1 + 1 + 1 + True + + + + False + True + expand False - True - 3 + False + 0 - - + + False - True - - - + 16 + + + True False - True - expand - - - + Info False - False - 0 - - - - - False - 16 - - - True - False - Info - - - False - True - 1 - - - - - False - False - 0 + True + 1 False - True - 5 + False + 0 + + + - True + False True - 1 + 4 - - cancel_download_dialog_button - diff --git a/app/ui/download_dialog.py b/app/ui/download_dialog.py index a27f3238..2eab2110 100644 --- a/app/ui/download_dialog.py +++ b/app/ui/download_dialog.py @@ -2,7 +2,9 @@ from gi.repository import GLib from app.commons import run_idle, run_task from app.connections import download_data, DownloadType, upload_data -from app.properties import Profile +from app.properties import Profile, get_config +from app.ui.main_helper import append_text_to_tview +from app.ui.settings_dialog import show_settings_dialog from .uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN from .dialogs import show_dialog, DialogType, get_message @@ -15,6 +17,8 @@ class DownloadDialog: handlers = {"on_receive": self.on_receive, "on_send": self.on_send, + "on_settings_button": self.on_settings_button, + "on_preferences": self.on_preferences, "on_info_bar_close": self.on_info_bar_close} builder = Gtk.Builder() @@ -22,10 +26,14 @@ class DownloadDialog: builder.add_from_file(UI_RESOURCES_PATH + "download_dialog.glade") builder.connect_signals(handlers) - self._dialog = builder.get_object("download_dialog") - self._dialog.set_transient_for(transient) + self._current_property = "FTP" + self._dialog_window = builder.get_object("download_dialog_window") + self._dialog_window.set_transient_for(transient) self._info_bar = builder.get_object("info_bar") self._message_label = builder.get_object("info_bar_message_label") + self._text_view = builder.get_object("text_view") + self._expander = builder.get_object("expander") + self._host_entry = builder.get_object("host_entry").set_text(properties["host"]) self._data_path_entry = builder.get_object("data_path_entry").set_text(properties["data_dir_path"]) self._remove_unused_check_button = builder.get_object("remove_unused_check_button") @@ -33,12 +41,18 @@ class DownloadDialog: self._bouquets_radio_button = builder.get_object("bouquets_radio_button") self._satellites_radio_button = builder.get_object("satellites_radio_button") self._webtv_radio_button = builder.get_object("webtv_radio_button") + self._login_entry = builder.get_object("login_entry") + self._password_entry = builder.get_object("password_entry") + self._host_entry = builder.get_object("host_entry") + self._port_entry = builder.get_object("port_entry") + if profile is Profile.NEUTRINO_MP: self._webtv_radio_button.set_visible(True) + builder.get_object("http_radio_button").set_visible(False) + builder.get_object("use_http_box").set_visible(False) def show(self): - self._dialog.run() - self._dialog.destroy() + self._dialog_window.show() @run_idle def on_receive(self, item): @@ -46,7 +60,7 @@ class DownloadDialog: @run_idle def on_send(self, item): - if show_dialog(DialogType.QUESTION, self._dialog) != Gtk.ResponseType.CANCEL: + if show_dialog(DialogType.QUESTION, self._dialog_window) != Gtk.ResponseType.CANCEL: self.download(False, self.get_download_type()) def get_download_type(self): @@ -56,14 +70,31 @@ class DownloadDialog: elif self._satellites_radio_button.get_active(): download_type = DownloadType.SATELLITES elif self._webtv_radio_button.get_active(): - download_type = DownloadType.WEBTV + download_type = DownloadType.WEB_TV return download_type - def run(self): - return self._dialog.run() - def destroy(self): - self._dialog.destroy() + self._dialog_window.destroy() + + def on_settings_button(self, button): + if button.get_active(): + label = button.get_label() + if label == "Telnet": + self._login_entry.set_text(self._properties.get("telnet_user", "")) + self._password_entry.set_text(self._properties.get("telnet_password", "")) + self._port_entry.set_text(self._properties.get("telnet_port", "")) + elif label == "HTTP": + self._login_entry.set_text(self._properties.get("http_user", "root")) + self._password_entry.set_text(self._properties.get("http_password", "")) + self._port_entry.set_text(self._properties.get("http_port", "")) + elif label == "FTP": + self._login_entry.set_text(self._properties.get("user", "")) + self._password_entry.set_text(self._properties.get("password", "")) + self._port_entry.set_text(self._properties.get("port", "")) + self._current_property = label + + def on_preferences(self, item): + show_settings_dialog(self._dialog_window, get_config()) def on_info_bar_close(self, bar=None, resp=None): self._info_bar.set_visible(False) @@ -72,15 +103,19 @@ class DownloadDialog: def download(self, download, d_type): """ Download/upload data from/to receiver """ try: + self._expander.set_expanded(True) + self.clear_output() + if download: - download_data(properties=self._properties, download_type=d_type) + download_data(properties=self._properties, download_type=d_type, callback=self.append_output) else: self.show_info_message(get_message("Please, wait..."), Gtk.MessageType.INFO) upload_data(properties=self._properties, download_type=d_type, remove_unused=self._remove_unused_check_button.get_active(), profile=self._profile, - callback=lambda: self.show_info_message(get_message("Done!"), Gtk.MessageType.INFO)) + callback=self.append_output, + done_callback=lambda: self.show_info_message(get_message("Done!"), Gtk.MessageType.INFO)) except Exception as e: message = str(getattr(e, "message", str(e))) self.show_info_message(message, Gtk.MessageType.ERROR) @@ -94,6 +129,14 @@ class DownloadDialog: self._info_bar.set_message_type(message_type) self._message_label.set_text(text) + @run_idle + def append_output(self, text): + append_text_to_tview(text, self._text_view) + + @run_idle + def clear_output(self): + self._text_view.get_buffer().set_text("") + if __name__ == "__main__": pass diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 0fb92783..e88a6f92 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -14,7 +14,7 @@ from app.eparser.enigma.bouquets import BqServiceType from app.eparser.neutrino.bouquets import BqType from app.properties import get_config, write_config, Profile from app.tools.media import Player -from .new_download_dialog import DownloadDialog +from .download_dialog import DownloadDialog from .iptv import IptvDialog, SearchUnavailableDialog, IptvListConfigurationDialog from .search import SearchProvider from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH, LOCKED_ICON, HIDE_ICON, IPTV_ICON, MOVE_KEYS, KeyboardKey diff --git a/app/ui/new_download_dialog.glade b/app/ui/new_download_dialog.glade deleted file mode 100644 index 35d0a3ad..00000000 --- a/app/ui/new_download_dialog.glade +++ /dev/null @@ -1,689 +0,0 @@ - - - - - - - - - - - 500 - False - False - True - center-on-parent - mail-send-receive - True - True - center - - - True - False - 5 - True - - - True - False - 2 - - - 48 - True - True - True - Receive - - - - True - False - gtk-goto-bottom - - - - - False - True - 0 - - - - - 48 - True - True - True - Send - - - - True - False - gtk-goto-top - - - - - False - True - 1 - - - - - - - True - False - 5 - 2 - vertical - 5 - - - True - False - FTP-transfer - - - False - True - 0 - - - - - True - False - 5 - 5 - - - True - False - 0 - - - False - True - 0 - - - - - All - True - True - False - True - satellites_radio_button - - - False - True - 1 - - - - - Bouquets - True - True - False - True - satellites_radio_button - - - False - True - 2 - - - - - Satellites - True - True - False - True - all_radio_button - - - False - True - 3 - - - - - WebTV - True - False - True - all_radio_button - - - False - True - 4 - - - - - False - True - 1 - - - - - - - 48 - True - True - True - Options - - - - True - False - gtk-properties - - - - - end - 1 - - - - - - - True - False - 1 - 1 - 1 - vertical - 2 - - - True - False - 5 - 5 - 5 - 0.019999999552965164 - in - - - True - False - 5 - 5 - 5 - vertical - - - True - False - 2 - 2 - True - - - True - False - Receiver IP: - 0.10000000149011612 - - - 0 - 0 - - - - - True - True - False - 10 - 127.0.0.1 - False - network-transmit-receive-symbolic - - - 0 - 1 - - - - - True - False - Current data path: - 0.10000000149011612 - - - 1 - 0 - - - - - True - True - False - data/ - False - folder-open-symbolic - - - 1 - 1 - - - - - False - True - 0 - - - - - True - False - 5 - 5 - 5 - - - Remove unused bouquets - True - True - False - True - True - - - False - True - 0 - - - - - True - False - 2 - - - True - False - Use HTTP - - - False - True - 1 - - - - - True - True - Use http to reload data in the receiver. - True - - - False - True - 2 - - - - - False - True - end - 2 - - - - - False - True - 2 - - - - - - - - - - False - True - 0 - - - - - True - False - 5 - 5 - 5 - 5 - 0.019999999552965164 - in - - - True - False - - - 5 - 5 - 5 - 2 - 2 - - - True - False - Login: - 0.10000000149011612 - - - 0 - 0 - - - - - True - True - root - False - avatar-default-symbolic - - - 0 - 1 - - - - - True - False - Password: - 0.10000000149011612 - - - 1 - 0 - - - - - True - True - False - - root - emblem-readonly - password - - - 1 - 1 - - - - - True - False - Port: - 0.10000000149011612 - - - 2 - 0 - - - - - True - True - False - 8 - 21 - False - network-workgroup-symbolic - - - 2 - 1 - - - - - True - True - False - 8 - False - alarm-symbolic - digits - - - 3 - 1 - - - - - True - False - Timeout: - - - 3 - 0 - - - - - - - True - False - - - FTP - True - True - False - True - False - telnet_radio_button - - - - False - True - 0 - - - - - HTTP - True - True - False - False - telnet_radio_button - - - - False - True - 1 - - - - - Telnet - True - True - False - False - ftp_radio_button - - - - False - True - 2 - - - - - - - False - True - 1 - - - - - True - True - 1 - 1 - 1 - True - - - 120 - True - True - in - - - True - True - - - - - - - True - False - Extra: - - - - - False - True - 3 - - - - - False - 1 - 1 - 1 - True - - - - False - True - expand - - - - - - False - False - 0 - - - - - False - 16 - - - True - False - Info - - - False - True - 1 - - - - - False - False - 0 - - - - - - - - False - True - 4 - - - - - - diff --git a/app/ui/new_download_dialog.py b/app/ui/new_download_dialog.py deleted file mode 100644 index 27e58e77..00000000 --- a/app/ui/new_download_dialog.py +++ /dev/null @@ -1,126 +0,0 @@ -from gi.repository import GLib - -from app.commons import run_idle, run_task -from app.connections import download_data, DownloadType, upload_data -from app.properties import Profile, get_config -from app.ui.settings_dialog import show_settings_dialog -from .uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN -from .dialogs import show_dialog, DialogType, get_message - - -class DownloadDialog: - def __init__(self, transient, properties, open_data_callback, profile=Profile.ENIGMA_2): - self._properties = properties - self._open_data_callback = open_data_callback - self._profile = profile - - handlers = {"on_receive": self.on_receive, - "on_send": self.on_send, - "on_settings_button": self.on_settings_button, - "on_preferences": self.on_preferences, - "on_info_bar_close": self.on_info_bar_close} - - builder = Gtk.Builder() - builder.set_translation_domain(TEXT_DOMAIN) - builder.add_from_file(UI_RESOURCES_PATH + "new_download_dialog.glade") - builder.connect_signals(handlers) - - self._current_property = "FTP" - self._dialog_window = builder.get_object("download_dialog_window") - self._dialog_window.set_transient_for(transient) - self._info_bar = builder.get_object("info_bar") - self._message_label = builder.get_object("info_bar_message_label") - self._host_entry = builder.get_object("host_entry").set_text(properties["host"]) - self._data_path_entry = builder.get_object("data_path_entry").set_text(properties["data_dir_path"]) - self._remove_unused_check_button = builder.get_object("remove_unused_check_button") - self._all_radio_button = builder.get_object("all_radio_button") - self._bouquets_radio_button = builder.get_object("bouquets_radio_button") - self._satellites_radio_button = builder.get_object("satellites_radio_button") - self._webtv_radio_button = builder.get_object("webtv_radio_button") - self._login_entry = builder.get_object("login_entry") - self._password_entry = builder.get_object("password_entry") - self._host_entry = builder.get_object("host_entry") - self._port_entry = builder.get_object("port_entry") - - if profile is Profile.NEUTRINO_MP: - self._webtv_radio_button.set_visible(True) - builder.get_object("http_radio_button").set_visible(False) - builder.get_object("use_http_box").set_visible(False) - - def show(self): - self._dialog_window.show() - - @run_idle - def on_receive(self, item): - self.download(True, self.get_download_type()) - - @run_idle - def on_send(self, item): - if show_dialog(DialogType.QUESTION, self._dialog_window) != Gtk.ResponseType.CANCEL: - self.download(False, self.get_download_type()) - - def get_download_type(self): - download_type = DownloadType.ALL - if self._bouquets_radio_button.get_active(): - download_type = DownloadType.BOUQUETS - elif self._satellites_radio_button.get_active(): - download_type = DownloadType.SATELLITES - elif self._webtv_radio_button.get_active(): - download_type = DownloadType.WEBTV - return download_type - - def destroy(self): - self._dialog_window.destroy() - - def on_settings_button(self, button): - if button.get_active(): - label = button.get_label() - if label == "Telnet": - self._login_entry.set_text(self._properties.get("telnet_user", "")) - self._password_entry.set_text(self._properties.get("telnet_password", "")) - self._port_entry.set_text(self._properties.get("telnet_port", "23")) - elif label == "HTTP": - self._login_entry.set_text(self._properties.get("user", "root")) - self._password_entry.set_text(self._properties.get("password", "root")) - self._port_entry.set_text("80") - elif label == "FTP": - self._login_entry.set_text(self._properties.get("user", "root")) - self._password_entry.set_text(self._properties.get("password", "root")) - self._port_entry.set_text(self._properties.get("port", "21")) - self._current_property = label - - def on_preferences(self, item): - show_settings_dialog(self._dialog_window, get_config()) - - def on_info_bar_close(self, bar=None, resp=None): - self._info_bar.set_visible(False) - - @run_task - def download(self, download, d_type): - """ Download/upload data from/to receiver """ - try: - if download: - download_data(properties=self._properties, download_type=d_type) - else: - self.show_info_message(get_message("Please, wait..."), Gtk.MessageType.INFO) - upload_data(properties=self._properties, - download_type=d_type, - remove_unused=self._remove_unused_check_button.get_active(), - profile=self._profile, - callback=lambda: self.show_info_message(get_message("Done!"), Gtk.MessageType.INFO)) - except Exception as e: - message = str(getattr(e, "message", str(e))) - self.show_info_message(message, Gtk.MessageType.ERROR) - else: - if download and d_type is not DownloadType.SATELLITES: - GLib.idle_add(self._open_data_callback) - - @run_idle - def show_info_message(self, text, message_type): - self._info_bar.set_visible(True) - self._info_bar.set_message_type(message_type) - self._message_label.set_text(text) - - -if __name__ == "__main__": - pass diff --git a/app/ui/settings_dialog.py b/app/ui/settings_dialog.py index 420ed319..90954bd3 100644 --- a/app/ui/settings_dialog.py +++ b/app/ui/settings_dialog.py @@ -173,7 +173,7 @@ class SettingsDialog: user, password = self._http_login_field.get_text(), self._http_password_field.get_text() try: params = urlencode({"text": "Connection test", "type": 2, "timeout": 5}) - with urlopen("http://{}/web/message?%s".format(self._host_field.get_text()) % params, timeout=2) as f: + with urlopen("http://{}/web/message?%s".format(self._host_field.get_text()) % params, timeout=5) as f: dom = parse(f) for elem in dom.getElementsByTagName("e2simplexmlresult"): for ch in elem.childNodes: @@ -206,7 +206,7 @@ class SettingsDialog: try: with FTP(host=host, user=user, passwd=password, timeout=5) as ftp: self.show_info_message("OK. {}".format(ftp.getwelcome()), Gtk.MessageType.INFO) - except (error_perm, ConnectionRefusedError) as e: + except (error_perm, ConnectionRefusedError, OSError) as e: self.show_info_message(str(e), Gtk.MessageType.ERROR) finally: self.show_spinner(False)