<commit_before>
import re

from PyQt5.QtCore import pyqtSignal, QObject
from PyQt5.QtCore import Qt, QRect, QSize
from PyQt5.QtGui import QFont, QPalette
from PyQt5.QtWidgets import QTreeWidget, QHeaderView
from PyQt5.QtWidgets import QTreeWidgetItem
from PyQt5.QtWidgets import QSizePolicy, QStyledItemDelegate
from PyQt5.QtWidgets import QDoubleSpinBox, QSpinBox, QLineEdit
from PyQt5.QtWidgets import QStyleOptionButton, QStyleOptionViewItem
from PyQt5.QtWidgets import QCheckBox
from PyQt5.QtWidgets import QStyle, QCommonStyle

from cadnano import util
from cadnano.enum import ItemType
from cadnano.gui.palette import getColorObj, getPenObj, getBrushObj
from cadnano.gui.controllers.viewrootcontroller import ViewRootController
from cadnano.gui.views.pathview import pathstyles as styles

from .oligoitem import OligoItem
from .nucleicacidpartitem import NucleicAcidPartItem
from .virtualhelixitem import VirtualHelixItem
from .cnpropertyitem import CNPropertyItem

COLOR_PATTERN = re.compile("#[0-9a-f].....")
_FONT = QFont(styles.THE_FONT, 12)
_QCOMMONSTYLE = QCommonStyle()


class PropertyEditorWidget(QTreeWidget):
    """
    PropertyEditorWidget enables direct editing attributes of an
    item that is selected in the Outliner.
    """
    def __init__(self, parent=None):
        super(PropertyEditorWidget, self).__init__(parent)
        self.setAttribute(Qt.WA_MacShowFocusRect, 0) # no mac focus halo

    def configure(self, window, document):
        self._window = window
        self._document = document
        self._controller = ViewRootController(self, document)
        self._root = self.invisibleRootItem()

        # Appearance
        self.setFont(_FONT)
        # Columns
        self.setColumnCount(2)
        self.setIndentation(14)
        # Header
        self.setHeaderLabels(["Property", "Value"])
        h = self.header()
        h.resizeSection(0, 200)
        h.resizeSection(1, 100)
        h.setSectionResizeMode(QHeaderView.Interactive)
        # h.setStretchLastSection(False)

        custom_delegate = CustomStyleItemDelegate(self)
        self.setItemDelegate(custom_delegate)

        self.model().dataChanged.connect(self.dataChangedSlot)

        # Add some dummy items
        # p1 = self.addDummyRow("sequence", "ATCGACTGATCG")
        # p2 = self.addDummyRow("circular",  True)
    # end def

    # def addDummyRow(self, property_name, value, parent_QTreeWidgetItem=None):
    #     if parent_QTreeWidgetItem is None:
    #         parent_QTreeWidgetItem = self.invisibleRootItem()
    #     tw_item = QTreeWidgetItem(parent_QTreeWidgetItem)
    #     tw_item.setData(0, Qt.EditRole, property_name)
    #     tw_item.setData(1, Qt.EditRole, value)
    #     tw_item.setFlags(tw_item.flags() | Qt.ItemIsEditable)
    #     return tw_item
    # end def

    ### SIGNALS ###

    ### SLOTS ###
    def outlinerItemSelectionChanged(self):
        o = self._window.outliner_widget
        for child in self.children():
            if isinstance(child, (CNPropertyItem, VirtualHelixItem)):
                child.disconnectSignals()

        selected_items = o.selectedItems()

        self.clear()    # remove pre-existing items
        if len(selected_items) == 1:
            # get the selected item
            item = selected_items[0]
            item_type = item.itemType()
            if item_type is ItemType.OLIGO:
                pe_item = OligoItem(item.cnModel(), self)<commit_msg>fix for property widget showing items not in the document filter set<commit_after>
import re

