diff --git a/sloth/gui/labeltool.py b/sloth/gui/labeltool.py index 3906b5f..c4c0f6e 100755 --- a/sloth/gui/labeltool.py +++ b/sloth/gui/labeltool.py @@ -16,14 +16,12 @@ from sloth.conf import config from sloth.core.utils import import_callable from sloth.annotations.model import AnnotationTreeView, FrameModelItem, ImageFileModelItem from sloth import APP_NAME, ORGANIZATION_DOMAIN +from sloth.utils.bind import bind, compose_noargs GUIDIR=os.path.join(os.path.dirname(__file__)) LOG=logging.getLogger(__name__) -def bind(function, labeltool): - return lambda: function(labeltool) - class BackgroundLoader(QObject): finished = pyqtSignal() @@ -165,7 +163,10 @@ class MainWindow(QMainWindow): hk = QAction(desc, self) hk.setShortcut(QKeySequence(key)) hk.setEnabled(True) - hk.triggered.connect(bind(fun, self.labeltool)) + if hasattr(fun, '__call__'): + hk.triggered.connect(bind(fun, self.labeltool)) + else: + hk.triggered.connect(compose_noargs([bind(f, self.labeltool) for f in fun])) self.ui.menuShortcuts.addAction(hk) self.shortcuts.append(hk) diff --git a/sloth/utils/bind.py b/sloth/utils/bind.py index d2a2c2a..1d208ee 100644 --- a/sloth/utils/bind.py +++ b/sloth/utils/bind.py @@ -1,2 +1,14 @@ def bind(fun, *args): return lambda: fun(*args) + +def compose_noargs(funs): + def tmp(): + for f in funs: + f() + return tmp + +def compose(funs): + def tmp(*args, **kwargs): + for f in funs: + f(*args, **kwargs) + return tmp