Exemplo n.º 1
0
 def __init__(self, parent):
  self.name = '&Play'
  super(PlayMenu, self).__init__()
  parent.Bind(wx.EVT_MENU, application.frame.play_pause, self.Append(wx.ID_ANY, '&Play / Pause', 'Play or pause the current track.'))
  parent.Bind(wx.EVT_MENU, application.frame.do_stop, self.Append(wx.ID_ANY, '&Stop\tCTRL+.', 'Stop the currently playing track.'))
  stop_after = self.AppendCheckItem(wx.ID_ANY, 'Stop &After Current Track\tCTRL+SHIFT+.', 'Stop when the currently playing track has finished playing.')
  stop_after.Check(config.system['stop_after'])
  parent.Bind(wx.EVT_MENU, lambda event: application.frame.add_command(self.do_stop_after, bool(event.GetSelection())), stop_after)
  if not hasattr(application.frame, 'stop_after'):
   application.frame.stop_after = stop_after
  parent.Bind(wx.EVT_MENU, lambda event: queue(application.frame.get_result()) if application.frame.get_result() is not None else wx.Bell(), self.Append(wx.ID_ANY, '&Queue Item\tSHIFT+RETURN', 'Add the currently focused track to the play queue.'))
  parent.Bind(wx.EVT_MENU, application.frame.on_previous, self.Append(wx.ID_ANY, '&Previous Track%s\tCTRL+LEFT' % ('' if get_previous() is None else ' (%s)' % (get_previous())), 'Play the previous track.'))
  parent.Bind(wx.EVT_MENU, application.frame.on_next, self.Append(wx.ID_ANY, '&Next Track%s\tCTRL+RIGHT' % ('' if get_next(False) is None else ' (%s)' % (get_next(remove = False))), 'Play the next track.'))
  parent.Bind(wx.EVT_MENU, lambda event: set_volume(max(0, application.frame.volume.GetValue() - 5)), self.Append(wx.ID_ANY, 'Volume &Down\tCTRL+DOWN', 'Reduce volume by 5%.'))
  parent.Bind(wx.EVT_MENU, lambda event: set_volume(min(100, application.frame.volume.GetValue() + 5)), self.Append(wx.ID_ANY, 'Volume &Up\tCTRL+UP', 'Increase volume by 5%.'))
  repeat_menu = wx.Menu()
  self.repeat_off = repeat_menu.AppendRadioItem(wx.ID_ANY, '&Off', 'No repeat.')
  self.repeat_track = repeat_menu.AppendRadioItem(wx.ID_ANY, '&Track', 'Repeat just the currently playing track.')
  self.repeat_all = repeat_menu.AppendRadioItem(wx.ID_ANY, '&All', 'Repeat all.')
  wx.CallAfter([self.repeat_off, self.repeat_track, self.repeat_all][config.system['repeat']].Check, True)
  for value, option in enumerate(['repeat_off', 'repeat_track', 'repeat_all']):
   control = getattr(self, option)
   parent.Bind(wx.EVT_MENU, lambda event, value = value: config.system.repeat.set(value), control)
   if not hasattr(application.frame, option):
    setattr(application.frame, option, control)
  self.AppendSubMenu(repeat_menu, '&Repeat')#, 'Repeat options')
  shuffle = self.AppendCheckItem(wx.ID_ANY, '&Shuffle\tCTRL+H', 'Play all tracks shuffled.')
  parent.Bind(wx.EVT_MENU, lambda event: application.frame.add_command(self.do_shuffle, bool(event.GetSelection())), shuffle)
  shuffle.Check(config.system['shuffle'])
  if not hasattr(application.frame, 'shuffle'):
   application.frame.shuffle = shuffle
  parent.Bind(wx.EVT_MENU, parent.cast_result, self.Append(wx.ID_ANY, '&Cast...\tF11', 'Cast the currently-focused item'))
