def InitObjectListView(self): groupImage = self.myOlv.AddImages(ExampleImages.getGroup16Bitmap(), ExampleImages.getGroup32Bitmap()) userImage = self.myOlv.AddImages(ExampleImages.getUser16Bitmap(), ExampleImages.getUser32Bitmap()) musicImage = self.myOlv.AddImages(ExampleImages.getMusic16Bitmap(), ExampleImages.getMusic32Bitmap()) soloArtists = ["Nelly Furtado", "Missy Higgins", "Moby", "Natalie Imbruglia", "Dido", "Paul Simon", "Bruce Cockburn"] def artistImageGetter(track): if track.artist in soloArtists: return userImage else: return groupImage def sizeToNiceString(byteCount): """ Convert the given byteCount into a string like: 9.9bytes/KB/MB/GB """ for (cutoff, label) in [(1024*1024*1024, "GB"), (1024*1024, "MB"), (1024, "KB")]: if byteCount >= cutoff: return "%.1f %s" % (byteCount * 1.0 / cutoff, label) if byteCount == 1: return "1 byte" else: return "%d bytes" % byteCount self.myOlv.SetColumns([ ColumnDefn("Title", "left", 120, "title", imageGetter=musicImage), ColumnDefn("Artist", "left", 120, "artist", imageGetter=artistImageGetter), ColumnDefn("Size", "center", 100, "sizeInBytes", stringConverter=sizeToNiceString), ColumnDefn("Last Played", "left", 100, "lastPlayed", stringConverter="%d-%m-%Y"), ColumnDefn("Rating", "center", 100, "rating") ]) self.myOlv.SetObjects(self.songs)
def InitObjectListView(self): groupImage = self.myOlv.AddImages(ExampleImages.getGroup16Bitmap(), ExampleImages.getGroup32Bitmap()) userImage = self.myOlv.AddImages(ExampleImages.getUser16Bitmap(), ExampleImages.getUser32Bitmap()) musicImage = self.myOlv.AddImages(ExampleImages.getMusic16Bitmap(), ExampleImages.getMusic32Bitmap()) soloArtists = [ "Nelly Furtado", "Missy Higgins", "Moby", "Natalie Imbruglia" ] def artistImageGetter(track): if track["artist"] in soloArtists: return userImage else: return groupImage self.myOlv.SetColumns([ ColumnDefn("Title", "left", -1, "title", imageGetter=musicImage), ColumnDefn("Artist", "left", -1, "artist", imageGetter=artistImageGetter), ColumnDefn("Album", "center", -1, "album") ]) self.myOlv.SetObjects(self.listOfDictionaries)
def InitObjectListView(self): groupImage = self.myOlv.AddImages(ExampleImages.getGroup16Bitmap(), ExampleImages.getGroup32Bitmap()) userImage = self.myOlv.AddImages(ExampleImages.getUser16Bitmap(), ExampleImages.getUser32Bitmap()) musicImage = self.myOlv.AddImages(ExampleImages.getMusic16Bitmap(), ExampleImages.getMusic32Bitmap()) soloArtists = ["Nelly Furtado", "Missy Higgins", "Moby", "Natalie Imbruglia", "Dido", "Paul Simon", "Bruce Cockburn"] def artistImageGetter(track): if track.artist in soloArtists: return userImage else: return groupImage def sizeToNiceString(byteCount): """ Convert the given byteCount into a string like: 9.9bytes/KB/MB/GB """ for (cutoff, label) in [(1024*1024*1024, "GB"), (1024*1024, "MB"), (1024, "KB")]: if byteCount >= cutoff: return "%.1f %s" % (byteCount * 1.0 / cutoff, label) if byteCount == 1: return "1 byte" else: return "%d bytes" % byteCount def lastPlayedGroupKey(track): """ Return the grouping key for the given track when group by last played column """ # We only want to group tracks by the month in which they were played return datetime.date(track.lastPlayed.year, track.lastPlayed.month, 1) def lastPlayedGroupKeyConverter(groupKey): # Convert the given group key (which is a date) into a representation string return groupKey.strftime("%B %Y") self.myOlv.useExpansionColumn = True self.myOlv.SetColumns([ ColumnDefn("Title", "left", 120, "title", imageGetter=musicImage, useInitialLetterForGroupKey=True), ColumnDefn("Artist", "left", 120, "artist", imageGetter=artistImageGetter), ColumnDefn("Size", "center", 100, "sizeInBytes", stringConverter=sizeToNiceString), ColumnDefn("Last Played", "left", 100, "lastPlayed", groupKeyGetter=lastPlayedGroupKey, groupKeyConverter=lastPlayedGroupKeyConverter), ColumnDefn("Rating", "center", 100, "rating") ]) #self.myOlv.CreateCheckStateColumn() self.myOlv.SetSortColumn(self.myOlv.columns[2]) self.myOlv.SetObjects(self.songs)
def InitObjectListView(self): groupImage = self.myOlv.AddImages(ExampleImages.getGroup16Bitmap(), ExampleImages.getGroup32Bitmap()) musicImage = self.myOlv.AddImages(ExampleImages.getMusic16Bitmap(), ExampleImages.getMusic32Bitmap()) userImage = self.myOlv.AddImages(ExampleImages.getUser16Bitmap(), ExampleImages.getUser32Bitmap()) soloArtists = [ "Nelly Furtado", "Missy Higgins", "Moby", "Natalie Imbruglia" ] def artistImageGetter(track): if track["artist"] in soloArtists: return userImage else: return groupImage self.myOlv.SetColumns([ ColumnDefn("Title", "left", 150, "title", imageGetter=musicImage), ColumnDefn("Artist", "left", 150, "artist", imageGetter=artistImageGetter), ColumnDefn("Album", "center", 150, "album") ]) # Fetch rows from the database when required # In a real app, this would cache a certain number of rows def fetchFromDatabase(rowIndex): cur = self.connection.cursor() if len(self.reorderList): rowIndex = self.reorderList[rowIndex] cur.execute(self.SELECT_ONE_STMT, (rowIndex, )) return cur.fetchone() self.myOlv.SetObjectGetter(fetchFromDatabase) # We want to receive sort events for the virtual list self.myOlv.EnableSorting() self.myOlv.Bind(EVT_SORT, self.HandleSort) # Let the user know that we are building the database self.myOlv.SetEmptyListMsg("Building database...") self.myOlv.SetItemCount(0)
def InitObjectListView(self): groupImage = self.myOlv.AddImages(ExampleImages.getGroup16Bitmap(), ExampleImages.getGroup32Bitmap()) userImage = self.myOlv.AddImages(ExampleImages.getUser16Bitmap(), ExampleImages.getUser32Bitmap()) musicImage = self.myOlv.AddImages(ExampleImages.getMusic16Bitmap(), ExampleImages.getMusic32Bitmap()) soloArtists = ["Nelly Furtado", "Missy Higgins", "Moby", "Natalie Imbruglia"] def artistImageGetter(track): if track["artist"] in soloArtists: return userImage else: return groupImage self.myOlv.SetColumns([ ColumnDefn("Title", "left", -1, "title", imageGetter=musicImage), ColumnDefn("Artist", "left", -1, "artist", imageGetter=artistImageGetter), ColumnDefn("Album", "center", -1, "album") ]) self.myOlv.SetObjects(self.listOfDictionaries)
def InitObjectListView(self): groupImage = self.myOlv.AddImages(ExampleImages.getGroup16Bitmap(), ExampleImages.getGroup32Bitmap()) musicImage = self.myOlv.AddImages(ExampleImages.getMusic16Bitmap(), ExampleImages.getMusic32Bitmap()) userImage = self.myOlv.AddImages(ExampleImages.getUser16Bitmap(), ExampleImages.getUser32Bitmap()) soloArtists = ["Nelly Furtado", "Missy Higgins", "Moby", "Natalie Imbruglia"] def artistImageGetter(track): if track["artist"] in soloArtists: return userImage else: return groupImage self.myOlv.SetColumns([ ColumnDefn("Title", "left", 150, "title", imageGetter=musicImage), ColumnDefn("Artist", "left", 150, "artist", imageGetter=artistImageGetter), ColumnDefn("Album", "center", 150, "album") ]) # Fetch rows from the database when required # In a real app, this would cache a certain number of rows def fetchFromDatabase(rowIndex): cur = self.connection.cursor() if len(self.reorderList): rowIndex = self.reorderList[rowIndex] cur.execute(self.SELECT_ONE_STMT, (rowIndex,)) return cur.fetchone() self.myOlv.SetObjectGetter(fetchFromDatabase) # We want to receive sort events for the virtual list self.myOlv.EnableSorting() self.myOlv.Bind(EVT_SORT, self.HandleSort) # Let the user know that we are building the database self.myOlv.SetEmptyListMsg("Building database...") self.myOlv.SetItemCount(0)
def InitObjectListView(self): groupImage = self.myOlv.AddImages(ExampleImages.getGroup16Bitmap(), ExampleImages.getGroup32Bitmap()) userImage = self.myOlv.AddImages(ExampleImages.getUser16Bitmap(), ExampleImages.getUser32Bitmap()) musicImage = self.myOlv.AddImages(ExampleImages.getMusic16Bitmap(), ExampleImages.getMusic32Bitmap()) soloArtists = [ "Nelly Furtado", "Missy Higgins", "Moby", "Natalie Imbruglia", "Dido", "Paul Simon", "Bruce Cockburn" ] def artistImageGetter(track): if track.artist in soloArtists: return userImage else: return groupImage def sizeToNiceString(byteCount): """ Convert the given byteCount into a string like: 9.9bytes/KB/MB/GB """ for (cutoff, label) in [(1024 * 1024 * 1024, "GB"), (1024 * 1024, "MB"), (1024, "KB")]: if byteCount >= cutoff: return "%.1f %s" % (byteCount * 1.0 / cutoff, label) if byteCount == 1: return "1 byte" else: return "%d bytes" % byteCount def lastPlayedGroupKey(track): """ Return the grouping key for the given track when group by last played column """ # We only want to group tracks by the month in which they were played return datetime.date(track.lastPlayed.year, track.lastPlayed.month, 1) def lastPlayedGroupKeyConverter(groupKey): # Convert the given group key (which is a date) into a representation string return groupKey.strftime("%B %Y") self.myOlv.useExpansionColumn = True self.myOlv.SetColumns([ ColumnDefn("Title", "left", 120, "title", imageGetter=musicImage, useInitialLetterForGroupKey=True), ColumnDefn("Artist", "left", 120, "artist", imageGetter=artistImageGetter), ColumnDefn("Size", "center", 100, "sizeInBytes", stringConverter=sizeToNiceString), ColumnDefn("Last Played", "left", 100, "lastPlayed", groupKeyGetter=lastPlayedGroupKey, groupKeyConverter=lastPlayedGroupKeyConverter), ColumnDefn("Rating", "center", 100, "rating") ]) #self.myOlv.CreateCheckStateColumn() self.myOlv.SetSortColumn(self.myOlv.columns[2]) self.myOlv.SetObjects(self.songs)
def InitObjectListView(self): groupImage = self.myOlv.AddImages(ExampleImages.getGroup16Bitmap(), ExampleImages.getGroup32Bitmap()) userImage = self.myOlv.AddImages(ExampleImages.getUser16Bitmap(), ExampleImages.getUser32Bitmap()) musicImage = self.myOlv.AddImages(ExampleImages.getMusic16Bitmap(), ExampleImages.getMusic32Bitmap()) self.myOlv.AddNamedImages("collapsed", ExampleImages.getCollapsedBitmap()) self.myOlv.AddNamedImages("expanded", ExampleImages.getExpandedBitmap()) def trackImageGetter(track): if isinstance(track, (ListGroup, EmptyRow)): return -1 else: return musicImage soloArtists = ["Nelly Furtado", "Missy Higgins", "Moby", "Natalie Imbruglia", "Dido", "Paul Simon", "Bruce Cockburn"] def artistImageGetter(track): if isinstance(track, (ListGroup, EmptyRow)): return -1 if track.artist in soloArtists: return userImage else: return groupImage def sizeToNiceString(byteCount): """ Convert the given byteCount into a string like: 9.9bytes/KB/MB/GB """ if byteCount < 0: return "" for (cutoff, label) in [(1024*1024*1024, "GB"), (1024*1024, "MB"), (1024, "KB")]: if byteCount >= cutoff: return "%.1f %s" % (byteCount * 1.0 / cutoff, label) if byteCount == 1: return "1 byte" else: return "%d bytes" % byteCount def isExpanded(modelObject): if isinstance(modelObject, ListGroup): if modelObject.isExpanded: return "expanded" else: return "collapsed" else: return -1 def rowFormatter(listItem, model): if isinstance(model, ListGroup): listItem.SetFont(wx.FFont(9, wx.FONTFAMILY_SWISS, wx.FONTFLAG_BOLD, "MS Sans Serif")) self.myOlv.SetColumns([ ColumnDefn("", "left", 24, None, imageGetter=isExpanded), ColumnDefn("Title", "left", 120, "title", imageGetter=trackImageGetter), ColumnDefn("Artist", "left", 120, "artist", imageGetter=artistImageGetter), ColumnDefn("Size", "center", 100, "sizeInBytes", stringConverter=sizeToNiceString), ColumnDefn("Last Played", "left", 100, "lastPlayed"), ColumnDefn("Rating", "center", 100, "rating") ]) songsAndGroups = list() for (i, x) in enumerate(self.songs): if i % 5 == 0: if i > 0: songsAndGroups.append(EmptyRow()) songsAndGroups.append(ListGroup(i, "Group #%d" % i)) songsAndGroups.append(x) self.myOlv.rowFormatter = rowFormatter self.myOlv.SetObjects(songsAndGroups)