def body1(): allTags = db.getAllTags() songTags = song.tags boolDict = {} for tag in allTags: if tag in songTags: boolDict[tag.name] = True else: boolDict[tag.name] = False app.properties('song tag selection', value=boolDict) def editTagPress(button): if button == 'submit': result = app.getProperties('song tag selection') newTags = [] for tag in result: if result[tag] is True: newTags.append(db.getTag(tag)) db.setSongTags(song, newTags) app.destroySubWindow('edit tags window') app.addButton('submit', editTagPress)
def updateTagTable(): tags = db.getAllTags() tableArr = [[tag.name] for tag in tags] tableArr.sort() app.replaceAllTableRows('tag table', tableArr)
def formContents(): allTags = db.getAllTags() includedTags = [] excludedTags = [] if playlist is not None: includedTags = playlist.includedTags excludedTags = playlist.excludedTags includedTagDict = {} excludedTagDict = {} # both going to be {tagname => boolean, ...} for tag in allTags: includedTagDict[tag.name] = tag in includedTags excludedTagDict[tag.name] = tag in excludedTags if playlist is None: app.addLabel('playlist name:') app.entry('name') app.properties('included tags', includedTagDict) app.properties('excluded tags', excludedTagDict) app.addLabel('minimum and maximum bangericity:') app.addNumericEntry('minimum bangericity') app.addNumericEntry('maximum bangericity') min = 0 max = 100 if playlist is not None: min = playlist.minBangericity max = playlist.maxBangericity app.setEntry('minimum bangericity', min) app.setEntry('maximum bangericity', max) app.addCheckBox('use AND logic on includes') ticked = True if playlist is not None: ticked = playlist.andLogic app.setCheckBox('use AND logic on includes', ticked=ticked) def submit(button): if button == 'submit': # bangericity minBangericity = float(app.getEntry('minimum bangericity')) maxBangericity = float(app.getEntry('maximum bangericity')) # validate bangericities if not minBangericity < maxBangericity: app.errorBox( 'invalid bangericities', 'minimum bangericity\ must be less than maximum bangericity') return None # include logic andLogic = app.getCheckBox('use AND logic on includes') # tags newIncludedTags = [] newExcludedTags = [] includedTagDict = app.getProperties('included tags') excludedTagDict = app.getProperties('excluded tags') ##### left off here investigating bug where you can't edit then add # also label entries # figure out what the new tags will be for tag in includedTagDict: if includedTagDict[tag] is True: newIncludedTags.append(db.getTag(tag)) if excludedTagDict[tag] is True: newExcludedTags.append(db.getTag(tag)) # name if playlist is None: name = app.getEntry('name') # validate name if name == '': app.errorBox('invalid name', 'playlist must have a name') return None existingPlaylistNames = [ playlist.name for playlist in db.getAllPlaylists() ] if name in existingPlaylistNames: app.errorBox( 'duplicate name', 'a playlist with that\ name already exists') return None # create playlist db.addPlaylist(name, newIncludedTags, newExcludedTags, minBangericity, maxBangericity, andLogic) showPlaylistSongs(name) updatePlaylistTable() app.destroySubWindow(title) else: # edit playlist playlist.includedTags = newIncludedTags playlist.excludedTags = newExcludedTags playlist.minBangericity = minBangericity playlist.maxBangericity = maxBangericity playlist.andLogic = andLogic showPlaylistSongs(playlist) updatePlaylistTable() app.destroySubWindow(title) app.addButton('submit', submit)
app.addTable('song table', [['Name', 'Bangericity']] + tableArr, colspan=3, addRow=addSong, showMenu=True, action=songAction) with app.tab('playlists'): playlists = db.getAllPlaylists() tableArr = [[playlist.name] for playlist in playlists] tableArr.sort() app.addTable('playlist table', [['Name']] + tableArr, colspan=3, showMenu=True, action=playlistAction, addRow=playlistForm) with app.tab('tags'): tags = db.getAllTags() tableArr = [[tag.name] for tag in tags] tableArr.sort() app.addTable('tag table', [['Name']] + tableArr, colspan=3, showMenu=True, action=tagAction, addRow=addTag) def updateSongTable(): songs = db.getAllSongs() tableArr = [[song.name, song.bangericity] for song in songs] tableArr.sort() app.replaceAllTableRows('song table', tableArr)