コード例 #1
0
def extensions_gui(parent=None):
    from pymol.Qt import QtCore, QtGui, QtWidgets
    from pymol.Qt.utils import PopupOnException
    Qt = QtCore.Qt

    def connectItemChangedDec(func):
        def wrapper(self, *args, **kwargs):
            try:
                self.model.itemChanged.disconnect()
            except Exception as e:
                pass

            try:
                return func(self, *args, **kwargs)
            finally:
                self.model.itemChanged.connect(self.itemChanged)

        return wrapper

    class PyMOLExtensionsHelper(QtWidgets.QWidget):
        def __init__(self):
            QtWidgets.QWidget.__init__(self, parent, Qt.Window)
            self.setMinimumSize(400, 500)
            self.setWindowTitle('Register File Extensions')

            self.model = QtGui.QStandardItemModel(self)

            layout = QtWidgets.QVBoxLayout(self)
            self.setLayout(layout)

            label = QtWidgets.QLabel(
                "Select file types to register them with PyMOL", self)
            layout.addWidget(label)

            alluserslayout = QtWidgets.QHBoxLayout()
            alluserslayout.setObjectName("alluserslayout")
            layout.addLayout(alluserslayout)

            buttonlayout = QtWidgets.QHBoxLayout()
            buttonlayout.setObjectName("buttonlayout")
            layout.addLayout(buttonlayout)

            self.table = QtWidgets.QTableView(self)
            self.table.setModel(self.model)
            layout.addWidget(self.table)

            button = QtWidgets.QPushButton("Register Recommended (*)", self)
            buttonlayout.addWidget(button)
            button.pressed.connect(self.setRecommended)

            button = QtWidgets.QPushButton("Register All", self)
            buttonlayout.addWidget(button)
            button.pressed.connect(self.setAll)

            button = QtWidgets.QPushButton("Clear", self)
            button.setToolTip("Clean up Registry")
            buttonlayout.addWidget(button)
            button.pressed.connect(self.clear)

            if isAdmin():
                r0 = QtWidgets.QRadioButton("Only for me")
                r0.setToolTip("HKEY_CURRENT_USER registry branch")
                r0.setChecked(True)
                r1 = QtWidgets.QRadioButton("For all users")
                r1.setToolTip("HKEY_LOCAL_MACHINE registry branch")
                allusersgroup = QtWidgets.QButtonGroup(self)
                allusersgroup.addButton(r0)
                allusersgroup.addButton(r1)
                allusersgroup.buttonClicked.connect(self.populateData)
                alluserslayout.addWidget(r0)
                alluserslayout.addWidget(r1)
                alluserslayout.addStretch()
                self.allusersbutton = r1
            else:
                self.allusersbutton = None

            self.finalize_timer = QtCore.QTimer()
            self.finalize_timer.setSingleShot(True)
            self.finalize_timer.setInterval(500)
            self.finalize_timer.timeout.connect(finalize)

            self.populateData()

            # keep reference to window, otherwise Qt will auto-close it
            self._self_ref = self

        def closeEvent(self, event):
            self._self_ref = None
            super(PyMOLExtensionsHelper, self).closeEvent(event)

        def allusers(self):
            if self.allusersbutton is None:
                return False
            return self.allusersbutton.isChecked()

        @connectItemChangedDec
        def populateData(self, _button=None):
            """
            Fill the model with data from PyMOL
            """
            QSI = QtGui.QStandardItem  # For brevity
            cmd = get_cmd()

            self.model.clear()

            for ext in sorted(extensions):
                name_item = QSI(ext.upper())
                name_item.setFlags(Qt.ItemIsEnabled)

                desc_item = QSI(
                    descriptions.get(
                        ext, descriptions.get(ext_get_primary(ext), '')))

                desc_item.setFlags(Qt.ItemIsEnabled)

                recom_item = QSI('*' if extensions[ext] else '')
                recom_item.setFlags(Qt.ItemIsEnabled)

                value_item = QSI()
                value_item.setData(ext)
                value_item.setCheckable(True)
                value_item.setEditable(False)  # Can't edit text (but toggles)
                if check_file_association(ext, cmd, self.allusers()):
                    value_item.setCheckState(Qt.Checked)

                self.model.appendRow(
                    [value_item, name_item, desc_item, recom_item])

            self.formatTable()

        def setAll(self):
            for i in range(len(extensions)):
                item = self.model.item(i)
                item.setCheckState(Qt.Checked)

            self.finalize_timer.start()

        def setRecommended(self):
            for i in range(len(extensions)):
                item = self.model.item(i)
                ext = self.itemGetData(item)
                if extensions[ext]:
                    item.setCheckState(Qt.Checked)

            self.finalize_timer.start()

        @PopupOnException.decorator
        @connectItemChangedDec
        def clear(self):
            for i in range(len(extensions)):
                item = self.model.item(i)
                item.setCheckState(Qt.Unchecked)

            cleanup(self.allusers())
            self.finalize_timer.start()

        def formatTable(self):
            """
            Set up the table to look appropriately
            """
            hh = self.table.horizontalHeader()
            hh.setVisible(False)
            hh.setSectionResizeMode(2, QtWidgets.QHeaderView.Stretch)
            self.table.verticalHeader().setVisible(False)
            self.table.resizeColumnsToContents()

        def itemGetData(self, item):
            try:
                return item.data().toString()
            except AttributeError:  # PySide not PyQT, different QVariant handling
                return item.data()

        @PopupOnException.decorator
        def itemChanged(self, item):
            ext = self.itemGetData(item)

            if item.checkState() == Qt.Checked:
                register_extensions([ext], self.allusers())
            else:
                unregister_extension(ext, self.allusers())

            self.finalize_timer.start()

    if QtWidgets.QApplication.instance() is None:
        app = QtWidgets.QApplication([])
    else:
        app = None

    w = PyMOLExtensionsHelper()
    w.show()

    if app is None:
        return w

    app.exec_()
