add test connection button disabling, fix DEFAULT port constant, fix gui closeEvent issues, test launching after connectionDialog

This commit is contained in:
Xevion
2021-01-25 12:05:02 -06:00
parent 628aaea937
commit 66d85369e1
4 changed files with 15 additions and 19 deletions

View File

@@ -73,14 +73,15 @@ class ConnectionDialog(QDialog, Ui_ConnectionDialog):
@property @property
def settings(self) -> ConnectionOptions: def settings(self) -> ConnectionOptions:
return ConnectionOptions(ip=self.server_address_input.text(), return ConnectionOptions(ip=self.server_address_input.text() or constants.DEFAULT_IP,
port=int(self.port_input.text()), port=int(self.port_input.text() or constants.DEFAULT_PORT),
nickname=self.nickname_input.text(), nickname=self.nickname_input.text(),
password=self.password_input.text(), password=self.password_input.text(),
remember=self.remember_checkbox.checkState()) remember=self.remember_checkbox.checkState())
def validation(self, full: bool = True) -> None: def validation(self, full: bool = True) -> None:
address, port = self.validate_address() address, port = self.validate_address()
nickname = self.validate_nickname()
if not address and not port: if not address and not port:
self.status_bar.showMessage('Please fill in a valid server address and port.', 3000) self.status_bar.showMessage('Please fill in a valid server address and port.', 3000)
@@ -88,10 +89,11 @@ class ConnectionDialog(QDialog, Ui_ConnectionDialog):
self.status_bar.showMessage('Please fill in a valid server address.', 3000) self.status_bar.showMessage('Please fill in a valid server address.', 3000)
elif not port: elif not port:
self.status_bar.showMessage('Please fill in a valid port number.', 3000) self.status_bar.showMessage('Please fill in a valid port number.', 3000)
elif full and not self.validate_nickname(): elif full and not nickname:
self.status_bar.showMessage('Please use a valid nickname. Letters and digits, 3-15 characters long.', 3000) self.status_bar.showMessage('Please use a valid nickname. Letters and digits, 3-15 characters long.', 3000)
self.connect_button.setDisabled(not (self.validate_address() and self.validate_nickname())) self.connect_button.setDisabled(not (address and port and nickname))
self.test_connection_button.setDisabled(not (address and port))
def validate_nickname(self) -> bool: def validate_nickname(self) -> bool:
"""Returns True if the nickname follows the nickname guidelines requested.""" """Returns True if the nickname follows the nickname guidelines requested."""
@@ -100,7 +102,7 @@ class ConnectionDialog(QDialog, Ui_ConnectionDialog):
def validate_address(self) -> Tuple[bool, bool]: def validate_address(self) -> Tuple[bool, bool]:
"""Returns True if the server address and port combination is valid""" """Returns True if the server address and port combination is valid"""
address = self.server_address_input.text() or constants.DEFAULT_IP address = self.server_address_input.text() or constants.DEFAULT_IP
port = self.port_input.text() or constants.DEFAULT_PORT port = self.port_input.text() or str(constants.DEFAULT_PORT)
valid_address = len(address) > 0 and re.match(r'^\d{1,4}\.\d{1,4}\.\d{1,4}\.\d{1,4}|localhost$', valid_address = len(address) > 0 and re.match(r'^\d{1,4}\.\d{1,4}\.\d{1,4}\.\d{1,4}|localhost$',
address) is not None address) is not None

View File

@@ -82,14 +82,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.get_message_history() self.get_message_history()
def closeEvent(self, event): def closeEvent(self, event):
if self.nicknameDialog and not self.closed: self.receiveThread.stop()
logger.debug('Closing nickname dialog before main window')
self.closed = True
self.nicknameDialog.close()
else:
self.receiveThread.stop()
self.connectionsListTimer.stop()
event.accept() # let the window close event.accept() # let the window close
def eventFilter(self, obj, event) -> bool: def eventFilter(self, obj, event) -> bool:

View File

@@ -1,3 +1,4 @@
import logging
from typing import Tuple from typing import Tuple
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
@@ -5,16 +6,16 @@ from PyQt5.QtWidgets import QApplication
from client.dialog import ConnectionDialog from client.dialog import ConnectionDialog
from client.gui import MainWindow from client.gui import MainWindow
logger = logging.getLogger(__file__)
# def connection_dialog() -> Tuple[str, int, str, str, bool]:
# connect_dialog = ConnectionDialog()
def main(): def main():
app = QApplication([]) app = QApplication([])
app.setApplicationName("TCPChat Client") app.setApplicationName("TCPChat Client")
connect_dialog = ConnectionDialog() connect_dialog = ConnectionDialog()
# m = MainWindow()
app.exec_() app.exec_()
if connect_dialog.connect_pressed: if connect_dialog.connect_pressed:
print(connect_dialog.settings) settings = connect_dialog.settings
m = MainWindow(settings.ip, settings.port, settings.nickname)
app.exec_()

View File

@@ -11,7 +11,7 @@ MINIMUM_CONTRAST = 4.65
DATABASE = os.path.join(__BASE_DIR, 'messages.db') DATABASE = os.path.join(__BASE_DIR, 'messages.db')
DEFAULT_IP = "127.0.0.1" DEFAULT_IP = "127.0.0.1"
DEFAULT_PORT = "5555" DEFAULT_PORT = 5555
ConnectionOptions = namedtuple('ConnectionOptions', ['ip', 'port', 'nickname', 'password', 'remember']) ConnectionOptions = namedtuple('ConnectionOptions', ['ip', 'port', 'nickname', 'password', 'remember'])