コード例 #1
0
ファイル: main_frame.py プロジェクト: pool-prateek/gmp
 def add_saved_result(self, name = None, results = None):
  """Saves results to the config and the history menu."""
  if not results:
   results = self.get_results()
  if not results:
   return functions.bell()()
  if not name:
   dlg = wx.TextEntryDialog(self, 'Enter a name for this result', 'Save Result')
   if dlg.ShowModal() == wx.ID_OK:
    name = dlg.GetValue()
   dlg.Destroy()
  if name:
   if name not in application.saved_results or wx.MessageBox('There is already a saved result by that name. Replace?', 'Duplicate Name', style = wx.YES_NO) == wx.YES:
    application.saved_results[name] = results
    self.current_saved_result = name
    id = wx.NewId()
    self.saved_results_indices[name] = id
    self.Bind(
    wx.EVT_MENU,
    lambda event: self.add_results(application.saved_results[name], clear = True, saved_result = name),
    self.history_menu.Append(
    id,
    '&%s' % name,
    'Load the %s saved history item.' % name
    ))
コード例 #2
0
ファイル: url_frame.py プロジェクト: chrisnorman7/gmp
 def on_delete(self, event):
  cr = self.streams.GetSelection()
  if cr == -1:
   return functions.bell()
  else:
   if wx.MessageBox('Really delete the %s stream?' % self._streams[cr][0], 'Are You Sure', style = wx.ICON_EXCLAMATION | wx.YES_NO) == wx.YES:
    del self._streams[cr]
    self.streams.Delete(cr)
コード例 #3
0
ファイル: gui.py プロジェクト: chrisnorman7/mmc2
 def do_command_history(self, i):
  """
  Retrieve an item from the command history.
  
  Arguments:
   i - The index to retrieve.
  """
  if not self.commands:
   return functions.bell()
  if i >= 0:
   functions.bell()
   return self.do_clear(save = True)
  try:
   self.entry.SetValue(self.commands[i])
   self.entry.SetInsertionPoint(-1)
   self._command_pos = i
  except IndexError:
   return functions.bell()
コード例 #4
0
ファイル: login_frame.py プロジェクト: chrisnorman7/gmp
 def do_login(self, event = None):
  """Starts the thread that performs the login, so the GUI doesn't freeze."""
  if self.processing:
   return functions.bell()()
  self.processing = True
  self.login.SetLabel('Logging in...')
  self.login.Disable()
  self.uid.Disable()
  self.pwd.Disable()
  Thread(target = self._do_login, args = [self.uid.GetValue(), self.pwd.GetValue()]).start()
コード例 #5
0
 def on_delete(self, event):
     cr = self.streams.GetSelection()
     if cr == -1:
         return functions.bell()
     else:
         if wx.MessageBox('Really delete the %s stream?' %
                          self._streams[cr][0],
                          'Are You Sure',
                          style=wx.ICON_EXCLAMATION | wx.YES_NO) == wx.YES:
             del self._streams[cr]
             self.streams.Delete(cr)
コード例 #6
0
ファイル: login_frame.py プロジェクト: pool-prateek/gmp
 def do_login(self, event=None):
     """Starts the thread that performs the login, so the GUI doesn't freeze."""
     if self.processing:
         return functions.bell()()
     self.processing = True
     self.login.SetLabel('Logging in...')
     self.login.Disable()
     self.uid.Disable()
     self.pwd.Disable()
     Thread(target=self._do_login,
            args=[self.uid.GetValue(),
                  self.pwd.GetValue()]).start()
コード例 #7
0
ファイル: main_frame.py プロジェクト: pool-prateek/gmp
 def select_item(self, event):
  """Play the track under the mouse."""
  ctrl = self.FindFocus()
  if application.platform == 'darwin':
   ctrl = self.results
  if ctrl == self.queue:
   func = self.get_queue
  elif ctrl == self.results:
   func = self.get_results
  else:
   return event.Skip()
  id = self.get_current_result(ctrl)
  if id == -1:
   return functions.bell()
  track = func()[id]
  if ctrl == self.queue:
   self.unqueue_item(id)
  Thread(target = self.play, args = [track]).start()
コード例 #8
0
ファイル: lyrics_viewer.py プロジェクト: chrisnorman7/gmp
 def do_browse(self, event):
  """Opens the URL in the web browser."""
  if self.url:
   webbrowser.open(self.url)
  else:
   functions.bell()()
