From f9239f0642ab203db247d89e781b0c42b7d9799b Mon Sep 17 00:00:00 2001 From: Dmitriy Yefremov Date: Wed, 25 Apr 2018 17:26:29 +0300 Subject: [PATCH] new variant of satellites download skeleton --- README.md | 22 +- app/tools/satellites.py | 60 +- app/ui/main_app_window.py | 8 +- app/ui/main_window.glade | 21 - .../{tools.glade => picons_downloader.glade} | 267 ---- app/ui/{tools => }/picons_downloader.py | 2 +- app/ui/satellites_dialog.glade | 1306 ++++++++++------- app/ui/satellites_dialog.py | 64 +- app/ui/tools/__init__.py | 0 app/ui/tools/satellites_downloader.py | 36 - 10 files changed, 879 insertions(+), 907 deletions(-) rename app/ui/{tools.glade => picons_downloader.glade} (76%) rename app/ui/{tools => }/picons_downloader.py (99%) delete mode 100644 app/ui/tools/__init__.py delete mode 100644 app/ui/tools/satellites_downloader.py diff --git a/README.md b/README.md index bfa8baef..60a66588 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,17 @@ Experimental support of Neutrino-MP or others on the same basis (BPanther, etc). Focused on the convenience of working in lists from the keyboard. The mouse is also fully supported (Drag and Drop etc) ### Keyboard shortcuts: -#### Ctrl + X, C, V, Up, Down, PageUp, PageDown, Home, End, S, T, E, L, H, Space; Insert, Delete, F2. -Insert - copies the selected channels from the main list to the bouquet or inserts (creates) a new bouquet. -Ctrl + X - only in bouquet list. Ctrl + C - only in services list. +**Ctrl + X, C, V, Up, Down, PageUp, PageDown, Home, End, S, T, E, L, H, Space; Insert, Delete, F2.** +*Insert* - copies the selected channels from the main list to the bouquet or inserts (creates) a new bouquet. +*Ctrl + X* - only in bouquet list. *Ctrl + C* - only in services list. Clipboard is "rubber". There is an accumulation before the insertion! -Ctrl + E - edit. -Ctrl + R, F2 - rename. -Ctrl + S, T in Satellites edit tool for create satellite or transponder. -Ctrl + L - parental lock. -Ctrl + H - hide/skip. -Space - select/deselect. -Left/Right - remove selection. +*Ctrl + E* - edit. +*Ctrl + R, F2* - rename. +*Ctrl + S, T* in Satellites edit tool for create satellite or transponder. +*Ctrl + L* - parental lock. +*Ctrl + H* - hide/skip. +*Space* - select/deselect. +*Left/Right* - remove selection. ### Extra: Multiple selections in lists only with Space key (as in file managers). @@ -29,6 +29,6 @@ To create a simple debian package, you can use the build-deb.sh Tests only in image based on OpenPLi or last BPanther(neutrino) images with GM 990 Spark Reloaded receiver in my preferred linux distro (Last Linux Mint 18.* - MATE 64-bit)! -#### Terrestrial and cable channels at the moment are not supported! +**Terrestrial and cable channels at the moment are not supported!** diff --git a/app/tools/satellites.py b/app/tools/satellites.py index 45c1ce7f..b2afab8c 100644 --- a/app/tools/satellites.py +++ b/app/tools/satellites.py @@ -5,9 +5,12 @@ import requests from html.parser import HTMLParser +from app.commons import run_task +from app.eparser import Satellite, Transponder + class SatellitesParser(HTMLParser): - """ Parser for satellite html page. (https://www.lyngsat.com/*sat-name*.html) """ + """ Parser for satellite html page. """ _HEADERS = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:45.0) Gecko/20100101 Firefox/59.02"} @@ -56,18 +59,65 @@ class SatellitesParser(HTMLParser): def error(self, message): pass - def get_satellites(self): + @run_task + def get_satellites(self, callback): self.reset() request = requests.get(url=self._url, headers=self._HEADERS) reason = request.reason + satellites = [] if reason == "OK": self.feed(request.text) if self._rows: - return list(filter(lambda x: all(x) and len(x) == 5, self._rows)) + for sat in list(filter(lambda x: all(x) and len(x) == 5, self._rows)): + if callback(self.get_satellite(sat)): + break else: print(reason) + return satellites + + def get_satellite(self, sat): + pos = "".join(c for c in sat[2] if c.isdigit() or c.isalpha() or c == ".") + return Satellite(name=sat[1] + " ({})".format(pos), + flags="0", + position=self.get_position(pos.replace(".", "")), + transponders=self.get_transponders(sat[0])) + + def get_position(self, pos): + return "{}{}".format("-" if pos[-1] == "W" else "", pos[:-1]) + + def get_transponders(self, sat_url): + self._rows.clear() + url = "https://www.flysat.com/" + sat_url + request = requests.get(url=url, headers=self._HEADERS) + reason = request.reason + trs = [] + if reason == "OK": + self.feed(request.text) + if self._rows: + zeros = "000" + for r in self._rows: + if len(r) < 3: + continue + data = r[2].split(" ") + if len(data) != 2: + continue + sr, fec = data + data = r[1].split(" ") + if len(data) < 3: + continue + freq, pol, tr_type = data[0], data[1], data[2] + tr_type = tr_type.split("/") + if len(tr_type) != 2: + continue + tr_type, mod = tr_type + mod = "QPSK" if tr_type == "DVB-S" else mod + trs.append(Transponder(freq + zeros, sr + zeros, pol, fec, tr_type, mod, None, None, None)) + + return trs + if __name__ == "__main__": - parser = SatellitesParser(url="https://www.flysat.com/satlist.php") - parser.get_satellites() + pass + + diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 9a764efa..a2a4a5f5 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -19,8 +19,7 @@ from .download_dialog import show_download_dialog from .main_helper import edit_marker, insert_marker, move_items, rename, ViewTarget, set_flags, locate_in_services, \ scroll_to, get_base_model, update_picons, copy_picon_reference, assign_picon, remove_picon, \ is_only_one_item_selected, gen_bouquets, BqGenType -from .tools.picons_downloader import PiconsDialog -from .tools.satellites_downloader import SatellitesDownloaderDialog +from .picons_downloader import PiconsDialog from .satellites_dialog import show_satellites_dialog from .settings_dialog import show_settings_dialog from .service_details_dialog import ServiceDetailsDialog, Action @@ -105,7 +104,6 @@ class MainAppWindow: "on_fav_popup": self.on_fav_popup, "on_locate_in_services": self.on_locate_in_services, "on_picons_loader_show": self.on_picons_loader_show, - "on_satellites_downloader_show": self.on_satellites_downloader_show, "on_filter_changed": self.on_filter_changed, "on_assign_picon": self.on_assign_picon, "on_remove_picon": self.on_remove_picon, @@ -931,10 +929,6 @@ class MainAppWindow: dialog.show() self.update_picons() - @run_idle - def on_satellites_downloader_show(self, item): - SatellitesDownloaderDialog(self._main_window, self._options).show() - @run_idle def on_filter_toggled(self, toggle_button: Gtk.ToggleToolButton): self._filter_info_bar.set_visible(toggle_button.get_active()) diff --git a/app/ui/main_window.glade b/app/ui/main_window.glade index 62b43a7c..b45c25db 100644 --- a/app/ui/main_window.glade +++ b/app/ui/main_window.glade @@ -122,11 +122,6 @@ False gtk-save-as - - True - False - gtk-goto-bottom - True False @@ -798,22 +793,6 @@ - - - Satellites downloader - True - False - image10 - False - - - - - - True - False - - Picons downloader diff --git a/app/ui/tools.glade b/app/ui/picons_downloader.glade similarity index 76% rename from app/ui/tools.glade rename to app/ui/picons_downloader.glade index a2daed3a..ea187745 100644 --- a/app/ui/tools.glade +++ b/app/ui/picons_downloader.glade @@ -839,271 +839,4 @@ - - - - - - - - - - - - - - - - - - - - - - FlySat - - - - - 480 - False - Satellites download tool - False - True - True - dialog - True - - - False - vertical - 2 - - - False - center - - - gtk-close - True - True - True - True - True - - - True - True - 0 - - - - - False - False - 0 - - - - - True - False - vertical - 2 - - - True - False - center - 2 - - - True - False - Source: - - - False - True - 0 - - - - - True - False - source_urls_list_store - 0 - - - - 0 - - - - - False - True - 1 - - - - - False - True - 0 - - - - - True - False - - - False - True - 1 - - - - - 150 - True - True - in - - - 100 - True - True - satellites_list_store - - - - - - Satellite - - - - 0 - - - - - - - Position - - - - 1 - - - - - - - Type - - - - 2 - - - - - - - Url - - - - 3 - - - - - - - Selected - - - - 4 - - - - - - - - - False - True - 2 - - - - - True - False - - - False - True - 3 - - - - - True - False - False - - - True - False - True - Receive - True - gtk-goto-bottom - - - - True - True - - - - - - False - True - 4 - - - - - True - False - - - False - True - 5 - - - - - False - True - 1 - - - - - diff --git a/app/ui/tools/picons_downloader.py b/app/ui/picons_downloader.py similarity index 99% rename from app/ui/tools/picons_downloader.py rename to app/ui/picons_downloader.py index 45b5440e..964a2b6e 100644 --- a/app/ui/tools/picons_downloader.py +++ b/app/ui/picons_downloader.py @@ -38,7 +38,7 @@ class PiconsDialog: builder = Gtk.Builder() builder.set_translation_domain(TEXT_DOMAIN) - builder.add_objects_from_file(UI_RESOURCES_PATH + "tools.glade", + builder.add_objects_from_file(UI_RESOURCES_PATH + "picons_downloader.glade", ("picons_dialog", "receive_image", "providers_list_store")) builder.connect_signals(handlers) self._dialog = builder.get_object("picons_dialog") diff --git a/app/ui/satellites_dialog.glade b/app/ui/satellites_dialog.glade index 68bacbb9..fab809f9 100644 --- a/app/ui/satellites_dialog.glade +++ b/app/ui/satellites_dialog.glade @@ -194,6 +194,11 @@ 0.10000000000000001 10 + + True + False + gtk-goto-bottom + @@ -222,550 +227,6 @@ - - 640 - False - Satellites edit tool - True - True - applications-utilities - dialog - - - - False - vertical - 2 - - - False - end - - - gtk-cancel - True - True - True - 5 - 2 - True - - - True - True - 0 - - - - - False - False - 0 - - - - - 320 - True - False - vertical - - - True - False - - - True - False - _Файл - True - - - True - False - - - gtk-open - True - False - True - True - - - - - - gtk-save - True - False - True - True - - - - - - True - False - - - - - gtk-quit - True - False - True - True - - - - - - - - - - True - False - _Правка - True - - - True - False - - - gtk-add - True - False - True - True - - - True - False - - - True - False - Satellite - True - - - - - - True - False - Transponder - True - - - - - - - - - - gtk-edit - True - False - True - True - - - - - - gtk-delete - True - False - True - True - - - - - - - - - - False - True - 0 - - - - - True - False - - - True - False - Open - Load - True - gtk-open - - - - False - True - - - - - True - False - - - False - False - - - - - True - False - Save - Save - True - gtk-floppy - - - - False - True - - - - - True - False - - - False - False - - - - - True - False - Up - True - gtk-go-up - - - - False - True - - - - - True - False - Down - True - gtk-go-down - - - - False - True - - - - - True - False - - - False - False - - - - - True - False - - - True - True - True - Add - add_popup_menu - none - - - - - - - - False - False - - - - - True - False - Edit - Edit - True - gtk-edit - - - - False - True - - - - - True - False - Remove - immediate - Remove - True - gtk-remove - - - - False - True - - - - - - False - True - 1 - - - - - True - True - in - - - True - True - satellites_tree_store - 0 - True - True - - - - - - multiple - - - - - True - Satellite - True - - - - 0 - - - - - - - True - Freq - True - - - - 1 - - - - - - - True - Rate - True - - - - 2 - - - - - - - True - Pol - True - - - - 3 - - - - - - - True - FEC - True - - - - 4 - - - - - - - True - System - True - - - - 5 - - - - - - - True - Mod - True - - - - 6 - - - - - - - False - True - Pls mode - True - - - - 7 - - - - - - - False - True - Pls code - True - - - - 8 - - - - - - - False - True - Is ID - True - - - - 9 - - - - - - - False - True - Flags - - - - 10 - - - - - - - False - True - Pos: - - - - 11 - - - - - - - - - True - True - 2 - - - - - True - True - 0 - - - - - True - False - - - False - True - 1 - - - - - - sat_ed_cancel_button - - @@ -1388,4 +849,761 @@ button2 + + + + + + + + + FlySat + + + + + 640 + False + Satellites edit tool + True + True + applications-utilities + dialog + + + + False + vertical + 2 + + + False + end + + + gtk-cancel + True + True + True + 5 + 2 + True + + + True + True + 0 + + + + + False + False + 0 + + + + + 320 + True + False + vertical + + + True + False + + + True + False + _Файл + True + + + True + False + + + gtk-open + True + False + True + True + + + + + + gtk-save + True + False + True + True + + + + + + True + False + + + + + gtk-quit + True + False + True + True + + + + + + + + + + True + False + _Правка + True + + + True + False + + + gtk-add + True + False + True + True + + + True + False + + + True + False + Satellite + True + + + + + + True + False + Transponder + True + + + + + + + + + + gtk-edit + True + False + True + True + + + + + + gtk-delete + True + False + True + True + + + + + + + + + + False + True + 0 + + + + + True + False + + + True + False + Open + Load + True + gtk-open + + + + False + True + + + + + True + False + + + False + False + + + + + True + False + Save + Save + True + gtk-floppy + + + + False + True + + + + + True + False + + + False + False + + + + + True + False + Update from internet + Receive from internet + True + gtk-refresh + + + + False + True + + + + + True + False + + + False + False + + + + + True + False + Up + True + gtk-go-up + + + + False + True + + + + + True + False + Down + True + gtk-go-down + + + + False + True + + + + + True + False + + + False + False + + + + + True + False + + + True + True + True + Add + add_popup_menu + none + + + + + + + + False + False + + + + + True + False + Edit + Edit + True + gtk-edit + + + + False + True + + + + + True + False + Remove + immediate + Remove + True + gtk-remove + + + + False + True + + + + + + False + True + 1 + + + + + True + False + + + False + end + + + gtk-cancel + True + True + True + True + True + + + + True + True + 0 + + + + + False + False + 0 + + + + + False + 2 + True + + + True + False + 2 + + + True + False + 2 + + + Receive satellites list + True + True + True + 10 + receive_menu_icon + True + + + + 7 + 0 + + + + + True + True + + + 6 + 0 + + + + + True + False + to: + + + 5 + 0 + + + + + True + True + + + 4 + 0 + + + + + True + False + Riceive from: + + + 3 + 0 + + + + + True + False + 10 + update_source_store + 0 + + + + 0 + + + + + 2 + 0 + + + + + True + False + Source: + + + 1 + 0 + + + + + + + + False + False + 2 + + + + + True + False + + + False + True + 7 + + + + + False + False + 3 + + + + + False + False + 0 + + + + + False + True + 2 + + + + + True + True + in + + + True + True + satellites_tree_store + 0 + True + True + + + + + + multiple + + + + + True + Satellite + True + + + + 0 + + + + + + + True + Freq + True + + + + 1 + + + + + + + True + Rate + True + + + + 2 + + + + + + + True + Pol + True + + + + 3 + + + + + + + True + FEC + True + + + + 4 + + + + + + + True + System + True + + + + 5 + + + + + + + True + Mod + True + + + + 6 + + + + + + + False + True + Pls mode + True + + + + 7 + + + + + + + False + True + Pls code + True + + + + 8 + + + + + + + False + True + Is ID + True + + + + 9 + + + + + + + False + True + Flags + + + + 10 + + + + + + + False + True + Pos: + + + + 11 + + + + + + + + + True + True + 4 + + + + + True + True + 0 + + + + + True + False + + + False + True + 1 + + + + + + sat_ed_cancel_button + + diff --git a/app/ui/satellites_dialog.py b/app/ui/satellites_dialog.py index 61596337..2fadfa47 100644 --- a/app/ui/satellites_dialog.py +++ b/app/ui/satellites_dialog.py @@ -3,29 +3,30 @@ from math import fabs from app.commons import run_idle from app.eparser import get_satellites, write_satellites, Satellite, Transponder +from app.tools.satellites import SatellitesParser from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH, TEXT_DOMAIN, MOVE_KEYS from .dialogs import show_dialog, DialogType, WaitDialog from .main_helper import move_items, scroll_to def show_satellites_dialog(transient, options): - dialog = SatellitesDialog(transient, options) - dialog.run() - dialog.destroy() + SatellitesDialog(transient, options).show() class SatellitesDialog: - __slots__ = ["_dialog", "_data_path", "_stores", "_options", "_sat_view", "_wait_dialog"] - _aggr = [None for x in range(9)] # aggregate def __init__(self, transient, options): self._data_path = options.get("data_dir_path") + "satellites.xml" self._options = options + self._download_task = False handlers = {"on_open": self.on_open, "on_remove": self.on_remove, "on_save": self.on_save, + "on_update": self.on_update, + "on_receive": self.on_receive, + "on_cancel_receive": self.on_cancel_receive, "on_up": self.on_up, "on_down": self.on_down, "on_popup_menu": self.on_popup_menu, @@ -40,8 +41,8 @@ class SatellitesDialog: builder = Gtk.Builder() builder.set_translation_domain(TEXT_DOMAIN) builder.add_objects_from_file(UI_RESOURCES_PATH + "satellites_dialog.glade", - ("satellites_editor_dialog", "satellites_tree_store", - "popup_menu", "add_popup_menu", "add_menu_icon")) + ("satellites_editor_dialog", "satellites_tree_store", "popup_menu", + "add_popup_menu", "add_menu_icon", "receive_menu_icon", "update_source_store")) builder.connect_signals(handlers) # Adding custom image for add_menu_tool_button add_menu_tool_button = builder.get_object("add_menu_tool_button") @@ -51,6 +52,7 @@ class SatellitesDialog: self._dialog.set_transient_for(transient) self._dialog.get_content_area().set_border_width(0) # The width of the border around the app dialog area! self._sat_view = builder.get_object("satellites_editor_tree_view") + self._download_bar = builder.get_object("download_bar") self._wait_dialog = WaitDialog(self._dialog) # Setting the last size of the dialog window if it was saved window_size = self._options.get("sat_editor_window_size", None) @@ -63,10 +65,10 @@ class SatellitesDialog: 6: builder.get_object("mod_store")} self.on_satellites_list_load(self._sat_view.get_model()) - def run(self): + @run_idle + def show(self): self._dialog.run() - - def destroy(self): + self.on_cancel_receive() self._dialog.destroy() def on_resize(self, window): @@ -75,7 +77,8 @@ class SatellitesDialog: self._options["sat_editor_window_size"] = window.get_size() def on_quit(self, item): - self.destroy() + self.on_cancel_receive() + self._dialog.destroy() def on_open(self, model): file_filter = Gtk.FileFilter() @@ -147,10 +150,14 @@ class SatellitesDialog: @run_idle def append_data(self, model, satellites): - for name, flags, pos, transponders in satellites: - parent = model.append(None, [name, *self._aggr, flags, pos]) - for transponder in transponders: - model.append(parent, ["Transponder:", *transponder, None, None]) + for sat in satellites: + self.append_satellite(model, sat) + + def append_satellite(self, model, sat): + name, flags, pos, transponders = sat + parent = model.append(None, [name, *self._aggr, flags, pos]) + for transponder in transponders: + model.append(parent, ["Transponder:", *transponder, None, None]) def on_add(self, view): """ Common adding """ @@ -279,6 +286,33 @@ class SatellitesDialog: model.foreach(self.parse_data, satellites) write_satellites(satellites, self._data_path) + def on_update(self, button: Gtk.ToggleToolButton): + self._download_bar.set_visible(button.get_active()) + + @run_idle + def on_receive(self, item): + if self._download_task: + show_dialog(DialogType.ERROR, self._dialog, "The task is already running!") + return + + model = self._sat_view.get_model() + model.clear() + self._download_task = True + + def callback(sat): + if self._download_task: + self.append_satellite(model, sat) + return False + else: + print("Canceled!") + return True + + SatellitesParser(url="https://www.flysat.com/satlist.php").get_satellites(callback) + + @run_idle + def on_cancel_receive(self, item=None): + self._download_task = False + @staticmethod def parse_data(model, path, itr, sats): if model.iter_has_child(itr): diff --git a/app/ui/tools/__init__.py b/app/ui/tools/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/app/ui/tools/satellites_downloader.py b/app/ui/tools/satellites_downloader.py deleted file mode 100644 index 32cdcc0f..00000000 --- a/app/ui/tools/satellites_downloader.py +++ /dev/null @@ -1,36 +0,0 @@ -from app.commons import run_idle -from app.tools.satellites import SatellitesParser -from ..uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN - - -class SatellitesDownloaderDialog: - def __init__(self, transient, options): - - handlers = {"on_satellites_receive": self.on_satellites_receive} - - builder = Gtk.Builder() - builder.set_translation_domain(TEXT_DOMAIN) - builder.add_objects_from_file(UI_RESOURCES_PATH + "tools.glade", - ("satellites_dialog", "source_urls_list_store", "satellites_list_store")) - builder.connect_signals(handlers) - self._dialog = builder.get_object("satellites_dialog") - self._dialog.set_transient_for(transient) - self._satellites_tree_view = builder.get_object("satellites_tree_view") - - def show(self): - self._dialog.run() - self._dialog.destroy() - - @run_idle - def on_satellites_receive(self, item): - parser = SatellitesParser(url="https://www.flysat.com/satlist.php") - sats = parser.get_satellites() - if sats: - model = self._satellites_tree_view.get_model() - model.clear() - for sat in sats: - model.append((sat[1], sat[2], sat[3], sat[0], False)) - - -if __name__ == "__main__": - pass