Example #1
0
    def _on_add_token(self, *args):
        """
        Creates a new token and add it to the Naming Manager
        :return: None
        """

        load_token = True
        if len(args) == 0:
            load_token = False

        token = None
        if not load_token:
            token = self._naming_lib.get_token_unique_name(name='New_Token')
        elif load_token and len(args) == 1:
            token = args[0].name

        if token:
            # Create a new item based on the token name and add it
            item = QListWidgetItem(token)
            item.setFlags(item.flags() | Qt.ItemIsEditable)
            self.tokens_list.addItem(item)

            # Add the data of the token to our JSON data file
            if len(args) == 0:
                self._naming_lib.add_token(token)

            # Update necessary UI wigdets
            if not load_token:
                self.tokens_list.setCurrentItem(item)
Example #2
0
    def update_view(self):
        """
        Updates file/folder view
        :return:
        """

        self.view.clear()
        qdir = QDir(self.directory)
        qdir.setNameFilters(self.get_filter_patterns())
        filters = QDir.Dirs | QDir.AllDirs | QDir.Files | QDir.NoDot | QDir.NoDotDot
        if self.show_hidden.isChecked():
            filters = filters | QDir.Hidden
        entries = qdir.entryInfoList(filters=filters,
                                     sort=QDir.DirsFirst | QDir.Name)
        file_path = self.get_file_path('..')
        if os.path.exists(file_path) and file_path != self.directory:
            icon = QFileIconProvider().icon(QFileInfo(self.directory))
            QListWidgetItem(icon, '..', self.view, 0)
        for info in entries:
            icon = QFileIconProvider().icon(info)
            suf = info.completeSuffix()
            name, tp = (info.fileName(), 0) if info.isDir() else (
                '%s%s' % (info.baseName(), '.%s' % suf if suf else ''), 1)
            QListWidgetItem(icon, name, self.view, tp)
        self.view.setFocus()
    def update_complete_list(self, lines=None, extra=None):
        self.clear()
        if lines or extra:
            self.show_me()
            if lines:
                for i in [x for x in lines if not x.name == 'mro']:
                    item = QListWidgetItem(i.name)
                    item.setData(32, i)
                    self.addItem(item)
            if extra:
                font = self.font()
                font.setItalic(True)
                font.setPointSize(font.pointSize() * 0.8)
                for e in extra:
                    item = QListWidgetItem(e.name)
                    item.setData(32, e)
                    item.setFont(font)
                    self.addItem(item)

            font = QFont('monospace', self.line_height, False)
            fm = QFontMetrics(font)
            width = fm.width(' ') * max([len(x.name)
                                         for x in lines or extra]) + 40

            self.resize(max(250, width), 250)
            self.setCurrentRow(0)
        else:
            self.hide_me()
Example #4
0
    def _on_add_rule(self, *args):
        """
        Creates a new standard rule and add it to the Naming Manager
        :return:
        """

        load_rule = True
        if len(args) == 0:
            load_rule = False

        self.description_rule_text.blockSignals(True)

        rule = None
        if not load_rule:
            rule = self._naming_lib.get_rule_unique_name(name='New_Rule')
        elif load_rule and len(args) == 1:
            rule = args[0].name

        if rule is not None:
            # Create a new item based on the rule name and add it
            item = QListWidgetItem(rule)
            item.setFlags(item.flags() | Qt.ItemIsEditable)
            self.rules_list.addItem(item)

            # Add the data of the rule to our JSON data file
            if len(args) == 0:
                self._naming_lib.add_rule(rule)

            # Update necessary UI Widgets
            if not load_rule:
                self.rules_list.setCurrentItem(item)
            self.update_expression_menu()
            self.update_rules_properties_state()

        self.description_rule_text.blockSignals(False)
Example #5
0
    def _on_add_template_token(self, *args):
        """
        Creates a new template token
        :param args:
        :return:
        """

        load_template_token = True
        if len(args) == 0:
            load_template_token = False

        template_token = None
        if not load_template_token:
            template_token = self._naming_lib.get_template_token_unique_name(
                'New_Template_Token')
        elif load_template_token and len(args) == 1:
            template_token = args[0].name

        if template_token is not None:
            item = QListWidgetItem(template_token)
            item.setFlags(item.flags() | Qt.ItemIsEditable)
            self.template_tokens_list.addItem(item)

            if len(args) == 0:
                self._naming_lib.add_template_token(template_token)

            if not load_template_token:
                self.template_tokens_list.setCurrentItem(item)
