mirror of
https://github.com/wassname/sloth.git
synced 2026-09-09 11:35:32 +08:00
Add support for hotkeys which trigger a sequence of functions
This commit is contained in:
@@ -16,14 +16,12 @@ from sloth.conf import config
|
|||||||
from sloth.core.utils import import_callable
|
from sloth.core.utils import import_callable
|
||||||
from sloth.annotations.model import AnnotationTreeView, FrameModelItem, ImageFileModelItem
|
from sloth.annotations.model import AnnotationTreeView, FrameModelItem, ImageFileModelItem
|
||||||
from sloth import APP_NAME, ORGANIZATION_DOMAIN
|
from sloth import APP_NAME, ORGANIZATION_DOMAIN
|
||||||
|
from sloth.utils.bind import bind, compose_noargs
|
||||||
|
|
||||||
GUIDIR=os.path.join(os.path.dirname(__file__))
|
GUIDIR=os.path.join(os.path.dirname(__file__))
|
||||||
|
|
||||||
LOG=logging.getLogger(__name__)
|
LOG=logging.getLogger(__name__)
|
||||||
|
|
||||||
def bind(function, labeltool):
|
|
||||||
return lambda: function(labeltool)
|
|
||||||
|
|
||||||
class BackgroundLoader(QObject):
|
class BackgroundLoader(QObject):
|
||||||
finished = pyqtSignal()
|
finished = pyqtSignal()
|
||||||
|
|
||||||
@@ -165,7 +163,10 @@ class MainWindow(QMainWindow):
|
|||||||
hk = QAction(desc, self)
|
hk = QAction(desc, self)
|
||||||
hk.setShortcut(QKeySequence(key))
|
hk.setShortcut(QKeySequence(key))
|
||||||
hk.setEnabled(True)
|
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.ui.menuShortcuts.addAction(hk)
|
||||||
self.shortcuts.append(hk)
|
self.shortcuts.append(hk)
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,14 @@
|
|||||||
def bind(fun, *args):
|
def bind(fun, *args):
|
||||||
return lambda: 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
|
||||||
|
|||||||
Reference in New Issue
Block a user