<commit_before>import os
import PythonQt
from PythonQt import QtCore, QtGui
from ddapp.propertyset import PropertySet, PropertyAttributes, PropertyPanelHelper

class Icons(object):

  Directory = QtGui.QApplication.style().standardIcon(QtGui.QStyle.SP_DirIcon)
  Eye = QtGui.QIcon(':/images/eye_icon.png')
  EyeOff = QtGui.QIcon(':/images/eye_icon_gray.png')
  Matlab = QtGui.QIcon(':/images/matlab_logo.png')
  Robot = QtGui.QIcon(':/images/robot_icon.png')
  Laser = QtGui.QIcon(':/images/laser_icon.jpg')
  Feet = QtGui.QIcon(':/images/feet.png')
  Hand = QtGui.QIcon(':/images/claw.png')


class ObjectModelItem(object):

    def __init__(self, name, icon=Icons.Robot, tree=None, properties=None):

        self.properties = properties or PropertySet()
        self.properties.connectPropertyChanged(self._onPropertyChanged)
        self.properties.connectPropertyAdded(self._onPropertyAdded)
        self.properties.connectPropertyAttributeChanged(self._onPropertyAttributeChanged)

        self.icon = icon
        self._tree = tree
        self.addProperty('Name', name, attributes=PropertyAttributes(hidden=True))

    def setIcon(self, icon):
        self.icon = icon
        if self._tree:
            self._tree.updateObjectIcon(self)

    def propertyNames(self):
        return self.properties.propertyNames()

    def hasProperty(self, propertyName):
        return self.properties.hasProperty(propertyName)

    def getProperty(self, propertyName):
        return self.properties.getProperty(propertyName)

    def getPropertyEnumValue(self, propertyName):
        return self.properties.getPropertyEnumValue(propertyName)

    def addProperty(self, propertyName, propertyValue, attributes=None):
        self.properties.addProperty(propertyName, propertyValue, attributes)

    def setProperty(self, propertyName, propertyValue):
        self.properties.setProperty(propertyName, propertyValue)

    def getPropertyAttribute(self, propertyName, propertyAttribute):
        return self.properties.getPropertyAttribute(propertyName, propertyAttribute)

    def setPropertyAttribute(self, propertyName, propertyAttribute, value):
        self.properties.setPropertyAttribute(propertyName, propertyAttribute, value)

    def _onPropertyChanged(self, propertySet, propertyName):
        if self._tree is not None:
            self._tree._onPropertyValueChanged(self, propertyName)

    def _onPropertyAdded(self, propertySet, propertyName):
        pass

    def _onPropertyAttributeChanged(self, propertySet, propertyName, propertyAttribute):
        pass

    def hasDataSet(self, dataSet):
        return False

    def getActionNames(self):
        return []

    def onAction(self, action):
        pass

    def getObjectTree(self):
        return self._tree

    def onRemoveFromObjectModel(self):
        pass

    def parent(self):
        if self._tree is not None:
            return self._tree.getObjectParent(self)

    def children(self):
        if self._tree is not None:
            return self._tree.getObjectChildren(self)
        else:
            return []

    def findChild(self, name):
        if self._tree is not None:
            return self._tree.findChildByName(self, name)


class ContainerItem(ObjectModelItem):

    def __init__(self, name):
        ObjectModelItem.__init__(self, name, Icons.Directory)
        self.addProperty('Visible', True)

    def _onPropertyChanged(self, propertySet, propertyName):
        ObjectModelItem._onPropertyChanged(self, propertySet, propertyName)
        if propertyName == 'Visible':
            visible = self.getProperty(propertyName)
            for child in self.children():
                child.setProperty(propertyName, visible)


class ObjectModelTree(object):

    def __init__(self):
        self._treeWidget = None
        self._propertiesPanel = None
        self._objects = {}
        self._blockSignals = False

    def getTreeWidget(self):
        return self._treeWidget

    def getPropertiesPanel(self):
        return self._propertiesPanel

    def getActiveItem(self):
        items = self.getTreeWidget().selectedItems()
        return items[0] if len(items) == 1 else None

    def getObjectParent(self, obj):
        item = self._getItemForObject(obj)
        if item.parent():
            return self._getObjectForItem(item.parent())

    def getObjectChildren(self, obj):
        item = self._getItemForObject(obj)
        return [self._getObjectForItem(item.child(i)) for i in xrange(item.childCount())]

    def getActiveObject(self):
        item = self.getActiveItem()<commit_msg>check property is available before setting it<commit_after>import os
import PythonQt
from PythonQt import QtCore, QtGui
from ddapp.propertyset import PropertySet, PropertyAttributes, PropertyPanelHelper

