Пример #1
0
    def initUI(self):

        self.setWindowTitle('PyMod Directory Selection')

        self.vertical_layout = QtWidgets.QVBoxLayout()

        # Main label.
        self.label = QtWidgets.QLabel(
            "Select a folder inside which to build the 'PyMod Directory'",
            self)
        self.vertical_layout.addWidget(self.label)

        # Entry and "Browse" button.
        self.horizontal_layout = QtWidgets.QHBoxLayout()

        self.main_entry = QtWidgets.QLineEdit(self.pymod.home_directory, self)
        self.main_entry.setStyleSheet("background-color: white; color: black")
        self.horizontal_layout.addWidget(self.main_entry)

        self.browse_button = QtWidgets.QPushButton("BROWSE", self)
        self.browse_button.clicked.connect(self.pymod_directory_browse_state)
        self.horizontal_layout.addWidget(self.browse_button)

        self.vertical_layout.addLayout(self.horizontal_layout)

        # "Submit" button.
        self.submit_button = QtWidgets.QPushButton("SUBMIT", self)
        self.submit_button.setFixedWidth(self.submit_button.sizeHint().width())
        self.submit_button.clicked.connect(self.on_submit_button_press)
        self.vertical_layout.addWidget(self.submit_button)
        self.vertical_layout.setAlignment(self.submit_button,
                                          QtCore.Qt.AlignCenter)

        # Set the layouts.
        self.setLayout(self.vertical_layout)
    def _build_table_elements(self, parent):
        '''
        Create the various elements in the table and add them to the
        proper layout.
        '''
        self.setWindowTitle('Scene Panel')
        layout = QtWidgets.QVBoxLayout(self)
        self.setLayout(layout)

        top_layout = QtWidgets.QGridLayout()
        layout.addLayout(top_layout)
        mid_layout = QtWidgets.QGridLayout()
        layout.addLayout(mid_layout)
        low_layout = QtWidgets.QGridLayout()
        layout.addLayout(low_layout)

        # Top Elements
        self.instructionLabel = QtWidgets.QLabel(self)
        self.instructionLabel.setText(
            'Double click selected thumbnail to \nload into Workspace.')
        top_layout.addWidget(self.instructionLabel, 0, 0)

        self.addSceneButton = QtWidgets.QPushButton(self)
        self.addSceneButton.setText('Add Scene')
        top_layout.addWidget(self.addSceneButton, 0, 1)

        # Mid Elements
        self.sceneTableWidget = QtWidgets.QTableWidget(self)
        mid_layout.addWidget(self.sceneTableWidget, 0, 0)
        self.sceneTableWidget.viewport().installEventFilter(self)

        self.sceneTableWidget.itemChanged.connect(self._item_changed)
        self.sceneTableWidget.selectionModel().selectionChanged.connect(
            self._selection_changed)
        self.sceneTableWidget.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.sceneTableWidget.verticalHeader().setSectionsMovable(True)

        # Lower Buttom Elements
        self.deleteButton = QtWidgets.QPushButton(self)
        self.deleteButton.setText("Delete Scene")
        low_layout.addWidget(self.deleteButton, 0, 1)
        self.deleteButton.setEnabled(False)

        self.updateButton = QtWidgets.QPushButton(self)
        self.updateButton.setText("Update Scene")
        low_layout.addWidget(self.updateButton, 0, 0)
        self.updateButton.setEnabled(False)
Пример #3
0
    def create_label_row(self):
        """
        Row with two labels and a "Remove" button.
        """

        # Create a first residue label that tells which residue has been selected.
        self.res1_label = QtWidgets.QLabel(self.text1)
        self.res1_label.setStyleSheet(small_font_style)
        self.res1_label.setAlignment(QtCore.Qt.AlignCenter)
        self.parent.loop_selector_frame_layout.addWidget(
            self.res1_label, self.row, 0)

        # Second residue label.
        self.res2_label = QtWidgets.QLabel(self.text2)
        self.res2_label.setStyleSheet(small_font_style)
        self.res2_label.setAlignment(QtCore.Qt.AlignCenter)
        self.parent.loop_selector_frame_layout.addWidget(
            self.res2_label, self.row, 1)

        # Adds the "Remove" button.
        self.remove_loop_button = QtWidgets.QPushButton("Remove")
        self.remove_loop_button.setStyleSheet(small_font_style)
        self.remove_loop_button.clicked.connect(self.press_remove_button)
        self.parent.loop_selector_frame_layout.addWidget(
            self.remove_loop_button, self.row, 2)
Пример #4
0
    def __init__(self, label_text="Input", buttons=[]):
        PyMod_form_item.__init__(self)

        # Label.
        self.label = QtWidgets.QLabel(label_text)

        # Buttons.
        self.input = QtWidgets.QVBoxLayout()

        if not buttons:
            raise ValueError("Please provide a list of button names")
        if len(buttons) != len(set(buttons)):
            raise ValueError("Please provide a non redundant list of buttons")

        self.button_group = QtWidgets.QButtonGroup()
        self.buttons_names = []
        self.buttons_dict = {}

        for button_name in buttons:
            button = QtWidgets.QPushButton(button_name)
            button.setCheckable(True)
            self.input.addWidget(button)
            self.buttons_names.append(button_name)
            self.buttons_dict[button_name] = button
            self.button_group.addButton(button)
Пример #5
0
    def initUI(self):

        self.setWindowTitle(self.title)

        vertical_layout = QtWidgets.QVBoxLayout()
        self.thread_progressbar = QtWidgets.QProgressBar(self)
        if self.progress:
            self.thread_progressbar.setMinimum(0)
            self.thread_progressbar.setMaximum(0)
        progressbar_label = "Computing..."  # "Wait for the protocol to complete."
        self.thread_progressbar.setFormat(progressbar_label)
        self.thread_progressbar.setValue(0)
        vertical_layout.addWidget(self.thread_progressbar)

        self.thread_progress_label = QtWidgets.QLabel(self.label_text, self)
        self.thread_progress_label.setWordWrap(True)
        vertical_layout.addWidget(self.thread_progress_label)

        # Button for canceling the execution of the thread.
        horizontal_layout = QtWidgets.QHBoxLayout()
        self.cancel_button = QtWidgets.QPushButton('Cancel', self)
        self.cancel_button.clicked.connect(self.on_cancel_button_click)
        self.cancel_button.setEnabled(not self.lock)
        horizontal_layout.addWidget(self.cancel_button)

        vertical_layout.addLayout(horizontal_layout)

        self.setLayout(vertical_layout)
Пример #6
0
 def show_advanced_button(self):
     self.advance_options_button = QtWidgets.QPushButton(
         "Show Advanced Options")
     self.advance_options_button.clicked.connect(
         self.toggle_advanced_options)
     self._advanced_options_label = QtWidgets.QLabel("")
     self.middle_formlayout.addRow(self.advance_options_button,
                                   self._advanced_options_label)
Пример #7
0
    def initUI(self):

        self.setWindowTitle('Import PDB Options')

        vertical_layout = QtWidgets.QVBoxLayout()

        # Installation options label.
        info_text = "Please select the 3D structure import mode:"
        self.fetch_info_label = QtWidgets.QLabel(info_text, self)
        # self.fetch_info_label.setStyleSheet(label_style_1)
        vertical_layout.addWidget(self.fetch_info_label)

        vertical_layout.addStretch(1)

        # Import options radiobuttons.
        horizontal_layout = QtWidgets.QHBoxLayout()

        self.import_all_radiobutton = QtWidgets.QRadioButton(
            "Import in PyMod the structure of every chain of the PDB files.")
        # self.import_all_radiobutton.setChecked(True)
        # self.import_all_radiobutton.setStyleSheet(label_font_1)
        vertical_layout.addWidget(self.import_all_radiobutton)
        self.import_fragment_radiobutton = QtWidgets.QRadioButton(
            "Import in PyMod only the structure of the hit sequences fragments."
        )
        # label_font_1
        self.import_fragment_radiobutton.setStyleSheet("margin-bottom: 10px")
        vertical_layout.addWidget(self.import_fragment_radiobutton)

        # Import fragments button.
        self.import_button = QtWidgets.QPushButton("Import 3D Structures",
                                                   self)
        # self.import_button.setStyleSheet(label_style_2)
        self.import_button.clicked.connect(self.on_import_button_click)
        horizontal_layout.addWidget(self.import_button)

        horizontal_layout.addStretch(1)

        # Cancel button.
        self.cancel_button = QtWidgets.QPushButton('Cancel', self)
        # self.cancel_button.setStyleSheet(label_style_2)
        self.cancel_button.clicked.connect(self.on_cancel_button_click)
        horizontal_layout.addWidget(self.cancel_button)

        vertical_layout.addLayout(horizontal_layout)
        self.setLayout(vertical_layout)
Пример #8
0
def makeFragmentButton():
    btn = QtWidgets.QPushButton()
    btn.setAttribute(Qt.WA_LayoutUsesWidgetRect) # OS X workaround
    btn.setSizePolicy(
            QtWidgets.QSizePolicy.Minimum,
            QtWidgets.QSizePolicy.MinimumExpanding)
    btn.setAutoDefault(False)
    return btn
