def make_calc_radio_button(self, *args, calc_function, calc_target, shortcut, **kwargs): ret = QRadioButton(*args, **kwargs) ret.setFocusPolicy(Qt.ClickFocus) @ret.toggled.connect def on_toggle(b): if b: self.calc_function = calc_function self.calc_target = calc_target self.target_changed() @ret.clicked.connect def on_click(c): ret.setFocusPolicy(Qt.ClickFocus) if shortcut: ret.setShortcut(shortcut) return ret
class Prescreen(QWidget): REASONS = ('Inattentive', 'Child Talking', 'Parent Talking', 'Parent Interference', 'Child Not Looking Before Sound', 'Equipment Malfunction', 'Experiment Ended Early', 'Other') def __init__(self, callback): super().__init__() self.callback = callback trial_label = QLabel('Trial:') self.trial_box = QSpinBox() self.trial_box.setFixedWidth(64) self.trial_box.setValue(1) # self.trial_box.setFocusPolicy(Qt.NoFocus) reason_label = QLabel('Reason:') self.reason_box = QComboBox() self.reason_box.addItems(self.REASONS) self.reason_box.setFocusPolicy(Qt.NoFocus) self.code_radio = QRadioButton('Code') self.nocode_radio = QRadioButton('Do Not Code') self.code_radio.setChecked(True) self.code_radio.setFocusPolicy(Qt.NoFocus) self.nocode_radio.setFocusPolicy(Qt.NoFocus) radio_layout = QVBoxLayout() radio_layout.addStretch() radio_layout.addWidget(self.code_radio) radio_layout.addWidget(self.nocode_radio) radio_layout.addStretch() self.group_code = QButtonGroup() self.group_code.addButton(self.code_radio) self.group_code.addButton(self.nocode_radio) self.record_button = QPushButton('Record Reason') self.record_button.clicked.connect(self.record_reason) self.record_button.setEnabled(False) self.record_button.setFocusPolicy(Qt.NoFocus) self.both_checkbox = QCheckBox('Display both coders') self.both_checkbox.setFocusPolicy(Qt.NoFocus) self.radio_primary = QRadioButton('Primary') self.radio_secondary = QRadioButton('Secondary') self.radio_primary.setChecked(True) self.radio_primary.setFocusPolicy(Qt.NoFocus) self.radio_secondary.setFocusPolicy(Qt.NoFocus) who_layout = QVBoxLayout() who_layout.addWidget(self.both_checkbox) who_layout.addWidget(self.radio_primary) who_layout.addWidget(self.radio_secondary) self.group_who = QButtonGroup() self.group_who.addButton(self.radio_primary, id=1) self.group_who.addButton(self.radio_secondary, id=2) layout = QHBoxLayout() layout.addWidget(trial_label) layout.addWidget(self.trial_box) layout.addWidget(reason_label) layout.addWidget(self.reason_box) layout.addLayout(radio_layout) layout.addWidget(self.record_button) layout.addStretch() layout.addLayout(who_layout) self.setLayout(layout) def record_reason(self): reason = Reason(trial=self.trial_box.value(), include=self.code_radio.isChecked(), reason=self.reason_box.currentText()) self.callback(reason) def prescreener(self): if self.both_checkbox.isChecked(): return 0 else: return self.group_who.checkedId()