from PyQt5.QtCore import pyqtSignal, QObject
from PyQt5.QtCore import Qt, QRect, QSize
from PyQt5.QtGui import QFont, QPalette
from PyQt5.QtWidgets import QTreeWidget, QHeaderView
from PyQt5.QtWidgets import QTreeWidgetItem
from PyQt5.QtWidgets import QSizePolicy, QStyledItemDelegate
from PyQt5.QtWidgets import QDoubleSpinBox, QSpinBox, QLineEdit
from PyQt5.QtWidgets import QStyleOptionButton, QStyleOptionViewItem
from PyQt5.QtWidgets import QCheckBox
from PyQt5.QtWidgets import QStyle, QCommonStyle

from cadnano import util
from cadnano.enum import ItemType
from cadnano.gui.palette import getColorObj, getPenObj, getBrushObj
from cadnano.gui.controllers.viewrootcontroller import ViewRootController
from cadnano.gui.views.pathview import pathstyles as styles

from .oligoitem import OligoItem
from .nucleicacidpartitem import NucleicAcidPartItem
from .virtualhelixitem import VirtualHelixItem
from .cnpropertyitem import CNPropertyItem

COLOR_PATTERN = re.compile("#[0-9a-f].....")
_FONT = QFont(styles.THE_FONT, 12)
_QCOMMONSTYLE = QCommonStyle()


class PropertyEditorWidget(QTreeWidget):
    """
    PropertyEditorWidget enables direct editing attributes of an
    item that is selected in the Outliner.
    """
    def __init__(self, parent=None):
        super(PropertyEditorWidget, self).__init__(parent)
        self.setAttribute(Qt.WA_MacShowFocusRect, 0) # no mac focus halo

    def configure(self, window, document):
        self._window = window
        self._document = document
        self._controller = ViewRootController(self, document)
        self._root = self.invisibleRootItem()

        # Appearance
        self.setFont(_FONT)
        # Columns
        self.setColumnCount(2)
        self.setIndentation(14)
        # Header
        self.setHeaderLabels(["Property", "Value"])
        h = self.header()
        h.resizeSection(0, 200)
        h.resizeSection(1, 100)
        h.setSectionResizeMode(QHeaderView.Interactive)
        # h.setStretchLastSection(False)

        custom_delegate = CustomStyleItemDelegate(self)
        self.setItemDelegate(custom_delegate)

        self.model().dataChanged.connect(self.dataChangedSlot)

        # Add some dummy items
        # p1 = self.addDummyRow("sequence", "ATCGACTGATCG")
        # p2 = self.addDummyRow("circular",  True)
    # end def

    # def addDummyRow(self, property_name, value, parent_QTreeWidgetItem=None):
    #     if parent_QTreeWidgetItem is None:
    #         parent_QTreeWidgetItem = self.invisibleRootItem()
    #     tw_item = QTreeWidgetItem(parent_QTreeWidgetItem)
    #     tw_item.setData(0, Qt.EditRole, property_name)
    #     tw_item.setData(1, Qt.EditRole, value)
    #     tw_item.setFlags(tw_item.flags() | Qt.ItemIsEditable)
    #     return tw_item
    # end def

    ### SIGNALS ###

    ### SLOTS ###
    def outlinerItemSelectionChanged(self):
        o = self._window.outliner_widget
        for child in self.children():
            if isinstance(child, (CNPropertyItem, VirtualHelixItem)):
                child.disconnectSignals()

        selected_items = o.selectedItems()

        self.clear()    # remove pre-existing items
        if len(selected_items) == 1:
            # get the selected item
            item = selected_items[0]
            if item.FILTER_NAME not in self._document.filter_set:
                return
            item_type = item.itemType()
            if item_type is ItemType.OLIGO:
                pe_item = OligoItem(item.cnModel(), self)
{'fraction_non_alphanumeric': 0.08342824601366743, 'fraction_numerical': 0.009111617312072893, 'mean_word_length': 3.214157168566287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '975738', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2099, 'n_words': 488}