From: stephendenham Date: Mon, 20 Dec 2010 14:31:13 +0000 (+0000) Subject: Slight performance improvement. Playlists bug fix. X-Git-Url: https://git.hcoop.net/clinton/xbmc-groove.git/commitdiff_plain/aa0c1263c8a5bc58cfb233356e2338bf2649fd9c Slight performance improvement. Playlists bug fix. git-svn-id: svn://svn.code.sf.net/p/xbmc-groove/code@18 2dec19e3-eb1d-4749-8193-008c8bba0994 --- diff --git a/default.py b/default.py index 8b6cf1a..695ce9c 100644 --- a/default.py +++ b/default.py @@ -1,4 +1,4 @@ -import urllib, urllib2, re, xbmcplugin, xbmcgui, xbmc, sys, os, time, pprint, shutil, xbmcaddon, pprint +import urllib, urllib2, re, xbmcplugin, xbmcgui, xbmc, sys, os, time, shutil, xbmcaddon MODE_SEARCH_SONGS = 1 MODE_SEARCH_ALBUMS = 2 @@ -52,9 +52,8 @@ class _Info: class GroovesharkPlaylistSelect(xbmcgui.WindowDialog): def __init__(self, items=[]): - w = int(self.getWidth()*0.5) gap = int(self.getHeight()/100) - titleH = 30 + w = int(self.getWidth()*0.5) h = self.getHeight()-30*gap rw = self.getWidth() rh = self.getHeight() @@ -63,11 +62,8 @@ class GroovesharkPlaylistSelect(xbmcgui.WindowDialog): self.imgBg = xbmcgui.ControlImage(x+gap, 5*gap+y, w-2*gap, h-5*gap, listBackground) self.addControl(self.imgBg) - - self.title = xbmcgui.ControlLabel(x, 5*gap+y, w, titleH, 'GROOVESHARK - PLAYLISTS', textColor='0xFFFFFFFF', alignment=2) - self.addControl(self.title) - - self.playlistControl = xbmcgui.ControlList(2*gap+x, titleH+y+3*gap, w-4*gap, h-10*gap, textColor='0xFFFFFFFF', selectedColor='0xFFFF4242') + + self.playlistControl = xbmcgui.ControlList(2*gap+x, y+3*gap+30, w-4*gap, h-10*gap, textColor='0xFFFFFFFF', selectedColor='0xFFFF4242', itemTextYOffset=0, itemHeight=30, alignmentY = 0) self.addControl(self.playlistControl) self.lastPos = 0 @@ -79,6 +75,7 @@ class GroovesharkPlaylistSelect(xbmcgui.WindowDialog): listitems.append(xbmcgui.ListItem('New...')) self.playlistControl.addItems(listitems) self.setFocus(self.playlistControl) + self.playlistControl.selectItem(0) item = self.playlistControl.getListItem(self.lastPos) item.select(True) @@ -98,20 +95,19 @@ class GroovesharkPlaylistSelect(xbmcgui.WindowDialog): self.lastPos = pos self.isSelecting = False + # Control + def onControl(self, control): + if control == self.playlistControl: + self.selected = self.playlistControl.getSelectedPosition() + self.close() + def onAction(self, action): - try: - if action == ACTION_MOVE_LEFT: - self.selected = self.playlistControl.getSelectedPosition() - self.close() - elif action == ACTION_PREVIOUS_MENU: - self.selected = -1 - self.close() - elif action == ACTION_MOVE_UP or action == ACTION_MOVE_DOWN or action == ACTION_PAGE_UP or action == ACTION_PAGE_DOWN == 6: - self.setFocus(self.playlistControl) - self.setHighlight() - except: - xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Press left arrow to make selection, 1000, ' + thumbDef + ')') - pass + if action == ACTION_PREVIOUS_MENU: + self.selected = -1 + self.close() + elif action == ACTION_MOVE_UP or action == ACTION_MOVE_DOWN or action == ACTION_PAGE_UP or action == ACTION_PAGE_DOWN == 6: + self.setFocus(self.playlistControl) + self.setHighlight() class Groveshark: @@ -262,12 +258,12 @@ class Groveshark: if (userid != 0): xbmc.log("Unfavorite song: " + str(songid) + ', previous mode was ' + str(prevMode)) groovesharkApi.unfavoriteSong(songID = songid) - xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from favorites, 1000, ' + thumbDef + ')') + xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Removed from Grooveshark favorites, 1000, ' + thumbDef + ')') if (int(prevMode) == MODE_FAVORITES): xbmc.executebuiltin("Container.Update(" + favoritesUrl + ")") else: dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to remove favorites.') + dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to remove Grooveshark favorites.') def frown(self, songid): userid = self._get_login() @@ -279,7 +275,7 @@ class Groveshark: xbmc.executebuiltin('XBMC.Notification(Grooveshark XBMC, Frowned, 1000, ' + thumbDef + ')') else: dialog = xbmcgui.Dialog() - dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to frown a song.') + dialog.ok('Grooveshark XBMC', 'You must be logged in', 'to frown a Grooveshark song.') def similarArtists(self, artistId): similar = groovesharkApi.artistGetSimilar(artistId, limit = self.artistsearchlimit) @@ -381,7 +377,7 @@ class Groveshark: def renamePlaylist(self, playlistid, name): userid = self._get_login() if (userid != 0): - newname = self._get_keyboard(default=name, heading="Playlist name") + newname = self._get_keyboard(default=name, heading="Grooveshark playlist name") if newname == '': return elif groovesharkApi.playlistRename(playlistid, newname) == 0: @@ -485,6 +481,7 @@ class Groveshark: def _add_songs_directory(self, songs, playlistid=0, playlistname='', isFavorites=False): n = len(songs) xbmc.log("Found " + str(n) + " songs...") + dirItems = [] i = 0 while i < n: song = songs[i] @@ -515,13 +512,19 @@ class Groveshark: menuItems.append(("Not Grooveshark favorite", "XBMC.RunPlugin("+unfav+")")) if playlistid > 0: rmplaylstsong=sys.argv[0]+"?playlistid="+str(playlistid)+"&id="+str(i+1)+"&mode="+str(MODE_REMOVE_PLAYLIST_SONG)+"&name="+playlistname - menuItems.append(("Remove from playlist", "XBMC.RunPlugin("+rmplaylstsong+")")) + menuItems.append(("Remove from Grooveshark playlist", "XBMC.RunPlugin("+rmplaylstsong+")")) else: addplaylstsong=sys.argv[0]+"?id="+str(songid)+"&mode="+str(MODE_ADD_PLAYLIST_SONG) menuItems.append(("Add to Grooveshark playlist", "XBMC.RunPlugin("+addplaylstsong+")")) item.addContextMenuItems(menuItems, replaceItems=False) - xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=False,totalItems=n) + dirItem = (u, item, False) + dirItems.append(dirItem) + if i % 5 == 0: + xbmcplugin.addDirectoryItems(int(sys.argv[1]), dirItems ,n) + dirItems = [] i = i + 1 + + xbmcplugin.addDirectoryItems(int(sys.argv[1]), dirItems ,n) xbmcplugin.setContent(self._handle, 'songs') xbmcplugin.setPluginFanart(int(sys.argv[1]), self.fanImg) @@ -581,9 +584,9 @@ class Groveshark: menuItems.append(("Make Grooveshark playlist", "XBMC.RunPlugin("+mkplaylst+")")) if mode == MODE_PLAYLIST: rmplaylst=sys.argv[0]+"?mode="+str(MODE_REMOVE_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id) - menuItems.append(("Delete playlist", "XBMC.RunPlugin("+rmplaylst+")")) + menuItems.append(("Delete Grooveshark playlist", "XBMC.RunPlugin("+rmplaylst+")")) mvplaylst=sys.argv[0]+"?mode="+str(MODE_RENAME_PLAYLIST)+"&name="+urllib.quote_plus(name)+"&id="+str(id) - menuItems.append(("Rename playlist", "XBMC.RunPlugin("+mvplaylst+")")) + menuItems.append(("Rename Grooveshark playlist", "XBMC.RunPlugin("+mvplaylst+")")) dir.addContextMenuItems(menuItems, replaceItems=False) return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=dir,isFolder=True, totalItems=items) diff --git a/resources/img/popularSongs.png b/resources/img/popularSongs.png dissimilarity index 99% index e2c18f3..1556a52 100644 Binary files a/resources/img/popularSongs.png and b/resources/img/popularSongs.png differ