def add_submenu(self, submenu, name, terminal): # create menu item menu = MenuItem(name) # call on_click method while Clicking on menu item menu.connect("activate", self.on_click, terminal) # append menu item to context menu submenu.append(menu) return menu
def cb_labels(self, labels): for child in self.sub_menu.get_children(): self.sub_menu.remove(child) for label in [NO_LABEL] + list(labels): if label == NO_LABEL: item = MenuItem(_(NO_LABEL)) # noqa: F821 else: item = MenuItem(label.replace('_', '__')) item.connect('activate', self.on_select_label, label) self.sub_menu.append(item) self.show_all()
class Gtk3UI(Gtk3PluginBase): def enable(self): self.builder = Gtk.Builder() self.builder.add_from_file(get_resource('config.ui')) component.get('Preferences').add_page('Streaming', self.builder.get_object('prefs_box')) component.get('PluginManager').register_hook('on_apply_prefs', self.on_apply_prefs) component.get('PluginManager').register_hook('on_show_prefs', self.on_show_prefs) file_menu = self.get_widget('menu_file_tab') self.sep = SeparatorMenuItem() self.item = MenuItem(_("Stream this file")) self.item.connect("activate", self.on_menuitem_stream) file_menu.append(self.sep) file_menu.append(self.item) self.sep.show() self.item.show() torrentmenu = component.get("MenuBar").torrentmenu self.sep_torrentmenu = SeparatorMenuItem() self.item_torrentmenu = MenuItem(_("Stream this torrent")) self.item_torrentmenu.connect("activate", self.on_torrentmenu_menuitem_stream) torrentmenu.append(self.sep_torrentmenu) torrentmenu.append(self.item_torrentmenu) self.sep_torrentmenu.show() self.item_torrentmenu.show() def disable(self): component.get('Preferences').remove_page('Streaming') component.get('PluginManager').deregister_hook('on_apply_prefs', self.on_apply_prefs) component.get('PluginManager').deregister_hook('on_show_prefs', self.on_show_prefs) file_menu = self.get_widget('menu_file_tab') file_menu.remove(self.item) file_menu.remove(self.sep) torrentmenu = component.get("MenuBar").torrentmenu torrentmenu.remove(self.item_torrentmenu) torrentmenu.remove(self.sep_torrentmenu) def get_widget(self, widget_name): main_builder = component.get('MainWindow').get_builder() return main_builder.get_object(widget_name) @defer.inlineCallbacks def on_apply_prefs(self): log.debug("applying prefs for Streaming") serve_method = 'standalone' # if self.builder.get_object("input_serve_standalone").get_active(): # serve_method = 'standalone' # elif self.builder.get_object("input_serve_webui").get_active(): # serve_method = 'webui' if self.builder.get_object("input_ssl_cert_daemon").get_active(): ssl_source = 'daemon' elif self.builder.get_object("input_ssl_cert_custom").get_active(): ssl_source = 'custom' config = { "ip": self.builder.get_object("input_ip").get_text(), "port": int(self.builder.get_object("input_port").get_text()), "use_stream_urls": self.builder.get_object("input_use_stream_urls").get_active(), "auto_open_stream_urls": self.builder.get_object("input_auto_open_stream_urls").get_active(), "aggressive_prioritizing": self.builder.get_object("input_aggressive_prioritizing").get_active(), "allow_remote": self.builder.get_object("input_allow_remote").get_active(), "download_only_streamed": self.builder.get_object("input_download_only_streamed").get_active(), "reverse_proxy_enabled": self.builder.get_object("input_reverse_proxy_enabled").get_active(), # "download_in_order": self.builder.get_object("input_download_in_order").get_active(), "use_ssl": self.builder.get_object("input_use_ssl").get_active(), # "remote_username": self.builder.get_object("input_remote_username").get_text(), "reverse_proxy_base_url": self.builder.get_object("input_reverse_proxy_base_url").get_text(), "remote_password": self.builder.get_object("input_remote_password").get_text(), "ssl_priv_key_path": self.builder.get_object("input_ssl_priv_key_path").get_text(), "ssl_cert_path": self.builder.get_object("input_ssl_cert_path").get_text(), "serve_method": serve_method, "ssl_source": ssl_source, } result = yield client.streaming.set_config(config) if result: message_type, message_class, message = result if message_type == 'error': topic = 'Unknown error type' if message_class == 'ssl': topic = 'SSL Failed' dialogs.ErrorDialog(topic, message).run() def on_show_prefs(self): client.streaming.get_config().addCallback(self.cb_get_config) def cb_get_config(self, config): """callback for on show_prefs""" self.builder.get_object("input_ip").set_text(config["ip"]) self.builder.get_object("input_port").set_text(str(config["port"])) self.builder.get_object("input_use_stream_urls").set_active(config["use_stream_urls"]) self.builder.get_object("input_auto_open_stream_urls").set_active(config["auto_open_stream_urls"]) self.builder.get_object("input_aggressive_prioritizing").set_active(config["aggressive_prioritizing"]) self.builder.get_object("input_allow_remote").set_active(config["allow_remote"]) self.builder.get_object("input_use_ssl").set_active(config["use_ssl"]) self.builder.get_object("input_download_only_streamed").set_active(config["download_only_streamed"]) self.builder.get_object("input_reverse_proxy_enabled").set_active(config["reverse_proxy_enabled"]) # self.builder.get_object("input_download_in_order").set_active(config["download_in_order"]) # self.builder.get_object("input_download_everything").set_active(not config["download_in_order"] and not config["download_only_streamed"]) # self.builder.get_object("input_remote_username").set_text(config["remote_username"]) self.builder.get_object("input_reverse_proxy_base_url").set_text(config["reverse_proxy_base_url"]) self.builder.get_object("input_remote_password").set_text(config["remote_password"]) self.builder.get_object("input_ssl_priv_key_path").set_text(config["ssl_priv_key_path"]) self.builder.get_object("input_ssl_cert_path").set_text(config["ssl_cert_path"]) # self.builder.get_object("input_serve_standalone").set_active(config["serve_method"] == "standalone") # self.builder.get_object("input_serve_webui").set_active(config["serve_method"] == "webui") self.builder.get_object("input_ssl_cert_daemon").set_active(config["ssl_source"] == "daemon") self.builder.get_object("input_ssl_cert_custom").set_active(config["ssl_source"] == "custom") api_url = 'http%s://%s:%s@%s:%s/streaming/stream' % (('s' if config["use_ssl"] else ''), config["remote_username"], config["remote_password"], config["ip"], config["port"]) self.builder.get_object("output_remote_url").set_text(api_url) def on_torrentmenu_menuitem_stream(self, data=None): torrent_id = component.get("TorrentView").get_selected_torrents()[0] client.streaming.stream_torrent(infohash=torrent_id).addCallback(self.stream_ready) def on_menuitem_stream(self, data=None): torrent_id = component.get("TorrentView").get_selected_torrents()[0] ft = component.get("TorrentDetails").tabs['Files'] paths = ft.listview.get_selection().get_selected_rows()[1] selected = [] for path in paths: selected.append(ft.treestore.get_iter(path)) for select in selected: path = ft.get_file_path(select) client.streaming.stream_torrent(infohash=torrent_id, filepath_or_index=path, includes_name=True).addCallback(self.stream_ready) break def stream_ready(self, result): if result['status'] == 'success': if result.get('use_stream_urls', False): url = "stream+%s" % result['url'] if result.get('auto_open_stream_urls', False): threads.deferToThread(execute_url, url) else: def on_dialog_callback(response): if response == Gtk.ResponseType.YES: threads.deferToThread(execute_url, url) dialogs.YesNoDialog('Stream ready', 'Do you want to play the video?').run().addCallback(on_dialog_callback) else: dialogs.ErrorDialog('Stream ready', 'Copy the link into a media player', details=result['url']).run() else: dialogs.ErrorDialog('Stream failed', 'Was unable to prepare the stream', details=result).run()