Пример #9
0
    def __init__(self, widget, window=None, name='', _self=None):

        if window:
            window.setWindowTitle(name + ' - Volume Color Map Editor')

        cmd = _self

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

        widget.editor = VolumeEditorWidget(widget, name, _self)
        layout.addWidget(widget.editor)
        layout.setContentsMargins(5, 5, 5, 5)
        get_colors_btn = QtWidgets.QPushButton("Get colors as script")
        get_colors_btn.setAutoDefault(False)
        get_colors_btn.clicked.connect(widget.editor.displayScript)
        help_btn = QtWidgets.QPushButton("Help")
        help_btn.setAutoDefault(False)
        help_btn.clicked.connect(widget.editor.displayHelp)
        reset_btn = QtWidgets.QPushButton("Reset Data Range")
        reset_btn.setAutoDefault(False)
        reset_btn.clicked.connect(widget.editor.reset)
        widget.editor.update_cb = QtWidgets.QCheckBox(
            "Update volume colors in real-time")
        widget.editor.update_cb.setObjectName("volume_checkbox")
        widget.editor.update_cb.setChecked(True)
        widget.editor.update_cb.setMinimumWidth(30)
        widget.editor.update_cb.toggled.connect(
            widget.editor.toggleRealTimeUpdates)

        button_layout = QtWidgets.QHBoxLayout()
        button_layout.addWidget(get_colors_btn)
        button_layout.addWidget(reset_btn)
        button_layout.addWidget(help_btn)
        button_layout.addStretch()
        button_layout.addWidget(widget.editor.update_cb)

        layout.addLayout(button_layout)

        histogram = cmd.get_volume_histogram(name)
        widget.editor.setHistogram(histogram)

        colors = cmd.volume_color(name)
        widget.editor.setColors(colors)
Пример #10
0
def create_dialog():
    dialog = QtWidgets.QDialog()
    dialog.setWindowTitle('AlignIt Pymol plugin')
    layout = QtWidgets.QVBoxLayout(dialog)
    alignit = AlignItPlugin()
    actions = {
        'Read pharmacophore...': lambda: alignit.readAlignIt(dialog),
    }

    for name, action in actions.items():
        btn = QtWidgets.QPushButton(name, dialog)
        btn.pressed.connect(action)
        layout.addWidget(btn)

    return dialog
Пример #11
0
    def __init__(self,
                 button_text="Submit",
                 button_command=None,
                 *args,
                 **kwargs):
        PyMod_entryfield_qt.__init__(self, *args, **kwargs)

        self.input = QtWidgets.QHBoxLayout()
        self.input.addWidget(self.entry)

        # Adds a button.
        self.button = QtWidgets.QPushButton(button_text)
        self.input.addWidget(self.button)
        self.button.setFixedWidth(self.button.sizeHint().width())
        self.button_command = button_command
        if self.button_command is not None:
            self.button.clicked.connect(self.button_command)
Пример #12
0
    def create_combobox_row(self):
        """
        Builds a row with two comboboxes an "Add" button for defining a loop.
        """

        # First residue combobox.
        self.res1_combobox = QtWidgets.QComboBox(
        )  # Select the starting residue:
        for item in self.scrollable_res_list:
            self.res1_combobox.addItem(item)
        self.res1_combobox.setEditable(False)
        self.res1_combobox.setStyleSheet(small_font_style)
        self.res1_combobox.setFixedWidth(
            self.res1_combobox.sizeHint().width() + self.combobox_padding)

        # Second residue combobox.
        self.res2_combobox = QtWidgets.QComboBox(
        )  # Select the ending residue:
        for item in self.scrollable_res_list:
            self.res2_combobox.addItem(item)
        self.res2_combobox.setEditable(False)
        self.res2_combobox.setStyleSheet(small_font_style)
        self.res2_combobox.setFixedWidth(
            self.res2_combobox.sizeHint().width() + self.combobox_padding)

        # "Add" button.
        self.new_loop_button = QtWidgets.QPushButton("Add")
        self.new_loop_button.setStyleSheet(small_font_style)
        self.new_loop_button.clicked.connect(self.press_add_button)
        self.new_loop_button.setFixedWidth(
            self.new_loop_button.sizeHint().width() + self.button_padding)

        self.parent.loop_selector_frame_layout.addWidget(
            self.res1_combobox, self.row, 0)
        self.parent.loop_selector_frame_layout.addWidget(
            self.res2_combobox, self.row, 1)
        self.parent.loop_selector_frame_layout.addWidget(
            self.new_loop_button, self.row, 2)

        User_loop_combo_qt.id_counter += 1
