def open_news(self): if not os.path.isfile("NEWS.txt"): QMessageBox.question(self, "Внимание!", "Файл \"NEWS.txt\" не был обнаружен в директории с исполняемым \ файлом. Для ознакомления со списком изменений вы можете обратиться к репозиторию на GitHub по ссылке выше.", QMessageBox.Ok) else: os.startfile("NEWS.txt")
def http_finished(self): return_result = self.reply.readAll().data().decode() result_json = json.loads(return_result) print(return_result) print(result_json) QMessageBox.question(self, '结果', f'搜索到了{result_json.__len__()}个文件') self.reply.deleteLater() self.reply = None
def CloseChip(self) -> bool: if AppGlobals.ProgramRunner().runningPrograms: status = QMessageBox.question( self, "Confirm", "There is a program running. Are you sure you want to stop?") if status is not QMessageBox.Yes: return False AppGlobals.ProgramRunner().StopAll() if self._editorWindow.isVisible(): if not self._editorWindow.RequestCloseAll(): return False if AppGlobals.Chip().modified: ret = QMessageBox.warning( self, "Confirm", "The current chip project has been modified.\nDo you want to save changes?", QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel, QMessageBox.Save) if ret is QMessageBox.Save: if not self.SaveChip(): return False elif ret is QMessageBox.Cancel: return False return True
def prompt_to_discard(self): if QMessageBox.question( self, "", 'Unsaved changes will be lost, continue?') == QMessageBox.Yes: return True else: return False
def auto_duplicate(self): """Automatically duplicate current data set. If the current data set is stored in a file (i.e. was loaded directly from a file), a new data set is automatically created. If the current data set is not stored in a file (i.e. was created by operations in MNELAB), a dialog box asks the user if the current data set should be overwritten or duplicated. Returns ------- duplicated : bool True if the current data set was automatically duplicated, False if the current data set was overwritten. """ # if current data is stored in a file create a new data set if self.model.current["fname"]: self.model.duplicate_data() return True # otherwise ask the user else: msg = QMessageBox.question(self, "Overwrite existing data set", "Overwrite existing data set?") if msg == QMessageBox.No: # create new data set self.model.duplicate_data() return True return False
def slot_remove_pointer(self, pointer: Pointer) -> None: pointer_addresses = { pointer.rom_variant: pointer.points_to - ROM_OFFSET } virtual_address = self.constraint_manager.to_virtual(pointer.rom_variant, pointer.address) print(f'remove {pointer}') remove_pointers = [pointer] for rom_variant in self.linked_variants: if rom_variant == pointer.rom_variant: continue local_address = self.constraint_manager.to_local(rom_variant, virtual_address) pointers = get_pointer_database().get_pointers(rom_variant).get_pointers_at(local_address) if len(pointers) != 1: continue pointer_addresses[rom_variant] = pointers[0].points_to - ROM_OFFSET print(f'remove {pointers[0]}') remove_pointers.append(pointers[0]) # Find the corresponding constraints to delete remove_constraints = [] constraints = get_constraint_database().get_constraints() for constraint in constraints: if constraint.romA in pointer_addresses and constraint.addressA == pointer_addresses[constraint.romA]: if constraint.romB in pointer_addresses and constraint.addressB == pointer_addresses[constraint.romB]: remove_constraints.append(constraint) print(f'Remove {constraint}') if QMessageBox.question(self.parent(), 'Remove Pointer', f'Remove {len(remove_pointers)} pointers and {len(remove_constraints)} constraints?') == QMessageBox.Yes: get_pointer_database().remove_pointers(remove_pointers) get_constraint_database().remove_constraints(remove_constraints)
def _inner_clear(): result = QMessageBox.question(self, self.windowTitle(), 'Delete all images ?', QMessageBox.Ok | QMessageBox.Cancel, QMessageBox.Cancel) if result == QMessageBox.Ok: shutil.rmtree(self.__dirname)
def close_all(self): """Close all currently open data sets.""" msg = QMessageBox.question(self, "Close all data sets", "Close all data sets?") if msg == QMessageBox.Yes: while len(self.model) > 0: self.model.remove_data()
def selectFile(self, new, old): if (self.resetting): self.resetting = False return if len(new.indexes()) == 0: self.clearSelection() self.currentFile = "" self.readOnly(True) return newSelection = self.files.filePath(new.indexes()[0]) self.settings.setValue("ui/snippeteditor/selected", newSelection) if QFileInfo(newSelection).isDir(): self.readOnly(True) self.clearSelection() self.currentFile = "" return if old and old.length() > 0: oldSelection = self.files.filePath(old.indexes()[0]) if not QFileInfo(oldSelection).isDir() and self.snippetChanged(): question = QMessageBox.question( self, self.tr("Discard"), self.tr("Snippet changed. Discard changes?")) if question != QMessageBox.StandardButton.Yes: self.resetting = True self.tree.selectionModel().select( old, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows) return False self.currentFile = newSelection self.loadSnippet()
def run(self): if self.context == None: log_warn("Cannot run snippets outside of the UI at this time.") return if self.snippetChanged(): question = QMessageBox.question( self, self.tr("Confirm"), self.tr("You have unsaved changes, must save first. Save?")) if (question == QMessageBox.StandardButton.No): return else: self.save() actionText = actionFromSnippet(self.currentFile, self.snippetDescription.text()) UIActionHandler.globalActions().executeAction(actionText, self.context) log_debug("Saving snippet %s" % self.currentFile) outputSnippet = codecs.open(self.currentFile, "w", "utf-8") outputSnippet.write("#" + self.snippetDescription.text() + "\n") outputSnippet.write("#" + self.keySequenceEdit.keySequence().toString() + "\n") outputSnippet.write(self.edit.toPlainText()) outputSnippet.close() self.registerAllSnippets()
def check_words_existence(calling_window): """Если не был обнаружен words.txt, то создаём его и заполняем несколькими словами и сообщаем о ненахождении.""" if not os.path.isfile("words.txt"): QMessageBox.question(calling_window, "Внимание!", "Файл \"words.txt\" не был обнаружен в директории с исполняемым\ файлом. Он будет создан и заполнен несколькими словами. \ Пожалуйста, поместите исходный файл \"words.txt\" или \ настройте его самостоятельно в соответствии с инструкцией в \ \"README.txt\".", QMessageBox.Ok) filler = "бАнты\nтОрты\nшАрфы\nпОрты\nсрЕдства\nИксы\nкрАны\nкОнусы\nлЕкторы\nпОручни" with open("words.txt", "w") as file: file.write(filler)
def show_question_message_box(self): sender = self.sender() reply = QMessageBox.question( self, 'Message', "Are you sure to quit?", QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel, QMessageBox.Yes) ''' mesg_bx = QMessageBox(self) mesg_bx.setWindowTitle("title") mesg_bx.setText("Message") mesg_bx.addButton(QMessageBox.Yes) mesg_bx.addButton(QMessageBox.No) mesg_bx.addButton(QMessageBox.Cancel) mesg_bx.setDefaultButton(QMessageBox.Yes) reply = mesg_bx.exec() ''' btn_text = "" if reply == QMessageBox.Yes: btn_text = "OK" self.ok() elif reply == QMessageBox.No: btn_text = "No" self.ney() elif reply == QMessageBox.Cancel: btn_text = "Cancel" print("hop hey, lalaley") sender.setText(btn_text)
def closeEvent(self, event): reply = QMessageBox.question(self, "Message", "Are you sure to quit?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()
def closeEvent(self, event: QCloseEvent): reply = QMessageBox.question(self, 'Message', 'Are you sure you want to quit?', QMessageBox.No | QMessageBox.No) if reply == QMessageBox.No: event.accept() else: event.ignore()
def prompt_calc_dvh(self): """ Windows displays buttons in a different order from Linux. A check for platform is performed to ensure consistency of button positioning across platforms. """ message = "DVHs not present in RTDOSE or do not correspond to ROIs. " message += "Would you like to calculate DVHs? (This may take up to " message += "several minutes on some systems.)" if platform.system() == "Linux": choice = QMessageBox.question(self, "Calculate DVHs?", message, QMessageBox.Yes | QMessageBox.No) if choice == QMessageBox.Yes: self.signal_advise_calc_dvh.emit(True) else: self.signal_advise_calc_dvh.emit(False) else: stylesheet_path = "" # Select appropriate style sheet if platform.system() == 'Darwin': stylesheet_path = Path.cwd().joinpath('res', 'stylesheet.qss') else: stylesheet_path = Path.cwd().joinpath( 'res', 'stylesheet-win-linux.qss') # Create a message box and add attributes mb = QMessageBox() mb.setIcon(QMessageBox.Question) mb.setWindowTitle("Calculate DVHs?") mb.setText(message) button_no = QtWidgets.QPushButton("No") button_yes = QtWidgets.QPushButton("Yes") # We want the buttons 'No' & 'Yes' to be displayed in that # exact order. QMessageBox displays buttons in respect to # their assigned roles. (0 first, then 1 and so on) # 'AcceptRole' is 0 and 'RejectRole' is 1 thus by assigning # 'No' to 'AcceptRole' and 'Yes' to 'RejectRole' the buttons # are positioned as desired. mb.addButton(button_no, QtWidgets.QMessageBox.AcceptRole) mb.addButton(button_yes, QtWidgets.QMessageBox.RejectRole) # Apply stylesheet to the message box and add icon to the window mb.setStyleSheet(open(stylesheet_path).read()) mb.setWindowIcon( QtGui.QIcon( resource_path(Path.cwd().joinpath('res', 'images', 'btn-icons', 'onkodicom_icon.png')))) mb.exec_() if mb.clickedButton() == button_yes: self.signal_advise_calc_dvh.emit(True) else: self.signal_advise_calc_dvh.emit(False)
def showGetInfoDialog(self) -> None: if QMessageBox.question( self, 'Update Mod details' if self else getTitleString('Update Mod details'), f''' <p>Update details of the selected mod(s) with information from Nexus Mods?</p> <p>This will replace existing details.</p> ''', QMessageBox.Yes | QMessageBox.Cancel) == QMessageBox.Yes: asyncio.create_task( self.mainwidget.modlist.updateSelectedModsDetails())
def deleteSnippet(self): selection = self.tree.selectedIndexes()[::self.columns][0] #treeview returns each selected element in the row snippetName = self.files.fileName(selection) question = QMessageBox.question(self, self.tr("Confirm"), self.tr("Confirm deletion: ") + snippetName) if (question == QMessageBox.StandardButton.Yes): log_debug("Deleting snippet %s." % snippetName) self.clearSelection() self.files.remove(selection) self.registerAllSnippets()
def questionMessage(parent: Optional[QWidget], message: str, dismissable: bool = False) -> bool: if dismissable: button = _dismissableMessage(parent, message, QMessageBox.Question, QMessageBox.Yes | QMessageBox.No, _dismissed_question_messages) else: button = QMessageBox.question(parent, QApplication.applicationName(), message) return button == QMessageBox.Yes
def jump_to_next_image(self) -> None: if len(self._list_of_images) == 0: self.mainWindow.statusbar.flash_message( red("no more"), wait=cfg.MESSAGE_FLASH_TIME_1) self.mainWindow.play_error_sound() return # else if self._curr_img_idx == len(self._list_of_images) - 1: self.mainWindow.statusbar.flash_message( red("no more"), wait=cfg.MESSAGE_FLASH_TIME_1) if self._curr_img.is_it_really_the_last(): # type: ignore self.mainWindow.play_error_sound() img = self._curr_img subreddit_name = img.extra_info.get("subreddit") # type: ignore after_id = img.extra_info.get("after_id") # type: ignore if img and subreddit_name and after_id: urls = [] if self.mainWindow.auto_load_next_subreddit_page: urls = subreddit.read_subreddit( subreddit_name, after_id, statusbar=self.mainWindow.statusbar, mainWindow=self.mainWindow) else: reply = QMessageBox.question( self.mainWindow, 'Question', "Load the next page?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes) if reply == QMessageBox.No: return else: # self.open_subreddit(subreddit, after_id) urls = subreddit.read_subreddit( subreddit_name, after_id, statusbar=self.mainWindow.statusbar, mainWindow=self.mainWindow) if len(urls) == 0: QMessageBox.information(self.mainWindow, "Info", "No new images were found.") else: lst = [ImageProperty(url, self.mainWindow) for url in urls] self._list_of_images.extend(lst) self.jump_to_next_image() return else: return # else new_idx = self._curr_img_idx + 1 if new_idx >= len(self._list_of_images): new_idx = len(self._list_of_images) - 1 # self.jump_to_image(new_idx)
def reject(self): self.settings.setValue("ui/snippeteditor/geometry", self.saveGeometry()) if self.snippetChanged(): question = QMessageBox.question( self, self.tr("Discard"), self.tr("You have unsaved changes, quit anyway?")) if question != QMessageBox.StandardButton.Yes: return self.accept()
def prompt_calc_dvh(self): choice = QMessageBox.question( self, "Calculate DVHs?", "RTSTRUCT and RTDOSE datasets identified. Would you " "like to calculate DVHs? (This may take up to several " "minutes on some systems.)", QMessageBox.Yes | QMessageBox.No) if choice == QMessageBox.Yes: self.signal_advise_calc_dvh.emit(True) else: self.signal_advise_calc_dvh.emit(False)
def delete_board(self): """Send a confirm message to delete the board""" reply = QMessageBox.question( self, "Delete Board", "Confirm to delete the sub-board (cannot be reversed)", QMessageBox.Yes | QMessageBox.Cancel, QMessageBox.Cancel, ) if reply == QMessageBox.Yes: self.delBoardSig.emit()
def mark_as_all_pointer(self): if abs(self.selected_bytes) % 4 != 0: return if abs(self.selected_bytes) == 4: # Mark one pointer dialog = self.get_new_pointer_dialog() dialog.pointer_changed.connect(self.add_new_pointer_and_constraints) dialog.show() else: # Mark multiple pointers reply = QMessageBox.question(self.dock, 'Add pointer and constraints', f'Do you really want to mark {abs(self.selected_bytes)//4} pointers and add the corresponding constraints?') if reply == QMessageBox.Yes: base_address = self.cursor if self.selected_bytes <0: base_address += self.selected_bytes + 1 self.signal_multiple_pointers_discovered.emit(base_address, abs(self.selected_bytes)//4)
def get_resource_set_name(self, default=''): filename = QInputDialog.getText(self, 'Save Resource Set', 'Enter resource set name:', text=default)[0] while filename in self.remote_resources['sets']: filename = QInputDialog.getText(self, 'Save Resource Set', 'Reserved name, enter new name:', text=default)[0] if filename in self.resource_set_slugs: if QMessageBox.question( self, 'Overwrite?', 'Name in use, overwrite?') == QMessageBox.No: return return filename
def begin_scan(self): if self.worker: self.stop_event.set() self.scan_button.setEnabled(False) return items = self.process_list_box.selectedItems() if not items: QMessageBox.warning(self, TITLE, 'Please choose a process from the list!') return process = items[0].text()[:-1].split(' ') self.process_name = ' '.join(process[:-2]) pid = int(process[-1]) multifiles = self.multifileBox.text().split() if not multifiles: QMessageBox.warning(self, TITLE, 'Please choose some multifiles to target!') return multifile_names = '\n'.join( [f'- {multifile}' for multifile in multifiles]) question = f'Do you really want to scan {self.process_name} for the following multifiles?\n\n{multifile_names}' if QMessageBox.question( self, TITLE, question, QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No ) != QMessageBox.StandardButton.Yes: return self.count = 0 self.setWindowTitle(f'{TITLE} - Scanning...') self.scan_button.setText('Stop') self.worker = ScanWorker(self, pid, multifiles) self.worker.signals.finished.connect(self.scan_over) self.worker.signals.error.connect(self.error_occurred) self.worker.signals.progress.connect(self.report_progress) self.thread_pool.start(self.worker)
def slot_multiple_pointers_discovered(self, controller: HexViewerController, base_address: int, count: int) -> None: print(base_address) for i in range(0, count): address = base_address + i * 4 points_to = controller.get_as_pointer(address) if points_to < ROM_OFFSET or points_to > ROM_OFFSET + ROM_SIZE: QMessageBox.critical(self.parent(), 'Add pointer and constraints', f'Address {hex(points_to)} is not inside the rom.') return pointer = Pointer(controller.rom_variant, controller.address_resolver.to_local( address), points_to, 5, settings.get_username()) try: if self.add_pointers_and_constraints(pointer): if i == count -1: QMessageBox.information(self.parent(), 'Add constraints', 'A constraint that changes the relations was added.') elif QMessageBox.question(self.parent(), 'Add pointer and constraints', 'A constraint that changes the relations was added.\nDo you want to continue adding the rest of the pointers?') != QMessageBox.Yes: return except InvalidConstraintError as e: QMessageBox.critical(self.parent(), 'Add constraints', 'Invalid Constraint') return
def save_layout(self): (layout_name, res) = QInputDialog.getText(self, 'Save Layout', 'Enter name for the layout') if res: layouts = settings.get_layouts() if layout_name in layouts: # TODO res = QMessageBox.question( self, 'Save Layout', f'Do you want to overwrite the existing layout {layout_name}?' ) print(res) if res != QMessageBox.StandardButton.Yes: return else: layout = Layout(layout_name, self.saveState(), self.saveGeometry(), self.dock_manager.save_state()) layouts.append(layout) settings.set_layouts(layouts) self.build_layouts_toolbar()
def closeEvent(self, event): reply = QMessageBox.question(self, '종료', '창을 닫으시겠습니까?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore()
def _remove_item(self, item): message = "Would you like to remove \"{}\"?".format(item.text()) button = QMessageBox.question(self, "Remove", message, QMessageBox.Yes | QMessageBox.No) if button == QMessageBox.Yes: item.parent().removeRow(item.row())
def closeEvent(self, event): if QMessageBox.question(self, "退出程序", "确定退出吗?") == QMessageBox.No: event.ignore() else: event.accept() self.shutdown_aria2.emit()