|
|
|
|
|
|
|
|
from PySide2 import QtWidgets as qt |
|
|
from PySide2 import QtWidgets as qt |
|
|
from PySide2 import QtCore as qtc |
|
|
from PySide2 import QtCore as qtc |
|
|
|
|
|
from PySide2.QtGui import QColor |
|
|
import configparser, sys, os |
|
|
import configparser, sys, os |
|
|
from datetime import datetime as dt |
|
|
from datetime import datetime as dt |
|
|
|
|
|
|
|
|
set_debug = False |
|
|
set_debug = False |
|
|
|
|
|
|
|
|
class TextLine: |
|
|
class TextLine: |
|
|
def __init__(self, username, textarea, timestamp, logfile): |
|
|
|
|
|
|
|
|
def __init__(self, username, color, textarea, timestamp, logfile): |
|
|
self.username = username |
|
|
self.username = username |
|
|
|
|
|
self.color = "#000000" if color == "" else color |
|
|
|
|
|
self.qcolor = QColor(int(self.color[1:3], 16), int(self.color[3:5], 16), int(self.color[5:7], 16)) |
|
|
self.label = qt.QLabel("&{}:".format(username)) |
|
|
self.label = qt.QLabel("&{}:".format(username)) |
|
|
self.message = qt.QLineEdit() |
|
|
|
|
|
self.message.returnPressed.connect(self.pressButton) |
|
|
|
|
|
|
|
|
self.message = qt.QPlainTextEdit() |
|
|
|
|
|
self.message.keyPressEvent = self.isItEnter |
|
|
|
|
|
self.message.setMaximumSize(600, 40) |
|
|
self.textarea = textarea |
|
|
self.textarea = textarea |
|
|
self.label.setBuddy(self.message) |
|
|
self.label.setBuddy(self.message) |
|
|
self.timestamp = timestamp |
|
|
self.timestamp = timestamp |
|
|
self.logfile = logfile |
|
|
self.logfile = logfile |
|
|
|
|
|
|
|
|
def pressButton(self): |
|
|
|
|
|
if self.timestamp: |
|
|
|
|
|
t = dt.now() |
|
|
|
|
|
o = "[{}] {}: {}".format(t.strftime("%H:%M:%S"), self.username, self.message.text()) |
|
|
|
|
|
|
|
|
def isItEnter(self, event): |
|
|
|
|
|
if event.key() == qtc.Qt.Key_Enter or event.key() == qtc.Qt.Key_Return: |
|
|
|
|
|
mod = qt.QApplication.keyboardModifiers() |
|
|
|
|
|
if mod == qtc.Qt.ShiftModifier: |
|
|
|
|
|
self.message.insertPlainText("\n") |
|
|
|
|
|
else: |
|
|
|
|
|
sentText = self.message.toPlainText() |
|
|
|
|
|
sentText = sentText.replace("\n", "\t\n") |
|
|
|
|
|
if self.timestamp: |
|
|
|
|
|
t = dt.now() |
|
|
|
|
|
o = "[{}] {}: {}".format(t.strftime("%H:%M:%S"), self.username, sentText) |
|
|
|
|
|
else: |
|
|
|
|
|
o = "{}: {}".format(self.username, sentText) |
|
|
|
|
|
self.textarea.setTextColor(self.qcolor) |
|
|
|
|
|
self.textarea.append(o) |
|
|
|
|
|
if self.logfile != "": |
|
|
|
|
|
with open(self.logfile, "a", encoding="utf8") as file: |
|
|
|
|
|
file.write(o + "\n") |
|
|
|
|
|
self.message.clear() |
|
|
else: |
|
|
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() |
|
|
|
|
|
|
|
|
qt.QPlainTextEdit.keyPressEvent(self.message, event) |
|
|
|
|
|
|
|
|
def toString(self): |
|
|
def toString(self): |
|
|
print(self.username) |
|
|
print(self.username) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug("Getting users...") |
|
|
debug("Getting users...") |
|
|
users = [x.strip() for x in cfg["users"].split(",")] |
|
|
users = [x.strip() for x in cfg["users"].split(",")] |
|
|
|
|
|
colors = [x.strip() for x in cfg["colors"].split(",")] |
|
|
|
|
|
while len(colors) < len(users): |
|
|
|
|
|
colors.append("#000000") |
|
|
debug("Users are {}".format(users)) |
|
|
debug("Users are {}".format(users)) |
|
|
inputs = [] |
|
|
inputs = [] |
|
|
for user in users: |
|
|
|
|
|
ipt = TextLine(user, text_area, timestamp, cfg["logfile"]) |
|
|
|
|
|
|
|
|
for i in range(len(users)): |
|
|
|
|
|
ipt = TextLine(users[i], colors[i], text_area, timestamp, cfg["logfile"]) |
|
|
inputs.append(ipt) |
|
|
inputs.append(ipt) |
|
|
for ipt in inputs: |
|
|
for ipt in inputs: |
|
|
layout.addWidget(ipt.label) |
|
|
layout.addWidget(ipt.label) |