def delete_confirmation(parent, _id: str, action: Callable): msg = QMessageBox() msg.setText("Are you sure, you want to remove ?") msg.setStyleSheet(''' background-color: #1d251c; color: #bdc0bd; ''') msg.setParent(parent) msg.setWindowModality(Qt.WindowModality.WindowModal) style = ''' margin-top: 20px; border: none; ''' yes_btn = QPushButton(" Yes") yes_btn.setIcon(QIcon(full_path("assets/images/icons/trash-can.ico"))) yes_btn.setStyleSheet(style) no_btn = QPushButton(" Cancel") no_btn.setStyleSheet(style) no_btn.setIcon(QIcon(full_path("assets/images/icons/cancel.ico"))) yes_btn.setDefault(True) msg.addButton(no_btn, msg.ButtonRole.NoRole) msg.addButton(yes_btn, msg.ButtonRole.YesRole) msg.buttonClicked.connect(lambda x: action(_id) if x.text().lower().strip() == "yes" else do_nothing()) msg.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 window_prompt(title: str, prompt_text: str): """ Window prompt template used across the app. :param title: Window title. :param prompt_text: Text to prompt. :return: Nothing, just shows a window prompt. """ # Loads the current ui style and assigns it current_style = stylesheets.load_current_style() prompt = QMessageBox() prompt.setWindowTitle(title) prompt.setText(prompt_text) prompt.setStyleSheet(current_style) prompt.exec()
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()