Пример #13
0
    def __init__(self):  # noqa
        QtWidgets.QMainWindow.__init__(self)
        self.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks
                            | QtWidgets.QMainWindow.AllowNestedDocks)

        # resize Window before it is shown
        options = pymol.invocation.options
        self.resize(options.win_x + (220 if options.internal_gui else 0),
                    options.win_y + (246 if options.external_gui else 18))

        # for thread-safe viewport command
        self.viewportsignal.connect(self.pymolviewport)

        # reusable dialogs
        self.dialog_png = None
        self.advanced_settings_dialog = None
        self.props_dialog = None
        self.builder = None

        # setting index -> callable
        self.setting_callbacks = defaultdict(list)

        # "session_file" setting in window title
        self.setting_callbacks[440].append(lambda v: self.setWindowTitle(
            "PyMOL (" + os.path.basename(v) + ")"))

        # "External" Command Line and Loggin Widget
        self._setup_history()
        self.lineedit = CommandLineEdit()
        self.lineedit.setObjectName("command_line")
        self.browser = QtWidgets.QPlainTextEdit()
        self.browser.setObjectName("feedback_browser")
        self.browser.setReadOnly(True)

        # convenience: clicking into feedback browser gives focus to command
        # line. Drawback: Copying with CTRL+C doesn't work in feedback
        # browser -> clear focus proxy while text selected
        self.browser.setFocusProxy(self.lineedit)

        @self.browser.copyAvailable.connect
        def _(yes):
            self.browser.setFocusProxy(None if yes else self.lineedit)
            self.browser.setFocus()

        # Font
        self.browser.setFont(getMonospaceFont())
        connectFontContextMenu(self.browser)

        lineeditlayout = QtWidgets.QHBoxLayout()
        command_label = QtWidgets.QLabel("PyMOL>")
        command_label.setObjectName("command_label")
        lineeditlayout.addWidget(command_label)
        lineeditlayout.addWidget(self.lineedit)
        self.lineedit.setToolTip('''Command Input Area

Get the list of commands by hitting <TAB>

Get the list of arguments for one command with a question mark:
PyMOL> color ?

Read the online help for a command with "help":
PyMOL> help color

Get autocompletion for many arguments by hitting <TAB>
PyMOL> color ye<TAB>    (will autocomplete "yellow")
''')

        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self.browser)
        layout.addLayout(lineeditlayout)

        quickbuttonslayout = QtWidgets.QVBoxLayout()
        quickbuttonslayout.setSpacing(2)

        extguilayout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.LeftToRight)
        extguilayout.setContentsMargins(2, 2, 2, 2)
        extguilayout.addLayout(layout)
        extguilayout.addLayout(quickbuttonslayout)

        class ExtGuiFrame(QtWidgets.QFrame):
            def mouseDoubleClickEvent(_, event):
                self.toggle_ext_window_dockable(True)

            _size_hint = QtCore.QSize(options.win_x, options.ext_y)

            def sizeHint(self):
                return self._size_hint

        dockWidgetContents = ExtGuiFrame(self)
        dockWidgetContents.setLayout(extguilayout)
        dockWidgetContents.setObjectName("extgui")

        self.ext_window = \
            dockWidget = QtWidgets.QDockWidget(self)
        dockWidget.setWindowTitle("External GUI")
        dockWidget.setWidget(dockWidgetContents)
        if options.external_gui:
            dockWidget.setTitleBarWidget(QtWidgets.QWidget())
        else:
            dockWidget.hide()

        self.addDockWidget(Qt.TopDockWidgetArea, dockWidget)

        # rearrange vertically if docking left or right
        @dockWidget.dockLocationChanged.connect
        def _(area):
            if area == Qt.LeftDockWidgetArea or area == Qt.RightDockWidgetArea:
                extguilayout.setDirection(QtWidgets.QBoxLayout.BottomToTop)
                quickbuttonslayout.takeAt(quickbuttons_stretch_index)
            else:
                extguilayout.setDirection(QtWidgets.QBoxLayout.LeftToRight)
                if quickbuttons_stretch_index >= quickbuttonslayout.count():
                    quickbuttonslayout.addStretch()

        # OpenGL Widget
        self.pymolwidget = PyMOLGLWidget(self)
        self.setCentralWidget(self.pymolwidget)

        cmd = self.cmd = self.pymolwidget.cmd
        '''
        # command completion
        completer = QtWidgets.QCompleter(cmd.kwhash.keywords, self)
        self.lineedit.setCompleter(completer)
        '''

        # overload <Tab> action
        self.lineedit.installEventFilter(self)
        self.pymolwidget.installEventFilter(self)

        # Quick Buttons
        for row in [
            [
                ('Reset', cmd.reset),
                ('Zoom', lambda: cmd.zoom(animate=1.0)),
                ('Orient', lambda: cmd.orient(animate=1.0)),

                # render dialog will be constructed when the menu is shown
                # for the first time. This way it's populated with the current
                # viewport and settings. Also defers parsing of the ui file.
                ('Draw/Ray', WidgetMenu(self).setSetupUi(self.render_dialog)),
            ],
            [
                ('Unpick', cmd.unpick),
                ('Deselect', cmd.deselect),
                ('Rock', cmd.rock),
                ('Get View', self.get_view),
            ],
            [
                ('|<', cmd.rewind),
                ('<', cmd.backward),
                ('Stop', cmd.mstop),
                ('Play', cmd.mplay),
                ('>', cmd.forward),
                ('>|', cmd.ending),
                ('MClear', cmd.mclear),
            ],
            [
                ('Builder', self.open_builder_panel),
                ('Properties', self.open_props_dialog),
                ('Rebuild', cmd.rebuild),
            ],
        ]:
            hbox = QtWidgets.QHBoxLayout()
            hbox.setSpacing(2)

            for name, callback in row:
                btn = QtWidgets.QPushButton(name)
                btn.setProperty("quickbutton", True)
                btn.setAttribute(Qt.WA_LayoutUsesWidgetRect)  # OS X workaround
                hbox.addWidget(btn)

                if callback is None:
                    btn.setEnabled(False)
                elif isinstance(callback, QtWidgets.QMenu):
                    btn.setMenu(callback)
                else:
                    btn.released.connect(callback)

            quickbuttonslayout.addLayout(hbox)

        # progress bar
        hbox = QtWidgets.QHBoxLayout()
        self.progressbar = QtWidgets.QProgressBar()
        self.progressbar.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                       QtWidgets.QSizePolicy.Minimum)
        hbox.addWidget(self.progressbar)
        self.abortbutton = QtWidgets.QPushButton('Abort')
        self.abortbutton.setStyleSheet("background: #FF0000; color: #FFFFFF")
        self.abortbutton.released.connect(cmd.interrupt)
        hbox.addWidget(self.abortbutton)
        quickbuttonslayout.addLayout(hbox)

        quickbuttonslayout.addStretch()
        quickbuttons_stretch_index = quickbuttonslayout.count() - 1

        # menu top level
        self.menubar = menubar = self.menuBar()

        # action groups
        actiongroups = {}

        def _addmenu(data, menu):
            '''Fill a menu from "data"'''
            menu.setTearOffEnabled(True)
            menu.setWindowTitle(menu.title())  # needed for Windows
            for item in data:
                if item[0] == 'separator':
                    menu.addSeparator()
                elif item[0] == 'menu':
                    _addmenu(item[2], menu.addMenu(item[1].replace('&', '&&')))
                elif item[0] == 'command':
                    command = item[2]
                    if command is None:
                        print('warning: skipping', item)
                    else:
                        if isinstance(command, str):
                            command = lambda c=command: cmd.do(c)
                        menu.addAction(item[1], command)
                elif item[0] == 'check':
                    if len(item) > 4:
                        menu.addAction(
                            SettingAction(self, cmd, item[2], item[1], item[3],
                                          item[4]))
                    else:
                        menu.addAction(
                            SettingAction(self, cmd, item[2], item[1]))
                elif item[0] == 'radio':
                    label, name, value = item[1:4]
                    try:
                        group, type_, values = actiongroups[item[2]]
                    except KeyError:
                        group = QtWidgets.QActionGroup(self)
                        type_, values = cmd.get_setting_tuple(name)
                        actiongroups[item[2]] = group, type_, values
                    action = QtWidgets.QAction(label, self)
                    action.triggered.connect(lambda _=0, args=(name, value):
                                             cmd.set(*args, log=1, quiet=0))

                    self.setting_callbacks[cmd.setting._get_index(
                        name)].append(
                            lambda v, V=value, a=action: a.setChecked(v == V))

                    group.addAction(action)
                    menu.addAction(action)
                    action.setCheckable(True)
                    if values[0] == value:
                        action.setChecked(True)
                elif item[0] == 'open_recent_menu':
                    self.open_recent_menu = menu.addMenu('Open Recent...')
                else:
                    print('error:', item)

        # recent files menu
        self.open_recent_menu = None

        # for plugins
        self.menudict = {'': menubar}

        # menu
        for _, label, data in self.get_menudata(cmd):
            assert _ == 'menu'
            menu = menubar.addMenu(label)
            self.menudict[label] = menu
            _addmenu(data, menu)

        # hack for macOS to hide "Edit > Start Dictation"
        # https://bugreports.qt.io/browse/QTBUG-43217
        if pymol.IS_MACOS:
            self.menudict['Edit'].setTitle('Edit_')
            QtCore.QTimer.singleShot(
                10, lambda: self.menudict['Edit'].setTitle('Edit'))

        # recent files menu
        if self.open_recent_menu:

            @self.open_recent_menu.aboutToShow.connect
            def _():
                self.open_recent_menu.clear()
                for fname in self.recent_filenames:
                    self.open_recent_menu.addAction(
                        fname if len(fname) < 128 else '...' + fname[-120:],
                        lambda fname=fname: self.load_dialog(fname))

        # some experimental window control
        menu = self.menudict['Display'].addSeparator()
        menu = self.menudict['Display'].addMenu('External GUI')
        menu.addAction('Toggle floating', self.toggle_ext_window_dockable,
                       QtGui.QKeySequence('Ctrl+E'))
        ext_vis_action = self.ext_window.toggleViewAction()
        ext_vis_action.setText('Visible')
        menu.addAction(ext_vis_action)

        # extra key mappings (MacPyMOL compatible)
        QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+O'),
                            self).activated.connect(self.file_open)
        QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+S'),
                            self).activated.connect(self.session_save)

        # feedback
        self.feedback_timer = QtCore.QTimer()
        self.feedback_timer.setSingleShot(True)
        self.feedback_timer.timeout.connect(self.update_feedback)
        self.feedback_timer.start(100)

        # legacy plugin system
        self.menudict['Plugin'].addAction('Initialize Plugin System',
                                          self.initializePlugins)

        # focus in command line
        if options.external_gui:
            self.lineedit.setFocus()
        else:
            self.pymolwidget.setFocus()

        # Apply PyMOL stylesheet
        try:
            with open(
                    cmd.exp_path('$PYMOL_DATA/pmg_qt/styles/pymol.sty')) as f:
                style = f.read()
        except IOError:
            print('Could not read PyMOL stylesheet.')
            print('DEBUG: PYMOL_DATA=' + repr(os.getenv('PYMOL_DATA')))
            style = ""

        if style:
            self.setStyleSheet(style)
Пример #14
0
def create_dialog():

    dialog = QtWidgets.QDialog()
    dialog.setWindowTitle('Lighting Settings')

    sliders = [
        "Diffuse Reflection",
        ('ambient', 0, 1, None),
        ('reflect', -1, 1, None),
        "Direct Light from Front",
        ('direct (+reflect)', -1, 1, None),  # diffuse, coupled with "reflect"
        ('spec_direct', 0, 1, None),
        ('spec_direct_power', 0, 100, 1),
        "Free placeable directed Lights",
        ('light_count', 1, 8, 1),
        ('edit_light', 1, 7, 1),
        "Specular Reflection",
        ('spec_count', -1, 8, 1),
        # ('spec_power', -1, 200, 1), # deprecated since v1.5
        ('shininess', 0, 100, None),  # same as spec_power
        ('spec_reflect', -0.01, 1, None),
        ('specular', 0, 1, None),
        ('specular_intensity (=specular)', 0, 1, None),  # same as specular
        "Ambient Occlusion (Surface only)",
        ('ambient_occlusion_mode', 0, 2, 1),
        ('ambient_occlusion_scale', 1.0, 50., None),
        ('ambient_occlusion_smooth', 1, 20, 1),
        "Ray trace only",
        ('power', 1, 10, None),
        ('reflect_power', 1, 10, None),
    ]

    layout = QtWidgets.QVBoxLayout(dialog)

    button_layout = QtWidgets.QHBoxLayout()
    layout.addLayout(button_layout)
    layout.setContentsMargins(5, 0, 5, 0)
    button_layout.addWidget(
        QtWidgets.QLabel("<font color=red>Presets:</font>"))

    presets = [
        ("Default", preset_default),
        ("Metal", preset_metal),
        ("Plastic", preset_plastic),
        ("Rubber", preset_rubber),
        ("X-Ray", preset_xray),
    ]

    for name, fun in presets:
        btn = QtWidgets.QPushButton(name, dialog)
        btn.pressed.connect(fun)
        btn.setAutoDefault(False)
        button_layout.addWidget(btn)

    form_layout = QtWidgets.QFormLayout()
    form_layout.setContentsMargins(0, 0, 0, 0)
    form_layout.setVerticalSpacing(0)
    form_layout.setLabelAlignment(Qt.AlignLeft)
    layout.addLayout(form_layout)

    for i, item in enumerate(sliders, 1):
        if isinstance(item, str):
            label = QtWidgets.QLabel("<font color=blue>" + item + "</font>")
            form_layout.addRow(label)
            continue

        name, min, max, res = item
        if res is None:
            res = 0.01 if (max - min < 100) else 0.1

        line_edit = QtWidgets.QLineEdit(dialog)
        slider = SettingSlider(dialog,
                               name.split()[0], min, max, res, line_edit)

        h_layout = QtWidgets.QHBoxLayout()
        h_layout.addWidget(slider, 3)
        h_layout.addWidget(line_edit, 1)

        form_layout.addRow(name, h_layout)

    return dialog
