Add support for hotkeys which trigger a sequence of functions

This commit is contained in:
Mika Fischer
2011-08-02 17:07:02 +02:00
parent e70e51ed7a
commit 249ac44fdf
2 changed files with 17 additions and 4 deletions
+5 -4
View File
@@ -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)
+12
View File
@@ -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