Exemplo n.º 2
0
 def on_show(self, event):
     """Show the window."""
     if not self.initialised:
         from .menus.main import MainMenu
         from .menus.playlists import PlaylistsMenu
         from .menus.stations import StationsMenu
         from .menus.taskbar import TaskBarMenu
         self.menu.Bind(
             wx.EVT_BUTTON, lambda event: self.PopupMenu(
                 TaskBarMenu(self), wx.GetMousePosition()))
         from .taskbar import TaskBarIcon, FakeTaskBarIcon
         try:
             self.tb_icon = TaskBarIcon()
         except SystemError as e:
             self.tb_icon = FakeTaskBarIcon()
             logger.warning('Creating the taskbar icon caused an errorL')
             logger.exception(e)
         self.playlists_menu = PlaylistsMenu(self, add_playlists=False)
         self.stations_menu = StationsMenu(self, add_stations=False)
         self.delete_stations_menu = self.stations_menu.delete_menu
         self.SetMenuBar(MainMenu(self))
         for p in session.query(Playlist).order_by(
                 Playlist.name.desc()).all():
             self.add_playlist(p)
         for s in session.query(Station).order_by(
                 Station.name.desc()).all():
             self.add_station(s)
         set_volume(config.system['volume'])
Exemplo n.º 3
0
 def f(device, result):
     """Cast result to the specified device."""
     if isinstance(result, URLStream):
         url = result.url
     else:
         url = application.api.get_stream_url(result.id)
     self.do_stop(None)
     device.wait()
     set_volume(device.status.volume_level * 100)
     device.play_media(url, 'audio/mp3')
     self.cast_device = device
Exemplo n.º 4
0
 def f(device, result):
     """Cast result to the specified device."""
     if isinstance(result, URLStream):
         url = result.url
     else:
         url = application.api.get_stream_url(result.id)
     self.do_stop(None)
     device.wait()
     set_volume(device.status.volume_level * 100)
     device.play_media(url, 'audio/mp3')
     self.cast_device = device
Exemplo n.º 5
0
 def __init__(self):
  super(AudioOptions, self).__init__(application.frame, title = 'Audio Options')
  p = self.GetContentsPane()
  add_accelerator(self, 'ESCAPE', lambda event: self.Close(True))
  self.default_volume = config.system['volume']
  self.default_frequency = config.system['frequency']
  self.default_pan = config.system['pan']
  p.SetSizerType('form')
  wx.StaticText(p, label = '&Output Device')
  self.device = wx.Choice(p, choices = sorted(application.output.get_device_names()))
  self.device.SetStringSelection(config.system['output_device_name'])
  self.device.Bind(wx.EVT_CHOICE, lambda event: set_output_device(self.device.GetStringSelection()))
  wx.StaticText(p, label = '&Volume')
  self.volume = wx.Slider(p, style = wx.VERTICAL)
  self.volume.SetValue(self.default_volume)
  self.volume.Bind(wx.EVT_SLIDER, lambda event: set_volume(self.volume.GetValue()))
  wx.StaticText(p, label = '&Pan')
  self.pan = wx.Slider(p, style = wx.HORIZONTAL)
  self.pan.SetValue(self.default_pan)
  self.pan.Bind(wx.EVT_SLIDER, lambda event: set_pan(self.pan.GetValue()))
  wx.StaticText(p, label = '&Frequency')
  self.frequency = IntCtrl(p, value = self.default_frequency, min = min_frequency, max = max_frequency, limited = True)
  self.frequency.Bind(EVT_INT, set_frequency(self.frequency.GetValue()))
  add_accelerator(self.frequency, 'UP', lambda event: self.update_frequency(min(self.frequency.GetMax(), self.frequency.GetValue() + 100)))
  add_accelerator(self.frequency, 'DOWN', lambda event: self.update_frequency(max(self.frequency.GetMin(), self.frequency.GetValue() - 100)))
  self.ok = wx.Button(p, label = '&OK')
  self.ok.Bind(wx.EVT_BUTTON, lambda event: self.Close(True))
  self.restore = wx.Button(p, label = '&Restore Defaults')
  self.restore.Bind(wx.EVT_BUTTON, self.on_restore)
  self.Show(True)
  self.Maximize(True)
