From 5f0f1e4e64156cd838554f660debe0c7bc863f90 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Wed, 1 Sep 2021 14:15:39 +0300 Subject: [PATCH] added timers page --- app/ui/control.glade | 232 +++++++++++++++++++++++++++++++------------ app/ui/control.py | 42 +++++++- app/ui/main.glade | 3 +- app/ui/main.py | 14 ++- 4 files changed, 223 insertions(+), 68 deletions(-) diff --git a/app/ui/control.glade b/app/ui/control.glade index 14ed206c..398f61c5 100644 --- a/app/ui/control.glade +++ b/app/ui/control.glade @@ -1154,78 +1154,182 @@ Author: Dmitriy Yefremov - + + + + + + + + + + + + + + + True False - vertical - 5 + 2 + 0.49000000953674316 + in - - True - True - in - - - True - False - - - True - False - multiple - False - - - - - - - - - True - True - 0 - - - - + True False - end - True - expand + 5 + 5 + 5 + 5 + vertical - - Add - True - True - app.on_timer_add + + True + False + 15 + 15 + 7 + 5 + 5 + + + True + False + True + True + + + True + False + document-new-symbolic + + + + + False + True + 0 + + + + + False + True + True + + + True + False + user-trash-symbolic + + + + + False + True + 1 + + + + + Edit + True + True + app.on_timer_edit + + + False + True + 2 + + - True + False True 0 - - Remove + + True True - True - app.on_timer_remove - - - True - True - 2 - - - - - Edit - True - True - app.on_timer_edit + in + + + True + True + True + timer_model + both + 3 + + + + + + 150 + Name + 0.5 + + + 5 + + + 0 + + + + + + + 150 + Service + 0.5 + + + 5 + 0.49000000953674316 + + + 1 + + + + + + + 100 + Time + 0.5 + + + 5 + + + 2 + + + + + + + Description + True + 0.5 + + + end + + + 3 + + + + + + True @@ -1234,11 +1338,13 @@ Author: Dmitriy Yefremov - - False - False - 2 - + + + + True + False + Timers + diff --git a/app/ui/control.py b/app/ui/control.py index 4f71240e..f0140cc9 100644 --- a/app/ui/control.py +++ b/app/ui/control.py @@ -34,7 +34,7 @@ from urllib.parse import quote from gi.repository import GLib from .dialogs import get_builder -from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH +from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH, Page from ..commons import run_task, run_with_delay, log, run_idle from ..connections import HttpAPI @@ -83,6 +83,46 @@ class EpgBox(Gtk.Box): return title, time, desc, event +class TimersBox(Gtk.Box): + def __init__(self, app, http_api, *args, **kwargs): + super().__init__(*args, **kwargs) + + self._http_api = http_api + self._app = app + self._app.connect("page-changed", self.update_timer_list) + + handlers = {} + + builder = get_builder(UI_RESOURCES_PATH + "control.glade", handlers, objects=("timers_frame", "timer_model")) + self._view = builder.get_object("timer_view") + self._remove_button = builder.get_object("timer_remove_button") + self.add(builder.get_object("timers_frame")) + self.show() + + def update_timer_list(self, app, page): + if page is Page.TIMERS: + self._app._wait_dialog.show() + self._http_api.send(HttpAPI.Request.TIMER_LIST, "", self.update_timers_data) + + @run_idle + def update_timers_data(self, timers): + model = self._view.get_model() + model.clear() + list(map(model.append, (self.get_timer_row(t) for t in timers.get("timer_list", [])))) + self._remove_button.set_visible(len(model)) + self._app._wait_dialog.hide() + + def get_timer_row(self, timer): + name = timer.get("e2name", "") or "" + description = timer.get("e2description", "") or "" + service = timer.get("e2servicename", "") or "" + start_time = datetime.fromtimestamp(int(timer.get("e2timebegin", "0"))) + end_time = datetime.fromtimestamp(int(timer.get("e2timeend", "0"))) + time = "{} - {}".format(start_time.strftime("%A, %H:%M"), end_time.strftime("%H:%M")) + + return name, service, time, description, timer + + class ControlBox(Gtk.HBox): def __init__(self, app, http_api, settings, *args, **kwargs): diff --git a/app/ui/main.glade b/app/ui/main.glade index 03cf0bab..8d74b466 100644 --- a/app/ui/main.glade +++ b/app/ui/main.glade @@ -2385,7 +2385,6 @@ Author: Dmitriy Yefremov True False 5 - 5 5 5 vertical @@ -2405,10 +2404,10 @@ Author: Dmitriy Yefremov True False 5 - 5 5 5 vertical + diff --git a/app/ui/main.py b/app/ui/main.py index d2fd52fb..0567fae6 100644 --- a/app/ui/main.py +++ b/app/ui/main.py @@ -48,7 +48,7 @@ from app.eparser.neutrino.bouquets import BqType from app.settings import (SettingsType, Settings, SettingsException, PlayStreamsMode, SettingsReadException, IS_DARWIN) from app.tools.media import Player, Recorder -from app.ui.control import ControlBox, EpgBox +from app.ui.control import ControlBox, EpgBox, TimersBox from app.ui.epg_dialog import EpgDialog from app.ui.ftp import FtpClientBox from app.ui.transmitter import LinksTransmitter @@ -200,6 +200,7 @@ class Application(Gtk.Application): "on_satellites_realize": self.on_satellites_realize, "on_picons_realize": self.on_picons_realize, "on_epg_realize": self.on_epg_realize, + "on_timers_realize": self.on_timers_realize, "on_control_realize": self.on_control_realize, "on_ftp_realize": self.on_ftp_realize, "on_visible_page": self.on_visible_page} @@ -234,6 +235,7 @@ class Application(Gtk.Application): self._satellite_tool = None self._picon_manager = None self._epg_box = None + self._timers_box = None self._control_box = None self._ftp_client = None # Player @@ -254,11 +256,14 @@ class Application(Gtk.Application): self._EXTRA_COLOR = None # Color for services with a extra name for the bouquet # Current page. self._page = Page.INFO + self._fav_pages = {Page.SERVICES, Page.PICONS, Page.PLAYBACK, Page.EPG, Page.TIMERS} # Signals. GObject.signal_new("profile-changed", self, GObject.SIGNAL_RUN_LAST, GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,)) GObject.signal_new("fav-changed", self, GObject.SIGNAL_RUN_LAST, GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,)) + GObject.signal_new("page-changed", self, GObject.SIGNAL_RUN_LAST, + GObject.TYPE_PYOBJECT, (GObject.TYPE_PYOBJECT,)) builder = get_builder(UI_RESOURCES_PATH + "main.glade", handlers) self._main_window = builder.get_object("main_window") @@ -734,6 +739,10 @@ class Application(Gtk.Application): self._epg_box = EpgBox(self, self._http_api) box.pack_start(self._epg_box, True, True, 0) + def on_timers_realize(self, box): + self._epg_box = TimersBox(self, self._http_api) + box.pack_start(self._epg_box, True, True, 0) + def on_ftp_realize(self, box): self._ftp_client = FtpClientBox(self, self._settings) box.pack_start(self._ftp_client, True, True, 0) @@ -744,8 +753,9 @@ class Application(Gtk.Application): def on_visible_page(self, stack, param): self._page = Page(stack.get_visible_child_name()) - self._fav_paned.set_visible(self._page in (Page.SERVICES, Page.PICONS, Page.PLAYBACK, Page.EPG)) + self._fav_paned.set_visible(self._page in self._fav_pages) self._save_tool_button.set_visible(self._page in (Page.SERVICES, Page.SATELLITE)) + self.emit("page-changed", self._page) def on_page_show(self, action, value): action.set_state(value)