<commit_before>__author__ = '<NAME>'

import os
import types
import importlib

#from mayaLib.utility.Qt import QtCore, QtWidgets, QtGui
from PySide2 import QtCore, QtWidgets, QtGui
from PySide2.QtCore import QObject, SIGNAL
from shiboken2 import wrapInstance
import maya.OpenMayaUI as omui
from maya import mel

import mayaLib
from mayaLib.pipelineLib.utility import listFunction as lm
from mayaLib.pipelineLib.utility import docs as doc
from mayaLib.guiLib.base import baseUI as ui


class SearchLineEdit(QtWidgets.QLineEdit):

    #buttonClicked = QtCore.pyqtSignal(bool)
    speak = QtCore.Signal(str)

    def __init__(self, icon_file, parent=None):
        super(SearchLineEdit, self).__init__(parent)

        self.button = QtWidgets.QToolButton(self)
        self.button.setIcon(QtGui.QIcon(icon_file))
        self.button.setStyleSheet('border: 0px; padding: 0px;')
        self.button.setCursor(QtCore.Qt.ArrowCursor)
        self.button.clicked.connect(self.clear) #self.buttonClicked.emit

        layout = QtWidgets.QHBoxLayout(self)
        layout.addWidget(self.button,0,QtCore.Qt.AlignRight)
        layout.setSpacing(0)
        layout.setMargin(5)

        frameWidth = self.style().pixelMetric(QtWidgets.QStyle.PM_DefaultFrameWidth)
        buttonSize = self.button.sizeHint()

        self.setStyleSheet('QLineEdit {padding-right: %dpx; }' % (buttonSize.width() + frameWidth + 1))
        self.setMinimumSize(max(self.minimumSizeHint().width(), buttonSize.width() + frameWidth*2 + 3),
                            max(self.minimumSizeHint().height(), buttonSize.height() + frameWidth*2 + 3))

        self.textChanged.connect(self.replaceText)

    def replaceText(self):
        text = self.text()
        text_list = text.split(' ')
        newtext = '*'.join(text_list)

        if newtext != text:
            self.setText(newtext)

        self.speak.emit(newtext)


class MenuLibWidget(QtWidgets.QWidget):

    updateWidget = QtCore.Signal()

    def __init__(self, libPath, parent=None):
        super(MenuLibWidget, self).__init__(parent)

        self.libStructure = lm.StructureManager(mayaLib)
        self.libDict = self.libStructure.getStructLib()['mayaLib']

        # set layout
        self.layout = QtWidgets.QVBoxLayout()
        self.setLayout(self.layout)

        # add menu
        self.mainMenu = self.addMenuBar()
        self.layout.addWidget(self.mainMenu)

        # search bar
        self.searchLineEdit = SearchLineEdit(libPath + '/mayaLib/icons/close.png')
        self.layout.addWidget(self.searchLineEdit)

        # WidgetList
        self.buttonItemList = []
        self.buttonListWidget = QtWidgets.QListWidget()
        self.buttonListWidget.setStyleSheet('background: transparent;')
        self.buttonListWidget.setFocusPolicy(QtCore.Qt.NoFocus)
        self.buttonListWidget.adjustSize()
        #self.buttonListWidget.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        #self.buttonListWidget.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
        #self.buttonListWidget.setSizeAdjustPolicy(QtWidgets.QListWidget.AdjustToContents)
        #self.buttonListWidget.setResizeMode(QtWidgets.QListView.Adjust)
        #self.buttonListWidget.setMinimumHeight(75)
        #self.buttonListWidget.setMaximumHeight(100)
        self.layout.addWidget(self.buttonListWidget)

        # Docs Label
        self.docLabel = QtWidgets.QLabel()
        self.docLabel.setStyleSheet("background-color: rgb(90,90,90); border-radius: 5px; border:1px solid rgb(255, 255, 255); ")
        self.layout.addWidget(self.docLabel)
        self.docLabel.setText('')

        # update Button
        self.updateButton = self.addIconButton('update', libPath + '/mayaLib/icons/update.png')
        self.reloadButton = self.addIconButton('reload', libPath + '/mayaLib/icons/reload.png')

        self.buttonLayout = QtWidgets.QHBoxLayout()
        self.buttonLayout.addWidget(self.reloadButton)
        self.buttonLayout.addWidget(self.updateButton)
        self.layout.addLayout(self.buttonLayout)

        # Connect
        self.reloadButton.clicked.connect(self.reloaded)
        #self.updateButton.clicked.connect(self.reloaded)
        self.searchLineEdit.speak.connect(lambda: self.buildButtonList(self.searchLineEdit.text()))
        self.buttonListWidget.itemClicked.connect(self.listWidgetButtonClick)

        self.show()

    def listWidgetButtonClick(self, item):
        libstr = item.toolTip()
        classString = libstr.split('.')
        module = '.'.join(classString[:-1])
        key = classString[-1]
        func = self.libStructure.importAndExec(module, key)
        self.buttonClicked(func)

    def buildButtonList(self, text):
        if self.buttonListWidget.count() > 0 or text == '':
            self.buttonListWidget.clear()
            del self.buttonItemList[:]

        doc_text = []
        text_list = text.split('*')
        for libstr in self.libStructure.finalClassList:
            str_match = [True for match in text_list if match in libstr]

            if True in str_match:
                doc_text.append(libstr)
                tt = '\n'.join(doc_text)
                self.docLabel.setText(tt)
                classString = libstr.split('.')
                key = classString[-1]

                buttonQListWidgetItem = QtWidgets.QListWidgetItem(key)
                buttonQListWidgetItem.setToolTip(libstr)
                self.buttonItemList.append(buttonQListWidgetItem)
                self.buttonListWidget.addItem(self.buttonItemList[-1])

        if text == '':
            self.docLabel.setText('')
            if self.buttonListWidget.count() > 0:
                self.buttonListWidget.clear()

        self.buttonListWidget.adjustSize()

    def reloaded(self):
        self.updateWidget.emit()

    def addIconButton(self, name, imgPath):<commit_msg>Update lib<commit_after>__author__ = 'L<NAME>'