Пример #15
0
    def __init__(self, parent=None):
        super(SurfStampFrame, self).__init__(parent)

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

        glayout1 = QtWidgets.QGridLayout()
        self.label_message = QtWidgets.QLabel(self)
        self.label_message.setText("SurfStamp PyMOL plugin")
        self.layout.addWidget(self.label_message)

        self.combo_model = QtWidgets.QComboBox()
        self.combo_model.addItems([])
        self.layout.addWidget(self.combo_model)

        self.label_reso = QtWidgets.QLabel(self)
        self.label_reso.setText("Surface Resolution")
        glayout1.addWidget(self.label_reso, 1, 0)
        self.spin_reso = QtWidgets.QDoubleSpinBox(self)
        self.spin_reso.setRange(0.1, 1.0)
        self.spin_reso.setSingleStep(0.05)
        self.spin_reso.setValue(0.7)
        glayout1.addWidget(self.spin_reso, 1, 1)

        self.label_imagesize = QtWidgets.QLabel(self)
        self.label_imagesize.setText("Image Size")
        glayout1.addWidget(self.label_imagesize, 2, 0)
        self.spin_imagesize = QtWidgets.QSpinBox(self)
        self.spin_imagesize.setRange(1000, 10000)
        #PILLOW?は 13000 くらいが Max っぽい
        self.spin_imagesize.setSingleStep(100)
        self.spin_imagesize.setValue(4000)
        glayout1.addWidget(self.spin_imagesize, 2, 1)

        self.label_fontsize = QtWidgets.QLabel(self)
        self.label_fontsize.setText("Font Size")
        glayout1.addWidget(self.label_fontsize, 3, 0)
        self.spin_fontsize = QtWidgets.QSpinBox(self)
        self.spin_fontsize.setRange(3, 100)
        self.spin_fontsize.setSingleStep(1)
        self.spin_fontsize.setValue(20)
        glayout1.addWidget(self.spin_fontsize, 3, 1)

        glayout2 = QtWidgets.QGridLayout()
        self.check_outline = QtWidgets.QCheckBox('Outline')
        self.check_outline.setChecked(True)
        glayout2.addWidget(self.check_outline, 0, 0)

        self.check_nowater = QtWidgets.QCheckBox('Remove Waters')
        self.check_nowater.setChecked(True)
        glayout2.addWidget(self.check_nowater, 0, 1)

        self.check_colorall = QtWidgets.QCheckBox('Color All')
        self.check_colorall.setChecked(False)
        glayout2.addWidget(self.check_colorall, 1, 0)

        self.check_tile = QtWidgets.QCheckBox('Repeating Tile')

        self.check_tile.clicked.connect(self.checkTileOn)
        self.check_tile.setChecked(False)
        glayout2.addWidget(self.check_tile, 1, 1)

        self.check_oneletter = QtWidgets.QCheckBox('One Letter')
        glayout2.addWidget(self.check_oneletter, 2, 0)

        self.check_nochainname = QtWidgets.QCheckBox('No Chain Name')
        glayout2.addWidget(self.check_nochainname, 2, 1)

        self.check_ignore_occupancy = QtWidgets.QCheckBox('Ignore Occupancy')
        glayout2.addWidget(self.check_ignore_occupancy, 3, 0)
        self.check_cartoon = QtWidgets.QCheckBox('Cartoon')
        self.check_cartoon.clicked.connect(self.checkCartoonOn)
        glayout2.addWidget(self.check_cartoon, 3, 1)

        self.check_mmcif = QtWidgets.QCheckBox('Use MMCIF')
        glayout2.addWidget(self.check_mmcif, 4, 0)

        self.check_builtin = QtWidgets.QCheckBox('Built-in Surface Generator')
        glayout2.addWidget(self.check_builtin, 4, 1)
        self.check_builtin.clicked.connect(self.checkBuiltinOn)

        #MMCIF は AUTH が不完全だ!
        #self.check_label = QtWidgets.QCheckBox('ID Label');
        #self.layout.addWidget(self.check_label);

        # Text field for output file
        glayout4 = QtWidgets.QVBoxLayout()

        self.label_outprefix = QtWidgets.QLabel(
            'Output Prefix (Prefix+<something> will be overwritten.)')
        glayout4.addWidget(self.label_outprefix)

        glayout4b = QtWidgets.QGridLayout()
        self.text_outprefix = QtWidgets.QLineEdit(self)
        self.text_outprefix.setReadOnly(True)
        glayout4b.addWidget(self.text_outprefix, 0, 0)

        self.button_outprefix = QtWidgets.QPushButton(self)
        self.button_outprefix.setText("Save As")

        self.button_outprefix.clicked.connect(self.getFile)
        self.text_outprefix.setStyleSheet("background-color: lightgray;")

        glayout4b.addWidget(self.button_outprefix, 0, 1)
        glayout4.addLayout(glayout4b)

        glayout3 = QtWidgets.QGridLayout()
        self.button_ok = QtWidgets.QPushButton('Create')
        self.button_ok.clicked.connect(self.runSurfStamp)
        glayout3.addWidget(self.button_ok, 0, 0)

        self.button_close = QtWidgets.QPushButton('Close')
        self.button_close.clicked.connect(self.hide)
        glayout3.addWidget(self.button_close, 0, 1)

        self.layout.addLayout(glayout1)
        self.layout.addLayout(glayout2)
        self.layout.addLayout(glayout4)
        self.layout.addLayout(glayout3)

        screengeom = QtWidgets.qApp.desktop().screenGeometry()

        wwidth = 300
        hheight = 200
        self.setGeometry(screengeom.width() / 2 - wwidth / 2,
                         screengeom.height() / 2 - hheight / 2, wwidth,
                         hheight)
        self.setWindowTitle('SurfStamp')
        self.checkTileOn()
        self.checkBuiltinOn()
        self.checkCartoonOn()
        self.show()
Пример #16
0
    def initialize_map(self,
                       pymod,
                       data_array,
                       pymod_elements,
                       ref_residues,
                       ref_selectors,
                       title=None,
                       pixel_size=5,
                       feature_type="contact",
                       threshold=8.0,
                       interaction_center="ca"):

        # Sets the attributes.
        self.data_array = data_array
        self.pixel_size = pixel_size
        self.feature_type = feature_type
        self.threshold = threshold
        self.interaction_center = interaction_center
        if self.feature_type in ("contact", "distance"):
            self.pymod_elements = pymod_elements
            self.pymod_element = self.pymod_elements[0]
        else:
            self.pymod_elements = pymod_elements
        # Get the PyMod residues for each residue having an interaction center and the PyMOL selectors
        # for each residue.
        self.ref_residues = ref_residues
        self.ref_selectors = ref_selectors

        # Assign the methods to get the labels.
        if self.feature_type == "contact":
            self.get_value_label = self._get_value_label_contact
        elif self.feature_type == "distance":
            self.get_value_label = self._get_value_label_distance
        elif self.feature_type == "distances_difference":
            self.get_value_label = self._get_value_label_distance_diff
        elif self.feature_type == "distances_mean":
            self.get_value_label = self._get_value_label_distance_mean
        elif self.feature_type == "distances_std":
            self.get_value_label = self._get_value_label_distance_std
        else:
            raise KeyError(self.feature_type)

        # Set the canvas size.
        min_size = 150
        h = self.pixel_size * len(self.data_array)
        win_size = min((910, h))
        win_size = max((min_size, win_size))

        if title:
            self.setWindowTitle(title)

        # Set some appearance parameters.
        self.controls_padding = 4
        if self.feature_type in ("contact", "distance"):
            self.controls_font = "helvetica 11 bold"
        else:
            self.controls_font = "helvetica 10 bold"
        self.controls_config = {
            "fg": "black",
            "font": self.controls_font,
            "padx": self.controls_padding,
            "pady": self.controls_padding
        }
        self.labels_pack_config = {
            "side": "left",
            "pady": (0, 5),
            "padx": (5, 0)
        }
        self.buttons_pack_config = {
            "side": "left",
            "pady": (0, 5),
            "padx": (1, 0)
        }

        # Frame of the window containing a row for some control buttons, a row for
        # the plot and a row for a messagebar.
        self.plot_frame = QtWidgets.QWidget()
        self.plot_frame_layout = QtWidgets.QGridLayout()
        self.plot_frame.setLayout(self.plot_frame_layout)
        self.setCentralWidget(self.plot_frame)

        # Control frame.
        self.controls_frame = QtWidgets.QWidget()
        self.controls_frame_layout = QtWidgets.QGridLayout()
        self.controls_frame.setLayout(self.controls_frame_layout)
        self.plot_frame_layout.addWidget(self.controls_frame)

        self.delete_distances_button = QtWidgets.QPushButton(
            "Delete all distances in PyMOL")
        self.delete_distances_button.setEnabled(False)
        self.delete_distances_button.clicked.connect(
            lambda a=None: self.clear_plot())
        self.controls_frame_layout.addWidget(self.delete_distances_button, 0,
                                             0)

        self.scale_factor = 0
        self.scale_down_button = QtWidgets.QPushButton("Zoom out")
        try:
            self.scale_down_button.setIcon(QtGui.QIcon.fromTheme("go-down"))
        except:
            pass
        self.scale_down_button.clicked.connect(
            lambda a=None: self.scale_plot_down())
        self.controls_frame_layout.addWidget(self.scale_down_button, 0, 1)

        self.scale_up_button = QtWidgets.QPushButton("Zoom in")
        try:
            self.scale_up_button.setIcon(QtGui.QIcon.fromTheme("go-up"))
        except:
            pass
        self.scale_up_button.clicked.connect(
            lambda a=None: self.scale_plot_up())
        self.controls_frame_layout.addWidget(self.scale_up_button, 0, 2)

        self.controls_frame_layout.setAlignment(QtCore.Qt.AlignLeft)

        # Frame containing the plot (with a scrollbar).
        self.canvas_plot_frame = QtWidgets.QWidget()
        self.canvas_plot_frame.setStyleSheet("background-color: white")
        self.canvas_plot_frame_layout = QtWidgets.QGridLayout()
        self.canvas_plot_frame.setLayout(self.canvas_plot_frame_layout)

        self.canvas_plot_scrollarea = QtWidgets.QScrollArea()
        self.canvas_plot_scrollarea.setWidgetResizable(True)
        self.canvas_plot_scrollarea.setWidget(self.canvas_plot_frame)
        self.plot_frame_layout.addWidget(self.canvas_plot_scrollarea)

        # Builds the scene where to draw the contact map.
        self.canvas_plot_scene = QtWidgets.QGraphicsScene()
        # Builds the graphics view containing the scene above.
        self.canvas_plot_view = Contact_map_graphics_view(
            self.canvas_plot_scene)
        self.canvas_plot_frame_layout.addWidget(self.canvas_plot_view)

        # A bottom frame fo the window, containing some buttons to interact with the graph.
        self.message_frame = QtWidgets.QFrame()
        self.message_frame_layout = QtWidgets.QHBoxLayout()
        self.message_frame.setLayout(self.message_frame_layout)
        self.plot_frame_layout.addWidget(self.message_frame)

        # Label to show which residue/position pair is currently being hovered by the mouse pointer.
        if self.feature_type in ("contact", "distance"):
            view_label_text = "Couple:"
        else:
            view_label_text = "Alignment positions:"
        self.view_label = QtWidgets.QLabel(view_label_text)
        # self.view_label.setStyleSheet(self.controls_config)
        self.message_frame_layout.addWidget(self.view_label)

        # Actually draws the contact map.
        self.draw_map()
