def createWidget(self, parent=None): hbox = QHBoxLayout(); self.waitYesNoCheckbox = QCheckBox('Await speech done'); hbox.addWidget(self.waitYesNoCheckbox); hbox.addWidget(QLabel('Text')); self.speechTextField = QPlainTextEdit(); self.speechTextField.setMaximumWidth(SpeechActionEditor.SPEECH_EDIT_FLD_WIDTH); hbox.addWidget(self.speechTextField); self.setLayout(hbox); self.setMaximumHeight(SpeechActionEditor.SPEECH_EDIT_FLD_HEIGHT + 10); self.setMaximumWidth(SpeechActionEditor.SPEECH_EDIT_FLD_WIDTH + self.waitYesNoCheckbox.width()); return self
def generateLetterCheckBoxes(self): self.lettersToCheckBoxes = {}; self.checkBoxesToLetters = {}; letters = sorted(codeKey.values()); numRows = (len(letters) % self.LETTER_CHECKBOX_NUM_COLS) + 1; col = 0; row = 0; letterIndex = 0; while(True): letter = letters[letterIndex]; checkbox = QCheckBox(); self.lettersToCheckBoxes[letter] = checkbox; self.checkBoxesToLetters[checkbox] = letter; checkbox.setText(str(letter)); checkbox.toggled.connect(partial(self.letterCheckAction, checkbox)); self.letterCheckboxGridLayout.addWidget(checkbox, row, col); col += 1; if (col >= self.LETTER_CHECKBOX_NUM_COLS): col = 0; row += 1; letterIndex += 1; if letterIndex >= len(letters): break;
def _createAutoRange(self): autoRange = QCheckBox(self) autoRange.stateChanged.connect(self._onAutoRangeChange) self.autoRange = autoRange return autoRange
class SpeechActionEditor(QWidget): SPEECH_EDIT_FLD_WIDTH = 400 SPEECH_EDIT_FLD_HEIGHT = 300 def __init__(self, parent=None): super(SpeechActionEditor, self).__init__(parent); #ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'src', 'speech_data_widget.ui') #editWidget = loadUi(ui_file, parent) # Must save the QFrame that holds the checkbox and text box, # so that the underlying C objects aren't GCed: self.editWidget = self.createWidget(parent); def createWidget(self, parent=None): hbox = QHBoxLayout(); self.waitYesNoCheckbox = QCheckBox('Await speech done'); hbox.addWidget(self.waitYesNoCheckbox); hbox.addWidget(QLabel('Text')); self.speechTextField = QPlainTextEdit(); self.speechTextField.setMaximumWidth(SpeechActionEditor.SPEECH_EDIT_FLD_WIDTH); hbox.addWidget(self.speechTextField); self.setLayout(hbox); self.setMaximumHeight(SpeechActionEditor.SPEECH_EDIT_FLD_HEIGHT + 10); self.setMaximumWidth(SpeechActionEditor.SPEECH_EDIT_FLD_WIDTH + self.waitYesNoCheckbox.width()); return self def setValue(self, blockBoolAndTextTuple): waitForSpeechDone, text = blockBoolAndTextTuple if waitForSpeechDone: self.waitYesNoCheckbox.setCheckState(Qt.Checked) else: self.waitYesNoCheckbox.setCheckState(Qt.Unchecked) self.speechTextField.setPlainText(text); def value(self): ''' Returns a tuple containing whether motions are to be suspended till speech is done, and the text to be spoken. @return: block instruction and text to speak @rtype: (boolean, string) ''' text = self.speechTextField.toPlainText(); waitForSpeechDone = self.waitYesNoCheckbox.checkState() == Qt.Checked; return (waitForSpeechDone, text); def sizeHint (self): ''' @param option: any style options @type option: QStyleOptionViewItem @param index: index into model @type index: QModelIndex ''' # Need to allow room for the checkbox, checkbox label, # and a text field: (waitForSpeechDone, utterance) = self.value() #width = self.waitYesNoCheckbox.width + self.speechTextField.width width = self.maximumWidth() #height = self.waitYesNoCheckbox.height + self.speechTextField.height height = self.maximumHeight() return QSize(width, height)