def __init__(self, parent: QWidget = None) -> None: super().__init__(parent) self.tcpServer = QTcpServer() self.tcpClient = QTcpSocket() self.tcpServerConnection: QTcpSocket = None self.bytesToWrite = 0 self.bytesWritten = 0 self.bytesReceived = 0 self.clientProgressBar = QProgressBar() self.clientStatusLabel = QLabel(self.tr("Client ready")) self.serverProgressBar = QProgressBar() self.serverStatusLabel = QLabel(self.tr("Server ready")) self.startButton = QPushButton(self.tr("&Start")) self.quitButton = QPushButton(self.tr("&Quit")) self.buttonBox = QDialogButtonBox() self.buttonBox.addButton(self.startButton, QDialogButtonBox.ActionRole) self.buttonBox.addButton(self.quitButton, QDialogButtonBox.RejectRole) self.startButton.clicked.connect(self.start) self.quitButton.clicked.connect(self.close) self.tcpServer.newConnection.connect(self.acceptConnection) self.tcpClient.connected.connect(self.startTransfer) self.tcpClient.bytesWritten.connect(self.updateClientProgress) self.tcpClient.error.connect(self.displayError) mainLayout = QVBoxLayout(self) mainLayout.addWidget(self.clientProgressBar) mainLayout.addWidget(self.clientStatusLabel) mainLayout.addWidget(self.serverProgressBar) mainLayout.addWidget(self.serverStatusLabel) mainLayout.addStretch(1) mainLayout.addSpacing(10) mainLayout.addWidget(self.buttonBox)
def __init__(self, username): super(editUserWinodw, self).__init__() self.setWindowModality(Qt.ApplicationModal) self.setMinimumSize(Data.getWindowHeight() / 1.5, Data.getWindowHeight() / 3) # self.setMinimumSize(Data.getWindowWidth() / 3, Data.getWindowHeight() / 3) # self.setMaximumSize(Data.getWindowWidth() / 3, Data.getWindowHeight() / 3) self.username = username self.key = None self.wchp = False self.wcun = False self.wcpw = False self.wcid = False # 设置窗口名称 self.setWindowTitle(u"用户窗口") self.tab = MLineTabWidget() widget = QWidget() widget_child = QWidget() widget_child_2 = QWidget() widget.setLayout(QHBoxLayout()) widget_child.setLayout(QVBoxLayout()) widget_child_2.setLayout(QVBoxLayout()) self.label_headProfile = MLabel() self.label_headProfile.setAlignment(Qt.AlignHCenter) self.btn_changeHead = MPushButton(u'选择新头像') widget_child.layout().addWidget(self.label_headProfile) widget_child.layout().addWidget(self.btn_changeHead) # widget_child.layout().addStretch() self.let_username = MLineEdit(text='username') tool_button = MLabel(text=u'用户名').mark().secondary() tool_button.setAlignment(Qt.AlignCenter) tool_button.setFixedWidth(80) self.let_username.set_prefix_widget(tool_button) widget_child_2.layout().addWidget(self.let_username) self.let_ID = MLineEdit(text='identity') self.btn_changeID = MPushButton(text=u'修改身份').primary() self.btn_changeID.setFixedWidth(80) self.let_ID.set_suffix_widget(self.btn_changeID) widget_child_2.layout().addWidget(self.let_ID) self.let_key = MLineEdit(text='') tool_button = MLabel(text=u'密钥').mark().secondary() tool_button.setAlignment(Qt.AlignCenter) tool_button.setFixedWidth(80) self.let_key.set_prefix_widget(tool_button) widget_child_2.layout().addWidget(self.let_key) self.let_password = MLineEdit(text='***********') self.btn_changePassword = MPushButton(text=u'修改密码').primary() self.btn_changePassword.setFixedWidth(80) self.let_password.set_suffix_widget(self.btn_changePassword) widget_child_2.layout().addWidget(self.let_password) self.btn_ok = MPushButton(u'确定').large().primary() self.btn_cancel = MPushButton(u'取消').large().primary() layout = QHBoxLayout() layout.addWidget(self.btn_ok) layout.addWidget(self.btn_cancel) widget_child_2.layout().addLayout(layout) widget.layout().addWidget(widget_child) widget.layout().addWidget(widget_child_2) self.tab.add_tab(widget, u'用户信息') widget2 = QWidget() self.ui = loadUi(file_path + r"\res\UI\EditUserWindow.ui") self.ui.setParent(widget2) widget2.setLayout(QVBoxLayout()) widget2.layout().addWidget(self.ui) self.tableWidget_operationNode = self.ui.findChild( QTableWidget, "tableWidget_operationNode") self.tableWidget_operationNode.setStyleSheet(Data.getQSS()) setSectionResizeMode(self.tableWidget_operationNode.horizontalHeader(), QHeaderView.Stretch) # 自适应 # widget2.layout().addSpacing(100) self.tab.add_tab(widget2, u'操作记录') btn_layout = QHBoxLayout() main_lay = QVBoxLayout() main_lay.addSpacing(20) main_lay.addWidget(self.tab) main_lay.addWidget(MDivider(u'')) main_lay.addLayout(btn_layout) main_lay.addSpacing(20) self.setLayout(main_lay) dayu_theme.background_color = "#262626" dayu_theme.apply(self) # 设置默认值 self.tableWidget_operationNode.setHorizontalHeaderLabels( [u'操作', u'文件名', u'时间']) # 设置资产操作记录表: colUser = userdb[self.username] userlist = colUser.find({}, {"FileName": 1, "Operation": 1, "Time": 1}) i = 0 for xdir in userlist: if "Operation" in xdir: str1 = xdir["Operation"] newItem1 = QTableWidgetItem(str1) self.tableWidget_operationNode.setItem(i, 0, newItem1) if "FileName" in xdir: str2 = xdir["FileName"] newItem2 = QTableWidgetItem(str2) self.tableWidget_operationNode.setItem(i, 1, newItem2) if "Time" in xdir: str3 = xdir["Time"] newItem3 = QTableWidgetItem(str3) self.tableWidget_operationNode.setItem(i, 2, newItem3) i += 1 #设置默认值 pixmap = QtGui.QPixmap(hpPath + "\\" + self.username + ".jpg") self.label_headProfile.setPixmap(pixmap) self.let_username.setText(self.username) self.let_username.setReadOnly(True) #只读 self.let_ID.setReadOnly(True) # 只读 self.let_password.setReadOnly(True) # 只读 self.let_password.setEchoMode(QLineEdit.Password) #输入密码形式 # 从数据库提取ID for x in colUser.find({"_id": "UserID"}, {"UserID": 1}): ID = x["UserID"] self.let_ID.setText(ID) # 显示身份 self.let_password.setText("**********") #链接信号与槽 self.btn_changeHead.clicked.connect(lambda: self.editHeadProfile()) self.btn_ok.clicked.connect(lambda: self.ok()) self.btn_cancel.clicked.connect(lambda: self.cancel()) self.btn_changePassword.clicked.connect(lambda: self.changePassword()) self.btn_changeID.clicked.connect(lambda: self.setID())