From 8f12454e19543afc635aacc64d731f2ce589f7e0 Mon Sep 17 00:00:00 2001 From: SelfConfusion <1822250894@qq.com> Date: Fri, 12 Jul 2024 20:07:17 +0800 Subject: [PATCH] fix can not connect to serial bug --- requirements.txt | 1 - src/main.py | 18 ++++++++++++------ src/messagebox.py | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4bf246b..a77812d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,3 @@ pyinstaller==6.9.0 pyinstaller-hooks-contrib==2024.7 pyserial==3.5 PyYAML==6.0.1 -serial==0.0.97 diff --git a/src/main.py b/src/main.py index 802bd4e..938ee8b 100644 --- a/src/main.py +++ b/src/main.py @@ -6,6 +6,7 @@ import serial.tools import serial.tools.list_ports as ls_ports from typing import Optional, Any +import platform import functools @@ -19,6 +20,7 @@ class App(ctk.CTk): gain_values = gain_default.copy() gain_values_store = gain_default.copy() gain_enable = [True for i in range(5)] + system_platform = platform.system() def __init__(self) -> None: super().__init__() @@ -45,8 +47,12 @@ class App(ctk.CTk): ctk.set_widget_scaling(0.8) # find the center point - center_x = int(screen_width / 2 - width / 2) - center_y = int(screen_height / 2 - height / 2) + if self.system_platform == "Linux": + center_x = int(screen_width / 2 - width / 2) + center_y = int(screen_height / 2 - height / 2) + elif self.system_platform == "Windows": + center_x = int(screen_width / 2 - width / 4) + center_y = int(screen_height / 2 - height / 4) # set the position of the self to the center of the screen self.geometry(f"{width}x{height}+{center_x}+{center_y}") @@ -287,11 +293,11 @@ class App(ctk.CTk): try: self.serial = serial.Serial(self.select_port, self.serial_baudrate) except AttributeError: - print("Please Select Serial Port") - messagebox.showError("Please Select Serial Port") + print("Port or Baudrate Wrong") + messagebox.showError("Port or Baudrate Wrong") except serial.serialutil.SerialException: - print("Can't Control the Serial Port") - messagebox.showError("Can't Control the Serial Port") + print("Can't Connect to the Serial Port") + messagebox.showError("Can't Connect to the Serial Port") else: self.serial_status = True self.serial_button_text.set("断开连接") diff --git a/src/messagebox.py b/src/messagebox.py index 9bdac7d..35bad84 100644 --- a/src/messagebox.py +++ b/src/messagebox.py @@ -78,6 +78,8 @@ class Message(CTkMessagebox): ) if isHighDPI: self._set_scaling(1.7, 1.7) + else: + self._set_scaling(1.1, 1.1) def showError(message:str)->None: Message(title="Error", message=message, icon="cancel", isHighDPI=isHighDIP) \ No newline at end of file