Beispiel #1
0
 def _thread_fun(self, queue, device, show_q):
     self.queue = queue
     self.show_q = show_q
     if self.use_buffer:
         self.input_buffer = {}
     try:
         self.setup_connections()
         self.start(device)
         if DEBUG:
             print(f"{self.name} starting...")
         try:
             while True:
                 try:
                     FPS.update(self.name)
                     if self.use_buffer:
                         self.consume_queue_data()
                     self.run()
                 except StopNodeException:
                     break
         finally:
             self.end(device)
     except Exception as e:
         traceback.print_exc()
         instance = self.getWrapper().canvasRef().pyFlowInstance
         threading.Thread(target=stop_pipeline, args=(instance, )).start()
         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()
Beispiel #2
0
    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
            )
Beispiel #3
0
def generic_warning(message):
    from Qt.QtWidgets import QMessageBox
    msg = QMessageBox()
    msg.setIcon(QMessageBox.Warning)
    msg.setText(message)
    msg.setStandardButtons(QMessageBox.Ok)
    msg.exec_()
Beispiel #4
0
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
Beispiel #5
0
    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)
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 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 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_()
Beispiel #10
0
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
Beispiel #11
0
 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()
Beispiel #12
0
    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
Beispiel #13
0
 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()
Beispiel #14
0
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
Beispiel #15
0
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
Beispiel #16
0
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
Beispiel #17
0
    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)
Beispiel #18
0
    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)