import os
import types
import importlib

#from mayaLib.utility.Qt import QtCore, QtWidgets, QtGui
from PySide2 import QtCore, QtWidgets, QtGui
from PySide2.QtCore import QObject, SIGNAL
from shiboken2 import wrapInstance
import maya.OpenMayaUI as omui
from maya import mel

import mayaLib
from mayaLib.pipelineLib.utility import listFunction as lm
from mayaLib.pipelineLib.utility import docs as doc
from mayaLib.pipelineLib.utility import libManager
from mayaLib.guiLib.base import baseUI as ui


class SearchLineEdit(QtWidgets.QLineEdit):

    #buttonClicked = QtCore.pyqtSignal(bool)
    speak = QtCore.Signal(str)

    def __init__(self, icon_file, parent=None):
        super(SearchLineEdit, self).__init__(parent)

        self.button = QtWidgets.QToolButton(self)
        self.button.setIcon(QtGui.QIcon(icon_file))
        self.button.setStyleSheet('border: 0px; padding: 0px;')
        self.button.setCursor(QtCore.Qt.ArrowCursor)
        self.button.clicked.connect(self.clear) #self.buttonClicked.emit

        layout = QtWidgets.QHBoxLayout(self)
        layout.addWidget(self.button,0,QtCore.Qt.AlignRight)
        layout.setSpacing(0)
        layout.setMargin(5)

        frameWidth = self.style().pixelMetric(QtWidgets.QStyle.PM_DefaultFrameWidth)
        buttonSize = self.button.sizeHint()

        self.setStyleSheet('QLineEdit {padding-right: %dpx; }' % (buttonSize.width() + frameWidth + 1))
        self.setMinimumSize(max(self.minimumSizeHint().width(), buttonSize.width() + frameWidth*2 + 3),
                            max(self.minimumSizeHint().height(), buttonSize.height() + frameWidth*2 + 3))

        self.textChanged.connect(self.replaceText)

    def replaceText(self):
        text = self.text()
        text_list = text.split(' ')
        newtext = '*'.join(text_list)

        if newtext != text:
            self.setText(newtext)

        self.speak.emit(newtext)


