示例#1
0
文件: main_frame.py 项目: J-tt/gmp3
 def do_delete(self, event):
     """Delete the current result from the current view."""
     res = self.get_result()
     if not self.view.HasFocus():
         event.Skip()
     elif res is None:
         return wx.Bell()
     elif self.showing is showing.SHOWING_LIBRARY:
         if wx.MessageBox(
                 'Are you sure you want to delete %s from your library?' %
                 res,
                 'Are You Sure',
                 style=wx.ICON_QUESTION | wx.YES_NO) == wx.YES:
             remove_from_library(res)
     elif isinstance(self.showing, Playlist):
         for entry in res.playlist_entries:
             if entry.playlist is self.showing:
                 if wx.MessageBox(
                         'Are you sure you want to remove %s from the %s playlist?'
                         % (res, self.showing.name),
                         'Are You Sure',
                         style=wx.ICON_QUESTION | wx.YES_NO) == wx.YES:
                     remove_from_playlist(entry)
                 break
         else:
             do_error('Cannot find %s in the %s playlist.' %
                      (res, self.showing.name))
     else:
         do_error('No way to delete %s from the current view.' % res)
示例#2
0
 def on_done(self, event):
  """The done button was pressed."""
  name = self.name.GetValue()
  description = self.description.GetValue()
  public = self.public.GetValue()
  logger.debug('Attempting to create playlist with name "%s", description "%s" and public %s.', name, repr(description), public)
  if not name:
   do_error('Playlist names cannot be blank.')
   self.name.SetFocus()
  else:
   try:
    id = application.api.create_playlist(name, description, public)
    logger.debug('New playlist ID is %s.', id)
    p = Playlist(id = id, name = name, description = description)
    logger.debug('Created Playlist object %s.', p)
    session.add(p)
    application.frame.add_playlist(p)
    entry_ids = application.api.add_songs_to_playlist(p.id, [t.id for t in self.tracks])
    logger.debug('Entry IDs are: %s.', entry_ids)
    if len(entry_ids) == len(self.tracks):
     for pos, track in enumerate(self.tracks):
      p.tracks.append(track)
      e = PlaylistEntry(playlist = p, track = track, id = entry_ids[pos])
      logger.debug('Created playlist entry %s (%s).', e, e.track)
      session.add(e)
    else:
     do_error('Only %s %s out of %s were added to the playlist.' % (len(entry_ids), 'track' if len(entry_ids) == 1 else 'tracks', len(self.tracks)))
    session.commit()
    logger.debug('Done. Closing %s.', self)
    self.Close(True)
   except NotLoggedIn:
    do_login(callback = self.on_done, args = [event])
示例#3
0
文件: lyrics_frame.py 项目: J-tt/gmp3
 def on_ok(self, event):
     self.track.lyrics = self.lyrics.GetValue()
     session.add(self.track)
     try:
         session.commit()
         self.Close(True)
         if self.track is application.track:
             application.frame.update_lyrics(self.track)
     except Exception as e:
         do_error(e)
示例#4
0
 def on_ok(self, event):
     self.track.lyrics = self.lyrics.GetValue()
     session.add(self.track)
     try:
         session.commit()
         self.Close(True)
         if self.track is application.track:
             application.frame.update_lyrics(self.track)
     except Exception as e:
         do_error(e)
示例#5
0
文件: main_frame.py 项目: J-tt/gmp3
 def rewind(self, event):
     """Rewind the current track."""
     if self.view.HasFocus():
         if application.stream is not None:
             try:
                 seek(seek_amount * -1)
             except BassError as e:
                 do_error(e)
         else:
             wx.Bell()
     else:
         event.Skip()
示例#6
0
文件: main_frame.py 项目: J-tt/gmp3
 def fastforward(self, event):
     """Fastforward the currently playing stream."""
     if self.view.HasFocus():
         if application.stream is not None:
             try:
                 seek(seek_amount)
             except BassError as e:
                 do_error(e)
         else:
             wx.Bell()
     else:
         event.Skip()
示例#7
0
 def fastforward(self, event):
     """Fastforward the currently playing stream."""
     if self.view.HasFocus():
         if application.stream is not None:
             try:
                 seek(seek_amount)
             except BassError as e:
                 do_error(e)
         else:
             wx.Bell()
     else:
         event.Skip()
示例#8
0
 def rewind(self, event):
     """Rewind the current track."""
     if self.view.HasFocus():
         if application.stream is not None:
             try:
                 seek(seek_amount * -1)
             except BassError as e:
                 do_error(e)
         else:
             wx.Bell()
     else:
         event.Skip()
