11import sys
2-
3-
4- from PyQt5 .QtWidgets import QApplication , QDialog , QVBoxLayout , QPushButton , QLabel
2+ from PyQt5 .QtWidgets import QApplication , QDialog , QVBoxLayout , QPushButton
53import qt_material
6- from src .sharer . client import Client
7- from src .sharer . server import Server
4+ from src .client import Client
5+ from src .server import Server
86
97
108class RoleSelectionDialog (QDialog ):
@@ -15,7 +13,10 @@ def __init__(self):
1513
1614 self .setWindowTitle ("身份选择" )
1715 self .layout = QVBoxLayout ()
18-
16+ qr = self .frameGeometry () # 获取对话框的几何框架
17+ cp = QApplication .primaryScreen ().availableGeometry ().center () # 获取屏幕中心点
18+ qr .moveCenter (cp ) # 将对话框几何框架的中心移动到屏幕中心
19+ self .move (qr .topLeft ()) # 将对话框的左上角移动到新的位置
1920 self .server_button = QPushButton ("主控机" )
2021 self .client_button = QPushButton ("被控机" )
2122
@@ -40,17 +41,20 @@ def select_client(self):
4041
4142def main ():
4243 app = QApplication (sys .argv )
43- qt_material .apply_stylesheet (app , theme = 'dark_blue .xml' )
44+ qt_material .apply_stylesheet (app , theme = 'light_blue .xml' )
4445 selected_role = 'client'
4546 # 显示身份选择弹窗
4647 role_dialog = RoleSelectionDialog ()
4748 if role_dialog .exec_ () == QDialog .Accepted :
4849 selected_role = role_dialog .selected_role
49- if selected_role == 'server' :
50- Server (app )
51- elif selected_role == 'client' :
52- Client (app )
53- app .exec_ ()
54-
50+ try :
51+ if selected_role == 'server' :
52+ Server (app ).run ()
53+ elif selected_role == 'client' :
54+ Client (app ).run ()
55+ except Exception as e :
56+ print (e )
57+ finally :
58+ app .quit ()
5559if __name__ == "__main__" :
5660 main ()
0 commit comments