def failed_template_warning(residue): ''' Warning dialog handling the case where a template is not recognised by OpenMM when attempting to start a simulation. ''' from Qt.QtWidgets import QMessageBox, QPushButton msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msgtext = 'Residue {} {} of chain {} (shown) does not match any template'\ + ' in the molecular dynamics database. It may be missing atoms (have'\ + ' you added hydrogens?) or be an unusual residue that has not been'\ + ' parameterised. Choose what you wish to do with it from the options'\ + ' below.' msg.setText(msgtext.format(residue.name, residue.number, residue.chain_id)) addh = QPushButton('Add hydrogens and retry') msg.addButton(addh, QMessageBox.AcceptRole) exclude = QPushButton('Exclude residue from simulations and retry') msg.addButton(exclude, QMessageBox.RejectRole) abort = QPushButton('Abort') msg.addButton(abort, QMessageBox.NoRole) msg.exec_() btn = msg.clickedButton() # print("Button: {}".format(btn)) if btn == addh: return "addh" if btn == exclude: return "exclude" return "abort"
def get_save_permission(message, file_path=None, title='Permission', parent=None): """ Shows a save path message box :param message: str, message to show to the user :param file_path: str, path you want to save :param title: str, title of the window :param parent: QWidget :return: bool """ message_box = QMessageBox() message_box.setWindowTitle(title) flags = message_box.windowFlags( ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint if file_path: path_message = 'Path: {}'.format(file_path) message_box.setInformativeText(path_message) message_box.setWindowFlags(flags) save = message_box.addButton('Save', QMessageBox.YesRole) no_save = message_box.addButton('Do not save', QMessageBox.NoRole) cancel = message_box.addButton('Cancel', QMessageBox.RejectRole) message_box.exec_() if message_box.clickedButton() == save: return True elif message_box.clickedButton() == no_save: return False elif message_box.clickedButton() == cancel: return None return None
def generic_warning(message): from Qt.QtWidgets import QMessageBox msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setText(message) msg.setStandardButtons(QMessageBox.Ok) msg.exec_()
def handleAbout(self): """ Displays the About dialog """ about_box = QMessageBox() about_box.setText(__doc__) about_box.exec_()
def help_about(self): """About Hypnotoad""" about_text = __doc__.strip() about_text += f"\nVersion : {__version__}" about_box = QMessageBox(self) about_box.setText(about_text) about_box.exec_()
def handleAbout(self): """ Displays the About dialog """ about_box = QMessageBox() version_text = f"PyXPad version {version}\n\n" about_box.setText(version_text + __doc__.strip()) about_box.exec_()
def accept(self, *args, **kwargs): selected_file, selected_dir, selected_file_name = self.get_result() if not os.path.isdir(selected_file): if os.path.exists(selected_file): super(BaseOpenFileDialog, self).accept() else: message_box = QMessageBox() message_box.setWindowTitle('Confirme file selection') message_box.setText( 'File "{0}" does not exists!'.format(selected_file)) message_box.exec_()
def show_info_dialog(self, msg, title='Info'): """ Shows a info dialog :param msg: str, message to show with the dialog :param title: str, title of the dialog """ dialog = QMessageBox() dialog.setIcon(QMessageBox.Information) dialog.setWindowTitle(title) dialog.setText(msg) dialog.exec_()
class PopUpWarning(Error): """ display a popup error box with a custom message """ def __init__(self, _msg): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Warning") self.msg_box.setIcon(QMessageBox.Warning) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText(_msg) self.msg_box.exec_()
class SidNotValid(Error): """ Raised when the file can't be open """ def __init__(self): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Error") self.msg_box.setIcon(QMessageBox.Warning) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText("Sid not valid") self.msg_box.exec_()
class NoSelectionError(Error): """ Raised when the user don't select a file needed """ def __init__(self): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Error") self.msg_box.setIcon(QMessageBox.Critical) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText("Select a file !") self.msg_box.exec_()
class Error(Exception): """ Basic exeption class """ def __init__(self, msg): self.msg_box = QMessageBox() self.msg_box.setWindowFlags(self.msg_box.windowFlags() | QtCore.Qt.WindowStaysOnTopHint) self.msg_box.setWindowTitle("Error") self.msg_box.setIcon(QMessageBox.Critical) self.msg_box.setStandardButtons(QMessageBox.Ok) self.msg_box.setText(msg) self.msg_box.exec_()
def save(self): if not config.HAVE_PYEVTK: msg = QMessageBox(QMessageBox.Critical, 'Error', 'VTK output disabled. Pleas install pyvtk.') msg.exec_() return filename = QFileDialog.getSaveFileName(self, 'Save as vtk file')[0] base_name = filename.split('.vtu')[0].split('.vtk')[0].split('.pvd')[0] if base_name: if len(self.U) == 1: write_vtk(self.grid, NumpyVectorSpace.make_array(self.U[0]), base_name, codim=self.codim) else: for i, u in enumerate(self.U): write_vtk(self.grid, NumpyVectorSpace.make_array(u), f'{base_name}-{i}', codim=self.codim)
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 info_message(message, parent=None): """ Shows a warning message :param message: str :param parent: QWidget """ parent = None message_box = QMessageBox(parent) flags = message_box.windowFlags( ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint message_box.setWindowFlags(flags) message_box.setText(message) message_box.exec_()
def save(self): if not config.HAVE_PYVTK: msg = QMessageBox(QMessageBox.Critical, 'Error', 'VTK output disabled. Pleas install pyvtk.') msg.exec_() return filename = QFileDialog.getSaveFileName(self, 'Save as vtk file')[0] base_name = filename.split('.vtu')[0].split('.vtk')[0].split('.pvd')[0] if base_name: if len(self.U) == 1: write_vtk(self.grid, NumpyVectorSpace.make_array(self.U[0]), base_name, codim=self.codim) else: for i, u in enumerate(self.U): write_vtk(self.grid, NumpyVectorSpace.make_array(u), '{}-{}'.format(base_name, i), codim=self.codim)
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 get_permission(message=None, cancel=True, title='Permission', parent=None): """ Shows a permission message box :param message: str, message to show to the user :param cancel: bool, Whether the user can cancel the operation or not :param title: str, title of the window :param parent: QWidget :return: bool """ message_box = QMessageBox() message_box.setWindowTitle(title) flags = message_box.windowFlags( ) ^ Qt.WindowContextHelpButtonHint | Qt.WindowStaysOnTopHint if message: message_box.setText(message) if cancel: message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel) else: message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) message_box.setWindowFlags(flags) result = message_box.exec_() if result == QMessageBox.Yes: return True elif result == QMessageBox.No: return False elif result == QMessageBox.Cancel: return None return None
def on_featurePermissionRequested(self, securityOrigin, feature): if feature != QWebEnginePage.Geolocation: return mgsbox = QMessageBox(self) mgsbox.setAttribute(Qt.WA_DeleteOnClose) mgsbox.setText( self.tr("{} wants to know your location".format(securityOrigin.host())) ) mgsbox.setInformativeText( self.tr("Do you want to send your current location to this website?") ) mgsbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No) mgsbox.setDefaultButton(QMessageBox.Yes) page = self.m_view.page() if mgsbox.exec_() == QMessageBox.Yes: page.setFeaturePermission( securityOrigin, feature, QWebEnginePage.PermissionGrantedByUser ) else: page.setFeaturePermission( securityOrigin, feature, QWebEnginePage.PermissionDeniedByUser )
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 libadd_ring(self): """add ring to library or open it in a new model""" selection = self.session.seqcrow_ordered_selection_manager.selection if not selection.single_structure: raise RuntimeError("selected atoms must be on the same model") rescol = ResidueCollection(selection[0].structure) walk_atoms = rescol.find( [AtomSpec(atom.atomspec) for atom in selection]) if len(walk_atoms) < 1: raise RuntimeError("no walk direction could be determined") ring_name = self.ring_name.text() ring = Ring(rescol, name=ring_name, end=walk_atoms) ring.comment = "E:%s" % ",".join( [str(rescol.atoms.index(atom) + 1) for atom in walk_atoms]) if len(ring_name) == 0: chimerax_ring = ResidueCollection(ring).get_chimera(self.session) chimerax_ring.name = "ring preview" self.session.models.add([chimerax_ring]) bild_obj = show_walk_highlight(ring, chimerax_ring, [0.9, 0.4, 0.3, 0.9], self.session) self.session.models.add(bild_obj, parent=chimerax_ring) else: check_aaronlib_dir() filename = os.path.join(AARONLIB, "Rings", ring_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: ring.write(outfile=filename) self.tool_window.status("%s added to ring library" % ring_name) else: self.tool_window.status( "%s has not been added to ring library" % ring_name) else: ring.write(outfile=filename) self.tool_window.status("%s added to ring library" % ring_name)
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 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 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 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 msgbox(message, detail=None): msgbox = QMessageBox() msgbox.setText(message) if detail: msgbox.setDetailedText(detail) return msgbox.exec_()
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)