示例#9
0
 def on_text_enter(self, event):
     """Enter was pressed in the text field."""
     value = self.search.GetValue()
     m = search(config.interface['id_regexp'], value)
     if m is not None:
         try:
             self.load_id(m.groupdict()['id'])
         except KeyError:
             do_error('No id found in the ID regexp. Please fix this in the Interface configuration.')
     elif self.offline_search.IsChecked():
         self.do_local_search(value)
     else:
         self.do_remote_search(value)
示例#10
0
 def on_ok(self, event):
     """The OK button was pressed."""
     cr = self.genre.GetSelection()
     if cr == -1:
         do_error('You must select a genre to seed from.')
     else:
         genre = self.genres[cr]
         name = self.name.GetValue()
         if name:
             s = create_station('genre_id', genre, name=name)
             if name is not None:
                 application.frame.load_station(s)
             self.Close(True)
         else:
             do_error('You must provide a name.')
示例#11
0
 def on_activate(self, event):
     """Enter was pressed on a track."""
     res = self.get_result()
     if res is None:
         wx.Bell()
     else:
         try:
             if self.cast_device is not None:
                 self.cast_device.media_controller.stop()
                 self.cast_device = None
             play(res)
         except BassError as e:
             do_error(e)
         if config.interface['clear_queue']:
             self.queue = []
示例#12
0
 def on_ok(self, event):
  """The OK button was pressed."""
  cr = self.genre.GetSelection()
  if cr == -1:
   do_error('You must select a genre to seed from.')
  else:
   genre = self.genres[cr]
   name = self.name.GetValue()
   if name:
    s = create_station('genre_id', genre, name = name)
    if name is not None:
     application.frame.load_station(s)
    self.Close(True)
   else:
    do_error('You must provide a name.')
示例#13
0
文件: main_frame.py 项目: J-tt/gmp3
 def on_text_enter(self, event):
     """Enter was pressed in the text field."""
     value = self.search.GetValue()
     m = search(config.interface['id_regexp'], value)
     if m is not None:
         try:
             self.load_id(m.groupdict()['id'])
         except KeyError:
             do_error(
                 'No id found in the ID regexp. Please fix this in the Interface configuration.'
             )
     elif self.offline_search.IsChecked():
         self.do_local_search(value)
     else:
         self.do_remote_search(value)
示例#14
0
文件: main_frame.py 项目: J-tt/gmp3
 def on_activate(self, event):
     """Enter was pressed on a track."""
     res = self.get_result()
     if res is None:
         wx.Bell()
     else:
         try:
             if self.cast_device is not None:
                 self.cast_device.media_controller.stop()
                 self.cast_device = None
             play(res)
         except BassError as e:
             do_error(e)
         if config.interface['clear_queue']:
             self.queue = []
示例#15
0
文件: main_frame.py 项目: J-tt/gmp3
 def f2(artists):
     """Run through artists and add them to the database before building the dialog."""
     results = []  # The list of Artist objects.
     for a in artists:
         try:
             artist = session.query(Artist).filter(
                 Artist.id == a['artistId']).one()
         except NoResultFound:
             artist = Artist(id=a['artistId'])
         artist.populate(a)
         session.add(artist)
         results.append(artist)
     session.commit()
     if not results:
         return do_error('There are no related artists.')
     dlg = wx.SingleChoiceDialog(self, 'Select a related artist',
                                 'Related Artists',
                                 [x.name for x in results])
     if dlg.ShowModal() == wx.ID_OK:
         res = results[dlg.GetSelection()]
     else:
         res = None
     dlg.Destroy()
     if res is not None:
         artist_action([res], load_artist_top_tracks)
示例#16
0
 def on_delete(self, event):
  """Delete this playlist."""
  if wx.MessageBox('Are you sure you want to delete the %s playlist?' % self.playlist.name, 'Really Delete', style = wx.ICON_QUESTION | wx.YES_NO) == wx.YES:
   if delete_playlist(self.playlist):
    self.Close(True)
   else:
    return do_error('Could not delete the %s playlist.' % self.playlist.name)
示例#17
0
 def on_ok(self, event):
  """The OK button was pressed."""
  name, description = self.name.GetValue(), self.description.GetValue()
  if not name:
   return do_error('Playlist names cannot be blank.')
  elif not description:
   return do_error('Playlist descriptions cannot be blank.')
  else:
   self.playlist.name = name
   self.playlist.description = description
   try:
    self.playlist.id = application.api.edit_playlist(self.playlist.id, new_name = name, new_description = description)
   except NotLoggedIn:
    return do_login(callback = self.on_ok, args = [event])
   session.add(self.playlist)
   session.commit()
   self.Close(True)
