def forumItemSelected(self): ''' user has selected an item in the forum ''' self.clear_browser() n_selected = len(self.tree_widget.selectionModel().selectedRows()) if n_selected > 0: self.archive_button.setEnabled(True) self.all_read_button.setEnabled(True) if n_selected != 1: return item = self.tree_widget.currentItem() post = item.data(0, QtCore.Qt.UserRole) LOGGER.debug("forum post selected %s", post) self.topic_label.setText("%s:\t<b>%s</b>" % (_("Subject"), post.topic)) heading = "%s:\t%s<br />" % (_("From"), post.inits) heading += "%s:\t%s<br />" % (_("To"), post.recipient) heading += "%s:\t%s" % (_("Post Date"), localsettings.readableDateTime(post.date)) self.header_label.setText(heading) self.browser.setPlainText(post.comment) self.reply_button.setEnabled(True) if post.important: self.important_button.setStyleSheet("color: red") self.important_button.setText(_("Remove importance")) else: self.important_button.setStyleSheet("") self.important_button.setText(_("Mark as important")) self.important_button.setEnabled(True) self.parent_button.setEnabled(True) if self.parenting_mode[0]: try: if self.parenting_mode[1] < post.ix: self.advise( _("Parent topic is newer, operation not allowed")) else: forum.setParent(self.parenting_mode[1], post.ix) except Exception as exc: raise exc finally: self.cancel_parenting_mode() self.loadForum() else: QtCore.QTimer.singleShot(3000, partial(self.mark_as_read, post.ix))
def forumItemSelected(self): """ user has selected an item in the forum """ self.clear_browser() n_selected = len(self.tree_widget.selectionModel().selectedRows()) if n_selected > 0: self.archive_button.setEnabled(True) self.all_read_button.setEnabled(True) if n_selected != 1: return item = self.tree_widget.currentItem() post = item.data(0, QtCore.Qt.UserRole) LOGGER.debug("forum post selected %s", post) self.topic_label.setText("%s:\t<b>%s</b>" % (_("Subject"), post.topic)) heading = "%s:\t%s<br />" % (_("From"), post.inits) heading += "%s:\t%s<br />" % (_("To"), post.recipient) heading += "%s:\t%s" % (_("Post Date"), localsettings.readableDateTime(post.date)) self.header_label.setText(heading) self.browser.setPlainText(post.comment) self.reply_button.setEnabled(True) if post.important: self.important_button.setStyleSheet("color: red") self.important_button.setText(_("Remove importance")) else: self.important_button.setStyleSheet("") self.important_button.setText(_("Mark as important")) self.important_button.setEnabled(True) self.parent_button.setEnabled(True) if self.parenting_mode[0]: try: if self.parenting_mode[1] < post.ix: self.advise(_("Parent topic is newer, operation not allowed")) else: forum.setParent(self.parenting_mode[1], post.ix) except Exception as exc: raise exc finally: self.cancel_parenting_mode() self.loadForum() else: QtCore.QTimer.singleShot(3000, partial(self.mark_as_read, post.ix))
def loadForum(self): """ loads the forum """ self.apply_new_reads() self.clear() user = self.forum_user() if not user: QtWidgets.QMessageBox.warning(self, _("Sorry"), _("Anonymous browsing of the forum is not supported")) return else: self.browser_user_label.setText("%s %s" % (_("Browing Forum as"), user)) self.wait() twidg = self.tree_widget posts = forum.getPosts(user, self.show_deleted_cb.isChecked()) parentItems = {None: twidg} alt_bg = False for post in posts: try: parentItem = parentItems[post.parent_ix] brush = parentItem.background(0) except KeyError: parentItem = twidg alt_bg = not alt_bg brush = self.ALT_BRUSH if alt_bg else self.NORM_BRUSH item = QtWidgets.QTreeWidgetItem(parentItem) item.setText(0, post.topic) item.setData(0, QtCore.Qt.UserRole, post) item.setText(1, post.inits) if post.recipient: item.setText(2, post.recipient) else: item.setText(2, "-") item.setText(3, localsettings.readableDateTime(post.date)) item.setText(4, post.briefcomment) if parentItem == twidg: item.setIcon(0, self.new_topic_button.icon()) if post.recipient == user: item.setForeground(2, self.BLUE_BRUSH) if post.inits == user: item.setForeground(1, self.BLUE_BRUSH) post_is_read = post.ix in self.read_ids.union(self.new_read_ids) for i in range(5): item.setBackground(i, brush) if not post_is_read: item.setFont(i, self.bold_font) if post.important: item.setForeground(i, self.RED_BRUSH) parentItems[post.ix] = item twidg.expandAll() for i in range(twidg.columnCount()): twidg.resizeColumnToContents(i) self.wait(False) twidg.verticalScrollBar().setValue(twidg.verticalScrollBar().maximum())
def loadForum(self): ''' loads the forum ''' self.apply_new_reads() self.clear() user = self.forum_user() if not user: QtWidgets.QMessageBox.warning( self, _("Sorry"), _("Anonymous browsing of the forum is not supported")) return else: self.browser_user_label.setText("%s %s" % (_("Browing Forum as"), user)) self.wait() twidg = self.tree_widget posts = forum.getPosts(user, self.show_deleted_cb.isChecked()) parentItems = {None: twidg} alt_bg = False for post in posts: try: parentItem = parentItems[post.parent_ix] brush = parentItem.background(0) except KeyError: parentItem = twidg alt_bg = not alt_bg brush = self.ALT_BRUSH if alt_bg else self.NORM_BRUSH item = QtWidgets.QTreeWidgetItem(parentItem) item.setText(0, post.topic) item.setData(0, QtCore.Qt.UserRole, post) item.setText(1, post.inits) if post.recipient: item.setText(2, post.recipient) else: item.setText(2, "-") item.setText(3, localsettings.readableDateTime(post.date)) item.setText(4, post.briefcomment) if parentItem == twidg: item.setIcon(0, self.new_topic_button.icon()) if post.recipient == user: item.setForeground(2, self.BLUE_BRUSH) if post.inits == user: item.setForeground(1, self.BLUE_BRUSH) post_is_read = post.ix in self.read_ids.union(self.new_read_ids) for i in range(5): item.setBackground(i, brush) if not post_is_read: item.setFont(i, self.bold_font) if post.important: item.setForeground(i, self.RED_BRUSH) parentItems[post.ix] = item twidg.expandAll() for i in range(twidg.columnCount()): twidg.resizeColumnToContents(i) self.wait(False) twidg.verticalScrollBar().setValue(twidg.verticalScrollBar().maximum())