class Icons(object):

  Directory = QtGui.QApplication.style().standardIcon(QtGui.QStyle.SP_DirIcon)
  Eye = QtGui.QIcon(':/images/eye_icon.png')
  EyeOff = QtGui.QIcon(':/images/eye_icon_gray.png')
  Matlab = QtGui.QIcon(':/images/matlab_logo.png')
  Robot = QtGui.QIcon(':/images/robot_icon.png')
  Laser = QtGui.QIcon(':/images/laser_icon.jpg')
  Feet = QtGui.QIcon(':/images/feet.png')
  Hand = QtGui.QIcon(':/images/claw.png')


class ObjectModelItem(object):

    def __init__(self, name, icon=Icons.Robot, tree=None, properties=None):

        self.properties = properties or PropertySet()
        self.properties.connectPropertyChanged(self._onPropertyChanged)
        self.properties.connectPropertyAdded(self._onPropertyAdded)
        self.properties.connectPropertyAttributeChanged(self._onPropertyAttributeChanged)

        self.icon = icon
        self._tree = tree
        self.addProperty('Name', name, attributes=PropertyAttributes(hidden=True))

    def setIcon(self, icon):
        self.icon = icon
        if self._tree:
            self._tree.updateObjectIcon(self)

    def propertyNames(self):
        return self.properties.propertyNames()

    def hasProperty(self, propertyName):
        return self.properties.hasProperty(propertyName)

    def getProperty(self, propertyName):
        return self.properties.getProperty(propertyName)

    def getPropertyEnumValue(self, propertyName):
        return self.properties.getPropertyEnumValue(propertyName)

    def addProperty(self, propertyName, propertyValue, attributes=None):
        self.properties.addProperty(propertyName, propertyValue, attributes)

    def setProperty(self, propertyName, propertyValue):
        self.properties.setProperty(propertyName, propertyValue)

    def getPropertyAttribute(self, propertyName, propertyAttribute):
        return self.properties.getPropertyAttribute(propertyName, propertyAttribute)

    def setPropertyAttribute(self, propertyName, propertyAttribute, value):
        self.properties.setPropertyAttribute(propertyName, propertyAttribute, value)

    def _onPropertyChanged(self, propertySet, propertyName):
        if self._tree is not None:
            self._tree._onPropertyValueChanged(self, propertyName)

    def _onPropertyAdded(self, propertySet, propertyName):
        pass

    def _onPropertyAttributeChanged(self, propertySet, propertyName, propertyAttribute):
        pass

    def hasDataSet(self, dataSet):
        return False

    def getActionNames(self):
        return []

    def onAction(self, action):
        pass

    def getObjectTree(self):
        return self._tree

    def onRemoveFromObjectModel(self):
        pass

    def parent(self):
        if self._tree is not None:
            return self._tree.getObjectParent(self)

    def children(self):
        if self._tree is not None:
            return self._tree.getObjectChildren(self)
        else:
            return []

    def findChild(self, name):
        if self._tree is not None:
            return self._tree.findChildByName(self, name)


class ContainerItem(ObjectModelItem):

    def __init__(self, name):
        ObjectModelItem.__init__(self, name, Icons.Directory)
        self.addProperty('Visible', True)

    def _onPropertyChanged(self, propertySet, propertyName):
        ObjectModelItem._onPropertyChanged(self, propertySet, propertyName)
        if propertyName == 'Visible':
            visible = self.getProperty(propertyName)
            for child in self.children():
                if child.hasProperty(propertyName):
                    child.setProperty(propertyName, visible)


class ObjectModelTree(object):

    def __init__(self):
        self._treeWidget = None
        self._propertiesPanel = None
        self._objects = {}
        self._blockSignals = False

    def getTreeWidget(self):
        return self._treeWidget

    def getPropertiesPanel(self):
        return self._propertiesPanel

    def getActiveItem(self):
        items = self.getTreeWidget().selectedItems()
        return items[0] if len(items) == 1 else None

    def getObjectParent(self, obj):
        item = self._getItemForObject(obj)
        if item.parent():
            return self._getObjectForItem(item.parent())

    def getObjectChildren(self, obj):
        item = self._getItemForObject(obj)
        return [self._getObjectForItem(item.child(i)) for i in xrange(item.childCount())]

    def getActiveObject(self):
        item = self.getActiveItem()
{'fraction_non_alphanumeric': 0.09387138541217091, 'fraction_numerical': 0.00043159257660768235, 'mean_word_length': 3.299165120593692, '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': '4309711', 'n_tokens_mistral': 2553, 'n_tokens_neox': 2467, 'n_words': 537}