Ejemplo n.º 1
0
    def file_run(self):
        formats = [
            'All Runnable (*.pml *.py *.pym)',
            'PyMOL Command Script (*.pml)',
            'PyMOL Command Script (*.txt)',
            'Python Script (*.py *.pym)',
            'Python Script (*.txt)',
            'All Files(*)',
        ]
        fnames, selectedfilter = getOpenFileNames(
            self, 'Open file', self.initialdir, filter=';;'.join(formats))
        is_py = selectedfilter.startswith('Python')

        with PopupOnException():
            for fname in fnames:
                self.initialdir = os.path.dirname(fname)
                self.cmd.cd(self.initialdir, quiet=0)
                # detect: .py, .pym, .pyc, .pyo, .py.txt
                if is_py or re.search(r'\.py(|m|c|o|\.txt)$', fname, re.I):
                    self.cmd.run(fname)
                else:
                    self.cmd.do("@" + fname)
Ejemplo n.º 2
0
 def run_copy_clipboard():
     with PopupOnException():
         _copy_image(self.cmd, False, form.input_dpi.currentText())
Ejemplo n.º 3
0
    def item_changed(item, column):
        """
        Edits current item.
        """

        if item_changed.skip:
            return

        model = form.input_model.currentText()
        state = form.input_state.value()
        key = item.text(0)
        new_value = item.text(1)
        parent = item.parent()

        result = False
        if item is item_object_ttt:
            try:
                if new_value:
                    result = cmd.set_object_ttt(model, new_value)
            except (ValueError, IndexError):
                result = False
        elif item is item_ostate_title:
            result = cmd.set_title(model, state, new_value)
        elif item is item_ostate_matrix:
            cmd.matrix_reset(model, state)
            try:
                new_value = cmd.safe_eval(new_value)
                result = cmd.transform_object(model, new_value, state)
            except:  # CmdTransformObject-DEBUG: bad matrix
                result = False
        elif parent is item_object_settings:
            with PopupOnException():
                cmd.set(key, new_value, model, quiet=0)
        elif parent is item_ostate_settings:
            with PopupOnException():
                cmd.set(key, new_value, model, state, quiet=0)
        elif parent is item_ostate_properties:
            cmd.set_property(key, new_value, model, state, quiet=0)
        else:
            is_state = False

            if parent is item_atom_properties:
                key = 'p.' + key
            elif parent is item_atom_settings:
                key = 's.' + key
            elif parent is item_astate_settings:
                key = 's.' + key
                is_state = True
            elif key in keys_astate_builtins:
                is_state = True

            def get_new_value(old_value):
                if isinstance(old_value, (tuple, list, bool)):
                    return cmd.safe_eval(new_value)

                try:
                    # cast to old type (required for e.g. 'resv = "3"')
                    if isinstance(old_value, int):
                        return int(new_value, 0)
                    return type(old_value)(new_value)
                except ValueError:
                    # return str and let PyMOL handle it (e.g. change
                    # type of user property)
                    return new_value.encode('utf-8')

            alter_args = ('pk1', key + '= get_new_value(' + key + ')', 0, {
                'get_new_value': get_new_value
            })

            with PopupOnException():
                if is_state:
                    result = cmd.alter_state(state, *alter_args)
                else:
                    result = cmd.alter(*alter_args)

        if not result:
            update_treewidget_model()