groakat / AudioTagger

5 stars 2 forks source link

Keyboard shortcut for selecting labelTypes #12

Closed ali-fairbrass closed 10 years ago

ali-fairbrass commented 10 years ago

I would like to be able make keyboard shortcuts using number keys to select different label types i.e. 1 = bat, 2 = bird, 3 = plane.

I have tried the following code to make a shortcut to select the lableType bat using the 1 key:

QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_1), self, self.labelTypes.index(0))

AND

QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_1), self, self.labelTypes == 0)

But receive the following error message:

AttributeError: 'TestClass' object has no attribute 'labelTypes'

groakat commented 10 years ago

I would do it by making several functions:

def selectLabel0(self):
    self.ui.cb_labelType.setCurrentIndex(0)

def selectLabel1(self):
    self.ui.cb_labelType.setCurrentIndex(1)

def selectLabel2(self):
    self.ui.cb_labelType.setCurrentIndex(2)

Then do:

QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_1),  self, self.selectLabel0)
QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_2),  self, self.selectLabel1)
QtGui.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_3),  self, self.selectLabel2)

The index of the cb_labelType will then be used here:

https://github.com/groakat/AudioTagger/blob/master/audioTagger.py#L262