From b7d0ba7f4b4122892482b993be69344aa0231ef8 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Tue, 28 Jan 2020 15:08:57 +0300 Subject: [PATCH] added controls to the transmitter --- app/ui/transmitter.glade | 130 +++++++++++++++++++++++++++++++++------ app/ui/transmitter.py | 53 +++++++++++++--- 2 files changed, 157 insertions(+), 26 deletions(-) diff --git a/app/ui/transmitter.glade b/app/ui/transmitter.glade index 6a2568de..867efbbf 100644 --- a/app/ui/transmitter.glade +++ b/app/ui/transmitter.glade @@ -3,7 +3,7 @@ The MIT License (MIT) -Copyright (c) 2018-2019 Dmitriy Yefremov +Copyright (c) 2018-2020 Dmitriy Yefremov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -26,13 +26,13 @@ THE SOFTWARE. Author: Dmitriy Yefremov --> - + - + False @@ -49,35 +49,127 @@ Author: Dmitriy Yefremov - + True False - vertical + center + center - + True - True - 2 - 2 - 2 - 2 - gtk-dnd-multiple - + False + Previous + Previous + True + gtk-media-previous + False - True - 0 + True + + + + + True + False + Next + Next + True + gtk-media-next + + + + False + True + + + + + True + False + + + True + True + Drag the link here + 2 + 2 + 2 + 2 + gtk-paste + + + + + + False + False + + + + + True + False + Play + Play + True + gtk-media-play + + + + False + True + + + + + True + False + Stop playback + Stop + True + gtk-media-stop + + + + False + True + + + + + True + False + + + False + False + + + + + True + False + Remove added links in the playlist + Clear + True + gtk-clear + + + + False + True - + - insert-link + demon-editor True diff --git a/app/ui/transmitter.py b/app/ui/transmitter.py index d418f1eb..8367526a 100644 --- a/app/ui/transmitter.py +++ b/app/ui/transmitter.py @@ -1,30 +1,42 @@ from urllib.parse import urlparse + from gi.repository import GLib + from app.connections import HttpRequestType from app.tools.yt import YouTube from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH, TEXT_DOMAIN class LinksTransmitter: + """ The main class for the "send to" function. + + It used for direct playback of media links by the enigma2 media player. + """ + __STREAM_PREFIX = "4097:0:1:0:0:0:0:0:0:0:" def __init__(self, http_api, app_window): handlers = {"on_popup_menu": self.on_popup_menu, "on_status_icon_activate": self.on_status_icon_activate, "on_query_tooltip": self.on_query_tooltip, "on_drag_data_received": self.on_drag_data_received, + "on_previous": self.on_previous, + "on_next": self.on_next, + "on_stop": self.on_stop, + "on_clear": self.on_clear, + "on_play": self.on_play, "on_exit": self.on_exit} self._http_api = http_api self._app_window = app_window builder = Gtk.Builder() - builder.set_translation_domain(TEXT_DOMAIN) builder.add_from_file(UI_RESOURCES_PATH + "transmitter.glade") builder.connect_signals(handlers) self._tray = builder.get_object("status_icon") self._main_window = builder.get_object("main_window") self._url_entry = builder.get_object("url_entry") + self._tool_bar = builder.get_object("tool_bar") style_provider = Gtk.CssProvider() style_provider.load_from_path(UI_RESOURCES_PATH + "style.css") @@ -65,30 +77,57 @@ class LinksTransmitter: result = urlparse(url) if result.scheme and result.netloc: - self._url_entry.set_sensitive(False) + self._tool_bar.set_sensitive(False) yt_id = YouTube.get_yt_id(url) yield True if yt_id: - self._url_entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, Gtk.STOCK_INFO) + self._url_entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, Gtk.STOCK_INFO) links, title = YouTube.get_yt_link(yt_id) yield True if links: url = links[sorted(links, key=lambda x: int(x.rstrip("p")), reverse=True)[0]] else: - self.on_play(links) + self.on_done(links) return else: self._url_entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, None) - self._http_api.send(HttpRequestType.PLAY, url, self.on_play) + self._http_api.send(HttpRequestType.PLAY, url, self.on_done, self.__STREAM_PREFIX) yield True - def on_play(self, res): + def on_done(self, res): """ Play callback """ - GLib.idle_add(self._url_entry.set_sensitive, True) res = res.get("e2state", None) if res else res self._url_entry.set_name("GtkEntry" if res else "digit-entry") + GLib.idle_add(self._tool_bar.set_sensitive, True) + + def on_previous(self, item): + self._http_api.send(HttpRequestType.PLAYER_PREV, None, self.on_done) + + def on_next(self, item): + self._http_api.send(HttpRequestType.PLAYER_NEXT, None, self.on_done) + + def on_play(self, item): + self._http_api.send(HttpRequestType.PLAYER_PLAY, None, self.on_done) + + def on_stop(self, item): + self._http_api.send(HttpRequestType.PLAYER_STOP, None, self.on_done) + + def on_clear(self, item): + """ Remove added links in the playlist. """ + GLib.idle_add(self._tool_bar.set_sensitive, False) + self._http_api.send(HttpRequestType.PLAYER_LIST, None, self.clear_playlist) + + def clear_playlist(self, res): + GLib.idle_add(self._tool_bar.set_sensitive, not res) + + for ref in res: + GLib.idle_add(self._tool_bar.set_sensitive, False) + self._http_api.send(HttpRequestType.PLAYER_REMOVE, + ref.get("e2servicereference", ""), + self.on_done, + self.__STREAM_PREFIX) def on_exit(self, item=None): self.show(False)