mirror of
https://github.com/Xevion/tcp-chat.git
synced 2025-12-06 03:16:44 -06:00
improve nickname dialog (add text, placeholder), fix > 3 letters check, close dialog with window properly
This commit is contained in:
@@ -63,13 +63,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
super(MainWindow, self).__init__(*args, **kwargs)
|
||||
self.setupUi(self)
|
||||
self.show()
|
||||
self.closed = False
|
||||
|
||||
# Get Nickname
|
||||
while True:
|
||||
nicknameDialog = NicknameDialog(self)
|
||||
nicknameDialog.exec_()
|
||||
self.nickname = nicknameDialog.lineEdit.text().strip()
|
||||
if len(self.nickname) > 3:
|
||||
self.nicknameDialog = NicknameDialog(self)
|
||||
self.nicknameDialog.exec_()
|
||||
self.nickname = self.nicknameDialog.lineEdit.text().strip()
|
||||
if len(self.nickname) >= 3 or self.closed:
|
||||
break
|
||||
|
||||
# Connect to server
|
||||
@@ -92,6 +93,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
self.messages = []
|
||||
|
||||
def closeEvent(self, event):
|
||||
if self.nicknameDialog:
|
||||
self.closed = True
|
||||
self.nicknameDialog.close()
|
||||
event.accept() # let the window close
|
||||
|
||||
def eventFilter(self, obj, event):
|
||||
if event.type() == QEvent.KeyPress and obj is self.messageBox:
|
||||
if event.key() == Qt.Key_Return and self.messageBox.hasFocus():
|
||||
|
||||
Reference in New Issue
Block a user