<commit_before>##########################################################################
#
#  Copyright (c) 2011-2012, <NAME>. All rights reserved.
#  Copyright (c) 2011-2013, Image Engine Design Inc. All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions are
#  met:
#
#      * Redistributions of source code must retain the above
#        copyright notice, this list of conditions and the following
#        disclaimer.
#
#      * Redistributions in binary form must reproduce the above
#        copyright notice, this list of conditions and the following
#        disclaimer in the documentation and/or other materials provided with
#        the distribution.
#
#      * Neither the name of <NAME> nor the names of
#        any other contributors to this software may be used to endorse or
#        promote products derived from this software without specific prior
#        written permission.
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
#  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
#  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
#  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
#  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
#  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
#  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
#  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################

import inspect
import functools
import weakref
import types
import re

import IECore

import Gaffer
import GafferUI

QtCore = GafferUI._qtImport( "QtCore" )
QtGui = GafferUI._qtImport( "QtGui" )

class Menu( GafferUI.Widget ) :

	def __init__( self, definition, _qtParent=None, searchable=False, title=None, **kw ) :

		GafferUI.Widget.__init__( self, _Menu( _qtParent ), **kw )

		self.__searchable = searchable

		self.__title = title
		# this property is used by the stylesheet
		self._qtWidget().setProperty( "gafferHasTitle", GafferUI._Variant.toVariant( title is not None ) )

		self._qtWidget().__definition = definition
		self._qtWidget().aboutToShow.connect( Gaffer.WeakMethod( self.__show ) )

		if searchable :
			self._qtWidget().aboutToHide.connect( Gaffer.WeakMethod( self.__hide ) )
			self.__lastAction = None

		self._setStyleSheet()

		self.__popupParent = None
		self.__popupPosition = None

	## Displays the menu at the specified position, and attached to
	# an optional parent. If position is not specified then it
	# defaults to the current cursor position. If forcePosition is specified
	# then the menu will be shown exactly at the requested position, even if
	# doing so means some of it will be off screen. If grabFocus is False, then
	# the menu will not take keyboard events unless the first such event is a
	# press of the up or down arrows.
	def popup( self, parent=None, position=None, forcePosition=False, grabFocus=True ) :

		if parent is not None :
			self.__popupParent = weakref.ref( parent )
		else :
			self.__popupParent = None

		if position is None :
			position = GafferUI.Widget.mousePosition()

		self.__popupPosition = position

		position = QtCore.QPoint( position.x, position.y )

		self._qtWidget().keyboardMode = _Menu.KeyboardMode.Grab if grabFocus else _Menu.KeyboardMode.Close

		self._qtWidget().popup( position )

		# qt is helpful and tries to keep you menu on screen, but this isn't always
		# what you want, so we override the helpfulness if requested.
		if forcePosition :
			self._qtWidget().move( position )

	## Reimplemented from Widget to report the parent passed to popup().
	def parent( self ) :

		if self.__popupParent is not None :
			p = self.__popupParent()
			if p is not None :
				return p

		return GafferUI.Widget.parent( self )

	## Returns the position for the last popup request, before it
	# was adjusted to keep the menu on screen.
	def popupPosition( self, relativeTo = None ) :

		result = self.__popupPosition
		if result is None :
			return result

		if relativeTo is not None :
			result = result - relativeTo.bound().min

		return result

	def searchable( self ) :

		return self.__searchable

	def __argNames( self, function ) :

		if isinstance( function, types.FunctionType ) :
			return inspect.getargspec( function )[0]
		elif isinstance( function, Gaffer.WeakMethod ) :
			return inspect.getargspec( function.method() )[0][1:]
		elif isinstance( function, functools.partial ) :
			return self.__argNames( function.func )[0]

		return []

	def __actionTriggered( self, qtActionWeakRef, toggled ) :

		qtAction = qtActionWeakRef()
		item = qtAction.__item

		if not self.__evaluateItemValue( item.active ) :
			return
