def __init__(self, parent, title = None): BasePanel.__init__(self, parent, title) self.fileList = FileInfoList(self) if wx.Platform == "__WXMAC__": self.fileList.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) self.il = wx.ImageList(16, 16) self.images = {} self.cache = {} self.images['folder'] = self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_TOOLBAR, (16, 16))) self.images['folder_open'] = self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, (16, 16))) self.images['file'] = self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_TOOLBAR, (16, 16))) self.fileList.SetImageList(self.il) self.sizer.Add(self.fileList, 1, wx.EXPAND, 0) self.initTasks() self.sizer.SetSizeHints(self.fileList)
class FilesPanel(BasePanel): def __init__(self, parent, title = None): BasePanel.__init__(self, parent, title) self.fileList = FileInfoList(self) if wx.Platform == "__WXMAC__": self.fileList.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) self.il = wx.ImageList(16, 16) self.images = {} self.cache = {} self.images['folder'] = self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_TOOLBAR, (16, 16))) self.images['folder_open'] = self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, (16, 16))) self.images['file'] = self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_TOOLBAR, (16, 16))) self.fileList.SetImageList(self.il) self.sizer.Add(self.fileList, 1, wx.EXPAND, 0) self.initTasks() self.sizer.SetSizeHints(self.fileList) def loadValues(self): self.fileList.DeleteAllItems() torrent = self.parent.getTorrent() if torrent is None: return self.filemap = {} info = torrent.info if torrent.files.isFile(): filename = os.path.split(torrent.files.getProcDest(pathonly = False, checkexists = False))[1] root = self.fileList.AddRoot(filename) self.filemap[0] = root self.fileList.SetItemImage(root, self.getFiletypeImage(filename.split('.')[-1]), which = wx.TreeItemIcon_Normal) else: root = self.fileList.AddRoot(torrent.getTitle("dest")) self.fileList.SetItemImage(root, self.images['folder'], which = wx.TreeItemIcon_Normal) self.fileList.SetItemImage(root, self.images['folder_open'], which = wx.TreeItemIcon_Expanded) alreadypresent = {} filearray = [] for fileindex in range(len(info['files'])): tempfile = info['files'][fileindex] patharray = tempfile['path'] relativepath = u"" addto = self.fileList.GetRootItem() # Add directories first if len(patharray) > 1: for index in range(len(patharray) - 1): part = patharray[index] relativepath += "\\" + part if not relativepath in alreadypresent: newitem = self.fileList.AppendItem(addto, part) self.fileList.SetItemImage(newitem, self.images['folder'], which = wx.TreeItemIcon_Normal) self.fileList.SetItemImage(newitem, self.images['folder_open'], which = wx.TreeItemIcon_Expanded) alreadypresent[relativepath] = newitem addto = alreadypresent[relativepath] filearray.append((patharray, addto)) # Add files after adding directories for index in range(len(filearray)): patharray, addto = filearray[index] filename = patharray[-1] newitem = self.fileList.AppendItem(addto, filename) self.filemap[index] = newitem self.fileList.SetItemImage(newitem, self.getFiletypeImage(filename.split('.')[-1]), which = wx.TreeItemIcon_Normal) # Default to having the root expanded self.fileList.Expand(root) self.fileList.onUpdateColumns() def getFiletypeImage(self, filetype): if not filetype or wx.Platform != "__WXMSW__": return self.images['file'] if not self.images.has_key(filetype): icon, iconfile, iconidx = getIcon(filetype) if icon and icon.Ok(): if (iconfile, iconidx) in self.cache: self.images[filetype] = self.cache[(iconfile, iconidx)] else: self.images[filetype] = self.il.AddIcon(icon) self.cache[(iconfile, iconidx)] = self.images[filetype] self.fileList.SetImageList(self.il) else: self.images[filetype] = self.images['file'] return self.images[filetype]