def __init__(self): self.reddit = util.Redditt() self.subreddit = "all" self.subreddit_type = "hot" self.submissions = self.reddit.getSubList(self.subreddit, self.SUBMISSION_LIST_LIMIT, self.subreddit_type) self.commentSubmissionId = None self.currentSubmissionIndex = 0 self.currentCommentsIndex = 0 self.currentAuthorCommentIndex = 0 self.currentAuthorSubmissionIndex = 0 self.author = None self.submissionItems = util.createSubmissionsList(self.submissions) self.submissionTextItems = main.getSubmissionTextList( self.currentSubmissionIndex, self.submissionItems, self.SUBLIST_LIMIT) self.commentItems = util.CustomOrderedDict({}) self.commentTextItems = util.CustomOrderedDict({}) self.authorItems = util.CustomOrderedDict({}) self.authorTextItems = util.CustomOrderedDict({}) self.view = util.SUBMISSION_VIEW # or util.COMMENT_VIEW self.lastView = util.SUBMISSION_VIEW self.content = urwid.SimpleListWalker([ urwid.AttrMap(w, util.DATA_BODY_PALETTE, util.FOCUS_PALETTE) for w in self.submissionTextItems.values() ]) self.listbox = urwid.ListBox(self.content) headText = util.getHeader(self.reddit.getUsername()) self.head = urwid.Text((util.HEADER_PALETTE, [ headText, (util.HEADER_PALETTE, (util.getMenuItems(util.SUBMISSION_VIEW))) ]), wrap='clip') footText = "\nr/" + self.subreddit + " - " + self.subreddit_type + "\nPage 1/" + str( int(self.SUBMISSION_LIST_LIMIT / self.SUBLIST_LIMIT)) self.foot = urwid.Text((util.FOOTER_PALETTE, footText), wrap='clip') self.frame = urwid.Frame(self.listbox, header=self.head, footer=self.foot) self.dialogBoxOpen = False super(ReddittApplication, self).__init__(self.frame)
def getAuthorSubmissionTextList(currentIndex, submissionItems, sublistLimit): textList = util.CustomOrderedDict({}) for index, (submissionId, output) in enumerate(submissionItems.items()): if index >= currentIndex and index < (currentIndex + sublistLimit): textList.append(submissionId, SelectableText(output)) elif index >= (currentIndex + sublistLimit): break return textList
def __initSubmissions(self, subreddit, type): exists = True try: self.reddit.getRedditInstance().subreddits.search_by_name( subreddit, exact=True) except: exists = False raise if exists == True: self.submissions = self.reddit.getSubList( subreddit, self.SUBMISSION_LIST_LIMIT, type) self.subreddit_type = type self.subreddit = subreddit self.currentSubmissionIndex = 0 self.currentCommentsIndex = 0 self.submissionItems = util.createSubmissionsList(self.submissions) self.submissionTextItems = main.getSubmissionTextList( self.currentSubmissionIndex, self.submissionItems, self.SUBLIST_LIMIT) self.commentItems = util.CustomOrderedDict({}) self.commentTextItems = util.CustomOrderedDict({}) self.authorItems = util.CustomOrderedDict({}) self.authorTextItems = util.CustomOrderedDict({}) footerText = "\nr/" + self.subreddit + " - " + self.subreddit_type + "\nPage 1/" + str( int(self.SUBMISSION_LIST_LIMIT / self.SUBLIST_LIMIT)) self.foot.set_text(footerText) self.content[:] = urwid.SimpleListWalker([ urwid.AttrMap(w, util.DATA_BODY_PALETTE, util.FOCUS_PALETTE) for w in self.submissionTextItems.values() ]) self.listbox.set_focus(self.currentSubmissionIndex)
def __initComments(self, sorting, submissionId, key=None): if submissionId == None: focus_widget, localIndex = self.listbox.get_focus() # Get the submission ID submissionId = list(self.submissionTextItems.keys())[localIndex] self.commentSubmissionId = submissionId if key != 'k': self.currentCommentsIndex = 0 self.reddit.setSubmission(submissionId) submission = self.reddit.getSubmission() comments = self.reddit.getSubmissionComments(sorting) comTextItems = util.CustomOrderedDict({}) submissionLink = util.getCommentLink(submission.permalink) textList = [ (util.DATA_INFO_PALETTE, "u/" + str(submission.author.name + " - " + submissionLink)) ] textList.append("\n" + util.encodeString(submission.title)) if len(str(submission.url)) > 0: textList.append("\n" + str(submission.url)) if len(submission.selftext) > 0: textList.append((util.HEADER_PALETTE, "\n\n" + util.encodeString(submission.selftext))) #textList.append(urwid.Divider(u'─', 0, 1)) textList.append("\n" + ("─" * int(main.getScreen().get_cols_rows()[0])) + "\n") comTextItems.append( str(submissionId) + "|comment_title", main.SelectableText(textList)) self.commentTextItems = self.__commentsToDictionary( comments, False, 0, comTextItems, str(submission.author.name)) headerText = util.getHeader(self.reddit.getUsername()) self.head.set_text((util.HEADER_PALETTE, [ headerText, (util.HEADER_PALETTE, util.getMenuItems(util.COMMENT_SUBMISSION_VIEW)) ])) self.foot.set_text("\nr/" + str(submission.subreddit)) self.view = util.COMMENT_VIEW self.content[:] = urwid.SimpleListWalker([ urwid.AttrMap(w, util.DATA_BODY_PALETTE, util.FOCUS_PALETTE) for w in self.commentTextItems.values() ]) if len(comments) > 0: # Go to top then shift down to be able see top level submission self.listbox.set_focus(self.currentCommentsIndex)