<commit_msg>Menu : Fixed support for functools.partial( classMethod ) commands.<commit_after>##########################################################################
#
#  Copyright (c) 2011-2012, <NAME>. All rights reserved.
#  Copyright (c) 2011-2013, Image Engine Design Inc. All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions are
#  met:
#
#      * Redistributions of source code must retain the above
#        copyright notice, this list of conditions and the following
#        disclaimer.
#
#      * Redistributions in binary form must reproduce the above
#        copyright notice, this list of conditions and the following
#        disclaimer in the documentation and/or other materials provided with
#        the distribution.
#
#      * Neither the name of <NAME> nor the names of
#        any other contributors to this software may be used to endorse or
#        promote products derived from this software without specific prior
#        written permission.
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
#  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
#  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
#  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
#  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
#  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
#  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
#  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################

import inspect
import functools
import weakref
import types
import re

import IECore

import Gaffer
import GafferUI

QtCore = GafferUI._qtImport( "QtCore" )
QtGui = GafferUI._qtImport( "QtGui" )

class Menu( GafferUI.Widget ) :

	def __init__( self, definition, _qtParent=None, searchable=False, title=None, **kw ) :

		GafferUI.Widget.__init__( self, _Menu( _qtParent ), **kw )

		self.__searchable = searchable

		self.__title = title
		# this property is used by the stylesheet
		self._qtWidget().setProperty( "gafferHasTitle", GafferUI._Variant.toVariant( title is not None ) )

		self._qtWidget().__definition = definition
		self._qtWidget().aboutToShow.connect( Gaffer.WeakMethod( self.__show ) )

		if searchable :
			self._qtWidget().aboutToHide.connect( Gaffer.WeakMethod( self.__hide ) )
			self.__lastAction = None

		self._setStyleSheet()

		self.__popupParent = None
		self.__popupPosition = None

	## Displays the menu at the specified position, and attached to
	# an optional parent. If position is not specified then it
	# defaults to the current cursor position. If forcePosition is specified
	# then the menu will be shown exactly at the requested position, even if
	# doing so means some of it will be off screen. If grabFocus is False, then
	# the menu will not take keyboard events unless the first such event is a
	# press of the up or down arrows.
	def popup( self, parent=None, position=None, forcePosition=False, grabFocus=True ) :

		if parent is not None :
			self.__popupParent = weakref.ref( parent )
		else :
			self.__popupParent = None

		if position is None :
			position = GafferUI.Widget.mousePosition()

		self.__popupPosition = position

		position = QtCore.QPoint( position.x, position.y )

		self._qtWidget().keyboardMode = _Menu.KeyboardMode.Grab if grabFocus else _Menu.KeyboardMode.Close

		self._qtWidget().popup( position )

		# qt is helpful and tries to keep you menu on screen, but this isn't always
		# what you want, so we override the helpfulness if requested.
		if forcePosition :
			self._qtWidget().move( position )

	## Reimplemented from Widget to report the parent passed to popup().
	def parent( self ) :

		if self.__popupParent is not None :
			p = self.__popupParent()
			if p is not None :
				return p

		return GafferUI.Widget.parent( self )

	## Returns the position for the last popup request, before it
	# was adjusted to keep the menu on screen.
	def popupPosition( self, relativeTo = None ) :

		result = self.__popupPosition
		if result is None :
			return result

		if relativeTo is not None :
			result = result - relativeTo.bound().min

		return result

	def searchable( self ) :

		return self.__searchable

	def __argNames( self, function ) :

		if isinstance( function, types.FunctionType ) :
			return inspect.getargspec( function )[0]
		elif isinstance( function, types.MethodType ) :
			return inspect.getargspec( function )[0][1:]
		elif isinstance( function, Gaffer.WeakMethod ) :
			return inspect.getargspec( function.method() )[0][1:]
		elif isinstance( function, functools.partial ) :
			return self.__argNames( function.func )

		return []

	def __actionTriggered( self, qtActionWeakRef, toggled ) :

		qtAction = qtActionWeakRef()
		item = qtAction.__item

		if not self.__evaluateItemValue( item.active ) :
			return

{'fraction_non_alphanumeric': 0.1005705444347742, 'fraction_numerical': 0.0039648003094478294, 'mean_word_length': 3.938872970391595, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3272078', 'n_tokens_mistral': 3114, 'n_tokens_neox': 2790, 'n_words': 1155}