Exemplo n.º 6
0
 def on_show(self, event):
     """Show the window."""
     if not self.initialised:
         from .menus.main import MainMenu
         from .menus.playlists import PlaylistsMenu
         from .menus.stations import StationsMenu
         from .menus.taskbar import TaskBarMenu
         self.menu.Bind(wx.EVT_BUTTON, lambda event: self.PopupMenu(TaskBarMenu(self), wx.GetMousePosition()))
         from .taskbar import TaskBarIcon, FakeTaskBarIcon
         try:
             self.tb_icon = TaskBarIcon()
         except SystemError as e:
             self.tb_icon = FakeTaskBarIcon()
             logger.warning('Creating the taskbar icon caused an errorL')
             logger.exception(e)
         self.playlists_menu = PlaylistsMenu(self, add_playlists = False)
         self.stations_menu = StationsMenu(self, add_stations = False)
         self.delete_stations_menu = self.stations_menu.delete_menu
         self.SetMenuBar(MainMenu(self))
         for p in session.query(Playlist).order_by(Playlist.name.desc()).all():
             self.add_playlist(p)
         for s in session.query(Station).order_by(Station.name.desc()).all():
             self.add_station(s)
         set_volume(config.system['volume'])
Exemplo n.º 7
0
 def __init__(self):
     super(AudioOptions, self).__init__(application.frame,
                                        title='Audio Options')
     p = self.GetContentsPane()
     add_accelerator(self, 'ESCAPE', lambda event: self.Close(True))
     self.default_volume = config.system['volume']
     self.default_frequency = config.system['frequency']
     self.default_pan = config.system['pan']
     p.SetSizerType('form')
     wx.StaticText(p, label='&Output Device')
     self.device = wx.Choice(p,
                             choices=sorted(
                                 application.output.get_device_names()))
     self.device.SetStringSelection(config.system['output_device_name'])
     self.device.Bind(
         wx.EVT_CHOICE,
         lambda event: set_output_device(self.device.GetStringSelection()))
     wx.StaticText(p, label='&Volume')
     self.volume = wx.Slider(p, style=wx.VERTICAL)
     self.volume.SetValue(self.default_volume)
     self.volume.Bind(wx.EVT_SLIDER,
                      lambda event: set_volume(self.volume.GetValue()))
     wx.StaticText(p, label='&Pan')
     self.pan = wx.Slider(p, style=wx.HORIZONTAL)
     self.pan.SetValue(self.default_pan)
     self.pan.Bind(wx.EVT_SLIDER,
                   lambda event: set_pan(self.pan.GetValue()))
     wx.StaticText(p, label='&Frequency')
     self.frequency = IntCtrl(p,
                              value=self.default_frequency,
                              min=min_frequency,
                              max=max_frequency,
                              limited=True)
     self.frequency.Bind(EVT_INT, set_frequency(self.frequency.GetValue()))
     add_accelerator(
         self.frequency, 'UP', lambda event: self.update_frequency(
             min(self.frequency.GetMax(),
                 self.frequency.GetValue() + 100)))
     add_accelerator(
         self.frequency, 'DOWN', lambda event: self.update_frequency(
             max(self.frequency.GetMin(),
                 self.frequency.GetValue() - 100)))
     self.ok = wx.Button(p, label='&OK')
     self.ok.Bind(wx.EVT_BUTTON, lambda event: self.Close(True))
     self.restore = wx.Button(p, label='&Restore Defaults')
     self.restore.Bind(wx.EVT_BUTTON, self.on_restore)
     self.Show(True)
     self.Maximize(True)
Exemplo n.º 8
0
Arquivo: tracks.py Projeto: J-tt/gmp3
class storage(object):
    """Store queries for get_info."""
    playlists = []
    stations = []
    tracks = []
    now_playing = None
    previous = None
    next = None
    play_pause = None

track_actions = {
    'previous': lambda: play(get_previous()),
    'next': lambda: play(get_next()),
    'play_pause': lambda: application.frame.play_pause(None),
    'volume_down': lambda: set_volume(max(0, application.frame.volume.GetValue() - 5)),
    'volume_up': lambda: set_volume(min(100, application.frame.volume.GetValue() + 5))
}

