comment_screen.py 2.0 KB

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