added timers page

This commit is contained in:
DYefremov
2021-09-01 14:15:39 +03:00
parent 3fe78e0292
commit 5f0f1e4e64
4 changed files with 223 additions and 68 deletions

View File

@@ -1154,78 +1154,182 @@ Author: Dmitriy Yefremov
</packing>
</child>
</object>
<object class="GtkBox" id="timers_box">
<object class="GtkListStore" id="timer_model">
<columns>
<!-- column-name name -->
<column type="gchararray"/>
<!-- column-name service -->
<column type="gchararray"/>
<!-- column-name time -->
<column type="gchararray"/>
<!-- column-name desc -->
<column type="gchararray"/>
<!-- column-name data -->
<column type="PyObject"/>
</columns>
</object>
<object class="GtkFrame" id="timers_frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<property name="margin_top">2</property>
<property name="label_xalign">0.49000000953674316</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkScrolledWindow" id="timers_screlled_window">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport" id="timers_viewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkListBox" id="timers_list_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selection_mode">multiple</property>
<property name="activate_on_single_click">False</property>
<signal name="button-press-event" handler="on_timers_press" swapped="no"/>
<signal name="drag-data-received" handler="on_timers_drag_data_received" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="timers_button_box">
<object class="GtkBox" id="timers_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">end</property>
<property name="homogeneous">True</property>
<property name="layout_style">expand</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton" id="timer_add_button">
<property name="label" translatable="yes">Add</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.on_timer_add</property>
<object class="GtkBox" id="timers_header_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">15</property>
<property name="margin_right">15</property>
<property name="margin_top">7</property>
<property name="margin_bottom">5</property>
<property name="spacing">5</property>
<child>
<object class="GtkButton" id="timer_add_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child>
<object class="GtkImage" id="timer_add_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">document-new-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="timer_remove_button">
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child>
<object class="GtkImage" id="timer_remove_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">user-trash-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="timer_edit_button">
<property name="label" translatable="yes">Edit</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.on_timer_edit</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="timer_remove_button">
<property name="label" translatable="yes">Remove</property>
<object class="GtkScrolledWindow" id="timers_screlled_window">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.on_timer_remove</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="timer_edit_button">
<property name="label" translatable="yes">Edit</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="action_name">app.on_timer_edit</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="timer_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="model">timer_model</property>
<property name="enable_grid_lines">both</property>
<property name="tooltip_column">3</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="timer_selection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="timer_name_column">
<property name="min_width">150</property>
<property name="title" translatable="yes">Name</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="timer_name_renderer">
<property name="xpad">5</property>
</object>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="timer_service_column">
<property name="min_width">150</property>
<property name="title" translatable="yes">Service</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="timer_service_renderer">
<property name="xpad">5</property>
<property name="xalign">0.49000000953674316</property>
</object>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="timer_time_column">
<property name="min_width">100</property>
<property name="title" translatable="yes">Time</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="timer_time_renderer">
<property name="xpad">5</property>
</object>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="timer_desc_column">
<property name="title" translatable="yes">Description</property>
<property name="expand">True</property>
<property name="alignment">0.5</property>
<child>
<object class="GtkCellRendererText" id="timer_desc_renderer">
<property name="ellipsize">end</property>
</object>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
@@ -1234,11 +1338,13 @@ Author: Dmitriy Yefremov
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child type="label">
<object class="GtkLabel" id="timers_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Timers</property>
</object>
</child>
</object>
<object class="GtkAdjustment" id="volume_adjustment">

View File

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

View File

@@ -2385,7 +2385,6 @@ Author: Dmitriy Yefremov
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="orientation">vertical</property>
@@ -2405,10 +2404,10 @@ Author: Dmitriy Yefremov
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="orientation">vertical</property>
<signal name="realize" handler="on_timers_realize" swapped="no"/>
<child>
<placeholder/>
</child>

View File

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