Skip to content

Commit

Permalink
avoid to proceed without channel selection
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianrosenzweig committed Oct 30, 2024
1 parent 497cec2 commit 7639bc6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pytch/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def __init__(self, *args, **kwargs):
layout.addWidget(dir_btn, 7, 1, 1, 1)

# OK and Cancel button
buttons = qw.QDialogButtonBox(
self.buttons = qw.QDialogButtonBox(
qw.QDialogButtonBox.StandardButton.Ok
| qw.QDialogButtonBox.StandardButton.Cancel
)
buttons.accepted.connect(self.on_ok_clicked)
buttons.rejected.connect(self.close)
layout.addWidget(buttons)
self.buttons.accepted.connect(self.on_ok_clicked)
self.buttons.rejected.connect(self.close)
layout.addWidget(self.buttons)

# load default device
self.input_options.setCurrentIndex(0)
Expand All @@ -104,7 +104,7 @@ def update_channel_info(self, menu_index):

sampling_rate_options = get_fs_options(sounddevice_index)
self.channel_selector = ChannelSelector(
n_channels=nmax_channels, channels_enabled=[0]
n_channels=nmax_channels, channels_enabled=[0], menu_buttons=self.buttons
)

self.channel_options.setWidget(self.channel_selector)
Expand Down Expand Up @@ -142,11 +142,12 @@ def get_input_settings(self):
class ChannelSelector(qw.QWidget):
"""Widget for the channel buttons on the right side of the input menu"""

def __init__(self, n_channels, channels_enabled):
def __init__(self, n_channels, channels_enabled, menu_buttons):
super().__init__()
self.setLayout(qw.QVBoxLayout())

self.buttons = []
self.menu_buttons = menu_buttons
self.ch_buttons = []
self.press_order = []
for i in range(n_channels):
button = qw.QPushButton("Channel %i" % (i + 1))
Expand All @@ -157,7 +158,7 @@ def __init__(self, n_channels, channels_enabled):
button.clicked.connect(
lambda checked, index=i: self.track_button_press(index)
)
self.buttons.append(button)
self.ch_buttons.append(button)
self.layout().addWidget(button)

def get_selected_channels(self):
Expand All @@ -171,6 +172,10 @@ def track_button_press(self, index):
else:
self.press_order.append(index)

self.menu_buttons.button(qw.QDialogButtonBox.StandardButton.Ok).setEnabled(
len(self.press_order) > 0
)


class MainWindow(qw.QMainWindow):
"""Main window that includes the main widget for the menu and all visualizations."""
Expand Down

0 comments on commit 7639bc6

Please sign in to comment.