Example #6
0
    def _on_add_template(self, *args):
        """
        Creates a new template and add it to the Naming Manager
        :return:
        """

        load_template = True
        if len(args) == 0:
            load_template = False

        template = None
        if not load_template:
            template = self._naming_lib.get_template_unique_name(
                'New_Template')
        elif load_template and len(args) == 1:
            template = args[0].name

        if template is not None:
            item = QListWidgetItem(template)
            item.setFlags(item.flags() | Qt.ItemIsEditable)
            self.templates_list.addItem(item)

            if len(args) == 0:
                self._naming_lib.add_template(template)

            if not load_template:
                self.templates_list.setCurrentItem(item)
Example #7
0
    def createVariable(self, uid=None):
        if uid == False:
            uid = uuid4()

        var = VariableBase(self.graph.getUniqVarName('NewVar'), 0, self.graph, self, DataTypes.Float, uid=uid)
        item = QListWidgetItem(self.listWidget)
        item.setSizeHint(QtCore.QSize(60, 38))        
        self.listWidget.setItemWidget(item, var)
        return var
Example #8
0
    def _show_selected_unparameterised_residue(self, item):
        residue, by_name, by_comp = item.data(USER_ROLE)
        tlist = self._template_list
        tlist.clear()
        self._do_for_all.setCheckState(False)
        from Qt.QtWidgets import QListWidgetItem
        tlist.addItem(QListWidgetItem("Matches by residue name"))

        def get_ccd_template_and_name(session, tname):
            from ..openmm.amberff.template_utils import template_name_to_ccd_name
            from chimerax import mmcif
            ccd_name, extra_info = template_name_to_ccd_name(tname)
            if ccd_name is None:
                return (None, '')
            try:
                tmpl = mmcif.find_template_residue(session, ccd_name)
            except ValueError:
                return (None, "No CCD template found")
            description = tmpl.description
            if extra_info is not None:
                description += ', ' + extra_info
            return (tmpl, description)

        for (tname, score) in by_name:
            ccd_template, description = get_ccd_template_and_name(
                self.session, tname)
            entry_text = tname
            entry_text += " (Score: {:.3f})".format(score)
            if len(description):
                entry_text += " " + description
            entry = QListWidgetItem(entry_text)
            entry.setData(USER_ROLE, (residue, tname, ccd_template))
            tlist.addItem(entry)
        tlist.addItem(QListWidgetItem("Matches by similar topology"))
        for (tname, score) in by_comp:
            ccd_template, description = get_ccd_template_and_name(
                self.session, tname)
            entry_text = tname
            entry_text += " (Score: {:.3f})".format(score)
            if len(description):
                entry_text += " " + description
            entry = QListWidgetItem(entry_text)
            entry.setData(USER_ROLE, (residue, tname, ccd_template))
            tlist.addItem(entry)

        tlist.repaint()
        from ..view import focus_on_selection
        # show all atoms in the residue and its bonded neighbors, to help
        # diagnose bonding errors
        residue.atoms.displays = True
        for r in residue.neighbors:
            r.atoms.displays = True
        focus_on_selection(self.session, residue.atoms)
 def refresh(self, directories):
     directories = python.force_list(directories)
     self.clear()
     for diretory_found in directories:
         name = diretory_found
         if not path_utils.is_dir(diretory_found):
             name = 'Directory Not Valid! {}'.format(diretory_found)
         item = QListWidgetItem()
         item.setText(name)
         item.setSizeHint(QSize(20, 25))
         self.addItem(item)
Example #10
0
 def appendOutput(self, pw):
     item = QListWidgetItem(self.lwOutputs)
     item.setSizeHint(QtCore.QSize(pw.sizeHint().width(), 80))
     self.lwOutputs.addItem(item)
     self.lwOutputs.setItemWidget(item, pw)
     del item
Example #11
0
 def createVariableWrapperAndAddToList(self, rawVariable):
     uiVariable = UIVariable(rawVariable, self)
     item = QListWidgetItem(self.listWidget)
     item.setSizeHint(QtCore.QSize(60, 20))
     self.listWidget.setItemWidget(item, uiVariable)
     return uiVariable
Example #12
0
    def addWidget(self, widget):

        item = QListWidgetItem(self)
        item.setSizeHint(widget.sizeHint())
        super(ItemWidgetsList, self).addItem(item)