<commit_before>import PythonQt
from PythonQt import QtCore, QtGui, QtUiTools
from director import objectmodel as om
from director import visualization as vis
from director import cameracontrol
from director import propertyset
from director import pointpicker

def addWidgetsToDict(widgets, d):

    for widget in widgets:
        if widget.objectName:
            d[str(widget.objectName)] = widget
        addWidgetsToDict(widget.children(), d)


class WidgetDict(object):

    def __init__(self, widgets):
        addWidgetsToDict(widgets, self.__dict__)


def clearLayout(w):
    children = w.findChildren(QtGui.QWidget)
    for child in children:
        child.delete()


class CameraControlPanel(object):

    def __init__(self, view):

        self.view = view
        self.trackerManager = cameracontrol.CameraTrackerManager()
        self.trackerManager.setView(view)

        loader = QtUiTools.QUiLoader()
        uifile = QtCore.QFile(':/ui/ddCameraControlPanel.ui')
        assert uifile.open(uifile.ReadOnly)


        self.widget = loader.load(uifile)
        self.ui = WidgetDict(self.widget.children())

        self.ui.targetNameLabel.setText('None')

        self.ui.setTargetButton.connect('clicked()', self.onSetTarget)

        for modeName in self.trackerManager.trackers.keys():
            self.ui.trackModeCombo.addItem(modeName)
        self.ui.trackModeCombo.connect('currentIndexChanged(const QString&)', self.onTrackModeChanged)

        self.ui.controlFrame.setEnabled(False)

        l = self.ui.propertiesFrame.layout()
        self.propertiesPanel = PythonQt.dd.ddPropertiesPanel()
        self.propertiesPanel.setBrowserModeToWidget()
        l.addWidget(self.propertiesPanel)
        self.panelConnector = None

        self.objectPicker = pointpicker.ObjectPicker(self.view)
        self.objectPicker.callbackFunc = self.onPickObject
        self.objectPicker.abortFunc = self.onAbortPick


    def onPickObject(self, objs):
        if objs:
            self.setTarget(objs[0])
        else:
            self.onAbortPick()

    def onAbortPick(self):
        self.ui.selectedObjectNameLabel.setText('')
        self.ui.setTargetButton.setVisible(True)
        self.objectPicker.stop()

    def getSelectedTarget(self):
        obj = om.getActiveObject()
        return obj if obj and hasattr(obj, 'actor') else None

    def getObjectShortName(self, obj):
        name = obj.getProperty('Name')
        maxLength = 15
        if len(name) > maxLength:
            name = name[:maxLength-3] + '...'
        return name

    def onObjectRemoved(self, objectModel, obj):
        if obj == self.trackerManager.target:
            self.setTarget(None)

    def onSetTarget(self):
        self.ui.setTargetButton.setVisible(False)
        self.ui.selectedObjectNameLabel.setText('Click an object in the view...')
        self.objectPicker.start()

    def setTarget(self, obj):

        self.onAbortPick()

        if obj:
            vis.addChildFrame(obj)
            obj.connectRemovedFromObjectModel(self.onObjectRemoved)<commit_msg>restrict camera control to objects with child frames<commit_after>import PythonQt
from PythonQt import QtCore, QtGui, QtUiTools
from director import objectmodel as om
from director import visualization as vis
from director import cameracontrol
from director import propertyset
from director import pointpicker

def addWidgetsToDict(widgets, d):

    for widget in widgets:
        if widget.objectName:
            d[str(widget.objectName)] = widget
        addWidgetsToDict(widget.children(), d)


class WidgetDict(object):

    def __init__(self, widgets):
        addWidgetsToDict(widgets, self.__dict__)


def clearLayout(w):
    children = w.findChildren(QtGui.QWidget)
    for child in children:
        child.delete()


class CameraControlPanel(object):

    def __init__(self, view):

        self.view = view
        self.trackerManager = cameracontrol.CameraTrackerManager()
        self.trackerManager.setView(view)

        loader = QtUiTools.QUiLoader()
        uifile = QtCore.QFile(':/ui/ddCameraControlPanel.ui')
        assert uifile.open(uifile.ReadOnly)


        self.widget = loader.load(uifile)
        self.ui = WidgetDict(self.widget.children())

        self.ui.targetNameLabel.setText('None')

        self.ui.setTargetButton.connect('clicked()', self.onSetTarget)

        for modeName in self.trackerManager.trackers.keys():
            self.ui.trackModeCombo.addItem(modeName)
        self.ui.trackModeCombo.connect('currentIndexChanged(const QString&)', self.onTrackModeChanged)

        self.ui.controlFrame.setEnabled(False)

        l = self.ui.propertiesFrame.layout()
        self.propertiesPanel = PythonQt.dd.ddPropertiesPanel()
        self.propertiesPanel.setBrowserModeToWidget()
        l.addWidget(self.propertiesPanel)
        self.panelConnector = None

        self.objectPicker = pointpicker.ObjectPicker(self.view)
        self.objectPicker.callbackFunc = self.onPickObject
        self.objectPicker.abortFunc = self.onAbortPick


    def onPickObject(self, objs):
        if objs:
            self.setTarget(objs[0])
        else:
            self.onAbortPick()

    def onAbortPick(self):
        self.ui.selectedObjectNameLabel.setText('')
        self.ui.setTargetButton.setVisible(True)
        self.objectPicker.stop()

    def getSelectedTarget(self):
        obj = om.getActiveObject()
        return obj if obj and hasattr(obj, 'actor') else None

    def getObjectShortName(self, obj):
        name = obj.getProperty('Name')
        maxLength = 15
        if len(name) > maxLength:
            name = name[:maxLength-3] + '...'
        return name

    def onObjectRemoved(self, objectModel, obj):
        if obj == self.trackerManager.target:
            self.setTarget(None)

    def onSetTarget(self):
        self.ui.setTargetButton.setVisible(False)
        self.ui.selectedObjectNameLabel.setText('Click an object in the view...')
        self.objectPicker.start()

    def setTarget(self, obj):

        self.onAbortPick()

        if not hasattr(obj, 'getChildFrame'):
            return

        if obj:
            vis.addChildFrame(obj)
            obj.connectRemovedFromObjectModel(self.onObjectRemoved)
{'fraction_non_alphanumeric': 0.09681038627985254, 'fraction_numerical': 0.0012822567719185766, 'mean_word_length': 2.8095238095238093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6948363', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1772, 'n_words': 357}