コード例 #2
0

def _edit_pymolrc(app, _list=()):
    try:
        pymolrc = _list[0]
    except (TypeError, IndexError):
        if sys.platform.startswith('win'):
            pymolrc = os.path.expandvars(r'$HOMEDRIVE$HOMEPATH\pymolrc.pml')
        else:
            pymolrc = os.path.expandvars(r'$HOME/.pymolrc')

        pymolrc, ok = QtWidgets.QInputDialog.getText(
            None, 'Create new pymolrc?', 'Filename of new pymolrc',
            QtWidgets.QLineEdit.Normal, pymolrc)

        if not ok:
            return

    if pymolrc:
        TextEditor(None, pymolrc)


if __name__ == '__main__':
    try:
        filename = sys.argv[1]
    except:
        filename = ''
    app = QtWidgets.QApplication(['Test'])
    edit_pymolrc()
    app.exec_()
コード例 #3
0
ファイル: gui.py プロジェクト: Mechachleopteryx/fretraj
                'browser'] = self.settingsWindow.lineEdit_browser.text()
            self.settings[
                'local_docs'] = self.settingsWindow.lineEdit_localdocs.text()
            self.lineEdit_rootDirectory.setText(self.settings['root_path'])
            with open('{}/.fretraj_settings.conf'.format(package_directory),
                      'w') as f:
                json.dump(self.settings, f, indent=2)

    def openPDBFile(self):
        self.textWindow.textBrowser_pdbFile.setText(self.pdbText)
        self.textWindow.setWindowTitle("FRETraj - {}".format(
            self.fileName_pdb))
        isOK = self.textWindow.exec_()

    def openErrorWin(self, title, message):
        """
        Open Error Window
        """
        msg = QtWidgets.QMessageBox()
        msg.setIcon(QtWidgets.QMessageBox.Critical)
        msg.setWindowTitle(title)
        msg.setText(message)
        msg.exec_()


if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = App()
    window.show()
    app.exec_()