Пример #17
0
    def initialize_plot(self, pymod, target_element, residues_tags, plot_title,
                        aa_list):

        self.pymod = pymod
        self.target_element = target_element
        self.residues_tags = residues_tags
        self.plot_title = plot_title
        self.setWindowTitle("%s Ramachandran Plot" %
                            self.target_element.my_header)
        self.aa_list = aa_list

        # Frame of the window containing a row for some control buttons, a row for
        # the plot and a row for a messagebar.
        self.plot_frame = QtWidgets.QWidget()
        self.plot_frame_layout = QtWidgets.QGridLayout()
        self.plot_frame.setLayout(self.plot_frame_layout)
        self.setCentralWidget(self.plot_frame)

        # Control frame.
        self.controls_frame = QtWidgets.QWidget()
        self.controls_frame_layout = QtWidgets.QGridLayout()
        self.controls_frame.setLayout(self.controls_frame_layout)
        self.plot_frame_layout.addWidget(self.controls_frame, 0, 0)

        self.scale_factor = 0
        self.scale_down_button = QtWidgets.QPushButton("Zoom out")
        try:
            self.scale_down_button.setIcon(QtGui.QIcon.fromTheme("go-down"))
        except:
            pass
        self.scale_down_button.clicked.connect(
            lambda a=None: self.scale_plot_down())
        self.controls_frame_layout.addWidget(self.scale_down_button, 0, 0)

        self.scale_up_button = QtWidgets.QPushButton("Zoom in")
        try:
            self.scale_up_button.setIcon(QtGui.QIcon.fromTheme("go-up"))
        except:
            pass
        self.scale_up_button.clicked.connect(
            lambda a=None: self.scale_plot_up())
        self.controls_frame_layout.addWidget(self.scale_up_button, 0, 1)

        self.controls_frame_layout.setAlignment(QtCore.Qt.AlignLeft)

        # Frame containing the plot (with a scrollbar).
        self.canvas_plot_frame = QtWidgets.QWidget()
        self.canvas_plot_frame.setStyleSheet("background-color: white")
        self.canvas_plot_frame_layout = QtWidgets.QGridLayout()
        self.canvas_plot_frame.setLayout(self.canvas_plot_frame_layout)

        self.canvas_plot_scrollarea = QtWidgets.QScrollArea()
        self.canvas_plot_scrollarea.setWidgetResizable(True)
        self.canvas_plot_scrollarea.setWidget(self.canvas_plot_frame)
        self.plot_frame_layout.addWidget(self.canvas_plot_scrollarea, 1, 0)

        self.default_pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 255), 1)
        self.default_brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 230))
        self.highlight_brush = QtGui.QBrush(QtGui.QColor(255, 0, 255))
        self.highlight_region_brush = QtGui.QBrush(QtGui.QColor(0, 255, 255))

        # Builds the scene where to draw the Ramachandran plot.
        self.canvas_plot_scene = QtWidgets.QGraphicsScene()
        # Builds the graphics view containing the scene above.
        self.canvas_plot_view = QtWidgets.QGraphicsView(self.canvas_plot_scene)
        self.canvas_plot_frame_layout.addWidget(self.canvas_plot_view)

        # A bottom frame fo the window, containing some buttons to interact with the graph.
        self.message_frame = QtWidgets.QFrame()
        self.message_frame_layout = QtWidgets.QFormLayout()
        self.message_frame.setLayout(self.message_frame_layout)
        self.plot_frame_layout.addWidget(self.message_frame, 1, 1)

        # Label to show which residue/position pair is currently being hovered by the mouse pointer.
        self.view_label_prefix = "Showing: "
        self.default_message = "Hover dots to color residues of the same type"  # Hover over title.
        self.message_label = QtWidgets.QLabel(self.default_message)
        self.message_label.setStyleSheet(small_font_style)
        self.message_frame_layout.addRow(self.message_label)

        # Actually draws the plot.
        self.draw_plot()

        # Shows some data about the type of residues and their dihedral angles.
        self.regions_labels_dict = {}
        tot_regular_res = float(self.residues_count["T"])

        label_params = [
            ("F", "Residues in the most favoured regions",
             "residues in most favoured regions", True, True),
            ("A", "Residues in additional allowed regions",
             "residues in additional allowed regions", True, True),
            ("G", "Residues in generously allowed regions",
             "residues in generously allowed regions", True, True),
            ("D", "Residues in disallowed regions",
             "residues in disallowed regions", True, True),
            ("T", "Non-gly and non-pro residues (circles)",
             "non-glycine and non-proline residues", True, True),
            ("end_res", "End-residues", "end residues", False, False),
            ("gly", "Gly residues (triangles)", "glycine residues", True,
             False),
            ("pro", "Pro residues (squares)", "proline residues", True, False),
            ("total", "Total number of residues", "all residues", True, False)
        ]
        for region, label, message, active, use_ratio in label_params:
            region_label = Ramachandran_plot_info_labels(
                label, message, region, active, self)
            region_label.setStyleSheet(small_font_style)
            if use_ratio:
                text = "%s (%s%%)" % (self.residues_count[region],
                                      round(
                                          self.residues_count[region] /
                                          tot_regular_res * 100, 1))
            else:
                text = str(self.residues_count[region])
            region_label_count = QtWidgets.QLabel(text)
            region_label_count.setStyleSheet(small_font_style)
            self.message_frame_layout.addRow(region_label, region_label_count)
            self.regions_labels_dict[region] = {
                "info": region_label,
                "data": region_label_count
            }
Пример #18
0
    def __init__(self, parent, protocol):

        super(Similarity_searches_results_window_qt, self).__init__(parent)
        self.protocol = protocol

        #########################
        # Configure the window. #
        #########################

        self.setWindowTitle(self._get_window_title())

        # Sets the central widget.
        self.central_widget = QtWidgets.QWidget()
        self.setCentralWidget(self.central_widget)

        # The window has a main vbox layout.
        self.main_vbox = QtWidgets.QVBoxLayout()


        ################
        # Upper frame. #
        ################

        title_text = self._get_upper_frame_title()

        self.upper_frame_title = QtWidgets.QLabel(title_text)
        self.main_vbox.addWidget(self.upper_frame_title)


        #################
        # Middle frame. #
        #################

        # Scroll area which contains the widgets, set as the centralWidget.
        self.middle_scroll = QtWidgets.QScrollArea()
        self.main_vbox.addWidget(self.middle_scroll)
        # Widget that contains the collection of Vertical Box.
        self.middle_widget = QtWidgets.QWidget()
        # Scroll area properties.
        self.middle_scroll.setWidgetResizable(True)
        self.middle_scroll.setWidget(self.middle_widget)

        # QFormLayout in the middle frame.
        self.middle_formlayout = QtWidgets.QFormLayout()
        self.middle_widget.setLayout(self.middle_formlayout)


        #-----------------
        # Buttons frame. -
        #-----------------

        # Set the frame and its layout.
        self.buttons_frame = QtWidgets.QFrame()
        self.middle_formlayout.addRow(self.buttons_frame)
        self.buttons_hbox = QtWidgets.QHBoxLayout()
        self.buttons_frame.setLayout(self.buttons_hbox)

        # Build the control buttons.
        self.blast_select_all_button = QtWidgets.QPushButton(text="Select All")
        self.blast_select_all_button.clicked.connect(self.blast_select_all)
        self.blast_select_none_button = QtWidgets.QPushButton(text="Select None")
        self.blast_select_none_button.clicked.connect(self.blast_select_none)
        self.blast_select_n_button = QtWidgets.QPushButton(text="Select Top:")
        self.blast_select_n_button.clicked.connect(self.blast_select_n)
        for button in [self.blast_select_all_button, self.blast_select_none_button, self.blast_select_n_button]:
            self.buttons_hbox.addWidget(button)

        # Build the line-edit for selecting only top entries.
        self.blast_select_n_enf = PyMod_entryfield_qt(label_text="", value="10",
                                                      validate={'validator': 'integer',
                                                                'min': 1, 'max': 5000})
        self.blast_select_n_enf.entry.setFixedWidth(70)
        self.buttons_hbox.addWidget(self.blast_select_n_enf.entry)

        # Align to the left all these widgets.
        self.buttons_hbox.setAlignment(QtCore.Qt.AlignLeft)
        for button in [self.blast_select_all_button, self.blast_select_none_button, self.blast_select_n_button]:
            button.setFixedWidth(button.sizeHint().width()+30)

        #-----------------
        # Results frame. -
        #-----------------

        # Set the frame and its layout.
        self.results_frame = QtWidgets.QFrame()
        self.middle_formlayout.addRow(self.results_frame)
        self.results_grid = QtWidgets.QGridLayout()
        self.results_frame.setLayout(self.results_grid)

        # Calls a method which actually displays the similarity searches results.
        self.display_blast_hits()

        # Align the gridded widgets to the left.
        self.results_grid.setAlignment(QtCore.Qt.AlignLeft)
        self.results_grid.setHorizontalSpacing(30)


        #################
        # Bottom frame. #
        #################

        self.main_button = QtWidgets.QPushButton("Submit")
        self.main_button.clicked.connect(lambda a=None: self.protocol.blast_results_state())
        self.main_vbox.addWidget(self.main_button)
        self.main_button.setFixedWidth(self.main_button.sizeHint().width())


        # Sets the main vertical layout.
        self.central_widget.setLayout(self.main_vbox)
        self.main_vbox.setAlignment(self.main_button, QtCore.Qt.AlignCenter)
