コード例 #1
0
ファイル: tool.py プロジェクト: Yongcheng123/ChimeraX
    def _fill_tree(self, *, always_rebuild=False):
        if not self.displayed():
            # Don't update panel when it is hidden.
            self._frame_drawn_handler = None
            from chimerax.core.triggerset import DEREGISTER
            return DEREGISTER

        self.countdown -= 1
        if self.countdown > 0:
            return

        self.tree.blockSignals(True) # particularly itemChanged
        if self.check_model_list or always_rebuild:
            update = self._process_models() and not always_rebuild
            self.check_model_list = False
        else:
            update = not always_rebuild
        if not update:
            expanded_models = { i._model : i.isExpanded()
                                for i in self._items if hasattr(i, '_model')}
            self.tree.clear()
            self._items = []
        all_selected_models = self.session.selection.models(all_selected=True)
        part_selected_models = self.session.selection.models()
        from PyQt5.QtWidgets import QTreeWidgetItem, QPushButton
        from PyQt5.QtCore import Qt
        from PyQt5.QtGui import QColor
        item_stack = [self.tree.invisibleRootItem()]
        for model in self.models:
            model_id, model_id_string, bg_color, display, name, selected, part_selected = \
                self._get_info(model, all_selected_models, part_selected_models)
            len_id = len(model_id)
            if update:
                if len_id == len(item_stack):
                    # first child
                    item = item_stack[-1].child(0)
                    item_stack.append(item)
                else:
                    # sibling
                    parent, previous_child = item_stack[len_id-1:len_id+1]
                    item = parent.child(parent.indexOfChild(previous_child)+1)
                    item_stack[len_id:] = [item]
            else:
                parent = item_stack[0] if len(item_stack) == 1 else item_stack[len_id-1]
                item = QTreeWidgetItem(parent)
                item._model = model
                item_stack[len_id:] = [item]
                self._items.append(item)
                if bg_color is not False:
                    from chimerax.ui.widgets import MultiColorButton
                    but = MultiColorButton(has_alpha_channel=True, max_size=(16,16))
                    def set_single_color(rgba, m=model):
                        for cm in m.all_models():
                            cm.single_color = rgba
                    but.color_changed.connect(set_single_color)
                    but.set_color(bg_color)
                    self.tree.setItemWidget(item, self.COLOR_COLUMN, but)
                
                    
                
            if self.simply_changed_models and model not in self.simply_changed_models:
                continue
            item.setText(self.ID_COLUMN, model_id_string)
            bg = item.background(self.ID_COLUMN)
            if bg_color is False:
                bg.setStyle(Qt.NoBrush)
            else:
                but = self.tree.itemWidget(item, self.COLOR_COLUMN)
                if but is not None:
                    but.set_color(bg_color)
            item.setBackground(self.COLOR_COLUMN, bg)
            if display is not None:
                item.setCheckState(self.SHOWN_COLUMN, Qt.Checked if display else Qt.Unchecked)
            if selected:
                item.setCheckState(self.SELECT_COLUMN, Qt.Checked)
            elif part_selected:
                item.setCheckState(self.SELECT_COLUMN, Qt.PartiallyChecked)
            else:
                item.setCheckState(self.SELECT_COLUMN, Qt.Unchecked)
            item.setText(self.NAME_COLUMN, name)
            if not update:
                # Expand new top-level displayed models, or if previously expanded
                if hasattr(model, 'model_panel_show_expanded'):
                    expand_default = model.model_panel_show_expanded
                else:
                    expand_default = (model.display
                                      and len(model.id) <= 1
                                      and len(model.child_models()) <= 10)
                expand = expanded_models.get(model, expand_default)
                if expand:
                    self.tree.expandItem(item)
        for i in range(1,self.tree.columnCount()):
            self.tree.resizeColumnToContents(i)
        self.tree.blockSignals(False)
        self.simply_changed_models = set()

        self._frame_drawn_handler = None
        from chimerax.core.triggerset import DEREGISTER
        return DEREGISTER
コード例 #2
0
    def fill_tree(self, *args):
        item_stack = [self.tree.invisibleRootItem()]

        self.tree.clear()
        self._items = []

        fr_dict = self.session.filereader_manager.filereader_dict

        for model in fr_dict.keys():
            id = model.id
            if id is None:
                continue

            name = model.name
            parent = item_stack[0]
            item = QTreeWidgetItem(parent)
            item._model = model
            item_stack.append(item)
            self._items.append(item)

            item.setData(self.NAME_COL, Qt.DisplayRole, model)
            item.setText(self.NAME_COL, name)
            item.setText(self.ID_COL, ".".join([str(x) for x in id]))

            if any(x.all_geom is not None and len(x.all_geom) > 1
                   for x in fr_dict[model]):
                item.setText(self.COORDSETS_COL, "yes")
            else:
                item.setText(self.COORDSETS_COL, "no")

            if any("energy" in x.other for x in fr_dict[model]):
                item.setText(self.NRG_COL, "yes")
            else:
                item.setText(self.NRG_COL, "no")

            if any("frequency" in x.other for x in fr_dict[model]):
                item.setText(self.FREQ_COL, "yes")
            else:
                item.setText(self.FREQ_COL, "no")

            for fr in fr_dict[model]:
                child = QTreeWidgetItem(item)
                child.setData(self.NAME_COL, Qt.DisplayRole, fr)
                child.setText(self.NAME_COL, fr.name)
                if fr.all_geom is not None and len(fr.all_geom) > 1:
                    child.setText(self.COORDSETS_COL, "yes")
                else:
                    child.setText(self.COORDSETS_COL, "no")

                if "energy" in fr.other:
                    child.setText(self.NRG_COL, "%.6f" % fr.other["energy"])
                else:
                    child.setText(self.NRG_COL, "")

                if "frequency" in fr.other:
                    child.setText(self.FREQ_COL, "yes")
                else:
                    child.setText(self.FREQ_COL, "no")

            #self.tree.expandItem(item)

        for i in [
                self.ID_COL, self.COORDSETS_COL, self.NRG_COL, self.FREQ_COL
        ]:
            self.tree.resizeColumnToContents(i)