def showDialog(title, message, buttons: QMessageBox.StandardButtons): msgBox = QMessageBox() msgBox.setWindowTitle(title) msgBox.setIcon(QMessageBox.Icon.Information) msgBox.setText(message) msgBox.setStandardButtons(buttons) msgBox.exec()
def call_del_chose_user(self): if self._del_user: if self._del_user != self._config.name: self.user_num -= 1 self._config.del_user(self._del_user) self.user_btns[self._del_user].close() self._del_user = "" if self.user_num <= 1: self.del_user_btn.close() self.del_user_btn = None return else: title = '不能删除' msg = '不能删除当前登录账户,请先切换用户!' else: title = '请选择账户' msg = '请单击选择需要删除的账户\n\n注意不能删除当前账户(绿色)' message_box = QMessageBox(self) message_box.setIcon(QMessageBox.Icon.Critical) message_box.setStyleSheet(btn_style) message_box.setWindowTitle(title) message_box.setText(msg) message_box.setStandardButtons(QMessageBox.StandardButton.Close) buttonC = message_box.button(QMessageBox.StandardButton.Close) buttonC.setText('关闭') message_box.exec()
def closeEvent(self, event): if self.isEdited: # pop up dialog to alert user of unsaved edits. # offer then a chance to save before exiting. # messageBox = QMessageBox(self) messageBox.setIcon(QMessageBox.Icon.Question) messageBox.setWindowTitle("Close Check") messageBox.setText("You Have Unsaved Edits") messageBox.setInformativeText( "You have made edits that have not been saved.\nReally close and not save?" ) messageBox.setStandardButtons(QMessageBox.StandardButtons.Yes | QMessageBox.StandardButtons.No) # # change the default Yes and No buttons to really say # what then mean: Yes = Save and No = Quit. # the button actions then match exactly what the dialog # is saying and there should be no disonnance. # buttonSave = messageBox.button(QMessageBox.StandardButtons.Yes) buttonSave.setText("Save") buttonQuit = messageBox.button(QMessageBox.StandardButtons.No) buttonQuit.setText("Close") messageBox.setDefaultButton(QMessageBox.StandardButtons.Yes) buttonReply = messageBox.exec() if buttonReply == QMessageBox.StandardButtons.Yes: print("QMessageBox.Save") event.accept() else: print("QMessageBox.Close") else: print("Close event") event.accept()
def noticeBox(self, msg, title="Notice!"): msgBox = QMessageBox() msgBox.setText(msg) msgBox.setWindowTitle(title) msgBox.setStandardButtons(QMessageBox.StandardButtons.Ok) returnValue = msgBox.exec() if returnValue == QMessageBox.StandardButtons.Ok: return
def start(self): super().__init__() self.setWindowTitle("Enter your credentials") QBtn = QDialogButtonBox.StandardButton.Ok self.buttonBox = QDialogButtonBox(QBtn) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) self.layout = QFormLayout() self.layout.addRow('Username:'******'Password:'******'Hostname:', QLineEdit()) self.layout.addRow('Database:', QLineEdit()) self.layout.addWidget(self.buttonBox) self.setLayout(self.layout) self.exec() if QBtn == QDialogButtonBox.StandardButton.Ok: cred = { 'user': self.layout.itemAt(1).widget().text(), 'password': self.layout.itemAt(3).widget().text(), 'host': self.layout.itemAt(5).widget().text(), 'database': self.layout.itemAt(7).widget().text() } try: success = CONNECT(cred) env = dotenv.find_dotenv() dotenv.set_key(env, 'USER', cred['user']) dotenv.set_key(env, 'PASS', cred['password']) dotenv.set_key(env, 'HOST', cred['host']) dotenv.set_key(env, 'DATA', cred['database']) return success except (sql.errors.InterfaceError, ValueError): message = QMessageBox(self) message.setWindowTitle('Error') message.setText('The entered credentials are incorrect') message.setStandardButtons(QMessageBox.StandardButton.Ok) if message == QMessageBox.StandardButton.Ok: self.start()
def change_ok_btn(self): if self._user and self._pwd: if self._user not in self._config.users_name: self._cookie = None if self._cookie: up_info = {"name": self._user, "pwd": self._pwd, "cookie": self._cookie, "work_id": -1} if self.ok_btn.text() == "切换用户": self._config.change_user(self._user) else: self._config.set_infos(up_info) self.clicked_ok.emit() self.close() elif USE_WEB_ENG: self.web = LoginWindow(self._user, self._pwd) self.web.cookie.connect(self.get_cookie_by_web) self.web.setWindowModality(Qt.WindowModality.ApplicationModal) self.web.exec() elif os.path.isfile(self._cookie_assister): try: result = os.popen(f'{self._cookie_assister} {self._user} {self._pwd}') cookie = result.read() try: self._cookie = {kv.split("=")[0].strip(" "): kv.split("=")[1].strip(" ") for kv in cookie.split(";")} except: self._cookie = None if not self._cookie: return None up_info = {"name": self._user, "pwd": self._pwd, "cookie": self._cookie, "work_id": -1} self._config.set_infos(up_info) self.clicked_ok.emit() self.close() except: pass else: title = '请使用 Cookie 登录或是选择 登录辅助程序' msg = '没有输入 Cookie,或者没有找到登录辅助程序!\n\n' + \ '推荐使用浏览器获取 cookie 填入 cookie 输入框\n\n' + \ '如果不嫌文件体积大,请下载登录辅助程序:\n' + \ 'https://github.com/rachpt/lanzou-gui/releases' message_box = QMessageBox(self) message_box.setIcon(QMessageBox.Icon.Critical) message_box.setStyleSheet(btn_style) message_box.setWindowTitle(title) message_box.setText(msg) message_box.setStandardButtons(QMessageBox.StandardButton.Close) buttonC = message_box.button(QMessageBox.StandardButton.Close) buttonC.setText('关闭') message_box.exec()
def eliminar(self): confirmacion = QMessageBox(self) confirmacion.setText( f'Desea Eliminar el Producto con ID {self.txt_producto.text()}?') confirmacion.setIcon(QMessageBox.Icon.Question) confirmacion.setDetailedText( 'El producto se eliminará definitivamente...') confirmacion.setWindowTitle('Confirmación...') confirmacion.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) boton_yes = confirmacion.button(QMessageBox.StandardButton.Yes) confirmacion.exec() if confirmacion.clickedButton() == boton_yes: self.lbl_resultado.setText( f'Se ha eliminado el producto con ID {self.txt_producto.text()}.' ) else: self.lbl_resultado.setText( f'No se ha eliminado el producto con ID {self.txt_producto.text()}.' )