コード例 #9
0
ファイル: lyrics_viewer.py プロジェクト: pool-prateek/gmp
 def do_browse(self, event):
     """Opens the URL in the web browser."""
     if self.url:
         webbrowser.open(self.url)
     else:
         functions.bell()()
コード例 #10
0
ファイル: main_frame.py プロジェクト: pool-prateek/gmp
 def __init__(self):
  """Create the window."""
  super(MainFrame, self).__init__(None, title = application.name)
  functions.frame = self # Save typing in the functions.
  self.current_pos = 0.0 # The position in the currently playing track for the Winamp-style control.
  self.duration = None # The duration of the track as a string.
  self.title = None # The title of the current track.
  self.add_to_playlist = None
  self._accelerator_table = [] # The raw accelerator table as a list. Add entries with add_accelerator.
  self.accelerator_table = {} # The human-readable accelerator table.
  self.frequency_up = lambda event: self.set_frequency(self.frequency.SetValue(min(100, self.frequency.GetValue() + 1)))
  self.frequency_down = lambda event: self.set_frequency(self.frequency.SetValue(max(0, self.frequency.GetValue() - 1)))
  self.pan_left = lambda event: self.set_pan(self.pan.SetValue(max(0, self.pan.GetValue() - 1)))
  self.pan_right = lambda event: self.set_pan(self.pan.SetValue(min(100, self.pan.GetValue() + 1)))
  self.hotkeys = {
   (0, ord('X')): lambda event: self.current_track.play(True) if self.current_track else functions.play_pause(),
   (0, ord('C')): functions.play_pause,
   (0, ord('Z')): functions.previous,
   (0, ord('B')): functions.next,
   (0, ord('V')): functions.stop,
   (0, ord(';')): functions.reset_fx,
   (0, wx.WXK_UP): functions.volume_up,
   (0, wx.WXK_DOWN): functions.volume_down,
   (0, wx.WXK_LEFT): functions.rewind,
   (0, wx.WXK_RIGHT): functions.fastforward,
   (0, ord('J')): self.pan_left,
   (0, ord('L')): self.pan_right,
   (0, ord('I')): self.frequency_up,
   (0, ord('K')): self.frequency_down,
   (0, ord('F')): functions.do_search_quick,
   (0, ord('G')): functions.do_search_again,
   (0, ord('8')): lambda event: Thread(target = functions.add_again_to_playlist, args = [event]).start(),
   (0, wx.WXK_RETURN): functions.focus_playing
  }
  self.http_server = None
  self.last_search = '' # Whatever the user last searched for.
  self.last_search_type = 0 # The type of the previous search.
  self.current_playlist = None # The current playlist
  self.current_station = None # The current radio station.
  self.current_library = [] # The user's library in it's current state.
  self.current_saved_result = None # The index of the currently focused daved result.
  self.saved_results_indices = {} # IDs of saved results.
  self._current_track = None # the meta data for the currently playing track.
  self.current_track = None
  self._queue = [] # The actual queue of tracks.
  self.track_history = [] # The play history.
  self.results_history_index = 0 # The index of the results history.
  self.bypass_history = False # Bypass the results history on the next insertion.
  p = wx.Panel(self)
  s = wx.BoxSizer(wx.VERTICAL)
  s1 = wx.BoxSizer(wx.HORIZONTAL)
  self.results = wx.ListBox(p, style = wx.LB_SINGLE)
  self.queue = wx.ListBox(p, style = wx.LB_SINGLE)
  self.results.SetFocus()
  self._results = [] # The raw json from Google.
  s1.Add(self.results, 7, wx.GROW)
  s1.Add(self.queue, 3, wx.GROW)
  s.Add(s1, 7, wx.GROW)
  bottom_sizer = wx.BoxSizer(wx.HORIZONTAL)
  bottom_left_sizer = wx.BoxSizer(wx.VERTICAL)
  s2 = wx.BoxSizer(wx.HORIZONTAL)
  s2.Add(wx.StaticText(p, label = '&Track Seek'), 0, wx.GROW)
  self.track_position = wx.Slider(p, name = 'Track Position')
  self.track_position.Bind(wx.EVT_SLIDER, functions.track_seek)
  s2.Add(self.track_position, 3, wx.GROW)
  self.previous = wx.Button(p, label = config.config.get('windows', 'previous_label'))
  self.Bind(wx.EVT_BUTTON, functions.previous)
  s2.Add(self.previous, 1, wx.GROW)
  self.play_pause = wx.Button(p, label = config.config.get('windows', 'play_label'))
  self.play_pause.Bind(wx.EVT_BUTTON, functions.play_pause)
  s2.Add(self.play_pause, 1, wx.GROW)
  self.next = wx.Button(p, label = config.config.get('windows', 'next_label'))
  self.next.Bind(wx.EVT_BUTTON, functions.next)
  s2.Add(self.next, 1, wx.GROW)
  s2.Add(wx.StaticText(p, label = config.config.get('windows', 'frequency_label')), 0, wx.GROW)
  self.frequency = wx.Slider(p, name = 'Track frequency', style = wx.SL_VERTICAL|wx.SL_INVERSE)
  self.frequency.Bind(wx.EVT_SLIDER, self.set_frequency)
  self.frequency.SetValue(config.config.get('sound', 'frequency'))
  s2.Add(self.frequency, 1, wx.GROW)
  self.s2 = s2
  bottom_left_sizer.Add(self.s2, 0, wx.GROW)
  s3 = wx.BoxSizer(wx.HORIZONTAL)
  s3.Add(wx.StaticText(p, label = config.config.get('windows', 'volume_label')), 0, wx.GROW)
  self.volume = wx.Slider(p, style = wx.SL_VERTICAL|wx.SL_INVERSE)
  self.volume.SetValue(config.config.get('sound', 'volume'))
  self.volume.Bind(wx.EVT_SLIDER, self.set_volume)
  s3.Add(self.volume, 1, wx.GROW)
  s3.Add(wx.StaticText(p, label = config.config.get('windows', 'pan_label')), 0, wx.GROW)
  self.pan = wx.Slider(p)
  self.pan.SetValue(config.config.get('sound', 'pan'))
  self.pan.Bind(wx.EVT_SLIDER, self.set_pan)
  s3.Add(self.pan, 1, wx.GROW)
  self.s3 = s3
  bottom_left_sizer.Add(self.s3, 0, wx.GROW)
  l = 'No song playing.'
  if application.platform == 'darwin':
   self.artist_bio = wx.StaticText(p, label = l)
   self.set_artist_bio = lambda value: self.artist_bio.SetLabel(value)
  else:
   self.artist_bio = wx.TextCtrl(p, style = wx.TE_MULTILINE|wx.TE_READONLY, value = l)
   self.set_artist_bio = lambda value: self.artist_bio.SetValue(value)
  bottom_left_sizer.Add(self.artist_bio, 1, wx.GROW)
  s4 = wx.BoxSizer(wx.HORIZONTAL)
  s4.Add(wx.StaticText(p, label = config.config.get('windows', 'now_playing_label')), 0, wx.GROW)
  self.hotkey_area = wx.TextCtrl(p)
  self.hotkey_area.Bind(wx.EVT_KEY_DOWN, self.hotkey_parser)
  s4.Add(self.hotkey_area, 1, wx.GROW)
  bottom_left_sizer.Add(s4, 0, wx.GROW)
  self._full_results = [] # The unadulterated results.
  s5 = wx.BoxSizer(wx.HORIZONTAL)
  s5.Add(wx.StaticText(p, label = '&Artists'), 0, wx.GROW)
  self.artists = wx.Choice(p, style = wx.CB_SORT)
  self.artists.Bind(wx.EVT_CHOICE, self.filter_results)
  s5.Add(self.artists, 1, wx.GROW)
  s5.Add(wx.StaticText(p, label = 'A&lbums'), 0, wx.GROW)
  self.albums = wx.Choice(p, style = wx.CB_SORT)
  self.albums.Bind(wx.EVT_CHOICE, self.filter_results)
  s5.Add(self.albums, 1, wx.GROW)
  bottom_left_sizer.Add(s5, 0, wx.GROW)
  bottom_sizer.Add(bottom_left_sizer, 1, wx.GROW)
  self.album_art = wx.StaticBitmap(p)
  self.album_art_filename= None # The path to the last album art.
  self.album_art.SetLabel('Album Art')
  bottom_sizer.Add(self.album_art, 1, wx.GROW)
  s.Add(bottom_sizer, 0, wx.GROW)
  p.SetSizerAndFit(s)
  self.panel = p
  self.main_sizer = s
  mb = wx.MenuBar()
  file_menu = wx.Menu()
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, 'n',
  lambda event: NewPlaylist().Show(True),
  '&New Playlist...',
  'Create a new playlist.'
  ))
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, 's',
  lambda event: self.add_saved_result(),
  '&Save Results...',
  'Save the current results to the saved results list.'
  ))
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL|wx.ACCEL_SHIFT, '/',
  lambda event: Thread(target = functions.results_to_library, args = [event]).start(),
  'Add Results To &Library',
  'Add all results currently showing to the library.'
  ))
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL|wx.ACCEL_SHIFT, 's',
  lambda event: Thread(target = functions.save_result).start(),
  'S&ave The Current Track...',
  'Save the currently selected track with a human-readable name.'
  ))
  station_menu = wx.Menu()
  station_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '9',
  lambda event: Thread(target = functions.station_from_result, args = [event]).start(),
  'Create Station From Current &Result...',
  'Creates a radio station from the currently focused result.'
  ))
  station_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_ALT, '4',
  lambda event: Thread(target = functions.station_from_artist, args = [event]).start(),
  'Create Station From Current &Artist',
  'Create a radio station based on the currently focused artist.'
  ))
  station_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_ALT, '5',
  lambda event: Thread(target = functions.station_from_album, args = [event]).start(),
  'Create Station From Current A&lbum',
  'Create a radio station based on the currently focused album.'
  ))
  station_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_ALT, '6',
  lambda event: Thread(target = functions.station_from_genre, args = [event]).start(),
  'Create Station From &Genre',
  'Create a radio station based on a particular genre.'
  ))
  file_menu.AppendMenu(wx.ID_ANY, 'Create &Station', station_menu, 'Create radio stations from various sources')
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '8',
  lambda event: Thread(target = functions.add_to_playlist, args = [event]).start(),
  'Add Current Result To &Playlist...',
  'Add the current result to one of your playlists.'
  ))
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL|wx.ACCEL_SHIFT, '8',
  lambda event: Thread(target = functions.results_to_playlist, args = [event]).start(),
  'Add all &results to a playlist',
  'Add the current results set in it\'s entirety to one of your playlists.'
  ))
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_NORMAL, wx.WXK_DELETE,
  functions.delete,
  '&Delete',
  'Removes an item from the play queue if selected, the library or the currently focused playlist.'
  ))
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_NORMAL, wx.WXK_F2,
  lambda event: NewPlaylist(self.current_playlist).Show() if self.current_playlist else functions.bell()(),
  '&Edit Current Playlist...',
  'Edit the properties of the currently focused playlist.'
  ))
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, wx.WXK_DELETE,
  functions.delete_thing,
  '&Delete Currently focused thing'
  ))
  file_menu.AppendSeparator()
  self.Bind(
  wx.EVT_MENU,
  functions.reveal_media,
  file_menu.Append(
  wx.ID_ANY,
  '&Reveal Media Directory',
  'Open the media directory in %s' % ('Finder' if sys.platform == 'darwin' else 'Windows Explorer')
  ))
  file_menu.AppendSeparator()
  file_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, 'q',
  lambda event: self.Close(True),
  'E&xit',
  'Quit the program.',
  id = wx.ID_EXIT
  ))
  mb.Append(file_menu, '&File')
  edit_menu = wx.Menu()
  edit_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, 'f',
  functions.do_search_quick,
  '&Quick Find...',
  'Search the Google Music catalog for songs.'
  ))
  edit_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL|wx.ACCEL_SHIFT, 'f',
  functions.do_search,
  '&Advanced Find...',
  'Search the Google Music catalog.'
  ))
  edit_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, 'g',
  functions.do_search_again,
  'Find &Again',
  'Repeat the previous search.'
  ))
  edit_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '/',
  lambda event: Thread(target = functions.add_to_library, args = [event]).start(),
  '&Add To Library',
  'Add the current song to the library.'
  ))
  mb.Append(edit_menu, '&Edit')
  view_menu = wx.Menu()
  view_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_ALT, wx.WXK_RETURN,
  functions.focus_playing,
  '&Focus Current',
  'Focus the currently playing track.'
  ))
  view_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL|wx.ACCEL_SHIFT, 'l',
  functions.get_lyrics,
  'View &Lyrics',
  'View lyrics for the currently selected result.'
  ))
  self.play_controls_check = view_menu.AppendCheckItem(
  wx.ID_ANY,
  '&Show / Hide Player Controls',
  'Show and hide the track seek and playback controls.'
  )
  self.play_controls_func(config.config.get('windows', 'play_controls_show'))
  self.Bind(
  wx.EVT_MENU,
  lambda event: self.play_controls_func(event.GetSelection()),
  self.play_controls_check
  )
  mb.Append(view_menu, '&View')
  source_menu = wx.Menu()
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, 'l',
  lambda event: Thread(target = self.init_results, args = [event]).start(),
  '&Library',
  'Return to the library.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '1',
  lambda event: Thread(target = functions.select_playlist, args = [event]).start(),
  'Select &Playlist...',
  'Select a playlist.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_SHIFT, wx.WXK_RETURN,
  lambda event: Thread(target = functions.add_again_to_playlist, args = [event]).start(),
  'Add A&gain To The Previously Selected Playlist',
  'Adds the current result to the playlist which items were last added too.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '2',
  lambda event: Thread(target = functions.select_station, args = [event]).start(),
  'Select &Station...',
  'Select a radio station.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, ';',
  lambda event: Thread(target = functions.top_tracks, kwargs = {'interactive': True}).start(),
  'Artist &Top Tracks',
  'Get the top tracks for the artist of the currently selected song.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '3',
  lambda event: Thread(target = functions.promoted_songs, args = [event]).start(),
  '&Promoted Songs',
  'Get a list of promoted tracks.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '4',
  lambda event: Thread(target = functions.artist_tracks, args = [event]).start(),
  'Go To Current &Artist',
  'Get a list of all tracks by the artist of the currently selected song.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '5',
  lambda event: Thread(target = functions.current_album, args = [event]).start(),
  'Go To Current A&lbum',
  'Go to the current album.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '6',
  lambda event: Thread(target = functions.artist_album, args = [event]).start(),
  'Select Al&bum...',
  'Go to a particular album.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '7',
  lambda event: Thread(target = functions.related_artists, args = [event]).start(),
  'Select &Related Artist...',
  'Select a related artist to view tracks.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '0',
  lambda event: Thread(target = functions.all_playlist_tracks, args = [event]).start(),
  'Loa&d All Playlist Tracks',
  'Load every item from every playlist into the results table.'
  ))
  source_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, 'U',
  functions.load_url,
  '&URL...',
  'Load and play a URL'
  ))
  mb.Append(source_menu, '&Source')
  track_menu = wx.Menu()
  track_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, wx.WXK_RETURN,
  lambda event: Thread(target = functions.queue_result, args = [event]).start(),
  '&Queue Item',
  'Add the currently selected item to the play queue.'
  ))
  self.Bind(wx.EVT_MENU, lambda event: self.add_results(functions.reverse_results(self.get_results()), clear = True), track_menu.Append(wx.ID_ANY, '&Reverse Results', 'Reverse the list of results.'))
  mb.Append(track_menu, '&Track')
  play_menu = wx.Menu()
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_NORMAL, wx.WXK_RETURN,
  self.select_item,
  '&Select Current Item',
  'Selects the current item.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_NORMAL, ' ',
  functions.play_pause,
  '&Play or Pause',
  'Play or pause the currently playing song.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, wx.WXK_UP,
  lambda event: Thread(target = functions.volume_up, args = [event]).start(),
  'Volume &Up',
  'Increase the Volume.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, wx.WXK_DOWN,
  lambda event: Thread(target = functions.volume_down, args = [event]).start(),
  'Volume &Down',
  'Decrease the volume.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, wx.WXK_LEFT,
  lambda event: event.Skip() if self.artist_bio.HasFocus() else Thread(target = functions.previous, args = [event]).start(),
  '&Previous',
  'Play the previous track.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, wx.WXK_RIGHT,
  lambda event: event.Skip() if self.artist_bio.HasFocus() else Thread(target = functions.next, args = [event]).start(),
  '&Next',
  'Play the next track.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '.',
  functions.stop,
  '&Stop',
  'Stop the currently playing song.'
  ))
  self.stop_after = play_menu.AppendCheckItem(
  *self.add_accelerator(
  wx.ACCEL_CTRL|wx.ACCEL_SHIFT, '.',
  lambda event: self.toggle(self.stop_after, ['sound', 'stop_after'], 'Stop after current track'),
  'Stop &After',
  'Stop after the currently playing track has finished playing.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_SHIFT, wx.WXK_LEFT,
  lambda event: Thread(target = functions.rewind, args = [event]).start(),
  '&Rewind',
  'Rewind.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_SHIFT, wx.WXK_RIGHT,
  lambda event: Thread(target = functions.fastforward, args = [event]).start(),
  '&Fastforward',
  'Fastforward.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, 'h',
  lambda event: self.add_results(functions.shuffle(self.get_results()), True, playlist = self.current_playlist, station = self.current_station, library = self.current_library),
  'Shuffle &Results',
  'Shuffle the currently shown results.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL|wx.ACCEL_SHIFT, 'h',
  lambda event: self.queue_tracks(functions.shuffle(self.get_queue()), True),
  'Shuffle &Queue',
  'Shuffle the play queue.'
  ))
  repeat_menu = wx.Menu()
  self.repeat = repeat_menu.AppendCheckItem(
  *self.add_accelerator(
  wx.ACCEL_CTRL, 'r',
  lambda event: self.toggle(self.repeat, ['sound', 'repeat'], 'Repeat all'),
  '&Repeat',
  'Repeat tracks.'
  ))
  self.repeat.Check(config.config.get('sound', 'repeat'))
  self.repeat_track = repeat_menu.AppendCheckItem(
  *self.add_accelerator(
  wx.ACCEL_CTRL|wx.ACCEL_SHIFT, 'r',
  lambda event: self.toggle(self.repeat_track, ['sound', 'repeat_track'], 'Repeat current track'),
  'Repeat &Track',
  'Repeat the current track.'
  ))
  self.repeat_track.Check(config.config.get('sound', 'repeat_track'))
  play_menu.AppendMenu(wx.ID_ANY, '&Repeat', repeat_menu, 'Repeat options.')
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_SHIFT, wx.WXK_UP,
  self.frequency_up,
  'Frequency &Up',
  'Shift the frequency up a little.'
  ))
  play_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_SHIFT, wx.WXK_DOWN,
  self.frequency_down,
  'Frequency &Down',
  'Shift the frequency down a little.'
  ))
  mb.Append(play_menu, '&Play')
  self.history_menu = wx.Menu()
  self.history_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '[',
  functions.results_history_back,
  '&Back',
  'Moves back through the results history.'
  ))
  self.history_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, ']',
  functions.results_history_forward,
  '&Forward',
  'Move forward through the results history.'
  ))
  mb.Append(self.history_menu, '&History')
  options_menu = wx.Menu()
  options_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, ',',
  lambda event: config.config.get_gui().Show(True),
  '&Preferences',
  'Configure the program.',
  id = wx.ID_PREFERENCES
  ))
  options_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_CTRL, '\\',
  functions.reset_fx,
  '&Reset FX',
  'Reset pan and frequency.'
  ))
  options_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_NORMAL, wx.WXK_F12,
  lambda event: Thread(target = functions.select_output, args = [event]).start(),
  '&Select sound output...',
  'Select a new output device for sound playback.'
  ))
  mb.Append(options_menu, '&Options')
  help_menu = wx.Menu()
  help_menu.Append(
  *self.add_accelerator(
  wx.ACCEL_NORMAL, wx.WXK_F1,
  lambda event: wx.AboutBox(application.info),
  '&About...',
  'About the program.',
  id = wx.ID_ABOUT
  ))
  self.Bind(
  wx.EVT_MENU,
  lambda event: UpdateFrame().Show(True),
  help_menu.Append(
  wx.ID_ANY,
  'Check For &Updates',
  'Check for updates to the program.'
  ))
  mb.Append(help_menu, '&Help')
  self.SetMenuBar(mb)
  self.timer = wx.Timer(self)
  self.Bind(wx.EVT_TIMER, self.track_thread, source = self.timer)
  self.timer.Start(100)
  self.Maximize()
  self.Raise()
  self.Bind(wx.EVT_CLOSE, self.do_close)