@app.route('/play_track/<key>')
def play_track(request, key):
    """Play the track with the given ID."""
    def f(key):
        try:
            track = session.query(Track).filter(Track.key == key).one()
            play(track)
        except NoResultFound:
            pass # No track with that id.
    wx.CallAfter(f, key)
    return jsonify(
        {
Exemplo n.º 9
0
 def __init__(self, *args, **kwargs):
     self.commands = []  # Commands to be executed from the context menu.
     self.initialised = False  # Set to True when everything's done.
     self.cast_device = None  # The device to cast to.
     super(MainFrame, self).__init__(*args, **kwargs)
     try:
         add_hotkey(self, 'MEDIA_PLAY_PAUSE', self.play_pause)
         add_hotkey(self, 'MEDIA_PREV_TRACK', self.on_previous)
         add_hotkey(self, 'MEDIA_NEXT_TRACK', self.on_next)
     except RuntimeError:
         logger.warning(
             'Media keys will not be available because no win32con found.')
     self.played = [
     ]  # The tracks from the current view which have already been played.
     self.last_playlist = None  # The playlist that most recently had a track added to it.
     self.playlist_action = None  # An action to be called when all playlists have been localised.
     self.autoload = []  # Tracks to autoload in order.
     self.showing = None  # Set it to the currently showing playlist or one of the showing.* constants from functions.sound.
     self.queue = []  # The play queue.
     self.results = []
     p = wx.Panel(self)
     s = wx.BoxSizer(wx.VERTICAL)
     s1 = wx.BoxSizer(wx.HORIZONTAL)
     self.previous = wx.Button(p, label='&Previous')
     self.previous.Bind(wx.EVT_BUTTON, self.on_previous)
     self.play = wx.Button(p, label=PLAY_LABEL)
     self.play.Bind(wx.EVT_BUTTON, self.play_pause)
     self.next = wx.Button(p, label='&Next')
     self.next.Bind(wx.EVT_BUTTON, self.on_next)
     self.menu = wx.Button(p, label='&Menu')
     self.search_label = wx.StaticText(p, label=SEARCH_LABEL)
     self.search = wx.TextCtrl(p, style=wx.TE_PROCESS_ENTER)
     self.search.Bind(wx.EVT_TEXT_ENTER, self.on_text_enter)
     s1.AddMany([(self.previous, 0, wx.GROW), (self.play, 0, wx.GROW),
                 (self.next, 0, wx.GROW), (self.menu, 0, wx.GROW),
                 (self.search_label, 0, wx.GROW),
                 (self.search, 1, wx.GROW)])
     s2 = wx.BoxSizer(wx.HORIZONTAL)
     vs = wx.BoxSizer(wx.VERTICAL)
     vs.Add(wx.StaticText(p, label='&Tracks'), 0, wx.GROW)
     self.view = wx.ListBox(p)
     add_accelerator(self.view, 'RETURN', self.on_activate)
     self.view.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_activate)
     add_accelerator(self.view, 'SPACE', self.play_pause)
     self.view.Bind(wx.EVT_LISTBOX_DCLICK, self.on_activate)
     self.view.SetFocus()
     self.view.Bind(wx.EVT_CONTEXT_MENU, self.on_context)
     if sys.platform == 'darwin':
         add_accelerator(self.view, 'SHIFT+F10', self.on_context)
     vs.Add(self.view, 1, wx.GROW)
     ls = wx.BoxSizer(wx.VERTICAL)
     ls.Add(wx.StaticText(p, label='&Lyrics'), 0, wx.GROW)
     self.lyrics = wx.TextCtrl(p,
                               value='Play a song to view lyrics.',
                               style=wx.TE_MULTILINE | wx.TE_READONLY)
     ls.Add(self.lyrics, 1, wx.GROW)
     ls.Add(wx.StaticText(p, label='Artist &Biography'), 0, wx.GROW)
     self.artist_bio = wx.TextCtrl(p,
                                   style=wx.TE_MULTILINE | wx.TE_READONLY)
     ls.Add(self.artist_bio, 0, wx.GROW)
     s2.AddMany([
         (vs, 1, wx.GROW),
         (ls, 1, wx.GROW),
     ])
     s3 = wx.BoxSizer(wx.HORIZONTAL)
     s3.Add(wx.StaticText(p, label='&Volume'), 0, wx.GROW)
     self.volume = wx.Slider(p,
                             value=config.system['volume'],
                             style=wx.SL_VERTICAL)
     self.volume.Bind(wx.EVT_SLIDER,
                      lambda event: set_volume(self.volume.GetValue()))
     s3.Add(self.volume, 1, wx.GROW)
     s3.Add(wx.StaticText(p, label='&Position'), 0, wx.GROW)
     self.position = wx.Slider(p, style=wx.SL_HORIZONTAL)
     self.position.Bind(
         wx.EVT_SLIDER, lambda event: application.stream.set_position(
             (int(application.stream.get_length() / 100) * self.position.
              GetValue())) if not isinstance(application.track, URLStream)
         and application.stream else None)
     add_accelerator(self, 'SHIFT+LEFT', self.rewind)
     add_accelerator(self, 'SHIFT+RIGHT', self.fastforward)
     self.position_timer = wx.Timer(self)
     self.Bind(wx.EVT_TIMER, self.play_manager, self.position_timer)
     self.position_timer.Start(50)
     s.AddMany([
         (s1, 0, wx.GROW),
         (s2, 1, wx.GROW),
         (s3, 0, wx.GROW),
     ])
     p.SetSizerAndFit(s)
     self.SetTitle()
     self.Bind(wx.EVT_CLOSE, self.on_close)
     self.Bind(wx.EVT_SHOW, self.on_show)
     self.playlists = {}  # A list of playlist: id key: value pairs.
     self.stations = {}  # The same as .playlists except for radio stations.
     self.status = self.CreateStatusBar()
     self.status.SetStatusText('Nothing playing yet')
     add_accelerator(self, 'CTRL+R', self.cycle_repeat)
     self.getting_stream_title = False
Exemplo n.º 10
0
 def on_restore(self, event):
  """Cancel button was pressed."""
  set_volume(100)
  set_pan(50)
  set_frequency(44100)
Exemplo n.º 11
0
 def __init__(self, *args, **kwargs):
     self.commands = [] # Commands to be executed from the context menu.
     self.initialised = False  # Set to True when everything's done.
     self.cast_device = None  # The device to cast to.
     super(MainFrame, self).__init__(*args, **kwargs)
     try:
         add_hotkey(self, 'MEDIA_PLAY_PAUSE', self.play_pause)
         add_hotkey(self, 'MEDIA_PREV_TRACK', self.on_previous)
         add_hotkey(self, 'MEDIA_NEXT_TRACK', self.on_next)
     except RuntimeError:
         logger.warning('Media keys will not be available because no win32con found.')
     self.played = [] # The tracks from the current view which have already been played.
     self.last_playlist = None # The playlist that most recently had a track added to it.
     self.playlist_action = None # An action to be called when all playlists have been localised.
     self.autoload = [] # Tracks to autoload in order.
     self.showing = None # Set it to the currently showing playlist or one of the showing.* constants from functions.sound.
     self.queue = [] # The play queue.
     self.results = []
     p = wx.Panel(self)
     s = wx.BoxSizer(wx.VERTICAL)
     s1 = wx.BoxSizer(wx.HORIZONTAL)
     self.previous = wx.Button(p, label = '&Previous')
     self.previous.Bind(wx.EVT_BUTTON, self.on_previous)
     self.play = wx.Button(p, label = PLAY_LABEL)
     self.play.Bind(wx.EVT_BUTTON, self.play_pause)
     self.next = wx.Button(p, label = '&Next')
     self.next.Bind(wx.EVT_BUTTON, self.on_next)
     self.menu = wx.Button(p, label = '&Menu')
     self.search_label = wx.StaticText(p, label = SEARCH_LABEL)
     self.search = wx.TextCtrl(p, style = wx.TE_PROCESS_ENTER)
     self.search.Bind(wx.EVT_TEXT_ENTER, self.on_text_enter)
     s1.AddMany([
         (self.previous, 0, wx.GROW),
         (self.play, 0, wx.GROW),
         (self.next, 0, wx.GROW),
         (self.menu, 0, wx.GROW),
         (self.search_label, 0, wx.GROW),
         (self.search, 1, wx.GROW)
     ])
     s2 = wx.BoxSizer(wx.HORIZONTAL)
     vs = wx.BoxSizer(wx.VERTICAL)
     vs.Add(wx.StaticText(p, label = '&Tracks'), 0, wx.GROW)
     self.view = wx.ListBox(p)
     add_accelerator(self.view, 'RETURN', self.on_activate)
     self.view.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_activate)
     add_accelerator(self.view, 'SPACE', self.play_pause)
     self.view.Bind(wx.EVT_LISTBOX_DCLICK, self.on_activate)
     self.view.SetFocus()
     self.view.Bind(wx.EVT_CONTEXT_MENU, self.on_context)
     if sys.platform == 'darwin':
         add_accelerator(self.view, 'SHIFT+F10', self.on_context)
     vs.Add(self.view, 1, wx.GROW)
     ls = wx.BoxSizer(wx.VERTICAL)
     ls.Add(wx.StaticText(p, label = '&Lyrics'), 0, wx.GROW)
     self.lyrics = wx.TextCtrl(p, value = 'Play a song to view lyrics.', style = wx.TE_MULTILINE | wx.TE_READONLY)
     ls.Add(self.lyrics, 1, wx.GROW)
     ls.Add(wx.StaticText(p, label = 'Artist &Biography'), 0, wx.GROW)
     self.artist_bio = wx.TextCtrl(p, style = wx.TE_MULTILINE | wx.TE_READONLY)
     ls.Add(self.artist_bio, 0, wx.GROW)
     s2.AddMany([
         (vs, 1, wx.GROW),
         (ls, 1, wx.GROW),
     ])
     s3 = wx.BoxSizer(wx.HORIZONTAL)
     s3.Add(wx.StaticText(p, label = '&Volume'), 0, wx.GROW)
     self.volume = wx.Slider(p, value = config.system['volume'], style = wx.SL_VERTICAL)
     self.volume.Bind(wx.EVT_SLIDER, lambda event: set_volume(self.volume.GetValue()))
     s3.Add(self.volume, 1, wx.GROW)
     s3.Add(wx.StaticText(p, label = '&Position'), 0, wx.GROW)
     self.position= wx.Slider(p, style = wx.SL_HORIZONTAL)
     self.position.Bind(wx.EVT_SLIDER, lambda event: application.stream.set_position((int(application.stream.get_length() / 100) * self.position.GetValue())) if not isinstance(application.track, URLStream) and application.stream else None)
     add_accelerator(self, 'SHIFT+LEFT', self.rewind)
     add_accelerator(self, 'SHIFT+RIGHT', self.fastforward)
     self.position_timer = wx.Timer(self)
     self.Bind(wx.EVT_TIMER, self.play_manager, self.position_timer)
     self.position_timer.Start(50)
     s.AddMany([
         (s1, 0, wx.GROW),
         (s2, 1, wx.GROW),
         (s3, 0, wx.GROW),
     ])
     p.SetSizerAndFit(s)
     self.SetTitle()
     self.Bind(wx.EVT_CLOSE, self.on_close)
     self.Bind(wx.EVT_SHOW, self.on_show)
     self.playlists = {} # A list of playlist: id key: value pairs.
     self.stations = {} # The same as .playlists except for radio stations.
     self.status = self.CreateStatusBar()
     self.status.SetStatusText('Nothing playing yet')
     add_accelerator(self, 'CTRL+R', self.cycle_repeat)
     self.getting_stream_title = False
Exemplo n.º 12
0
 def on_restore(self, event):
     """Cancel button was pressed."""
     set_volume(100)
     set_pan(50)
     set_frequency(44100)