Пример #19
0
    def setupUi(self, UpdateDialog):
        UpdateDialog.setObjectName("UpdateDialog")
        UpdateDialog.resize(950, 470)
        self.verticalLayout = QtWidgets.QVBoxLayout(UpdateDialog)
        self.verticalLayout.setObjectName("verticalLayout")
        self.select_comp_label = QtWidgets.QLabel(UpdateDialog)
        self.select_comp_label.setObjectName("select_comp_label")
        self.verticalLayout.addWidget(self.select_comp_label)
        self.components_tableWidget = QtWidgets.QTableWidget(UpdateDialog)
        default_font = QtGui.QFont()
        default_font.setPointSize(default_font.pointSize()-1)
        self.components_tableWidget.setFont(default_font)
        self.components_tableWidget.setProperty("showDropIndicator", False)
        self.components_tableWidget.setDragDropOverwriteMode(False)
        self.components_tableWidget.setAlternatingRowColors(True)
        self.components_tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        self.components_tableWidget.setGridStyle(QtCore.Qt.NoPen)
        self.components_tableWidget.setColumnCount(self.n_cols)
        self.components_tableWidget.setObjectName("components_tableWidget")
        self.components_tableWidget.setRowCount(1)
        vertical_header_item = QtWidgets.QTableWidgetItem()
        self.components_tableWidget.setVerticalHeaderItem(0, vertical_header_item)
        for i in range(self.n_cols):
            item = QtWidgets.QTableWidgetItem()
            self.components_tableWidget.setHorizontalHeaderItem(i, item)

        item = QtWidgets.QTableWidgetItem()
        self.components_tableWidget.setItem(0, self.component_col_idx, item)
        item = QtWidgets.QTableWidgetItem()
        self.components_tableWidget.setItem(0, self.databases_col_idx, item)
        self.components_tableWidget.horizontalHeader().setVisible(True)
        self.components_tableWidget.horizontalHeader().setCascadingSectionResizes(False)
        self.components_tableWidget.setColumnWidth(self.component_col_idx, 210)
        self.components_tableWidget.setColumnWidth(self.databases_col_idx, 180)
        self.components_tableWidget.setColumnWidth(self.status_col_idx, 190)
        # self.components_tableWidget.setColumnWidth(self.source_col_idx, 390)
        # self.components_tableWidget.setColumnWidth(self.last_download_col_idx, 250)

        self.components_tableWidget.horizontalHeader().setStretchLastSection(True)
        self.components_tableWidget.verticalHeader().setVisible(False)
        self.components_tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        self.verticalLayout.addWidget(self.components_tableWidget)
        self.statusLabel = QtWidgets.QLabel(UpdateDialog)
        self.statusLabel.setObjectName("statusLabel")
        self.verticalLayout.addWidget(self.statusLabel)
        self.installation_progressBar = QtWidgets.QProgressBar(UpdateDialog)
        self.installation_progressBar.setEnabled(True)
        self.installation_progressBar.setProperty("value", 10)
        self.installation_progressBar.setObjectName("installation_progressBar")
        self.verticalLayout.addWidget(self.installation_progressBar)
        self.buttonsHorizontalLayout = QtWidgets.QHBoxLayout()
        self.buttonsHorizontalLayout.setObjectName("buttonsHorizontalLayout")
        self.installSel_button = QtWidgets.QPushButton(UpdateDialog)
        self.installSel_button.setObjectName("installSel_button")
        self.buttonsHorizontalLayout.addWidget(self.installSel_button)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.buttonsHorizontalLayout.addItem(spacerItem)
        self.cancel_button = QtWidgets.QPushButton(UpdateDialog)
        self.cancel_button.setObjectName("cancel_button")
        self.buttonsHorizontalLayout.addWidget(self.cancel_button)
        self.verticalLayout.addLayout(self.buttonsHorizontalLayout)

        UpdateDialog.setWindowTitle("Install and update databases")
        self.select_comp_label.setText("Select components to install or update")
        self.components_tableWidget.setSortingEnabled(True)
        self.components_tableWidget.horizontalHeaderItem(self.component_col_idx).setText("Component")
        self.components_tableWidget.horizontalHeaderItem(self.databases_col_idx).setText("Databases Names")
        self.components_tableWidget.horizontalHeaderItem(self.status_col_idx).setText("Status")
        self.components_tableWidget.horizontalHeaderItem(self.source_col_idx).setText("Source")
        self.components_tableWidget.horizontalHeaderItem(self.last_download_col_idx).setText("Last Downloaded")
        __sortingEnabled = self.components_tableWidget.isSortingEnabled()
        self.components_tableWidget.setSortingEnabled(False)
        self.components_tableWidget.setSortingEnabled(__sortingEnabled)
        self.statusLabel.setText("")
        self.cancel_button.setText("Cancel")
        self.installSel_button.setText("Install Selected")

        QtCore.QMetaObject.connectSlotsByName(UpdateDialog)
Пример #20
0
    def display_paramenter_options(self, parameter):
        """
        Used to display a series of widgets to choose the parameter value in PyMod
        options window. This is conditioned on the type of input widget of the
        'parameter'.
        """

        # Label with the name of the parameter.
        param_full_name_label = QtWidgets.QLabel(parameter.full_name)
        self.middle_formlayout.addWidget(param_full_name_label,
                                         self.row_counter, 0)

        # Do not display any input widget.
        if parameter.widget_type is None:
            pass

        # Display any a text entry input.
        elif parameter.widget_type == "path_entryfield":

            # Entry for the path.
            path_entryfield = QtWidgets.QLineEdit(
                str(parameter.get_starting_value()))

            if parameter.editable:
                path_entryfield.setStyleSheet(active_entry_style + "; " +
                                              small_font_style)
            else:
                path_entryfield.setStyleSheet(inactive_entry_style + "; " +
                                              small_font_style)
                path_entryfield.setEnabled(False)

            self.middle_formlayout.addWidget(path_entryfield, self.row_counter,
                                             1)

            self.tools_params_dict[parameter.parent_tool.name][
                parameter.name] = path_entryfield

            # Button for browsing the path.
            if parameter.editable:
                path_browse_button = QtWidgets.QPushButton("Browse")
                path_browse_button.setStyleSheet(small_font_style)

                if parameter.path_type in ("file", "directory"):
                    path_browse_button.clicked.connect(
                        lambda a=None, p=parameter: self.choose_path(p))
                else:
                    raise KeyError("Unknown 'path_type': %s" %
                                   str(parameter.path_type))

                self.middle_formlayout.addWidget(path_browse_button,
                                                 self.row_counter, 2)

            # Button to automatically identifying the path.
            if parameter.auto_find:
                auto_find_button = QtWidgets.QPushButton("Auto Find")
                auto_find_button.setStyleSheet(small_font_style)
                self.middle_formlayout.addWidget(auto_find_button,
                                                 self.row_counter, 3)
                auto_find_button.clicked.connect(
                    lambda a=None, e=path_entryfield: parameter.
                    auto_find_command(e))

        # Show the status of a parameter.
        elif parameter.widget_type == "show_status":

            text_to_show, status = parameter.get_status()
            status_entryfield = QtWidgets.QLineEdit(text_to_show)
            if status:
                status_entryfield.setStyleSheet("background-color: %s" %
                                                success_bg_color)
            else:
                status_entryfield.setStyleSheet("background-color: %s" %
                                                failure_bg_color)
            status_entryfield.setEnabled(False)
            status_entryfield.setFixedWidth(200)

            self.middle_formlayout.addWidget(status_entryfield,
                                             self.row_counter, 1)

        else:
            raise KeyError("Unkown 'widget_type': %s" % parameter.widget_type)
