def showOtherInstanceDialog(self: Any) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle( 'Other instance' if self else getTitleString('Other instance')) messagebox.setText(f''' <p style="margin:10px 15px 10px 5px;"> <b>Another instance of the application is currently running.</b> </p> <p style="margin:10px 15px 10px 5px;"> Only one instance should be opened at the same time<br> to prevent data corruption. </p> <p style="margin:10px 15px 10px 5px;"> Continue anyway? </p> ''') messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) messagebox.setDefaultButton(QMessageBox.Cancel) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def showInvalidPermissionsDialog(self: Any, path: Path) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle('Invalid permissions' if self else getTitleString('Invalid permissions')) messagebox.setText(f''' <p style="margin:10px 15px 10px 5px;"> <b>Invalid permissions for directory:</b> </p> <p style="margin:10px 15px 10px 5px;"> <code>{path}</code> </p> <p style="margin:10px 15px 10px 5px;"> Write permissions to this directory are required for mod management.<br> Automatically set the correct permissions? </p> ''') messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def showInvalidConfigErrorDialog(self: Any) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle('Invalid game path' if self else getTitleString('Invalid game path')) messagebox.setText(f''' <p style="margin:10px 15px 10px 5px;"><b>Invalid game or config path.</b><br> Please restart w3modmanager and enter the paths of<br> your The Witcher 3 installation and the game config folder<br> (usually <code>User/Documents/The Witcher 3</code>). </p> <p style="margin:10px 15px 10px 5px;"><small> For updates and information visit <br> <a href="{w3modmanager.URL_WEB}" style="text-decoration:none;">\ {removeUrlScheme(w3modmanager.URL_WEB)}\ </a> </small></p> ''') messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setStandardButtons(QMessageBox.Ok) messagebox.setAttribute(Qt.WA_DeleteOnClose) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def showAboutDialog(self: Any) -> QMessageBox: messagebox = QMessageBox(self) messagebox.setWindowTitle('About' if self else getTitleString('About')) messagebox.setText(f''' <p style="margin:0 15px 0 0;"> <b>{w3modmanager.TITLE} {w3modmanager.VERSION}</b> <small>{f'({w3modmanager.VERSION_HASH})' if w3modmanager.VERSION_HASH else ''}</small><br> {w3modmanager.SUBTITLE}<br> <br> For updates and information visit <br> <a href="{w3modmanager.URL_WEB}" style="text-decoration:none;">\ {removeUrlScheme(w3modmanager.URL_WEB)}\ </a><br> <br> Thank you for using {w3modmanager.TITLE}! </p> ''') # TODO: enhancement: check if new version is available messagebox.setTextFormat(Qt.RichText) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.setMinimumSize(QSize(500, 500)) messagebox.setStandardButtons(QMessageBox.Ok) messagebox.setAttribute(Qt.WA_DeleteOnClose) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def showCritcalErrorDialog(self: Any, error: str = '', details: str = '') -> QMessageBox: import traceback messagebox = QMessageBox(self) messagebox.setWindowTitle( 'Critical Error' if self else getTitleString('Critical Error')) messagebox.setText(f''' <p><strong>\ Something unexpected happened. {'Detailed error message:' if error else ''}\ </strong></p> {f'<p><code>{error}</code></p>' if error else ''} <p><small> Please check if this is a known issue or create a report \ detailing the conditions of this error here:<br> <a href="{w3modmanager.URL_ISSUES}" style="text-decoration:none;"> {removeUrlScheme(w3modmanager.URL_ISSUES)} </a> </small></p> ''') if error: messagebox.setDetailedText( details if details else traceback.format_exc()) messagebox.setIconPixmap(messagebox.windowIcon().pixmap( messagebox.windowIcon().actualSize(QSize(64, 64)))) messagebox.layout().setContentsMargins(5, 5, 5, 5) messagebox.setModal(True) messagebox.open() return messagebox
def handleClicked(self): if not self.ui.locationInput.text(): msgBox = QMessageBox() msgBox.setIcon(QMessageBox.Warning) msgBox.setText("지역을 설정해주세요.") else: filter = json.load(open("mod.json"))["filter"] filter_list = [] for c in self.checkboxes: if c.isChecked(): filter_list.append(filter[c.text()]) filter = ":".join(filter_list) #thread self.thread = QThread() self.worker = Worker(self.ui.locationInput.text(), filter) self.worker.moveToThread(self.thread) self.thread.started.connect(self.worker.run) self.worker.finished.connect(self.thread.quit) self.worker.finished.connect(self.worker.deleteLater) self.thread.finished.connect(self.thread.deleteLater) self.worker.progress.connect(self.ui.progressBar.setValue) self.thread.start() self.ui.startButton.setEnabled(False) self.thread.finished.connect(self.handleFinished)
def show_about(self): """Show About dialog.""" from . import __version__ msg_box = QMessageBox(self) text = ( f"<img src='{image_path('mnelab_logo.png')}'><p>MNELAB {__version__}</p>" ) msg_box.setText(text) mnelab_url = "github.com/cbrnr/mnelab" mne_url = "github.com/mne-tools/mne-python" pkgs = [] for key, value in have.items(): if value: pkgs.append(f"{key} ({value})") else: pkgs.append(f"{key} (not installed)") version = ".".join(str(k) for k in version_info[:3]) text = ( f"<nobr><p>This program uses Python {version} and the following packages:" f"</p></nobr><p>{', '.join(pkgs)}</p>" f"<nobr><p>MNELAB repository: <a href=https://{mnelab_url}>{mnelab_url}</a>" f"</p></nobr><nobr><p>MNE repository: " f"<a href=https://{mne_url}>{mne_url}</a></p></nobr>" f"<p>Licensed under the BSD 3-clause license.</p>" f"<p>Copyright 2017–2021 by Clemens Brunner.</p>") msg_box.setInformativeText(text) msg_box.exec()
def updateMainRNG6(self): if self.mainRNG: values = self.manager.updateFrameCount() # Handle infinite loop if values is None: self.toggleMainRNG6() message = QMessageBox() message.setText("Exiting an infinite loop. Make sure no patches are installed and the game is on the latest version") message.exec_() return difference, initialSeed, currentSeed, frameCount, save, tiny3, tiny2, tiny1, tiny0 = values # Check to see if frame changed at all if difference != 0: self.lineEditInitialSeed6.setText(hexify(initialSeed)) self.lineEditCurrentSeed6.setText(hexify(currentSeed)) self.lineEditFrame6.setText(str(frameCount)) self.lineEditSaveVariable.setText(hexify(save)) self.lineEditTiny3.setText(hexify(tiny3)) self.lineEditTiny2.setText(hexify(tiny2)) self.lineEditTiny1.setText(hexify(tiny1)) self.lineEditTiny0.setText(hexify(tiny0))
def mouse_clicked(self): ## print(f'mouse clicked') mbox = QMessageBox() mbox.setText(f"fock u!") mbox.exec() sys.exit() pass
def addRepoHandler(self): path = self.ui.path.text() for r in enumerate(self.repos): if r[1][0] == path: errbox = QMessageBox() errbox.setText(f"{path} is already listed in {self.json_path}") errbox.exec() return colour = ColorPicker().getColor() hexcolour = '%02x%02x%02x' % ( int(colour[0]), # this is actually so dumb int(colour[1]) if int(colour[0]) != 255 or not int(colour[1]) else int(colour[1]) + 1, int(colour[2]) if int(colour[0]) != 255 or not int(colour[2]) else int(colour[2]) + 1) if self.ui.checkBox.isChecked(): if not re.match(self.urlregexp, self.ui.remote.text()): errbox = QMessageBox() errbox.setText("Invalid URL") errbox.exec() return self.addNewRepo(path, self.ui.remote.text(), hexcolour, self.repos) else: self.addRepoFromExisting(path, hexcolour, self.repos) self.updateTables()
def safeClose(self): check_folder = False for i in range(self.tab_folders.count()): if len(self.tab_folders.widget(i).model()) > 0: check_folder = True break if not (check_folder or self._executing): self.close() return msgbox = QMessageBox(self) msgbox.setWindowTitle("Close") msgbox.setIcon(QMessageBox.Warning) if self._executing: msgbox.setText( "There are pending jobs. Do you really want to close?") else: msgbox.setText("Do you really want to close?") msgbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) msgbox.setDefaultButton(QMessageBox.No) if msgbox.exec_() == QMessageBox.Yes: if self._task is not None: self._task.cancel() self.close()
def guess(self): if self.ui.txt_input.text().isnumeric(): if int(self.ui.txt_input.text()) == self.number: self.ui.lbl_comment.setText('✨🎁🧡تو بردی 😍🌺🎉') elif int(self.ui.txt_input.text()) > self.number: self.score -= 1 if self.score == 0: self.ui.lbl_comment.setText('نتونستی تشخیص بدی😒🤦♀️') self.new_game() else: self.ui.lbl_comment.setText('برو پایین تر') else: self.score -= 1 if self.score == 0: self.ui.lbl_comment.setText('نتونستی تشخیص بدی😒🤦♀️') self.new_game() else: self.ui.lbl_comment.setText('برو بالا تر') self.ui.lbl_joon.setText(str(self.score)) else: msg_box = QMessageBox() msg_box.setText("باهوش جان، مقدار عددی وارد کن") msg_box.exec_()
def aboutButton(self): aboutMessageBox = QMessageBox(self) aboutMessageBox.setWindowModality(Qt.NonModal) aboutMessageBox.setWindowTitle("About this program") aboutMessageBox.setText("<h5>About content</h5>") aboutMessageBox.setIcon(QMessageBox.Information) aboutMessageBox.open()
def showDialog(self, text: str, title: str, buttons, callback): dialog = QMessageBox(self.window) dialog.setWindowTitle(title) dialog.setText(text) dialog.setStandardButtons(buttons) dialog.buttonClicked.connect(callback) dialog.exec_()
def generate(size, dir, path, outputName, params): currentTime = datetime.datetime.now() if len(outputName) <= 0: batchName = currentTime.strftime("%b-%d-%Y-%H%M%p%s") else: batchName = util.checkPath(dir, outputName) currentDirectory = os.getcwd() childDirectory = dir + "/" + batchName childDirectory = os.mkdir(childDirectory) record = [['email', 'gender', 'school', 'date']] ID = 1 progressBarStep = int(size / 10) progress = QProgressDialog("Generating Resumes", "Close", 0, 100) progress.setWindowModality(QtCore.Qt.WindowModal) progress.setAutoClose(True) progress.show() while ID <= size: pair = getPair(path, params) record.append(makeDoc(pair, 'control', ID, batchName, params)) record.append(makeDoc(pair, 'test', ID, batchName, params)) ID += 1 progress.setValue(ID) message = QMessageBox() message.setText("Resume generation complete.") message.exec() del pair return record
def main(): sys.excepthook = exception_logger os.environ['QT_MAC_WANTS_LAYER'] = '1' # Workaround for https://bugreports.qt.io/browse/QTBUG-87014 error = init_and_check_db(get_app_path()) if error.code == LedgerInitError.EmptyDbInitialized: # If DB was just created from SQL - initialize it again error = init_and_check_db(get_app_path()) app = QApplication([]) language = JalDB().get_language_code(JalSettings().getValue('Language', default=1)) translator = QTranslator(app) language_file = get_app_path() + Setup.LANG_PATH + os.sep + language + '.qm' translator.load(language_file) app.installTranslator(translator) if error.code == LedgerInitError.OutdatedDbSchema: error = update_db_schema(get_app_path()) if error.code == LedgerInitError.DbInitSuccess: error = init_and_check_db(get_app_path()) if error.code != LedgerInitError.DbInitSuccess: window = QMessageBox() window.setAttribute(Qt.WA_DeleteOnClose) window.setWindowTitle("JAL: Start-up aborted") window.setIcon(QMessageBox.Critical) window.setText(error.message) window.setInformativeText(error.details) else: window = MainWindow(language) window.show() app.exec() app.removeTranslator(translator)
def checkAndSaveChanges(self): old, oldini = {}, {} if open(self.json_path).read() != '': old = json.load(open(self.json_path)) else: old = {"repos": [], "sysupdates": []} if open(self.ini_path).read() != '': oldini = configparser.ConfigParser().read(self.ini_path) else: oldini = {} if (old["repos"] == self.repos and old["sysupdates"] == self.sysupdates) or \ (oldini == self.inicontents): pass else: confirm = QMessageBox() confirm.setText( "You have unsaved changes. Would you like to save them now?") confirm.setStandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel) ret = confirm.exec() if ret == QMessageBox.Cancel: return 1 elif ret == QMessageBox.Yes: self.apply()
def message_box(self, message: str, buttons: int = 1) -> int: ''' Message box with "Yes/No" or "OK" buttons. Defaults to "OK".\n Parameters:\n message (str): Message shown inside the message box. buttons (int): Amount of buttons, 1 - "OK" button, 2 - "Yes/No" buttons. Returns:\n choice (int): ID of the clicked button. ''' pixmap = QPixmap(resource_path('icon.ico')).scaledToWidth( 35, Qt.SmoothTransformation) msg_box = QMessageBox() msg_box.setFont(ui.font) msg_box.setText(message) if buttons == 2: msg_yes = msg_box.addButton(QMessageBox.Yes) msg_no = msg_box.addButton(QMessageBox.No) msg_yes.setText(self.dialog_yes) msg_no.setText(self.dialog_no) msg_yes.setProperty('class', 'button_yes') msg_no.setProperty('class', 'button_no') msg_box.setWindowFlags(Qt.Dialog | Qt.CustomizeWindowHint) msg_box.setIconPixmap(pixmap) with open(resource_path('style.css'), 'r') as file: msg_box.setStyleSheet(file.read()) msg_box.move(ui.frameGeometry().center() - QRect(QPoint(), msg_box.sizeHint()).center()) choice = msg_box.exec_() return choice
def show_update_info(info: dict): print(info) html_url = info.get('html_url', '') content = [ f'New v{info.get("version")} (Now v{VERSION})', info.get('name', ''), html_url, ] title = 'Update available, download now?' msg = QMessageBox() msg.setIcon(QMessageBox.Information) msg.setText(title) msg.setInformativeText('\n\n'.join(content)) msg.setWindowTitle(title) msg.setDetailedText(info.get('desc', '')) msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No) btn_ret = msg.exec_() if btn_ret == QMessageBox.Yes: print('Yes clicked.') open_url(html_url) elif btn_ret == QMessageBox.Ok: print('Ok clicked.') elif btn_ret == QMessageBox.No: print('No clicked.') elif btn_ret == QMessageBox.Cancel: print('Cancel')
def inputChanged(self, content): path = Path(content) if not (content and path.exists()): return if self._input_folder == path: return self.reset() # read file list self._input_folder = path glob = (p for p in path.rglob("*") if p.is_file()) files = [str(p.relative_to(path)) for p in islice(glob, 50)] self.list_input_files.addItems(files) self._network.add_nodes_from(files) # read more files remains = True try: remains = next(glob) except StopIteration: remains = False if remains: msgbox = QMessageBox(self) msgbox.setIcon(QMessageBox.Warning) msgbox.setText("There are too many files in the directory.") msgbox.setInformativeText("Do you still want to list them?") msgbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) msgbox.setDefaultButton(QMessageBox.No) if msgbox.exec_() != QMessageBox.Yes: self.reset() return self.list_input_files.addItem(str(remains.relative_to(path))) self._network.add_node(str(remains.relative_to(path))) files = [str(p.relative_to(path)) for p in glob] self.list_input_files.addItems(files) self._network.add_nodes_from(files) # generate keywords keywords = set() keypattern = re.compile(global_config.organizer.keyword_splitter) keywords.update(k.strip() for k in keypattern.split(path.name) if k.strip()) if len(os.listdir(path)) == 0: subf = next(path.iterdir()) if subf.is_dir(): keywords.update(k.strip() for k in keypattern.split(subf.name) if k.strip()) # TODO: extract metadata from input audio files self.widget_keywords.extendKeywords(keywords) # default output path if not global_config.organizer.default_output_dir: self.txt_output_path.setText(str(path.parent / "organized"))
def show_success(self): box = QMessageBox() box.setWindowTitle('Export Complete') box.setWindowIcon(self.icon) box.setText( 'Success. The file has been exported and should show up in the same folder as this program.\n\nDCC by Gideon Tong v1.0' ) box.exec_()
def blurrer_alert(self, message: str): """ Display blurrer messages in the GUI :param message: Message to be displayed """ msg_box = QMessageBox() msg_box.setText(message) msg_box.exec_()
def showErrorDialog(message): box = QMessageBox() box.setIcon(QMessageBox.Critical) box.setText(message) box.setWindowTitle("puya-dl") box.setStandardButtons(QMessageBox.Ok) return box.exec_()
def message_box_error(self, title, text, error=None): message = QMessageBox(self, title, text) message.setIcon(QMessageBox.Warning) message.setWindowTitle(title) message.setText(text) if error is not None: message.setDetailedText(str(error)) message.exec_()
def gui_exception_hook(exc_type, value, traceback): msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setText(str(value)) msg.setInformativeText(''.join( tb.format_exception(exc_type, value, traceback))) msg.setWindowTitle(exc_type.__name__) msg.exec()
def alert_message(self, header: str, text: str): msg = QMessageBox() msg.setIcon(QMessageBox.Information) msg.setWindowTitle("Alert") msg.setText(header) msg.setInformativeText(text) msg.setStandardButtons(QMessageBox.Ok) msg.setDefaultButton(QMessageBox.Ok) msg.exec()
def information_message_box(win_title: str, msg: str): msg_box = QMessageBox() msg_box.setIcon(QMessageBox.Information) msg_box.setWindowIcon(QIcon(str(pkg_data.LOGO))) msg_box.setText(msg) msg_box.setWindowTitle(win_title) msg_box.setStandardButtons(QMessageBox.Ok) msg_box.exec()
def helpButton(self): helpMessageBox = QMessageBox(self) helpMessageBox.setWindowTitle("Help") helpMessageBox.setText( '<h5>Please open this link for help</h5>' '<a href="https://github.com/pirlite2/EEE231-group-A/blob/main/README.md">' 'link') helpMessageBox.setIcon(QMessageBox.Information) helpMessageBox.open()
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 showSimpleDialog(message): box = QMessageBox() box.setIcon(QMessageBox.Question) box.setText(message) box.setWindowTitle("puya-dl") box.setStandardButtons(QMessageBox.Cancel | QMessageBox.Ok) return box.exec_()