class MenuLibWidget(QtWidgets.QWidget):

    updateWidget = QtCore.Signal()

    def __init__(self, libPath, parent=None):
        super(MenuLibWidget, self).__init__(parent)

        self.libStructure = lm.StructureManager(mayaLib)
        self.libDict = self.libStructure.getStructLib()['mayaLib']

        # set layout
        self.layout = QtWidgets.QVBoxLayout()
        self.setLayout(self.layout)

        # add menu
        self.mainMenu = self.addMenuBar()
        self.layout.addWidget(self.mainMenu)

        # search bar
        self.searchLineEdit = SearchLineEdit(libPath + '/mayaLib/icons/close.png')
        self.layout.addWidget(self.searchLineEdit)

        # WidgetList
        self.buttonItemList = []
        self.buttonListWidget = QtWidgets.QListWidget()
        self.buttonListWidget.setStyleSheet('background: transparent;')
        self.buttonListWidget.setFocusPolicy(QtCore.Qt.NoFocus)
        self.buttonListWidget.adjustSize()
        #self.buttonListWidget.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        #self.buttonListWidget.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)
        #self.buttonListWidget.setSizeAdjustPolicy(QtWidgets.QListWidget.AdjustToContents)
        #self.buttonListWidget.setResizeMode(QtWidgets.QListView.Adjust)
        #self.buttonListWidget.setMinimumHeight(75)
        #self.buttonListWidget.setMaximumHeight(100)
        self.layout.addWidget(self.buttonListWidget)

        # Docs Label
        self.docLabel = QtWidgets.QLabel()
        self.docLabel.setStyleSheet("background-color: rgb(90,90,90); border-radius: 5px; border:1px solid rgb(255, 255, 255); ")
        self.layout.addWidget(self.docLabel)
        self.docLabel.setText('')

        # update Button
        self.updateButton = self.addIconButton('update', libPath + '/mayaLib/icons/update.png')
        self.reloadButton = self.addIconButton('reload', libPath + '/mayaLib/icons/reload.png')

        self.buttonLayout = QtWidgets.QHBoxLayout()
        self.buttonLayout.addWidget(self.reloadButton)
        self.buttonLayout.addWidget(self.updateButton)
        self.layout.addLayout(self.buttonLayout)

        # Connect
        self.reloadButton.clicked.connect(self.reloaded)
        self.updateButton.clicked.connect(self.download)
        self.searchLineEdit.speak.connect(lambda: self.buildButtonList(self.searchLineEdit.text()))
        self.buttonListWidget.itemClicked.connect(self.listWidgetButtonClick)

        self.show()

    def listWidgetButtonClick(self, item):
        libstr = item.toolTip()
        classString = libstr.split('.')
        module = '.'.join(classString[:-1])
        key = classString[-1]
        func = self.libStructure.importAndExec(module, key)
        self.buttonClicked(func)

    def buildButtonList(self, text):
        if self.buttonListWidget.count() > 0 or text == '':
            self.buttonListWidget.clear()
            del self.buttonItemList[:]

        doc_text = []
        text_list = text.split('*')
        for libstr in self.libStructure.finalClassList:
            str_match = [True for match in text_list if match in libstr]

            if True in str_match:
                doc_text.append(libstr)
                tt = '\n'.join(doc_text)
                self.docLabel.setText(tt)
                classString = libstr.split('.')
                key = classString[-1]

                buttonQListWidgetItem = QtWidgets.QListWidgetItem(key)
                buttonQListWidgetItem.setToolTip(libstr)
                self.buttonItemList.append(buttonQListWidgetItem)
                self.buttonListWidget.addItem(self.buttonItemList[-1])

        if text == '':
            self.docLabel.setText('')
            if self.buttonListWidget.count() > 0:
                self.buttonListWidget.clear()

        self.buttonListWidget.adjustSize()

    def reloaded(self):
        self.updateWidget.emit()

    def download(self):
        lib = libManager.InstallLibrary()
        lib.download()

        self.reloaded()

    def addIconButton(self, name, imgPath):
{'fraction_non_alphanumeric': 0.10795882500627668, 'fraction_numerical': 0.006862498953887354, 'mean_word_length': 2.8823911630929175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1522410', 'n_tokens_mistral': 3682, 'n_tokens_neox': 3538, 'n_words': 558}