from PySide2 import QtWidgets as qt from PySide2 import QtCore as qtc import configparser, sys, os from datetime import datetime as dt set_debug = False class TextLine: def __init__(self, username, textarea, timestamp, logfile): self.username = username self.label = qt.QLabel("&{}:".format(username)) self.message = qt.QLineEdit() self.message.returnPressed.connect(self.pressButton) self.textarea = textarea self.label.setBuddy(self.message) self.timestamp = timestamp self.logfile = logfile def pressButton(self): if self.timestamp: t = dt.now() o = "[{}] {}: {}".format(t.strftime("%H:%M:%S"), self.username, self.message.text()) else: o = "{}: {}".format(self.username, self.message.text()) self.textarea.append(o) if self.logfile != "": with open(self.logfile, "a", encoding="utf8") as file: file.write(o + "\n") self.message.clear() def toString(self): print(self.username) def debug(message): if set_debug: print(message) def main(): debug("Loading config...") cfg = config() timestamp = True if int(cfg["timestamp"]) == 1 else False debug("Setting up...") app = qt.QApplication([]) layout = qt.QVBoxLayout() debug("Making text area...") text_area = qt.QTextEdit() text_area.setFocusPolicy(qtc.Qt.NoFocus) layout.addWidget(text_area) debug("Getting users...") users = [x.strip() for x in cfg["users"].split(",")] debug("Users are {}".format(users)) inputs = [] for user in users: ipt = TextLine(user, text_area, timestamp, cfg["logfile"]) inputs.append(ipt) for ipt in inputs: layout.addWidget(ipt.label) layout.addWidget(ipt.message) debug("Starting window...") window = qt.QWidget() window.setLayout(layout) window.resize(int(cfg["sizew"]), int(cfg["sizeh"])) window.show() debug("Starting interactivity...") app.exec_() def config(): config = configparser.ConfigParser() if not os.path.isfile('config.ini'): print("config.ini is missing!") sys.exit(0) config.read('config.ini') return config["DEFAULT"] if __name__ == "__main__": main()