diff --git a/COMTool/Combobox.py b/COMTool/Combobox.py index 923867a..94e3929 100644 --- a/COMTool/Combobox.py +++ b/COMTool/Combobox.py @@ -1,4 +1,4 @@ -from PyQt5.QtWidgets import QComboBox,QListView +from PyQt5.QtWidgets import QComboBox,QListView,QApplication from PyQt5.QtCore import pyqtSignal @@ -26,7 +26,9 @@ def _showPopup(self): w = self.view().sizeHintForColumn(i) if w > max_w: max_w = w - self.view().setMinimumWidth(max_w + 50) + + screen_width = QApplication.desktop().availableGeometry().width() + self.view().setMinimumWidth(min(max_w + 50, screen_width)) super(ComboBox, self).showPopup() def showItems(self): diff --git a/COMTool/conn/conn_tcp_udp.py b/COMTool/conn/conn_tcp_udp.py index 5a3b7d9..cc83f15 100644 --- a/COMTool/conn/conn_tcp_udp.py +++ b/COMTool/conn/conn_tcp_udp.py @@ -174,8 +174,8 @@ def initEvet(self): self.updateClientsSignal.connect(self.updateClients) self.protoclTcpRadioBtn.clicked.connect(lambda: self.changeProtocol("tcp")) self.protoclUdpRadioBtn.clicked.connect(lambda: self.changeProtocol("udp")) - self.modeServerRadioBtn.clicked.connect(lambda: self.changeMode("server")) - self.modeClientRadioBtn.clicked.connect(lambda: self.changeMode("client")) + self.modeServerRadioBtn.clicked.connect(lambda: self.changeMode("server", self.config["protocol"])) + self.modeClientRadioBtn.clicked.connect(lambda: self.changeMode("client", self.config["protocol"])) self.clientsCombobox.currentIndexChanged.connect(self.serverModeClientChanged) self.disconnetClientBtn.clicked.connect(self.serverModeDisconnectClient) self.autoReconnect.stateChanged.connect(lambda x: self.setVar("auto_reconnect", value = x)) @@ -190,46 +190,46 @@ def changeProtocol(self, protocol, init=False): self.modeClientRadioBtn.show() self.modeServerRadioBtn.show() self.modeLabel.show() - self.changeMode(self.config["mode"], init=True) + self.changeMode(self.config["mode"], protocol, init=True) else: - self.targetCombobox.show() - self.targetLabel.show() - self.selfIPandPortLabel.show() - self.selfIPandPort.show() - self.porttEdit.show() - self.portLabel.show() - self.clientsCombobox.hide() - self.disconnetClientBtn.hide() - self.autoReconnect.hide() - self.autoReconnectIntervalEdit.hide() - self.autoReconnetLable.hide() - self.modeClientRadioBtn.hide() - self.modeServerRadioBtn.hide() - self.modeLabel.hide() - self.widget.adjustSize() + self.modeClientRadioBtn.show() + self.modeServerRadioBtn.show() + self.modeLabel.show() + self.changeMode(self.config["mode"], protocol, init=True) self.config["protocol"] = protocol - def changeMode(self, mode, init=False): + def changeMode(self, mode, protocol, init=False): if init or mode != self.config["mode"]: if self.isConnected(): self.openCloseSerial() if mode == "server": + if protocol == "tcp": + self.clientsCombobox.show() + self.disconnetClientBtn.show() + else: + self.clientsCombobox.hide() + self.disconnetClientBtn.hide() + self.targetCombobox.hide() self.targetLabel.hide() self.selfIPandPortLabel.hide() self.selfIPandPort.hide() self.porttEdit.show() self.portLabel.show() - self.clientsCombobox.show() - self.disconnetClientBtn.show() self.autoReconnect.hide() self.autoReconnectIntervalEdit.hide() self.autoReconnetLable.hide() else: + if protocol == "tcp": + self.selfIPandPortLabel.show() + self.selfIPandPort.show() + self.selfIPandPort.setReadOnly(True) + else: + self.selfIPandPortLabel.hide() + self.selfIPandPort.hide() + self.targetCombobox.show() self.targetLabel.show() - self.selfIPandPortLabel.show() - self.selfIPandPort.show() self.porttEdit.hide() self.portLabel.hide() self.clientsCombobox.hide() @@ -308,11 +308,11 @@ def setSerialConfig(self, conf_type, obj, value): elif conf_type == "mode": if value == "client": obj.setChecked(True) - self.changeMode("client", init=True) + self.changeMode("client", self.config["protocol"], init=True) else: obj.setChecked(False) self.modeServerRadioBtn.setChecked(True) - self.changeMode("server", init=True) + self.changeMode("server", self.config["protocol"], init=True) elif conf_type == "target": for i, target in enumerate(self.config["target"][1]): self.targetCombobox.addItem(target)