コード例 #1
0
ファイル: test_func_aux.py プロジェクト: soker90/betcon
    def test_paint_row_yellow(self):
        items = []
        for i in range(18):
            items.append("")

        item = QTreeWidgetItem(items)
        item.background(0)

        actual = paint_row(item, "0€", "0")
        assert_that(actual.background(0), is_(QBrush(Qt.yellow)))

        actual = paint_row(item, "-10.0€", "0")
        assert_that(actual.background(0), is_(QBrush(Qt.yellow)))

        actual = paint_row(item, 20.0, "0")
        assert_that(actual.background(0), is_(QBrush(Qt.yellow)))
コード例 #2
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