Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from PySide2 import QtWidgets as qt
  2. from PySide2 import QtCore as qtc
  3. from PySide2.QtGui import QColor
  4. import configparser, sys, os
  5. from datetime import datetime as dt
  6. set_debug = False
  7. class TextLine:
  8. def __init__(self, username, color, textarea, timestamp, logfile):
  9. self.username = username
  10. self.color = "#000000" if color == "" else color
  11. self.qcolor = QColor(int(self.color[1:3], 16), int(self.color[3:5], 16), int(self.color[5:7], 16))
  12. self.label = qt.QLabel("<span style='color: {}'>&{}:</span>".format(self.color, self.username))
  13. self.message = qt.QPlainTextEdit()
  14. self.message.keyPressEvent = self.isItEnter
  15. self.message.setMaximumSize(600, 40)
  16. self.textarea = textarea
  17. self.label.setBuddy(self.message)
  18. self.label
  19. self.timestamp = timestamp
  20. self.logfile = logfile
  21. def isItEnter(self, event):
  22. if event.key() == qtc.Qt.Key_Enter or event.key() == qtc.Qt.Key_Return:
  23. mod = qt.QApplication.keyboardModifiers()
  24. if mod == qtc.Qt.ShiftModifier:
  25. self.message.insertPlainText("\n")
  26. else:
  27. sentText = self.message.toPlainText()
  28. sentText = sentText.replace("\n", "\t\n")
  29. if self.timestamp:
  30. t = dt.now()
  31. o = "[{}] {}: {}".format(t.strftime("%H:%M:%S"), self.username, sentText)
  32. else:
  33. o = "{}: {}".format(self.username, sentText)
  34. self.textarea.setTextColor(self.qcolor)
  35. self.textarea.append(o)
  36. if self.logfile != "":
  37. with open(self.logfile, "a", encoding="utf8") as file:
  38. file.write(o + "\n")
  39. self.message.clear()
  40. else:
  41. qt.QPlainTextEdit.keyPressEvent(self.message, event)
  42. def toString(self):
  43. print(self.username)
  44. def debug(message):
  45. if set_debug:
  46. print(message)
  47. def main():
  48. debug("Loading config...")
  49. cfg = config()
  50. timestamp = True if int(cfg["timestamp"]) == 1 else False
  51. debug("Setting up...")
  52. app = qt.QApplication([])
  53. layout = qt.QVBoxLayout()
  54. debug("Making text area...")
  55. text_area = qt.QTextEdit()
  56. text_area.setFocusPolicy(qtc.Qt.NoFocus)
  57. layout.addWidget(text_area)
  58. debug("Getting users...")
  59. users = [x.strip() for x in cfg["users"].split(",")]
  60. colors = [x.strip() for x in cfg["colors"].split(",")]
  61. while len(colors) < len(users):
  62. colors.append("#000000")
  63. debug("Users are {}".format(users))
  64. inputs = []
  65. for i in range(len(users)):
  66. ipt = TextLine(users[i], colors[i], text_area, timestamp, cfg["logfile"])
  67. inputs.append(ipt)
  68. for ipt in inputs:
  69. layout.addWidget(ipt.label)
  70. layout.addWidget(ipt.message)
  71. debug("Starting window...")
  72. window = qt.QWidget()
  73. window.setLayout(layout)
  74. window.resize(int(cfg["sizew"]), int(cfg["sizeh"]))
  75. window.show()
  76. debug("Starting interactivity...")
  77. app.exec_()
  78. def config():
  79. config = configparser.ConfigParser()
  80. if not os.path.isfile('config.ini'):
  81. print("config.ini is missing!")
  82. sys.exit(0)
  83. config.read('config.ini')
  84. return config["DEFAULT"]
  85. if __name__ == "__main__":
  86. main()