fix QStatusBar not updating, ConnectionOptions namedtuple settings func, Connect button basic logic, DEFAULT_IP/PORT

This commit is contained in:
Xevion
2021-01-25 11:36:23 -06:00
parent 9f317f3b96
commit 628aaea937
3 changed files with 42 additions and 5 deletions

View File

@@ -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

View File

@@ -1,8 +1,20 @@
from typing import Tuple
from PyQt5.QtWidgets import QApplication
from client.dialog import ConnectionDialog
from client.gui import MainWindow
# def connection_dialog() -> Tuple[str, int, str, str, bool]:
# connect_dialog = ConnectionDialog()
def main():
app = QApplication([])
app.setApplicationName("TCPChat Client")
m = MainWindow()
connect_dialog = ConnectionDialog()
# m = MainWindow()
app.exec_()
if connect_dialog.connect_pressed:
print(connect_dialog.settings)

View File

@@ -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:
"""