Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from PySide2 import QtWidgets as qt
  2. from PySide2 import QtCore as qtc
  3. import configparser, sys, os
  4. from datetime import datetime as dt
  5. set_debug = False
  6. class TextLine:
  7. def __init__(self, username, textarea, timestamp, logfile):
  8. self.username = username
  9. self.label = qt.QLabel("&{}:".format(username))
  10. self.message = qt.QLineEdit()
  11. self.message.returnPressed.connect(self.pressButton)
  12. self.textarea = textarea
  13. self.label.setBuddy(self.message)
  14. self.timestamp = timestamp
  15. self.logfile = logfile
  16. def pressButton(self):
  17. if self.timestamp:
  18. t = dt.now()
  19. o = "[{}] {}: {}".format(t.strftime("%H:%M:%S"), self.username, self.message.text())
  20. else:
  21. o = "{}: {}".format(self.username, self.message.text())
  22. self.textarea.append(o)
  23. if self.logfile != "":
  24. with open(self.logfile, "a") as file:
  25. file.write(o + "\n")
  26. self.message.clear()
  27. def toString(self):
  28. print(self.username)
  29. def debug(message):
  30. if set_debug:
  31. print(message)
  32. def main():
  33. debug("Loading config...")
  34. cfg = config()
  35. timestamp = True if int(cfg["timestamp"]) == 1 else False
  36. debug("Setting up...")
  37. app = qt.QApplication([])
  38. layout = qt.QVBoxLayout()
  39. debug("Making text area...")
  40. text_area = qt.QTextEdit()
  41. text_area.setFocusPolicy(qtc.Qt.NoFocus)
  42. layout.addWidget(text_area)
  43. debug("Getting users...")
  44. users = [x.strip() for x in cfg["users"].split(",")]
  45. debug("Users are {}".format(users))
  46. inputs = []
  47. for user in users:
  48. ipt = TextLine(user, text_area, timestamp, cfg["logfile"])
  49. inputs.append(ipt)
  50. for ipt in inputs:
  51. layout.addWidget(ipt.label)
  52. layout.addWidget(ipt.message)
  53. debug("Starting window...")
  54. window = qt.QWidget()
  55. window.setLayout(layout)
  56. window.resize(int(cfg["sizew"]), int(cfg["sizeh"]))
  57. window.show()
  58. debug("Starting interactivity...")
  59. app.exec_()
  60. def config():
  61. config = configparser.ConfigParser()
  62. if not os.path.isfile('config.ini'):
  63. print("config.ini is missing!")
  64. sys.exit(0)
  65. config.read('config.ini')
  66. return config["DEFAULT"]
  67. if __name__ == "__main__":
  68. main()