<commit_before>
from maya import OpenMaya as api

from pulse.vendor.Qt import QtCore, QtWidgets, QtGui
import pymel.core as pm

from pulse.views import utils as viewutils
from pulse.views.utils import undoAndRepeatPartial as cmd
from pulse.views.core import PulseWindow, PulsePanelWidget
from pulse import editorutils
from pulse import links

__all__ = [
    "LayoutLinkEditorWidget",
    "LayoutLinkEditorWindow",
    "LayoutPanel",
]


class LayoutPanel(PulsePanelWidget):

    def __init__(self, parent):
        super(LayoutPanel, self).__init__(parent=parent)

    def getPanelDisplayName(self):
        return "Layout"

    def setupPanelUi(self, parent):
        layout = QtWidgets.QVBoxLayout(parent)
        layout.setMargin(0)

        frame = self.createPanelFrame(parent)
        layout.addWidget(frame)

        gridLayout = QtWidgets.QGridLayout(frame)
        gridLayout.setMargin(0)
        gridLayout.setSpacing(2)

        snapToTargetsBtn = QtWidgets.QPushButton(frame)
        snapToTargetsBtn.setText("Snap To Targets")
        snapToTargetsBtn.setStatusTip(
            "Snap controls and linked objects to their target positions")
        snapToTargetsBtn.clicked.connect(
            cmd(editorutils.positionLinkForSelected))

        linkEditorBtn = QtWidgets.QPushButton(frame)
        linkEditorBtn.setText("Link Editor")
        linkEditorBtn.setStatusTip(
            "Open the Layout Link Editor for managing how nodes are connected "
            "to each other during blueprint design")
        linkEditorBtn.clicked.connect(
            cmd(LayoutLinkEditorWindow.toggleWindow))

        gridItems = [
            [snapToTargetsBtn, linkEditorBtn],
        ]
        viewutils.addItemsToGrid(gridLayout, gridItems)


class LayoutLinkEditorWidget(QtWidgets.QWidget):

    def __init__(self, parent):
        super(LayoutLinkEditorWidget, self).__init__(parent=parent)

        self.linkInfoScrollArea = None
        self.linkInfoList = None

        self.setupUi(self)

        self.updateLinkInfoList()

        self.selection_changed_cb = None

    def showEvent(self, event):
        super(LayoutLinkEditorWidget, self).showEvent(event)
        if self.selection_changed_cb is None:
            print('adding selection changed callback')
            self.selection_changed_cb = api.MEventMessage.addEventCallback("SelectionChanged", self.onSceneSelectionChanged)

    def hideEvent(self, event):
        super(LayoutLinkEditorWidget, self).hideEvent(event)
        if self.selection_changed_cb is not None:
            print('removing selection changed callback')<commit_msg>fix link editor not refreshing on show<commit_after>
from maya import OpenMaya as api

from pulse.vendor.Qt import QtCore, QtWidgets, QtGui
import pymel.core as pm

from pulse.views import utils as viewutils
from pulse.views.utils import undoAndRepeatPartial as cmd
from pulse.views.core import PulseWindow, PulsePanelWidget
from pulse import editorutils
from pulse import links

__all__ = [
    "LayoutLinkEditorWidget",
    "LayoutLinkEditorWindow",
    "LayoutPanel",
]


class LayoutPanel(PulsePanelWidget):

    def __init__(self, parent):
        super(LayoutPanel, self).__init__(parent=parent)

    def getPanelDisplayName(self):
        return "Layout"

    def setupPanelUi(self, parent):
        layout = QtWidgets.QVBoxLayout(parent)
        layout.setMargin(0)

        frame = self.createPanelFrame(parent)
        layout.addWidget(frame)

        gridLayout = QtWidgets.QGridLayout(frame)
        gridLayout.setMargin(0)
        gridLayout.setSpacing(2)

        snapToTargetsBtn = QtWidgets.QPushButton(frame)
        snapToTargetsBtn.setText("Snap To Targets")
        snapToTargetsBtn.setStatusTip(
            "Snap controls and linked objects to their target positions")
        snapToTargetsBtn.clicked.connect(
            cmd(editorutils.positionLinkForSelected))

        linkEditorBtn = QtWidgets.QPushButton(frame)
        linkEditorBtn.setText("Link Editor")
        linkEditorBtn.setStatusTip(
            "Open the Layout Link Editor for managing how nodes are connected "
            "to each other during blueprint design")
        linkEditorBtn.clicked.connect(
            cmd(LayoutLinkEditorWindow.toggleWindow))

        gridItems = [
            [snapToTargetsBtn, linkEditorBtn],
        ]
        viewutils.addItemsToGrid(gridLayout, gridItems)


class LayoutLinkEditorWidget(QtWidgets.QWidget):

    def __init__(self, parent):
        super(LayoutLinkEditorWidget, self).__init__(parent=parent)

        self.linkInfoScrollArea = None
        self.linkInfoList = None

        self.setupUi(self)

        self.selection_changed_cb = None

    def showEvent(self, event):
        super(LayoutLinkEditorWidget, self).showEvent(event)
        if self.selection_changed_cb is None:
            print('adding selection changed callback')
            self.selection_changed_cb = api.MEventMessage.addEventCallback("SelectionChanged", self.onSceneSelectionChanged)
        self.updateLinkInfoList()

    def hideEvent(self, event):
        super(LayoutLinkEditorWidget, self).hideEvent(event)
        if self.selection_changed_cb is not None:
            print('removing selection changed callback')
{'fraction_non_alphanumeric': 0.07516215185043876, 'fraction_numerical': 0.0011446012972148034, 'mean_word_length': 3.1677265500794913, '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': '2363087', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1416, 'n_words': 327}