mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
replace _Callback with functools.partial
This commit is contained in:
parent
5d896b97de
commit
be1ae4a99c
1 changed files with 2 additions and 20 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import sys
|
||||
import json
|
||||
import traceback
|
||||
import functools
|
||||
|
||||
from Qt import QtWidgets, QtGui, QtCore
|
||||
|
||||
|
|
@ -12,22 +13,6 @@ from .lib import create_deffered_value_change_timer
|
|||
from .constants import DEFAULT_PROJECT_LABEL
|
||||
|
||||
|
||||
class _Callback:
|
||||
"""Callback wrapper which stores it's args and kwargs.
|
||||
|
||||
Using lambda has few issues if local variables are passed to called
|
||||
functions in loop it may change the value of the variable in already
|
||||
stored callback.
|
||||
"""
|
||||
def __init__(self, func, *args, **kwargs):
|
||||
self._func = func
|
||||
self._args = args
|
||||
self._kwargs = kwargs
|
||||
|
||||
def __call__(self):
|
||||
self._func(*self._args, **self._kwargs)
|
||||
|
||||
|
||||
class BaseWidget(QtWidgets.QWidget):
|
||||
allow_actions = True
|
||||
|
||||
|
|
@ -341,10 +326,7 @@ class BaseWidget(QtWidgets.QWidget):
|
|||
|
||||
action = QtWidgets.QAction(project_name)
|
||||
submenu.addAction(action)
|
||||
# Use custom callback object instead of lambda
|
||||
# - project_name value is changed each value so all actions will
|
||||
# use the same source project
|
||||
actions_mapping[action] = _Callback(
|
||||
actions_mapping[action] = functools.partial(
|
||||
self._apply_values_from_project,
|
||||
project_name
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue