def __readdItemToQueue(self): si = self.selectedLine try: dc = self.downloadManager.done[si] except: return self.videoURLDialog = VideoURLDialog(self) self.beginModalScreen(self.videoURLDialog) self.videoURLDialog.textField.setValue(dc.mediaObject.url) self.videoURLDialog.update()
class DoneBox(MultilineBox): def initialize(self): super(DoneBox, self).initialize() # Set this after the initialization of the done box! self.downloadManager self.title = "Done" def numberOfLines(self): return len(self.downloadManager.done) def lineAtIndex(self, index): mfl = self.__maximumFilenameLength() mul = self.size[1] - mfl - 3 url = self.__URLAtIndex(index, mul) fn = self.__filenameAtIndex(index, mfl) return url + ' '*(self.size[1] - mfl - len(url) - 2) + fn def display(self): super(DoneBox, self).display() x = self.size[1] - self.__maximumFilenameLength() - 2 y, x = self.abs(1, x) for i in range(0, self.size[0] - 2): attr = curses.A_NORMAL selected = self.selectedLine - self.getTopLine() == i selected = selected and len(self.downloadManager.done) != 0 if selected and self.isFirstResponder(): attr = attr | curses.A_REVERSE self.addch(y + i, x, curses.ACS_VLINE, attr) self.__connectBoxes() self.__drawLegend() def __connectBoxes(self): y, x = self.abs(self.size[0] - 1, 0) self.addch(y, x, curses.ACS_LTEE) self.addch(y, x + self.size[1] - 1, curses.ACS_RTEE) def __maximumFilenameLength(self): s = 0 for dc in self.downloadManager.done: l = len(dc.filename) if l > s: s = l if s < 10: s = 10 if int(self.size[1] / 2 - 1) < s: s = int(self.size[1] / 2 - 1) return s def __URLAtIndex(self, index, maxWidth): try: dc = self.downloadManager.done[index] except IndexError: # Concurrency error emergency stop return '' s = dc.mediaObject.url sl = len(s) if sl <= maxWidth: return s s = "..." + s[-maxWidth + 3:] return s def __filenameAtIndex(self, index, maxWidth): try: dc = self.downloadManager.done[index] except IndexError: # Concurrency error emergency stop return '' s = dc.filename sl = len(s) if sl <= maxWidth: return s s = s[:maxWidth - 3] + "..." return s def __drawLegend(self): y, x = self.abs(self.size[0] - 1, 0) drawLegend(self, y) def respondsTo(self, key): if chr(key) in ['c', 'r']: return True return super(DoneBox, self).respondsTo(key) def handleEvent(self, key): if chr(key) == 'c': self.downloadManager.clearDone() self.update() return True elif chr(key) == 'r': self.__readdItemToQueue() return True return super(DoneBox, self).handleEvent(key) def __readdItemToQueue(self): si = self.selectedLine try: dc = self.downloadManager.done[si] except: return self.videoURLDialog = VideoURLDialog(self) self.beginModalScreen(self.videoURLDialog) self.videoURLDialog.textField.setValue(dc.mediaObject.url) self.videoURLDialog.update() # Download Configuration management def addDownloadConfiguration(self, dc): self.downloadManager.addToQueue(dc)