示例#18
0
 def load_id(self, id):
     """Play a track with a specific ID."""
     try:
         info = application.api.get_track_info(id)
     except CallFailure:
         return do_error('Invalid track ID: %s.' % id)
     except NotLoggedIn:
         return do_login(callback=self.load_id, args=[id])
     self.add_results([info], showing='ID: %s' % id)
示例#19
0
文件: main_frame.py 项目: J-tt/gmp3
 def load_id(self, id):
     """Play a track with a specific ID."""
     try:
         info = application.api.get_track_info(id)
     except CallFailure:
         return do_error('Invalid track ID: %s.' % id)
     except NotLoggedIn:
         return do_login(callback=self.load_id, args=[id])
     self.add_results([info], showing='ID: %s' % id)
示例#20
0
 def on_ok(self, event):
     """OK button was pressed."""
     name = self.name.GetValue()
     url = self.url.GetValue()
     if not name:
         do_error('You must supply a name.')
         self.name.SetFocus()
     elif not url:
         do_error('You must specify a URL.')
         self.url.SetFocus()
     else:
         self.stream.name = name
         self.stream.url = url
         session.add(self.stream)
         session.commit()
         if application.frame.showing is SHOWING_STREAMS and self.stream not in application.frame.results:
             application.frame.add_result(self.stream)
         logger.info('Committed %r.', self.stream)
         self.Close(True)
示例#21
0
 def on_ok(self, event):
  """OK button was pressed."""
  name = self.name.GetValue()
  url = self.url.GetValue()
  if not name:
   do_error('You must supply a name.')
   self.name.SetFocus()
  elif not url:
   do_error('You must specify a URL.')
   self.url.SetFocus()
  else:
   self.stream.name = name
   self.stream.url = url
   session.add(self.stream)
   session.commit()
   if application.frame.showing is SHOWING_STREAMS and self.stream not in application.frame.results:
    application.frame.add_result(self.stream)
   logger.info('Committed %r.', self.stream)
   self.Close(True)
示例#22
0
 def on_ok(self, event):
     """The OK button was pressed."""
     name, description = self.name.GetValue(), self.description.GetValue()
     if not name:
         return do_error('Playlist names cannot be blank.')
     elif not description:
         return do_error('Playlist descriptions cannot be blank.')
     else:
         self.playlist.name = name
         self.playlist.description = description
         try:
             self.playlist.id = application.api.edit_playlist(
                 self.playlist.id,
                 new_name=name,
                 new_description=description)
         except NotLoggedIn:
             return do_login(callback=self.on_ok, args=[event])
         session.add(self.playlist)
         session.commit()
         self.Close(True)
示例#23
0
 def do_delete(self, event):
     """Delete the current result from the current view."""
     res = self.get_result()
     if not self.view.HasFocus():
         event.Skip()
     elif res is None:
         return wx.Bell()
     elif self.showing is showing.SHOWING_LIBRARY:
         if wx.MessageBox('Are you sure you want to delete %s from your library?' % res, 'Are You Sure', style = wx.ICON_QUESTION | wx.YES_NO) == wx.YES:
             remove_from_library(res)
     elif isinstance(self.showing, Playlist):
         for entry in res.playlist_entries:
             if entry.playlist is self.showing:
                 if wx.MessageBox('Are you sure you want to remove %s from the %s playlist?' % (res, self.showing.name), 'Are You Sure', style = wx.ICON_QUESTION | wx.YES_NO) == wx.YES:
                     remove_from_playlist(entry)
                 break
         else:
             do_error('Cannot find %s in the %s playlist.' % (res, self.showing.name))
     else:
         do_error('No way to delete %s from the current view.' % res)
示例#24
0
 def on_delete(self, event):
     """Delete this playlist."""
     if wx.MessageBox('Are you sure you want to delete the %s playlist?' %
                      self.playlist.name,
                      'Really Delete',
                      style=wx.ICON_QUESTION | wx.YES_NO) == wx.YES:
         if delete_playlist(self.playlist):
             self.Close(True)
         else:
             return do_error('Could not delete the %s playlist.' %
                             self.playlist.name)