コード例 #11
0
ファイル: gui.py プロジェクト: chrisnorman7/mmc2
 def __init__(self):
  application.frame = self
  self.last_review = [0.0, None, None]
  super(MainFrame, self).__init__(None, title = application.name)
  self._review = 0 # The current position of the review cursor.
  self.commands = [] # Command history.
  self._command_pos = 0 # The current position in the command history.
  p = wx.Panel(self)
  self.CreateStatusBar()
  self.SetStatusText('Not connected.')
  s = wx.BoxSizer(wx.VERTICAL)
  self.output = MyTextCtrl(p, style = wx.TE_READONLY | wx.TE_MULTILINE)
  s.Add(self.output, 1, wx.GROW)
  s1 = wx.BoxSizer(wx.HORIZONTAL)
  self.prompt = wx.StaticText(p, label = '&Entry')
  s1.Add(self.prompt, 0, wx.GROW)
  self.entry = wx.TextCtrl(p, style = wx.TE_RICH2)
  self.entry.SetFocus()
  s1.Add(self.entry, 1, wx.GROW)
  s.Add(s1, 0, wx.GROW)
  p.SetSizerAndFit(s)
  keys.add_accelerator(self.entry, 'RETURN', self.do_send)
  keys.add_accelerator(self.entry, 'ESCAPE', lambda event: self.do_clear(save = True))
  keys.add_accelerator(self.entry, 'UP', lambda event: self.do_command_history(self._command_pos - 1)) # Commands are entered using append.
  keys.add_accelerator(self.entry, 'DOWN', lambda event: self.do_command_history(self._command_pos + 1))
  keys.add_accelerator(self.entry, 'CTRL+HOME', lambda event: self.do_command_history(-1))
  keys.add_accelerator(self.entry, 'CTRL+END', lambda event: self.do_command_history(0))
  keys.add_accelerator(self.entry, 'SHIFT+RETURN', lambda event: self.do_send(event, clear = False))
  keys.add_accelerator(self.entry, 'CTRL+RETURN', lambda event: functions.send(self.commands[0]) if self.commands else functions.bell())
  for x in xrange(10):
   keys.add_accelerator(self, 'ALT+%s' % x, lambda event, i = x: self.do_review(-10 if not i else (i * -1), move = False))
   keys.add_accelerator(self, 'ALT+%s' % x, lambda event, i = x: self.output.SpeakLineText(10 if not i else i))
  keys.add_accelerator(self, 'CTRL+SHIFT+Y', lambda event: self.do_review(0))
  keys.add_accelerator(self, 'CTRL+SHIFT+P', lambda event: self.do_review(-1))
  keys.add_accelerator(self, 'CTRL+SHIFT+U', lambda event: self.do_review(max(self._review - 1, 0)))
  keys.add_accelerator(self, 'CTRL+SHIFT+I', lambda event: self.do_review(self._review))
  keys.add_accelerator(self, 'CTRL+SHIFT+O', lambda event: self.do_review(self._review + 1))
  functions.output('Welcome to %s (V%s).\nType %scommands() for help with builtin functions.' % (application.name, application.version, application.config.get('application', 'command_char')))
  mb = wx.MenuBar()
  self.file_menu = wx.Menu()
  self.Bind(wx.EVT_MENU, self.do_load, self.file_menu.Append(wx.ID_ANY, '&Load Script...', 'Load a script.'))
  self.Bind(wx.EVT_MENU, lambda event: application.config.get_gui().Show(True), self.file_menu.Append(wx.ID_PREFERENCES, '&Preferences...', 'Change program configuration.'))
  self.Bind(wx.EVT_MENU, lambda event: functions.quit(), self.file_menu.Append(wx.ID_EXIT, '&Quit', 'Quit the program.'))
  mb.Append(self.file_menu, '&File')
  self.connect_menu = wx.Menu()
  self.Bind(wx.EVT_MENU, lambda event: do_connect(), self.connect_menu.Append(wx.ID_ANY, '&Connect...', 'Create a new connection.'))
  self.Bind(wx.EVT_MENU, lambda event: functions.disconnect(), self.connect_menu.Append(wx.ID_ANY, '&Disconnect', 'Disconnect from the MUD.'))
  mb.Append(self.connect_menu, '&Connect')
  self.SetMenuBar(mb)
  self.Bind(wx.EVT_CLOSE, self.on_close)