diff --git a/client/dialog.py b/client/dialog.py index 024b8cc..c2aefdf 100644 --- a/client/dialog.py +++ b/client/dialog.py @@ -61,6 +61,24 @@ class ConnectionDialog(QDialog, Ui_ConnectionDialog): self.show() + def connect(self) -> None: + self.connect_pressed = True + self.close() + + def event(self, event: QEvent) -> bool: + if event.type() == QEvent.StatusTip: + self.status_bar.showMessage(event.tip()) + return True + return super().event(event) + + @property + def settings(self) -> ConnectionOptions: + return ConnectionOptions(ip=self.server_address_input.text(), + port=int(self.port_input.text()), + nickname=self.nickname_input.text(), + password=self.password_input.text(), + remember=self.remember_checkbox.checkState()) + def validation(self, full: bool = True) -> None: address, port = self.validate_address() @@ -84,7 +102,8 @@ class ConnectionDialog(QDialog, Ui_ConnectionDialog): address = self.server_address_input.text() or constants.DEFAULT_IP port = self.port_input.text() or 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$', address) is not None + 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 valid_port = len(port) > 0 and re.match(r'^\d{4,5}$', port) is not None and 1024 <= int(port) <= 65536 return valid_address, valid_port diff --git a/client/main.py b/client/main.py index 63e5928..d18349e 100644 --- a/client/main.py +++ b/client/main.py @@ -1,8 +1,20 @@ +from typing import Tuple + from PyQt5.QtWidgets import QApplication + +from client.dialog import ConnectionDialog from client.gui import MainWindow -app = QApplication([]) -app.setApplicationName("TCPChat Client") -m = MainWindow() -app.exec_() +# def connection_dialog() -> Tuple[str, int, str, str, bool]: +# connect_dialog = ConnectionDialog() + + +def main(): + app = QApplication([]) + app.setApplicationName("TCPChat Client") + connect_dialog = ConnectionDialog() + # m = MainWindow() + app.exec_() + if connect_dialog.connect_pressed: + print(connect_dialog.settings) diff --git a/constants.py b/constants.py index 3ec19ec..7fbd75b 100644 --- a/constants.py +++ b/constants.py @@ -1,4 +1,5 @@ from typing import List +from collections import namedtuple import os import webcolors @@ -9,6 +10,11 @@ HEADER_LENGTH = 10 MINIMUM_CONTRAST = 4.65 DATABASE = os.path.join(__BASE_DIR, 'messages.db') +DEFAULT_IP = "127.0.0.1" +DEFAULT_PORT = "5555" + +ConnectionOptions = namedtuple('ConnectionOptions', ['ip', 'port', 'nickname', 'password', 'remember']) + class Types: """