comment_screen.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from PyQt5 import QtWidgets, uic
  2. from PyQt5.QtCore import pyqtSignal
  3. from lyberry_qt import helpers
  4. class CommentWidget(QtWidgets.QDialog):
  5. change_url = pyqtSignal(str)
  6. def __init__(self, comment):
  7. super(CommentWidget, self).__init__()
  8. uic.loadUi(helpers.relative_path('designer/comment.ui'), self)
  9. self.comment = comment
  10. self.pub = comment.pub
  11. self._lbry = comment._LBRY_api
  12. self.message.setText(helpers.fix_markdown(self.comment.msg))
  13. self.message.linkActivated.connect(self.change_url.emit)
  14. self.channel_button.setText(comment.channel.name)
  15. self.show_replies_button.setText(str(comment.replies_amt) + " Replies")
  16. self.show_replies_button.clicked.connect(self.show_replies)
  17. self.show_replies_button.setEnabled(comment.replies_amt > 0)
  18. self.write_comment_button.clicked.connect(self.write_comment)
  19. def write_comment(self):
  20. self.writing_section = WriteCommentWidget(self, self.comment)
  21. self.write_comment_section.addWidget(self.writing_section)
  22. self.write_comment_button.setEnabled(False)
  23. self.writing_section.finished.connect(lambda:
  24. self.write_comment_button.setEnabled(True)
  25. )
  26. def show_replies(self):
  27. for comment in self.comment.replies:
  28. item = CommentWidget(comment)
  29. self.replies_section.addWidget(item)
  30. self.show_replies_button.setEnabled(False)
  31. class WriteCommentWidget(QtWidgets.QDialog):
  32. def __init__(self, parent, comment=None):
  33. super(WriteCommentWidget, self).__init__()
  34. uic.loadUi(helpers.relative_path('designer/write_comment.ui'), self)
  35. self.create_comment_button.clicked.connect(self.create_comment)
  36. self.parent = parent
  37. self.comment = comment
  38. self.add_my_channels_as_comment_options()
  39. def add_my_channels_as_comment_options(self):
  40. my_channels = self.parent._lbry.my_channels
  41. for channel in my_channels:
  42. self.channel_select.addItem(channel.name)
  43. def create_comment(self):
  44. channel_name = self.channel_select.currentText()
  45. channel = self.parent._lbry.channel_from_uri(channel_name)
  46. message = self.comment_box.toPlainText()
  47. self.parent._lbry.make_comment(channel, message, self.parent.pub, self.comment)
  48. self.comment_box.clear()
  49. self.close()