def handleAbout(self): """ Displays the About dialog """ about_box = QMessageBox() about_box.setText(__doc__) about_box.exec_()
def show_warning_dialog(self, msg, detail=None): """ Shows a warning dialog :param msg: str, message to show with the dialog :param detail: str, detail information to show (optional) """ dialog = QMessageBox() dialog.setIcon(QMessageBox.Warning) dialog.setWindowTitle('Warning') dialog.setText(msg) if detail: dialog.setDetailedText(detail) dialog.exec_()
def choice_warning(message): ''' Pop up a warning dialog box with the given message, and return True if the user wants to go ahead. ''' from Qt.QtWidgets import QMessageBox msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setText(message) msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) reply = msg.exec_() if reply == QMessageBox.Ok: return True return False
def setPassword(self): newPassword = self.let_password.text() if not newPassword: msgBox = QMessageBox() msgBox.setText(u'请输入密码!') msgBox.exec_() return 0 colUser = userdb[self.username] # 从数据库提取密码 for x in colUser.find({"_id": "Password"}, {"Password": 1}): if "Password" in x: DBpassword = x["Password"] oldD = {"Password": DBpassword} newD = {"$set": {"Password": newPassword}} x = colUser.update_many(oldD, newD)
def _fun(self, device): try: self.setup_connections() self.run(device) except Exception as e: traceback.print_exc() self._terminate() msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setText("Error occured during node execution!") msg.setInformativeText(str(e)) msg.setDetailedText(traceback.format_exc()) msg.setWindowTitle("Node execution error!") msg.setStandardButtons(QMessageBox.Ok) msg.exec()
def accept(self, *args, **kwargs): selected_file, selected_dir, selected_filename = self.get_result() if not os.path.isdir(selected_file): if os.path.exists(selected_file): message_box = QMessageBox() message_box.setWindowTitle('Confirm File Selection') message_box.setText( 'File "%s" exists.\nDo you want to overwrite it?' % selected_file) message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) message_box.setDefaultButton(QMessageBox.No) rv = message_box.exec_() if rv == QMessageBox.Yes and not os.path.isdir(selected_file): super(BaseSaveFileDialog, self).accept() else: super(BaseSaveFileDialog, self).accept()
def _ask_user_subset_override(self, instance): from Qt.QtWidgets import QMessageBox title = "Subset \"{}\" already exist".format(instance["subset"]) text = ("Instance with subset name \"{}\" already exists." "\n\nDo you want to override existing?").format( instance["subset"]) dialog = QMessageBox() dialog.setWindowTitle(title) dialog.setText(text) dialog.setStandardButtons(QMessageBox.Yes | QMessageBox.No) dialog.setDefaultButton(QMessageBox.Yes) dialog.exec_() if dialog.result() == QMessageBox.Yes: return True return False
def create_new_directory(self): name, ok = QInputDialog.getText(self, 'New directory name', 'Name:', QLineEdit.Normal, 'New Directory') if ok and name: path = os.path.join(self.directory, name) if os.path.exists(path): msg_box = QMessageBox(self) msg_box.setWindowTitle('Error') msg_box.setText('Directory already exists') msg_box.exec_() else: try: os.makedirs(path) self.update_view() except os.error as e: msg_box = QMessageBox(self) msg_box.setWindowTitle('Error') msg_box.setText('Cannot create directory') msg_box.exec_()
def save(): """ Saves current scene in current Maya file :return: bool, Whether the scene was saved or not """ file_check_state = maya.cmds.file(query=True, modified=True) if file_check_state: msg_box = QMessageBox() msg_box.setText('The Maya scene has been modified') msg_box.setInformativeText('Do you want to save your changes?') msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) msg_box.setDefaultButton(QMessageBox.Yes) res = msg_box.exec_() if res == QMessageBox.Yes: maya.cmds.SaveScene() return True return False
def save(file_path=None): """ Saves current scene in current Max file :return: bool, Whether the scene was saved or not """ file_path = file_path or '' file_check_state = rt.getSaveRequired() if file_check_state: msg_box = QMessageBox() msg_box.setText('The 3ds Max scene has been modified') msg_box.setInformativeText('Do you want to save your changes?') msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) msg_box.setDefaultButton(QMessageBox.Yes) res = msg_box.exec_() if res == QMessageBox.Yes: file_path = file_path or directory.save_file_dialog('Save File', filters='*.max') if not file_path: return rt.saveMaxFile(file_path) return True return False
def save(force=False): """ Saves current scene in current Max file :return: bool, Whether the scene was saved or not """ file_check_state = MaxPlus.FileManager.IsSaveRequired() if file_check_state: if file_check_state: if force: MaxPlus.FileManager.Save() return True else: msg_box = QMessageBox() msg_box.setText('The 3ds Max scene has been modified') msg_box.setInformativeText('Do you want to save your changes?') msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) msg_box.setDefaultButton(QMessageBox.Yes) res = msg_box.exec_() if res == QMessageBox.Yes: MaxPlus.FileManager.Save() return True return False
def msgbox(message, detail=None): msgbox = QMessageBox() msgbox.setText(message) if detail: msgbox.setDetailedText(detail) return msgbox.exec_()
def libadd_substituent(self): """add ligand to library or open it in a new model""" selection = selected_atoms(self.session) if not selection.single_structure: raise RuntimeError("selected atoms must be on the same model") residues = [] for atom in selection: if atom.residue not in residues: residues.append(atom.residue) rescol = ResidueCollection(selection[0].structure, convert_residues=residues) substituent_atoms = [ atom for atom in rescol.atoms if atom.chix_atom in selection ] start = None avoid = None for atom in substituent_atoms: for atom2 in atom.connected: if atom2 not in substituent_atoms: if start is None: start = atom avoid = atom2 else: raise RuntimeError( "substituent must only have one connection to the molecule" ) if start is None: raise RuntimeError( "substituent is not connected to a larger molecule") substituent_atoms.remove(start) substituent_atoms.insert(0, start) sub_name = self.sub_name.text() confs = self.sub_confs.value() angle = self.sub_angle.value() comment = "CF:%i,%i" % (confs, angle) if len(sub_name) == 0: sub = Substituent(substituent_atoms, name="test", conf_num=confs, conf_angle=angle) else: sub = Substituent(substituent_atoms, name=sub_name, conf_num=confs, conf_angle=angle) sub.comment = comment #align substituent bond to x axis sub.coord_shift(-avoid.coords) x_axis = np.array([1., 0., 0.]) n = np.linalg.norm(start.coords) vb = start.coords / n d = np.linalg.norm(vb - x_axis) theta = np.arccos((d**2 - 2) / -2) vx = np.cross(vb, x_axis) sub.rotate(vx, theta) add = False if len(sub_name) == 0: chimerax_sub = ResidueCollection(sub).get_chimera(self.session) chimerax_sub.name = "substituent preview" self.session.models.add([chimerax_sub]) bild_obj = ghost_connection_highlight( sub, [0.60784, 0.145098, 0.70196, 0.5], self.session) self.session.models.add(bild_obj, parent=chimerax_sub) else: check_aaronlib_dir() filename = os.path.join(AARONLIB, "Subs", sub_name + ".xyz") if os.path.exists(filename): exists_warning = QMessageBox() exists_warning.setIcon(QMessageBox.Warning) exists_warning.setText( "%s already exists.\nWould you like to overwrite?" % filename) exists_warning.setStandardButtons(QMessageBox.Yes | QMessageBox.No) rv = exists_warning.exec_() if rv == QMessageBox.Yes: add = True else: self.tool_window.status( "%s has not been added to substituent library" % sub_name) else: add = True if add: sub.write(outfile=filename) self.tool_window.status("%s added to substituent library" % sub_name) register_selectors(self.session.logger, sub_name) if self.session.ui.is_gui: if (sub_name not in ELEMENTS and sub_name[0].isalpha() and (len(sub_name) > 1 and not any(not (c.isalnum() or c in "+-") for c in sub_name[1:]))): add_submenu = self.session.ui.main_window.add_select_submenu add_selector = self.session.ui.main_window.add_menu_selector substituent_menu = add_submenu(['Che&mistry'], 'Substituents') add_selector(substituent_menu, sub_name, sub_name)
def libadd_ligand(self): """add ligand to library or open it in a new model""" selection = selected_atoms(self.session) if not selection.single_structure: raise RuntimeError("selected atoms must be on the same model") rescol = ResidueCollection(selection[0].structure) ligand_atoms = [ atom for atom in rescol.atoms if atom.chix_atom in selection ] key_chix_atoms = [ atom for atom in self.key_atomspec if not atom.deleted ] if len(key_chix_atoms) < 1: key_atoms = set([]) for atom in ligand_atoms: for atom2 in atom.connected: if atom2 not in ligand_atoms: key_atoms.add(atom) else: key_atoms = rescol.find( [AtomSpec(atom.atomspec) for atom in key_chix_atoms]) if len(key_atoms) < 1: raise RuntimeError("no key atoms could be determined") lig_name = self.ligand_name.text() ligand = Component(ligand_atoms, name=lig_name, key_atoms=key_atoms) ligand.comment = "K:%s" % ",".join( [str(ligand.atoms.index(atom) + 1) for atom in key_atoms]) if len(lig_name) == 0: chimerax_ligand = ResidueCollection(ligand).get_chimera( self.session) chimerax_ligand.name = "ligand preview" self.session.models.add([chimerax_ligand]) bild_obj = key_atom_highlight(ligand, [0.2, 0.5, 0.8, 0.5], self.session) self.session.models.add(bild_obj, parent=chimerax_ligand) else: check_aaronlib_dir() filename = os.path.join(AARONLIB, "Ligands", lig_name + ".xyz") if os.path.exists(filename): exists_warning = QMessageBox() exists_warning.setIcon(QMessageBox.Warning) exists_warning.setText( "%s already exists.\nWould you like to overwrite?" % filename) exists_warning.setStandardButtons(QMessageBox.Yes | QMessageBox.No) rv = exists_warning.exec_() if rv == QMessageBox.Yes: ligand.write(outfile=filename) self.tool_window.status("%s added to ligand library" % lig_name) else: self.tool_window.status( "%s has not been added to ligand library" % lig_name) else: ligand.write(outfile=filename) self.tool_window.status("%s added to ligand library" % lig_name)