Send messages using the enter key

Thanks to Boctor for putting me on the right track (My version is way
more shit though)
This commit is contained in:
Fierelier 2020-11-25 13:07:46 +01:00
parent 3412a8453a
commit 7461c9a49d
1 changed files with 19 additions and 12 deletions

View File

@ -512,7 +512,7 @@ class guiChannel:
self.title = getChannelDisplayName(channel)
self.width = 320
self.height = 350
self.window = dbfMainWindow(customEventFilter = (self,self.eventFilter))
self.window = dbfMainWindow()
global style
self.window.setStyleSheet(style)
self.window.setWindowTitle(getTitle(self.title))
@ -527,12 +527,28 @@ class guiChannel:
self.window.closeEvent = self.closeEvent
self.createElements()
class chatTextBox(QTextEdit):
def __init__(self,parent = None,exSelf = None):
super().__init__(parent = parent)
self.exSelf = exSelf
self.installEventFilter(self)
def eventFilter(self,source,event):
if event.type() == QEvent.KeyPress:
if event.key() in (Qt.Key_Return,Qt.Key_Enter):
modifiers = QApplication.keyboardModifiers()
if (modifiers & Qt.ShiftModifier): return False
if self.exSelf.window.focusWidget() in (self.exSelf.textbox,):
self.exSelf.sendMessage()
return True
return False
def createElements(self):
self.menuBar = self.window.menuBar()
self.fileMenu = self.menuBar.addMenu("File")
self.messageLog = dbfTextBrowser(self.window)
self.messageLogScroll = self.messageLog.widget.verticalScrollBar()
self.textbox = QTextEdit(self.window)
self.textbox = self.chatTextBox(self.window,self)
self.buttonSend = QPushButton("Send",self.window)
self.buttonSend.clicked.connect(self.sendMessage)
@ -577,15 +593,6 @@ class guiChannel:
self.pendingMessages.append(self.textbox.toPlainText())
self.textbox.setPlainText("")
def eventFilter(_,self,source,event):
if event.type() == QEvent.KeyPress:
if event.key() in (Qt.Key_Return,Qt.Key_Enter):
modifiers = QApplication.keyboardModifiers()
if (modifiers & Qt.ShiftModifier): return False
if self.window.focusWidget() in (self.textbox,):
self.sendMessage()
return True
def setReady(self):
self.ready = True
@ -734,7 +741,7 @@ def discordClient(token):
if config["messageTracking"]["paranoidMessages"] == "true":
async for msg in message.channel.history(limit=100,before=message.created_at,after=oldTime):
print("[paranoidMessages] post-fetching message")
messages = msg + messages
messages.append(msg)
setLastMessageTime(message.channel,message.created_at)