示例#25
0
 def on_done(self, event):
     """The done button was pressed."""
     name = self.name.GetValue()
     description = self.description.GetValue()
     public = self.public.GetValue()
     logger.debug(
         'Attempting to create playlist with name "%s", description "%s" and public %s.',
         name, repr(description), public)
     if not name:
         do_error('Playlist names cannot be blank.')
         self.name.SetFocus()
     else:
         try:
             id = application.api.create_playlist(name, description, public)
             logger.debug('New playlist ID is %s.', id)
             p = Playlist(id=id, name=name, description=description)
             logger.debug('Created Playlist object %s.', p)
             session.add(p)
             application.frame.add_playlist(p)
             entry_ids = application.api.add_songs_to_playlist(
                 p.id, [t.id for t in self.tracks])
             logger.debug('Entry IDs are: %s.', entry_ids)
             if len(entry_ids) == len(self.tracks):
                 for pos, track in enumerate(self.tracks):
                     p.tracks.append(track)
                     e = PlaylistEntry(playlist=p,
                                       track=track,
                                       id=entry_ids[pos])
                     logger.debug('Created playlist entry %s (%s).', e,
                                  e.track)
                     session.add(e)
             else:
                 do_error(
                     'Only %s %s out of %s were added to the playlist.' %
                     (len(entry_ids), 'track' if len(entry_ids) == 1 else
                      'tracks', len(self.tracks)))
             session.commit()
             logger.debug('Done. Closing %s.', self)
             self.Close(True)
         except NotLoggedIn:
             do_login(callback=self.on_done, args=[event])
示例#26
0
 def f2(artists):
     """Run through artists and add them to the database before building the dialog."""
     results = [] # The list of Artist objects.
     for a in artists:
         try:
             artist = session.query(Artist).filter(Artist.id == a['artistId']).one()
         except NoResultFound:
             artist = Artist(id = a['artistId'])
         artist.populate(a)
         session.add(artist)
         results.append(artist)
     session.commit()
     if not results:
         return do_error('There are no related artists.')
     dlg = wx.SingleChoiceDialog(self, 'Select a related artist', 'Related Artists', [x.name for x in results])
     if dlg.ShowModal() == wx.ID_OK:
         res = results[dlg.GetSelection()]
     else:
         res = None
     dlg.Destroy()
     if res is not None:
         artist_action([res], load_artist_top_tracks)
示例#27
0
 def __init__(self, parent):
  self.name = '&Source'
  super(SourceMenu, self).__init__()
  parent.Bind(wx.EVT_MENU, lambda event: Thread(target = application.frame.load_library).start(), self.Append(wx.ID_ANY, '&Library\tCTRL+L', 'Load every song in your Google Music library.'))
  parent.Bind(wx.EVT_MENU, lambda event: Thread(target = application.frame.load_promoted_songs).start(), self.Append(wx.ID_ANY, 'Promoted &Songs\tCTRL+3', 'Load promoted songs.'))
  parent.Bind(wx.EVT_MENU, lambda event: application.frame.add_results(application.frame.queue, showing = showing.SHOWING_QUEUE), self.Append(wx.ID_ANY, '&Queue\tCTRL+SHIFT+Q', 'Show all tracks in the play queue.'))
  parent.Bind(wx.EVT_MENU, lambda event: application.frame.add_results(session.query(Track).all(), showing = showing.SHOWING_CATALOGUE), self.Append(wx.ID_ANY, '&Catalogue\tCTRL+0', 'Load all songs which are stored in the local database.'))
  parent.Bind(wx.EVT_MENU, lambda event: application.frame.add_results([x for x in session.query(Track).all() if x.downloaded is True], showing = showing.SHOWING_DOWNLOADED), self.Append(wx.ID_ANY, '&Downloaded\tCTRL+D', 'Show all downloaded tracks.'))
  self.AppendSubMenu(parent.playlists_menu if parent is application.frame else PlaylistsMenu(parent), '&Playlists', 'Select a local or remote playlist to view.')
  self.AppendSubMenu(parent.stations_menu if parent is application.frame else StationsMenu(parent), '&Radio Stations', 'Locally stored and remote radio stations.')
  parent.Bind(wx.EVT_MENU, lambda event: application.frame.add_results(session.query(URLStream), showing=showing.SHOWING_STREAMS), self.Append(wx.ID_ANY, '&Internet Streams\tCTRL+I', 'Show all internet streams.'))
  parent.Bind(wx.EVT_MENU, lambda event: setattr(application.frame, 'autoload', [application.frame.autoload[0]] if application.frame.autoload else []), self.Append(wx.ID_ANY, 'St&op Loading Results', 'Stop loading results to the track view.'))
  parent.Bind(wx.EVT_MENU, self.load_track, self.Append(wx.ID_ANY, 'Load Specific Track...\tCTRL+SHIFT+V', 'Load a track with a specific ID.'))
  parent.Bind(wx.EVT_MENU, lambda event: webbrowser.open('http://%s:%s@localhost:%d' % (config.http['uid'], config.http['pwd'], app.port)) if config.http['enabled'] else do_error('The web server is not running. Enable it and restart GMP.'), self.Append(wx.ID_ANY, '&Web Interface...', 'Load the web interface.'))