Пример #21
0
    def __init__(
        self,
        parent,
        title="New PyMod Window",
        upper_frame_title="New PyMod Window Sub-title",
        submit_command=None,
        submit_button_text="Submit",
        with_scroll=True,
        # geometry=None
    ):

        super(PyMod_tool_window_qt, self).__init__(parent)

        #------------------------
        # Configure the window. -
        #------------------------

        # Command executed when pressing on the main button of the window.
        self.submit_command = submit_command

        # Configure the window.
        self.setWindowTitle(title)
        # if geometry is not None:
        #     self.setGeometry(*geometry)

        # Sets the central widget.
        self.central_widget = QtWidgets.QWidget()
        self.setCentralWidget(self.central_widget)

        # The window has a main vbox layout.
        self.main_vbox = QtWidgets.QVBoxLayout()

        #---------------
        # Upper frame. -
        #---------------

        self.upper_frame_title = QtWidgets.QLabel(upper_frame_title)
        self.main_vbox.addWidget(self.upper_frame_title)

        #----------------
        # Middle frame. -
        #----------------

        # Widget that contains the collection of Vertical Box.
        self.middle_widget = QtWidgets.QWidget()
        # The Vertical Box that contains other widgets to be displayed in the window.
        self.middle_vbox = QtWidgets.QVBoxLayout()
        self.middle_widget.setLayout(self.middle_vbox)

        # Scroll area which contains the widgets, set as the centralWidget.
        self.middle_scroll = QtWidgets.QScrollArea()

        # Scroll area properties.
        # self.middle_scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        # self.middle_scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.middle_scroll.setWidgetResizable(True)
        self.middle_scroll.setWidget(self.middle_widget)

        # QFormLayout in the middle frame.
        if self.middle_layout_type == "qform":
            self.middle_formlayout = PyMod_QFormLayout()
            self.middle_vbox.addLayout(self.middle_formlayout)
        elif self.middle_layout_type == "qgrid":
            self.middle_formlayout = QtWidgets.QGridLayout()
            self.middle_vbox.addLayout(self.middle_formlayout)
        else:
            raise KeyError("Unknown 'middle_layout_type': %s" %
                           middle_layout_type)

        self.add_middle_frame_widgets()

        self.main_vbox.addWidget(self.middle_scroll)

        #----------------
        # Bottom frame. -
        #----------------

        self.submit_command = submit_command
        if self.submit_command is not None:
            self.main_button = QtWidgets.QPushButton(submit_button_text)
            self.main_button.clicked.connect(
                lambda a=None: self.submit_command())
            self.main_vbox.addWidget(self.main_button)
            self.main_button.setFixedWidth(self.main_button.sizeHint().width())

        # Sets the main vertical layout.
        self.central_widget.setLayout(self.main_vbox)
        self.main_vbox.setAlignment(self.main_button, QtCore.Qt.AlignCenter)
Пример #22
0
        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
Пример #23
0
    def __init__(self, parent, protocol):

        super(Hmmscan_results_window_qt, self).__init__(parent)
        self.protocol = protocol

        self.query_len = len(
            self.protocol.query_element.my_sequence.replace('-', ''))

        #########################
        # Configure the window. #
        #########################

        self.setWindowTitle("HMMSCAN Results")

        # Sets the central widget.
        self.central_widget = QtWidgets.QWidget()
        self.setCentralWidget(self.central_widget)

        # The window has a main vbox layout.
        self.main_vbox = QtWidgets.QVBoxLayout()

        # Parameters used to draw the 'QGraphicsView' widgets for showing domains.
        self.preferred_size_policy = QtWidgets.QSizePolicy(
            QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        self.view_bg_color = "transparent"
        self.full_seq_pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 0), 2)
        self.full_seq_color = "#7f7f7f"
        qcolor = QtGui.QColor(0, 0, 0)
        qcolor.setNamedColor(self.full_seq_color)
        self.full_seq_brush = QtGui.QBrush(qcolor)
        self.font_qcolor = QtGui.QColor(220, 220, 220, 255)
        self.font_size = 7

        ################
        # Upper frame. #
        ################

        self.upper_frame = QtWidgets.QFrame()
        self.upper_frame_layout = QtWidgets.QGridLayout()
        self.upper_frame.setLayout(self.upper_frame_layout)
        self.main_vbox.addWidget(self.upper_frame)

        if 'query_descr' in self.protocol.parsed_res[
                0] and self.protocol.parsed_res[0]['query_descr']:
            labelseq = self.protocol.query_element.my_header  # + '\n' + querydescr
        else:
            try:
                if len(self.protocol.query_element.description) > 79:
                    labelseq = self.protocol.query_element.description[:78] + '...'
                else:
                    labelseq = self.protocol.query_element.description
            except TypeError:
                labelseq = self.protocol.query_element.my_header

        self.upper_frame_title = QtWidgets.QLabel(
            "HMMSCAN search results for " + labelseq)
        self.upper_frame_layout.addWidget(self.upper_frame_title)

        #-------------------------
        # Domain graphics frame. -
        #-------------------------

        # Builds the scene where to draw the domain representations.
        self.canvas_plot_scene = QtWidgets.QGraphicsScene()
        self.canvas_plot_view = QtWidgets.QGraphicsView(self.canvas_plot_scene)
        self.canvas_plot_view.setFixedHeight(120)
        self.canvas_plot_view.setSizePolicy(self.preferred_size_policy)
        self.canvas_plot_view.setStyleSheet("background: %s" %
                                            self.view_bg_color)
        self.upper_frame_layout.addWidget(self.canvas_plot_view)

        # Draw a rectangle with the full sequence.
        self.x_init = 10
        y_init = 95  # 95
        self.domain_y_init = y_init - 7
        self.full_seq_rect_w = 800
        full_seq_rect_h = 10
        self.canvas_plot_scene.addRect(self.x_init, y_init,
                                       self.full_seq_rect_w, full_seq_rect_h,
                                       self.full_seq_pen, self.full_seq_brush)

        # Draw the labels for the N- and C-terminal residues.
        text_offset_y = 15
        text_offset_x = 10
        text_n = self.canvas_plot_scene.addText("1")
        text_n.setPos(self.x_init - text_offset_x, y_init + text_offset_y)
        text_n.setDefaultTextColor(self.font_qcolor)
        text_n.setFont(QtGui.QFont(text_n.font().family(), self.font_size))

        c_label = str(self.query_len)
        text_c = self.canvas_plot_scene.addText(c_label)
        text_offset_x_add = 5
        if len(c_label) > 2:
            text_offset_x_add = 10
        text_c.setPos(
            self.x_init + self.full_seq_rect_w - text_offset_x -
            text_offset_x_add, y_init + text_offset_y)
        text_c.setDefaultTextColor(self.font_qcolor)
        text_c.setFont(QtGui.QFont(text_c.font().family(), self.font_size))

        #################
        # Middle frame. #
        #################

        # Scroll area which contains the widgets, set as the centralWidget.
        self.middle_scroll = QtWidgets.QScrollArea()
        self.main_vbox.addWidget(self.middle_scroll)
        # Widget that contains the collection of Vertical Box.
        self.middle_widget = QtWidgets.QWidget()
        # Scroll area properties.
        self.middle_scroll.setWidgetResizable(True)
        self.middle_scroll.setWidget(self.middle_widget)

        # QFormLayout in the middle frame.
        self.middle_formlayout = QtWidgets.QFormLayout()
        self.middle_widget.setLayout(self.middle_formlayout)

        #-----------------
        # Results frame. -
        #-----------------

        # Set the frame and its layout.
        self.results_frame = QtWidgets.QFrame()
        self.middle_formlayout.addRow(self.results_frame)
        self.results_grid = QtWidgets.QGridLayout()
        self.results_frame.setLayout(self.results_grid)

        # Calls a method which actually displays the similarity searches results.
        self.display_hmmscan_hits()

        # Align the gridded widgets to the left.
        self.results_grid.setAlignment(QtCore.Qt.AlignLeft)
        self.results_grid.setHorizontalSpacing(30)

        #################
        # Bottom frame. #
        #################

        self.main_button = QtWidgets.QPushButton("Submit")
        self.main_button.clicked.connect(
            lambda a=None: self.protocol.hmmer_results_state())
        self.main_vbox.addWidget(self.main_button)
        self.main_button.setFixedWidth(self.main_button.sizeHint().width())

        # Sets the main vertical layout.
        self.central_widget.setLayout(self.main_vbox)
        self.main_vbox.setAlignment(self.main_button, QtCore.Qt.AlignCenter)
