# -*- coding: UTF-8 -*- ''' SVPlayer user interface (menu) (c) 2011-2015 Jan ONDREJ (SAL) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ''' import sys, os.path from sgtk import Gtk, COLOR_GRAY from paths import file_browser_path from config import PROFILES import players, players.gstp from version import VERSION, RELEASE, LICENSE topmenu_ui = '''\ %s %s %s %s %s %s ''' class TopMenu(Gtk.UIManager): def __init__(self, parent): Gtk.UIManager.__init__(self) self.parentw = parent self.merge_id = None self.update() self.widget = self.get_widget('/TopMenu') self.widget.modify_bg(Gtk.STATE_NORMAL, COLOR_GRAY) self.hide() self.widget.connect("motion_notify_event", self.mouse_motion) #self.drag_dest_set_track_motion(self.mouse_motion) def mouse_motion(self, widget, event): #print "MOUSE MOVE", event return self.parentw.mouse_motion(widget, event) def update(self): if self.merge_id is not None: self.remove_action_group(self.actions) self.remove_ui(self.merge_id) self.actions = Gtk.ActionGroup("TopMenu") self.actions.add_actions([ ('File', Gtk.STOCK_OPEN, '_File'), ('Browse', Gtk.STOCK_OPEN, '_Browse', 'b', None, self.open_browser), ('YouTube search', None, '_YouTube search', 'y', None, self.open_youtube), ('YouTube new search', None, 'YouTube _new search', 'Y', None, self.open_youtube_new), ('YouTube history', None, 'YouTube h_istory', 'i', None, self.open_youtube_history), ('Default engine', None, 'Default engine', 'e', None, None), ('Quit', Gtk.STOCK_QUIT, '_Quit', 'Escape', None, self.parentw.destroy), ('Open', Gtk.STOCK_OPEN, '_Open', None, None, self.open_file), ('A/V', None, 'A/_V'), ('Aspect', None, "Aspect", 'z', None, self.aspect), ('Volume_up', None, 'Volume _up', 'plus', None, self.vol_up), ('Volume_down', None, 'Volume _down', 'minus', None, self.vol_down), ('FF_10s', Gtk.STOCK_GO_FORWARD, "Forward 10s", "bracketleft", None, self.ff_10s), ('REW_10s', Gtk.STOCK_GO_BACK, "Rewind 10s", "bracketright", None, self.rew_10s), ('FF_1m', Gtk.STOCK_GO_FORWARD, "Forward 1m", "apostrophe", None, self.ff_1m), ('REW_1m', Gtk.STOCK_GO_BACK, "Rewind 1m", "backslash", None, self.rew_1m), ('Profile', None, '_Profile'), ('Channel', None, '_Channel'), ('Source', None, '_Source'), ('Audio', None, '_Audio'), ('Subtitles', None, 'Subtitles'), ('Help', Gtk.STOCK_HELP, '_Help'), ('About', Gtk.STOCK_ABOUT, 'A_bout', None, None, self.about), ]) self.actions.add_toggle_actions([ ('GStreamer VAAPI', None, 'GStreamer VAAPI', None, None, self.engine_gstreamer_vaapi, players.default==players.GSTWidget and players.gstp.GST_cmd.prefer_vaapi!=""), ('GStreamer', None, 'GStreamer', None, None, self.engine_gstreamer_no_vaapi, players.default==players.GSTWidget and players.gstp.GST_cmd.prefer_vaapi==""), ('VLC', None, 'VLC', None, None, self.engine_vlc, players.default==players.VLCWidget), ('Mute', None, '_Mute', 'm', None, self.mute, self.get_status('get_mute')), ('Pause', None, '_Pause', 'p', None, self.pause, self.get_status('paused')), ('Fullscreen', None, '_Fullscreen', 'f', None, self.fullscreen, self.parentw.fullscreen), ]) # add archive if self.parentw.urls[self.parentw.channel-1].find_archive(): self.actions.add_actions([ ('Archive', None, 'A_rchive', 'r', None, self.open_archive), ]) archiveitem = '' else: archiveitem = '' # profiles profileitems = [] profileactions = [] for profile in range(len(PROFILES)): if PROFILES.name(profile+1): profileactions.append( ('F%d' % (profile+1), None, '%d. %s' % (profile+1, PROFILES.name(profile+1).replace('_', ' ')), 'F%d' % (profile+1), None, profile) ) profileitems.append('' % (profile+1)) self.actions.add_radio_actions( profileactions, self.parentw.profile-1, self.change_profile ) # channels channelitems = [] channelactions = [] for channel, url in zip(range(len(self.parentw.urls)), self.parentw.urls): channelactions.append( ('ch%d' % (channel+1), None, '%d. %s' % (channel+1, url.name), None, None, channel+1) ) channelitems.append('' % (channel+1)) self.actions.add_radio_actions( channelactions, self.parentw.channel, self.change_channel ) # sources sourceitems = [] sourceactions = [] url = self.parentw.urls[self.parentw.channel-1] for i in range(url.source_count()): if not url(i).archive_only and not url(i).guide_only: sourceactions.append( ('src%d' % i, None, ('%d. %s %s' % (i+1, url(i).source, url(i).name)).strip(), None, None, i) ) sourceitems.append('' % i) if len(sourceitems)>1: self.actions.add_radio_actions( sourceactions, self.parentw.source, self.change_source ) else: sourceitems = [] # audio tracks and subtitles trackitems = [] trackactions = [] subtitleitems = [] subtitleactions = [] if hasattr(self.parentw, 'player'): tracks = sorted( enumerate(self.parentw.player.audio_tracks), key=lambda x: x[1][0] ) for i, (n, track) in tracks: if n==-1: continue trackitems.append( '' % i ) trackactions.append( ('track%d' % i, None, '%s' % track, None, None, i) ) self.actions.add_radio_actions( trackactions, self.parentw.player.audio_track, self.change_track ) for i, (subid, subdesc) in enumerate(self.parentw.player.sub_list()): subtitleitems.append('' % i) subtitleactions.append( ('sub%d' % i, None, subdesc, None, None, i) ) self.actions.add_radio_actions( subtitleactions, self.parentw.player.subtitle, self.change_sub ) # glue all together self.merge_id = self.add_ui_from_string( topmenu_ui % ( archiveitem, '\n'.join(profileitems), '\n'.join(channelitems), '\n'.join(sourceitems), '\n'.join(trackitems), '\n'.join(subtitleitems) ) ) self.insert_action_group(self.actions, 0) def hide(self): self.widget.hide() self.visible = False def show(self): self.update() self.widget.show() self.visible = True def open_file(self, action): chooser = Gtk.FileChooserDialog( title=None, action=Gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(Gtk.STOCK_CANCEL,Gtk.RESPONSE_CANCEL,Gtk.STOCK_OPEN,Gtk.RESPONSE_OK) ) chooser.set_default_response(Gtk.RESPONSE_OK) gfilter = Gtk.FileFilter() gfilter.set_name("Videos") gfilter.add_mime_type("video/*") gfilter.add_pattern("*.ts") chooser.add_filter(gfilter) chooser.set_current_folder(file_browser_path) chooser.set_select_multiple(True) response = chooser.run() if response == Gtk.RESPONSE_OK: fn = chooser.get_filename() self.parentw.play_files([fn], [fn], player=players.default) elif response == Gtk.RESPONSE_CANCEL: print "File open canceled." chooser.destroy() def open_browser(self, action): self.hide() self.parentw.keyboard(key="b") def open_youtube(self, action): self.hide() self.parentw.keyboard(key="y") def open_youtube_new(self, action): self.hide() self.parentw.keyboard(key="Y") def open_youtube_history(self, action): self.hide() self.parentw.keyboard(key="i") def open_archive(self, action): self.hide() self.parentw.keyboard(key="r") def engine_gstreamer_vaapi(self, action): self.hide() players.gstp.GST_cmd.prefer_vaapi = "decode" players.default = players.GSTWidget self.parentw.last_url = None self.parentw.change_channel(0, player=players.default) def engine_gstreamer_no_vaapi(self, action): self.hide() players.gstp.GST_cmd.prefer_vaapi = "" players.default = players.GSTWidget self.parentw.last_url = None self.parentw.change_channel(0, player=players.default) def engine_vlc(self, action): self.hide() players.default = players.VLCWidget self.parentw.last_url = None self.parentw.change_channel(0, player=players.default) def pause(self, action): self.parentw.player.pause() def fullscreen(self, action): self.hide() self.parentw.change_fullscreen(1) def aspect(self, action): self.hide() self.parentw.keyboard(key='z') def mute(self, action): self.hide() self.parentw.player.toggle_mute() def get_status(self, var='mute'): if hasattr(self.parentw, 'player'): attr = getattr(self.parentw.player, var) if callable(attr): return attr() else: return attr return False def vol_up(self, action): self.hide() self.parentw.change_volume(5) def vol_down(self, action): self.hide() self.parentw.change_volume(-5) def change_profile(self, action1, action2): self.hide() self.parentw.keyboard(key=action2.get_name()) def change_channel(self, action1, action2): self.hide() channel = int(action2.get_name()[2:]) self.parentw.change_channel(channel=channel) def change_source(self, action1, action2): self.hide() source = int(action2.get_name()[3:]) self.parentw.source = source self.parentw.change_channel() def change_track(self, action1, action2): self.hide() track = int(action2.get_name()[5:]) self.parentw.audio_track = track self.parentw.change_track() def change_sub(self, action1, action2): self.hide() subtitle = int(action2.get_name()[3:]) self.parentw.player.next_sub(subtitle) def ff_10s(self, action): self.parentw.change_position(10) def rew_10s(self, action): self.parentw.change_position(-10) def ff_1m(self, action): self.parentw.change_position(60) def rew_1m(self, action): self.parentw.change_position(-60) def about(self, action): about = Gtk.AboutDialog() about.set_program_name("SVPlayer") about.set_version("%s-%s" % (VERSION, RELEASE)) about.set_copyright(u"(c) 2011 Ján ONDREJ (SAL), %s" % LICENSE) #readme_path = os.path.join(os.path.dirname(sys.argv[0]), "README") #if os.path.exists(readme_path): # about.set_comments(open(readme_path).read()) about.set_website("http://www.salstar.sk/svplayer") about.run() about.destroy()