Пример #24
0
    def __init__(self, *args, **kwargs):

        super(PyMod_plot_window_qt, self).__init__(*args, **kwargs)

        # Central widget.
        self.central_widget = QtWidgets.QWidget()
        self.setCentralWidget(self.central_widget)
        self.central_widget_layout = QtWidgets.QGridLayout()
        self.central_widget.setLayout(self.central_widget_layout)


        #------------------------------------------------
        # Upper frame (contains the plot and controls). -
        #------------------------------------------------

        expanding_size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                                      QtWidgets.QSizePolicy.Expanding)

        preferred_size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                                      QtWidgets.QSizePolicy.Preferred)

        # The upper frame contains three frames: info, plot and controls frames.
        # The infor and controls frames will be displayed only if the 'use_controls'
        # argument is set to 'True' when calling the 'build_plotting_area' method.
        self.upper_frame = QtWidgets.QFrame()
        self.upper_frame.setStyleSheet("background-color: #646464")
        self.upper_frame_layout = QtWidgets.QGridLayout()
        self.upper_frame.setLayout(self.upper_frame_layout)
        self.upper_frame.setSizePolicy(expanding_size_policy)
        self.central_widget_layout.addWidget(self.upper_frame, 0, 0)

        # Info frame, it contains the messagebar of the plot.
        self.info_frame = QtWidgets.QFrame()
        self.info_frame_layout = QtWidgets.QHBoxLayout()
        self.info_frame.setLayout(self.info_frame_layout)
        self.info_frame.setSizePolicy(preferred_size_policy)

        self.info_label = QtWidgets.QLabel("")
        self.info_frame_layout.addWidget(self.info_label)

        # Plot frame.
        self.plot_frame = QtWidgets.QFrame()
        # self.plot_frame.setStyleSheet("background-color: red")
        self.plot_frame_layout = QtWidgets.QGridLayout()
        self.plot_frame.setLayout(self.plot_frame_layout)
        self.plot_frame.setSizePolicy(expanding_size_policy)
        self.build_plot_widget()


        # Controls frame.
        self.controls_frame = QtWidgets.QWidget()
        self.controls_frame.setStyleSheet("background-color: #747474")
        self.controls_frame_layout = QtWidgets.QGridLayout()
        self.controls_frame.setLayout(self.controls_frame_layout)
        self.controls_frame_layout.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)

        self.controls_scrollarea = QtWidgets.QScrollArea()
        self.controls_scrollarea.setWidgetResizable(True)
        self.controls_scrollarea.setWidget(self.controls_frame)

        self.labels_title = QtWidgets.QLabel("Plots list")


        # Middle splitter.
        self.middle_splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
        self.middle_splitter.setSizePolicy(expanding_size_policy)


        #---------------------------------------
        # Lower frame (contains some options). -
        #---------------------------------------

        self.lower_frame = QtWidgets.QFrame()
        self.lower_frame_layout = QtWidgets.QGridLayout()
        self.lower_frame.setLayout(self.lower_frame_layout)
        self.central_widget_layout.addWidget(self.lower_frame, 1, 0)

        # View buttons.
        self.view_label = QtWidgets.QLabel("View:")
        self.lower_frame_layout.addWidget(self.view_label, 0, 0)

        self.home_view_button = QtWidgets.QPushButton("Fit to data")
        self.home_view_button.clicked.connect(self.on_home_button_click)
        self.lower_frame_layout.addWidget(self.home_view_button, 0, 1)

        # On click behaviour. The buttons will be shown later, in the
        # 'build_plotting_area' metohd.
        self.interact_buttons_group = QtWidgets.QButtonGroup()

        self.on_click_label = QtWidgets.QLabel("Interact on click:")

        self.interact_button = QtWidgets.QPushButton("Yes")
        self.interact_button.setCheckable(True)
        self.interact_buttons_group.addButton(self.interact_button)
        self.interact_button.clicked.connect(self.on_interact_button_click)

        self.no_interaction_button = QtWidgets.QPushButton("No")
        self.no_interaction_button.setCheckable(True)
        self.no_interaction_button.setChecked(True)
        self.interact_buttons_group.addButton(self.no_interaction_button)
        self.no_interaction_button.clicked.connect(self.on_no_interaction_button_click)


        # Show/hide all buttons. They will be shown later, in the 'build_plotting_area'
        # method.
        self.show_label = QtWidgets.QLabel("Show:")

        self.show_all_button = QtWidgets.QPushButton("All")
        self.show_all_button.clicked.connect(self.show_all_command)

        self.hide_all_button = QtWidgets.QPushButton("None")
        self.hide_all_button.clicked.connect(self.hide_all_command)

        self.lower_frame_layout.setAlignment(QtCore.Qt.AlignLeft)


        #---------------------
        # Build a main menu. -
        #---------------------

        self.save_to_csv_action = QtWidgets.QAction('Save to CSV', self)
        self.save_to_csv_action.triggered.connect(lambda a=None: self.save_to_csv_event())
        self.save_to_png_action = QtWidgets.QAction('Save to PNG', self)
        self.save_to_png_action.triggered.connect(lambda a=None: self.save_to_png_event())

        self.main_menubar = self.menuBar()
        self.file_menu = self.main_menubar.addMenu('File')
    def build_panel_elements(self, parent):
        '''
        Responsible for creating all panel elements in order and adding them to the layout.
        '''
        self.create_new_form = parent.load_form("create_shortcut", None)
        self.help_form = parent.load_form("help_shortcut", None)
        self.confirm_change = parent.load_form("change_confirm", None)

        self.model = QtGui.QStandardItemModel(self)
        self.proxy_model = QtCoreModels.QSortFilterProxyModel(self)
        self.proxy_model.setSourceModel(self.model)
        self.proxy_model.setFilterCaseSensitivity(Qt.CaseInsensitive)
        self.proxy_model.setFilterKeyColumn(-1)

        self.setWindowTitle('Keyboard Shortcut Menu')
        layout = QtWidgets.QVBoxLayout(self)
        self.setLayout(layout)

        # Create layout for filter bar and refresh button
        top_layout = QtWidgets.QGridLayout()
        layout.addLayout(top_layout)

        # Filter
        self.filter_le = QtWidgets.QLineEdit(self)
        top_layout.addWidget(self.filter_le)
        self.filter_le.setPlaceholderText("Filter")
        self.filter_le.textChanged.connect(self.proxy_model.setFilterRegExp)

        self.refresh_button = QtWidgets.QPushButton(self)
        self.refresh_button.resize(26, 26)
        top_layout.addWidget(self.refresh_button, 0, 1)
        # themed icons only available by default on X11
        if self.refresh_button.icon().isNull():
            self.refresh_button.setIcon(QtGui.QIcon(
                os.path.expandvars('$PYMOL_DATA/pmg_qt/icons/refresh.svg')))
        self.refresh_button.setToolTip(
            "Refresh the table to reflect any external changes")
        self.refresh_button.clicked.connect(self.refresh_populate)

        # Table
        self.table = QtWidgets.QTableView(self)
        self.table.setModel(self.proxy_model)
        layout.addWidget(self.table)
        self.intial_populate()
        self.formatTable()

        # Add layout for buttons
        button_layout = QtWidgets.QGridLayout()
        layout.addLayout(button_layout)

        # Buttons
        self.create_new_button = QtWidgets.QPushButton(self)
        button_layout.addWidget(self.create_new_button, 0, 0)
        self.create_new_button.setText("Create New")
        self.create_new_button.setToolTip(
            "Add a key binding that does not currently appear on the table")
        self.create_new_button.clicked.connect(
            lambda: self.create_new_form._dialog.show())

        self.delete_selected_button = QtWidgets.QPushButton(self)
        button_layout.addWidget(self.delete_selected_button, 0, 1)
        self.delete_selected_button.setText("Delete Selected")
        self.delete_selected_button.setToolTip(
            "Unbind selected key bindings and remove any that have been created")
        self.delete_selected_button.clicked.connect(self.delete_selected)
        self.delete_selected_button.setEnabled(False)

        self.reset_selected_button = QtWidgets.QPushButton(self)
        button_layout.addWidget(self.reset_selected_button, 0, 2)
        self.reset_selected_button.setText("Reset Selected")
        self.reset_selected_button.setToolTip(
            "Restore selected key bindings to their default values")
        self.reset_selected_button.clicked.connect(self.reset_selected)
        self.reset_selected_button.setEnabled(False)

        self.reset_all_button = QtWidgets.QPushButton(self)
        button_layout.addWidget(self.reset_all_button, 0, 3)
        self.reset_all_button.setText("Reset All")
        self.reset_all_button.setToolTip(
            "Restore all key bindings to their default values and remove any that have been created")
        self.reset_all_button.clicked.connect(self.reset_all_default)

        self.save_button = QtWidgets.QPushButton(self)
        button_layout.addWidget(self.save_button, 0, 4)
        self.save_button.setText("Save")
        self.save_button.setToolTip(
            "Save the current key bindings to be loaded automatically when opening PyMOL")
        self.save_button.clicked.connect(self.shortcut_manager.save_shortcuts)

        # Ensuring that confirmed key and binding remain in scope
        self.confirm_new_key = ''
        self.confirm_new_binding = ''

        # Connect create new and confirm menus
        self.create_new_shortcut_menu_connect()
        self.confirm_menu_connect()

        self.model.itemChanged.connect(self.itemChanged)
Пример #26
0
def new_manager_widget(manager, title):
    dockWidget = QtWidgets.QDockWidget()
    dockWidget.setWindowTitle(title)

    widget = QtWidgets.QWidget()
    layout = QtWidgets.QVBoxLayout(widget)
    dockWidget.setWidget(widget)
    widget.setLayout(layout)

    model = QtGui.QStandardItemModel(0, 1, widget)

    tree = QtWidgets.QTreeView(widget)
    tree.setModel(model)
    tree.setHeaderHidden(True)

    current_key = None

    def update_treeview():
        model.clear()
        for key in manager.get_keys():
            item = QtGui.QStandardItem()
            item.setText(key)
            model.blockSignals(True)
            model.appendRow(item)
            model.blockSignals(False)

    @model.rowsInserted.connect
    def onRowsInserted(index):
        key = model.itemFromIndex(index).text()
        store_view(key)
        update_treeview()

    @model.dataChanged.connect
    def onDataChanged(index):
        new_key = model.itemFromIndex(index).text()
        if new_key == "":
            manager.clear(current_key)
        else:
            manager.rename(current_key, new_key)
        update_treeview()

    @dockWidget.visibilityChanged.connect
    def onVisibilityChanged(visible):
        if not visible:
            return
        update_treeview()

    @tree.clicked.connect
    def onClicked(index):
        nonlocal current_key

        key = model.itemFromIndex(index).text()
        current_key = key

        manager.recall(key)

    storeBtn = QtWidgets.QPushButton("Store", widget)

    @storeBtn.clicked.connect
    def onClicked():
        count = len(manager.get_keys())
        manager.store(f"view{count}")
        update_treeview()

    layout.addWidget(tree)
    layout.addWidget(storeBtn)
    return dockWidget